1 #ifndef __DALI_INTERNAL_BITMAP_TEXTURE_H__
2 #define __DALI_INTERNAL_BITMAP_TEXTURE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 #include <stdint.h> // for uint32_t
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/render/gl-resources/texture.h>
26 #include <dali/internal/common/bitmap-upload.h>
27 #include <dali/integration-api/bitmap.h>
28 #include <dali/integration-api/debug.h>
37 typedef IntrusivePtr<BitmapTexture> BitmapTexturePointer;
42 * If you want to load a file to a BitmapTexture use
43 * TextureManager::GetTexture()
46 class BitmapTexture : public Texture
51 * Creates a new texture object from a Bitmap
52 * @param[in] bitmap The Bitmap
53 * @param[in] bitmapPackedPixelsProfile The Bitmap features related to an addressable array of raw pixel data
54 * @param context The GL context
56 BitmapTexture(Integration::Bitmap* const bitmap, const Integration::Bitmap::PackedPixelsProfile * const bitmapPackedPixelsProfile, Context& context);
60 * Creates a new texture object
61 * @param[in] width width in pixels
62 * @param[in] height height in pixels
63 * @param[in] pixelFormat pixel format
64 * @param[in] clearPixels True if the pixel data should be cleared before gl texture creation
65 * @param[in] context Dali context
67 BitmapTexture( unsigned int width, unsigned int height, Pixel::Format pixelFormat,
68 bool clearPixels, Context& context );
73 virtual ~BitmapTexture();
75 public: // Message interface
78 * Upload an array of bitmaps
79 * @param bitmapArray array of bitmap items
81 void UploadBitmapArray( const BitmapUploadArray& bitmapArray);
84 * Clear an array of areas from bitmap to the given color
85 * @param[in] areaArray Array of rects to clear
86 * @param[in] blockSize Size of block to clear
87 * @param[in] color Clear color
89 void ClearAreas( const BitmapClearArray& areaArray, std::size_t blockSize, uint32_t color );
93 * @copydoc Texture::Init
98 * @copydoc Texture::GetWidth
100 virtual unsigned int GetWidth() const;
103 * @copydoc Texture::GetHeight
105 virtual unsigned int GetHeight() const;
108 * @copydoc Texture::HasAlphaChannel
110 virtual bool HasAlphaChannel() const;
113 * @copydoc Texture::IsFullyOpaque
115 virtual bool IsFullyOpaque() const;
118 * Replace current bitmap with a fresh one, for instance after a Bitmap has
120 * @param[in] bitmap The new bitmap
122 virtual void Update( Integration::Bitmap* bitmap );
125 * Bitmap area has been modified - update the texture appropriately.
126 * @pre The bitmap hasn't been discarded (should be external type)
127 * @param[in] area The updated area
129 virtual void UpdateArea( const RectArea& area );
132 * @return Return true if the texture should be updated on GL texture creation.
134 virtual bool UpdateOnCreate();
138 * @copydoc Texture::CreateGlTexture
140 virtual bool CreateGlTexture();
145 * Uploads changes to GPU after Bitmap buffer has changed.
146 * @param [in] updateArea area which changed
147 * @param[in] pixels The pixel data
149 void AreaUpdated( const RectArea& updateArea, const unsigned char* pixels );
152 * Assigns the bitmap data to an OpenGL texture
153 * Creates a new texture object and copies
154 * the image data held in the pixels parameter
155 * @pre The texture has to have a width/height that is a power of 2.
156 * @param[in] generateTexture True if we should generate a GL texture id
157 * @param[in] pixels The pixel data
159 void AssignBitmap( bool generateTexture, const unsigned char* pixels );
162 Integration::BitmapPtr mBitmap; ///< The Bitmap the Texture was created from (may be NULL)
163 bool mClearPixels; ///< true if initial texture should be cleared on creation
165 // Changes scope, should be at end of class
166 DALI_LOG_OBJECT_STRING_DECLARATION;
170 // Upload bitmap array message
172 inline MessageBase* UploadBitmapArrayMessage( BitmapTexture& texture, const BitmapUploadArray& bitmapArray )
174 return new MessageValue1< BitmapTexture, BitmapUploadArray >( &texture, &BitmapTexture::UploadBitmapArray, bitmapArray );
177 } //namespace Internal
181 #endif //__DALI_INTERNAL_BITMAP_TEXTURE_H__