1 #ifndef __DALI_INTERNAL_BITMAP_TEXTURE_H__
2 #define __DALI_INTERNAL_BITMAP_TEXTURE_H__
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <stdint.h> // for uint32_t
25 #include <dali/internal/common/message.h>
26 #include <dali/integration-api/bitmap.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/internal/render/gl-resources/texture-cache.h>
29 #include <dali/internal/render/gl-resources/gl-texture.h>
38 typedef IntrusivePtr<BitmapTexture> BitmapTexturePointer;
43 * If you want to load a file to a BitmapTexture use
44 * TextureManager::GetTexture()
47 class BitmapTexture : public Texture
52 * Creates a new texture object from a Bitmap
53 * @param[in] bitmap The Bitmap
54 * @param[in] bitmapPackedPixelsProfile The Bitmap features related to an addressable array of raw pixel data
55 * @param context The GL context
57 BitmapTexture(Integration::Bitmap* const bitmap, const Integration::Bitmap::PackedPixelsProfile * const bitmapPackedPixelsProfile, Context& context, ResourcePolicy::Discardable discardPolicy);
61 * Creates a new texture object
62 * @param[in] width width in pixels
63 * @param[in] height height in pixels
64 * @param[in] pixelFormat pixel format
65 * @param[in] clearPixels True if the pixel data should be cleared before gl texture creation
66 * @param[in] context Dali context
68 BitmapTexture( unsigned int width, unsigned int height, Pixel::Format pixelFormat,
69 bool clearPixels, Context& context, ResourcePolicy::Discardable discardPolicy );
74 virtual ~BitmapTexture();
78 * @return The bitmap or NULL if already discarded
80 Integration::Bitmap* GetBitmap() { return mBitmap.Get(); }
85 * @copydoc Texture::Init
90 * @copydoc Texture::GetWidth
92 virtual unsigned int GetWidth() const;
95 * @copydoc Texture::GetHeight
97 virtual unsigned int GetHeight() const;
100 * @copydoc Texture::HasAlphaChannel
102 virtual bool HasAlphaChannel() const;
105 * @copydoc Texture::IsFullyOpaque
107 virtual bool IsFullyOpaque() const;
110 * Replace current bitmap with a fresh one, for instance after a Bitmap has
112 * @param[in] bitmap The new bitmap
114 virtual void Update( Integration::Bitmap* bitmap );
117 * Update part of the texture with a different bitmap
118 * @param[in] srcBitmap The bitmap to copy from
119 * @param [in] xOffset Specifies an offset in the x direction within the texture
120 * @param [in] yOffset Specifies an offset in the y direction within the texture
122 virtual void Update( Integration::Bitmap* srcBitmap, std::size_t xOffset, std::size_t yOffset );
125 * Update part of the texture with a pixel buffer
126 * @param[in] srcPixelData The pixel data to copy from
127 * @param [in] xOffset Specifies an offset in the x direction within the texture
128 * @param [in] yOffset Specifies an offset in the y direction within the texture
130 virtual void Update( PixelData* srcPixelData, std::size_t xOffset, std::size_t yOffset );
133 * Bitmap area has been modified - update the texture appropriately.
134 * @pre The bitmap hasn't been discarded (should be external type)
135 * @param[in] area The updated area
137 virtual void UpdateArea( const RectArea& area );
140 * @return Return true if the texture should be updated on GL texture creation.
142 virtual bool UpdateOnCreate();
146 * @copydoc Texture::CreateGlTexture
148 virtual bool CreateGlTexture();
153 * Uploads changes to GPU after Bitmap buffer has changed.
154 * @param [in] updateArea area which changed
155 * @param[in] pixels The pixel data
157 void AreaUpdated( const RectArea& updateArea, const unsigned char* pixels );
160 * Assigns the bitmap data to an OpenGL texture
161 * Creates a new texture object and copies
162 * the image data held in the pixels parameter
163 * @pre The texture has to have a width/height that is a power of 2.
164 * @param[in] generateTexture True if we should generate a GL texture id
165 * @param[in] pixels The pixel data
167 void AssignBitmap( bool generateTexture, const unsigned char* pixels );
170 * If the discard policy is not RETAIN, then discards the bitmap's pixel buffer
172 void DiscardBitmapBuffer();
175 * Update part of the texture.
176 * @param [in] pixels The pixel buffer.
177 * @param [in] width The buffer width in pixels
178 * @param [in] height The buffer height in pixels
179 * @param [in] pixelFormat The pixel format
180 * @param [in] xOffset Specifies an offset in the x direction within the texture
181 * @param [in] yOffset Specifies an offset in the y direction within the texture
183 void Update( const unsigned char* pixels, std::size_t width, std::size_t height, Pixel::Format pixelFormat, std::size_t xOffset, std::size_t yOffset );
186 Integration::BitmapPtr mBitmap; ///< The Bitmap the Texture was created from (may be NULL)
187 Pixel::Format mPixelFormat; ///< Pack pixel format into bitfield
188 ResourcePolicy::Discardable mDiscardPolicy; ///< The bitmap discard policy
189 bool mClearPixels; ///< true if initial texture should be cleared on creation
191 // Changes scope, should be at end of class
192 DALI_LOG_OBJECT_STRING_DECLARATION;
195 } //namespace Internal
199 #endif //__DALI_INTERNAL_BITMAP_TEXTURE_H__