+++ /dev/null
-#ifndef __DALI_INTERNAL_BITMAP_UPLOAD_H__
-#define __DALI_INTERNAL_BITMAP_UPLOAD_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/public-api/common/vector-wrapper.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-/**
- * Holds a bitmap and a x,y pixel position of where the bitmap
- * should be uploaded to in a texture.
- *
- */
-struct BitmapUpload
-{
-
- enum DiscardMode
- {
- DISCARD_PIXEL_DATA, ///< Delete the pixel data after upload
- DONT_DISCARD_PIXEL_DATA ///< Don't delete the pixel data after upload
- };
-
- typedef unsigned char PixelData; ///< pixel data type
-
- /**
- * Constructor
- * @param data pixel data
- * @param xPos x position of where to place the bitmap in a texture
- * @param yPos y position of where to place the bitmap in a texture
- * @param width bitmap width in pixels
- * @param height bitmap height in pixels
- * @param discardMode whether to delete the pixel data after the upload or not
- */
- BitmapUpload(PixelData* data,
- unsigned int xPos,
- unsigned int yPos,
- unsigned int width,
- unsigned int height,
- DiscardMode discardMode = DISCARD_PIXEL_DATA)
- :mPixelData(data),
- mXpos(xPos),
- mYpos(yPos),
- mWidth(width),
- mHeight(height),
- mDiscard(discardMode)
- {
- }
-
-
- PixelData* mPixelData; ///< bitmap data to upload
- unsigned int mXpos; ///< x position to place the bitmap in the texture
- unsigned int mYpos; ///< y position to place the bitmap in the texture
- unsigned int mWidth; ///< width of the bitmap to upload
- unsigned int mHeight; ///< height of the bitmap to upload
- DiscardMode mDiscard; ///< whether the pixel data should be discarded after the upload
-};
-
-typedef std::vector<BitmapUpload> BitmapUploadArray; ///< typedef for a array of uploads
-
-
-/**
- * Structure is used for clearing areas of the bitmap
- */
-typedef std::vector<Vector2> BitmapClearArray;
-
-} //namespace Internal
-
-} //namespace Dali
-
-#endif
return newTicket;
}
-void ResourceClient::UpdateTexture( ResourceId id,
- BitmapUploadArray uploadArray )
-{
- RequestUpdateTextureMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, id, uploadArray );
-}
-
ResourceTicketPtr ResourceClient::AllocateMesh( OwnerPointer<MeshData>& meshData )
{
ResourceTicketPtr newTicket;
#include <dali/internal/event/resources/resource-client-declarations.h>
#include <dali/internal/event/resources/image-ticket.h>
#include <dali/internal/event/resources/resource-ticket-lifetime-observer.h>
-#include <dali/internal/common/bitmap-upload.h>
#include <dali/internal/common/message.h>
#include <dali/internal/update/modeling/internal-mesh-data.h>
Pixel::Format pixelformat );
/**
- * Update a texture with an array of bitmaps.
- * @param[in] id texture resource id
- * @param[in] uploadArray the upload array
- */
- void UpdateTexture( ResourceId id,
- BitmapUploadArray uploadArray );
-
- /**
* Requests allocation of a mesh resource
* @param[in] meshData representing the mesh; ownership is taken.
*/
#include <dali/public-api/images/pixel.h>
#include <dali/internal/common/message.h>
#include <dali/internal/update/common/scene-graph-buffers.h>
-#include <dali/internal/common/bitmap-upload.h>
#include <dali/integration-api/resource-declarations.h>
#include <dali/integration-api/bitmap.h>
*/
virtual void DispatchUpdateTextureArea( ResourceId id, const RectArea& area ) = 0;
- /**
- * Dispatch a message to insert an array of bitmaps into the texture.
- * Used for uploading multiple images into an atlas.
- * @param[in] id Resource id of the texture
- * @param[in] uploadArray array of BitmapUpload structures
- */
- virtual void DispatchUploadBitmapArrayToTexture( ResourceId id, const BitmapUploadArray& uploadArray ) = 0;
-
- /**
- * Dispatch a message to clear multiple areas of a texture to a specific color
- * @param[in] id Resource id of the texture to clear
- * @param[in] area Rectangles to clear
- * @param[in] blockSize Size of block to clear
- * @param[in] color Clear color (as a pixel value)
- */
- virtual void DispatchClearAreas( ResourceId id, const BitmapClearArray& area, std::size_t blockSize, uint32_t color ) = 0;
-
/**
* Dispatch a message to discard a texture
* May be called from Update thread
// on the render thread. (And avoiding a potentially problematic virtual call in the destructor)
}
-void BitmapTexture::UploadBitmapArray( const BitmapUploadArray& bitmapArray )
-{
- DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
-
- if( mId == 0 )
- {
- CreateGlTexture();
- }
-
- mContext.ActiveTexture( TEXTURE_UNIT_UPLOAD );
- mContext.Bind2dTexture(mId);
- mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
-
- GLenum pixelFormat = GL_RGBA;
- GLenum pixelDataType = GL_UNSIGNED_BYTE;
-
- Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
-
- // go through each bitmap uploading it
-
- for( BitmapUploadArray::const_iterator iter = bitmapArray.begin(), endIter = bitmapArray.end(); iter != endIter ; ++iter)
- {
- const BitmapUpload& bitmapItem((*iter));
-
- DALI_ASSERT_ALWAYS(bitmapItem.mPixelData);
-
- const unsigned char* pixels = bitmapItem.mPixelData;
-
- DALI_ASSERT_DEBUG( (pixels!=NULL) && "bitmap has no data \n");
-
- unsigned int bitmapWidth(bitmapItem.mWidth);
- unsigned int bitmapHeight(bitmapItem.mHeight);
-
- DALI_LOG_INFO(Debug::Filter::gImage, Debug::General, "upload bitmap to texture :%d y:%d w:%d h:%d\n",
- bitmapItem.mXpos,
- bitmapItem.mYpos,
- bitmapWidth,
- bitmapHeight);
-
- mContext.TexSubImage2D(GL_TEXTURE_2D,
- 0, /* mip map level */
- bitmapItem.mXpos, /* X pos */
- bitmapItem.mYpos, /* Y pos */
- bitmapWidth, /* width */
- bitmapHeight, /* height */
- pixelFormat, /* our bitmap format (should match internal format) */
- pixelDataType, /* pixel data type */
- pixels); /* texture data */
-
- if( BitmapUpload::DISCARD_PIXEL_DATA == bitmapItem.mDiscard)
- {
- delete [] bitmapItem.mPixelData;
- }
- }
-}
-
bool BitmapTexture::HasAlphaChannel() const
{
return Pixel::HasAlpha(mPixelFormat);
}
}
-void BitmapTexture::ClearAreas( const BitmapClearArray& areaArray, std::size_t blockSize, uint32_t color )
-{
- if(mId > 0)
- {
- DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
- DALI_LOG_INFO(Debug::Filter::gGLResource, Debug::Verbose, "BitmapTexture::AreaUpdated()\n");
-
- GLenum pixelFormat = GL_RGBA;
- GLenum pixelDataType = GL_UNSIGNED_BYTE;
- Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
-
- mContext.ActiveTexture( TEXTURE_UNIT_UPLOAD );
- mContext.Bind2dTexture(mId);
-
- size_t numPixels = blockSize*blockSize;
- size_t bytesPerPixel = Pixel::GetBytesPerPixel(mPixelFormat);
- char* clearPixels = (char*)malloc(numPixels * bytesPerPixel);
-
- for(size_t i=0; i<numPixels; i++)
- {
- memcpy(&clearPixels[i*bytesPerPixel], &color, bytesPerPixel);
- }
-
- for( BitmapClearArray::const_iterator iter = areaArray.begin(), endIter = areaArray.end(); iter != endIter ; ++iter)
- {
- const Vector2& clearPos((*iter));
-
- mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
- DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "Update x:%0.2f y:%0.2f w:%d h:%d\n",
- clearPos.x, clearPos.y, blockSize, blockSize );
-
- mContext.TexSubImage2D(GL_TEXTURE_2D,
- 0,
- clearPos.x,
- clearPos.y,
- blockSize,
- blockSize,
- pixelFormat, /* our bitmap format (should match internal format) */
- pixelDataType, /* pixel data type */
- clearPixels); /* texture data */
-
- INCREASE_BY( PerformanceMonitor::TEXTURE_DATA_UPLOADED, numPixels * bytesPerPixel );
- }
- free(clearPixels);
- }
-}
-
bool BitmapTexture::UpdateOnCreate()
{
return true;
// INTERNAL INCLUDES
#include <dali/internal/common/message.h>
#include <dali/internal/render/gl-resources/texture.h>
-#include <dali/internal/common/bitmap-upload.h>
#include <dali/integration-api/bitmap.h>
#include <dali/integration-api/debug.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
*/
virtual ~BitmapTexture();
-public: // Message interface
-
- /**
- * Upload an array of bitmaps
- * @param bitmapArray array of bitmap items
- */
- void UploadBitmapArray( const BitmapUploadArray& bitmapArray);
-
- /**
- * Clear an array of areas from bitmap to the given color
- * @param[in] areaArray Array of rects to clear
- * @param[in] blockSize Size of block to clear
- * @param[in] color Clear color
- */
- void ClearAreas( const BitmapClearArray& areaArray, std::size_t blockSize, uint32_t color );
-
public:
/**
* @copydoc Texture::Init
DALI_LOG_OBJECT_STRING_DECLARATION;
};
-//
-// Upload bitmap array message
-//
-inline MessageBase* UploadBitmapArrayMessage( BitmapTexture& texture, const BitmapUploadArray& bitmapArray )
-{
- return new MessageValue1< BitmapTexture, BitmapUploadArray >( &texture, &BitmapTexture::UploadBitmapArray, bitmapArray );
-}
-
} //namespace Internal
} //namespace Dali
#include <dali/internal/common/message.h>
#include <dali/internal/render/gl-resources/texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
-#include <dali/internal/common/bitmap-upload.h>
#include <dali/integration-api/bitmap.h>
#include <dali/internal/event/images/bitmap-compressed.h>
#include <dali/integration-api/debug.h>
}
}
-void TextureCache::AddBitmapUploadArray( ResourceId id, const BitmapUploadArray& uploadArray )
-{
- DALI_LOG_INFO(Debug::Filter::gGLResource, Debug::General, "TextureCache::AddBitmapUploadArray(id=%i )\n", id);
-
- TextureIter textureIter = mTextures.find(id);
-
- DALI_ASSERT_DEBUG( textureIter != mTextures.end() );
- if( textureIter != mTextures.end() )
- {
- TexturePointer texturePtr = textureIter->second;
- if( texturePtr )
- {
- BitmapTexture* texture = static_cast< BitmapTexture* >( texturePtr.Get() );
- texture->UploadBitmapArray( uploadArray );
- }
- }
-}
-
-void TextureCache::ClearAreas( ResourceId id,
- const BitmapClearArray& areaArray,
- std::size_t blockSize,
- uint32_t color )
-{
- DALI_LOG_INFO(Debug::Filter::gGLResource, Debug::General, "TextureCache::ClearAreas(id: %d)\n", id);
- TextureIter textureIter = mTextures.find(id);
- DALI_ASSERT_DEBUG( textureIter != mTextures.end() );
- if( textureIter != mTextures.end() )
- {
- TexturePointer texturePtr = textureIter->second;
- if( texturePtr )
- {
- BitmapTexture* texture = static_cast< BitmapTexture* >( texturePtr.Get() );
- texture->ClearAreas( areaArray, blockSize, color );
- }
- }
-}
-
void TextureCache::DiscardTexture( ResourceId id )
{
bool deleted = false;
}
}
-void TextureCache::DispatchUploadBitmapArrayToTexture( ResourceId id, const BitmapUploadArray& uploadArray )
-{
- // NULL, means being shutdown, so ignore msgs
- if( mSceneGraphBuffers != NULL )
- {
- typedef MessageValue2< TextureCache, ResourceId, BitmapUploadArray > DerivedType;
-
- // Reserve some memory inside the render queue
- unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
-
- // Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( this, &TextureCache::AddBitmapUploadArray, id, uploadArray );
- }
-}
-
-void TextureCache::DispatchClearAreas( ResourceId id, const BitmapClearArray& areaArray, std::size_t blockSize, uint32_t color )
-{
- // NULL, means being shutdown, so ignore msgs
- if( mSceneGraphBuffers != NULL )
- {
- typedef MessageValue4< TextureCache, ResourceId, BitmapClearArray, std::size_t, uint32_t > DerivedType;
-
- // Reserve some memory inside the render queue
- unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
-
- // Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( this, &TextureCache::ClearAreas, id, areaArray, blockSize, color );
- }
-}
-
void TextureCache::DispatchDiscardTexture( ResourceId id )
{
// NULL, means being shutdown, so ignore msgs
*/
void UpdateTexture( ResourceId id, Integration::BitmapPtr bitmap );
- /**
- * Add an array of bitmaps to an existing texture used as an Atlas
- * @param[in] id Resource id of the texture
- * @param[in] uploadArray array of upload bitmap structures
- */
- void AddBitmapUploadArray( ResourceId id, const BitmapUploadArray& uploadArray );
-
/**
* Update the area of the texture from the associated bitmap
* @param[in] id Resource Id of the bitmap
void UpdateTextureArea( ResourceId id, const RectArea& area );
/**
- * Clear multiple areas of the texture
- * @param[in] id Resource id of the texture
- * @param[in] area Areas of the texture to clear
- * @param[in] blockSize Size of block to clear
- * @param[in] color Color to clear
- */
- void ClearAreas( ResourceId id,
- const BitmapClearArray& area,
- std::size_t blockSize,
- uint32_t color );
-
- /**
* Discard texture associated with resource ID
* @param[in] id Resource Id of the texture
*/
virtual void DispatchUpdateTextureArea( ResourceId id, const RectArea& area );
/**
- * @copydoc TextureCacheDispatcher::DispatchUploadBitmapArrayToTexture()
- */
- virtual void DispatchUploadBitmapArrayToTexture( ResourceId id, const BitmapUploadArray& uploadArray );
-
- /**
- * @copydoc TextureCacheDispatcher::DispatchClearAreas()
- */
- virtual void DispatchClearAreas( ResourceId id, const BitmapClearArray& area, std::size_t blockSize, uint32_t color );
-
- /**
* @copydoc TextureCacheDispatcher::DispatchDiscardTexture()
*/
virtual void DispatchDiscardTexture( ResourceId id );
mImpl->mTextureCacheDispatcher.DispatchCreateTexture( id, width, height, pixelFormat, true /* true = clear the texture */ );
}
-void ResourceManager::HandleUpdateTextureRequest( ResourceId id, const BitmapUploadArray& uploadArray )
-{
- mImpl->mTextureCacheDispatcher.DispatchUploadBitmapArrayToTexture( id, uploadArray );
-}
-
void ResourceManager::HandleAllocateMeshRequest( ResourceId id, MeshData* meshData )
{
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceManager: HandleAllocateMeshRequest(id:%u)\n", id);
#include <dali/internal/common/event-to-update.h>
#include <dali/internal/common/message.h>
#include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/common/bitmap-upload.h>
#include <dali/internal/event/modeling/model-data-impl.h>
#include <dali/internal/event/resources/resource-client-declarations.h>
#include <dali/internal/event/effects/shader-factory.h>
void HandleAllocateTextureRequest( ResourceId id, unsigned int width, unsigned int height, Pixel::Format pixelFormat );
/**
- * Upload an array of bitmaps to a texture.
- * @param[in] id The resource id
- * @param[in] uploadArray bitmap upload array.
- */
- void HandleUpdateTextureRequest( ResourceId id, const BitmapUploadArray& uploadArray );
-
- /**
* Requests allocation of a mesh resource
* @param[in] id The resource id
* @param[in] meshData The mesh data
new (slot) LocalType( &manager, &ResourceManager::HandleAllocateTextureRequest, id, width, height, pixelFormat );
}
-inline void RequestUpdateTextureMessage(EventToUpdate& eventToUpdate,
- ResourceManager& manager,
- ResourceId id,
- BitmapUploadArray uploadArray )
-{
- typedef MessageValue2< ResourceManager, ResourceId, BitmapUploadArray > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &manager, &ResourceManager::HandleUpdateTextureRequest, id, uploadArray );
-}
-
inline void RequestAllocateMeshMessage( EventToUpdate& eventToUpdate,
ResourceManager& manager,
ResourceId id,