Removed legacy resource tracking / logging
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / bitmap-texture.h
1 #ifndef __DALI_INTERNAL_BITMAP_TEXTURE_H__
2 #define __DALI_INTERNAL_BITMAP_TEXTURE_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 // EXTERNAL INCLUDES
21 #include <stdint.h> // for uint32_t
22
23 // INTERNAL INCLUDES
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>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 class BitmapTexture;
37 typedef IntrusivePtr<BitmapTexture> BitmapTexturePointer;
38
39 /**
40  *
41  * Texture class.
42  * If you want to load a file to a BitmapTexture use
43  * TextureManager::GetTexture()
44  *
45  */
46 class BitmapTexture : public Texture
47 {
48 public:
49   /**
50    * Constructor
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
55    */
56   BitmapTexture(Integration::Bitmap* const bitmap, const Integration::Bitmap::PackedPixelsProfile * const bitmapPackedPixelsProfile, Context& context);
57
58   /**
59    * Constructor
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
66    */
67   BitmapTexture( unsigned int width, unsigned int height, Pixel::Format pixelFormat,
68                  bool clearPixels, Context& context );
69
70   /**
71    * Destructor.
72    */
73   virtual ~BitmapTexture();
74
75 public: // Message interface
76
77   /**
78    * Upload an array of bitmaps
79    * @param bitmapArray array of bitmap items
80    */
81   void UploadBitmapArray( const BitmapUploadArray& bitmapArray);
82
83   /**
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
88    */
89   void ClearAreas( const BitmapClearArray& areaArray, std::size_t blockSize, uint32_t color );
90
91 public:
92   /**
93    * @copydoc Texture::Init
94    */
95   virtual bool Init();
96
97   /**
98    * @copydoc Texture::GetWidth
99    */
100   virtual unsigned int GetWidth() const;
101
102   /**
103    * @copydoc Texture::GetHeight
104    */
105   virtual unsigned int GetHeight() const;
106
107   /**
108    * @copydoc Texture::HasAlphaChannel
109    */
110   virtual bool HasAlphaChannel() const;
111
112   /**
113    * @copydoc Texture::IsFullyOpaque
114    */
115   virtual bool IsFullyOpaque() const;
116
117   /**
118    * Replace current bitmap with a fresh one, for instance after a Bitmap has
119    * been reloaded.
120    * @param[in] bitmap The new bitmap
121    */
122   virtual void Update( Integration::Bitmap* bitmap );
123
124   /**
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
128    */
129   virtual void UpdateArea( const RectArea& area );
130
131   /**
132    * @return Return true if the texture should be updated on GL texture creation.
133    */
134   virtual bool UpdateOnCreate();
135
136 protected:
137   /**
138    * @copydoc Texture::CreateGlTexture
139    */
140   virtual bool CreateGlTexture();
141
142 private:
143
144   /**
145    * Uploads changes to GPU after Bitmap buffer has changed.
146    * @param [in] updateArea area which changed
147    * @param[in] pixels The pixel data
148    */
149   void AreaUpdated( const RectArea& updateArea, const unsigned char* pixels );
150
151   /**
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
158    */
159   void AssignBitmap( bool generateTexture, const unsigned char* pixels );
160
161 private:
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
164
165   // Changes scope, should be at end of class
166   DALI_LOG_OBJECT_STRING_DECLARATION;
167 };
168
169 //
170 // Upload bitmap array message
171 //
172 inline MessageBase* UploadBitmapArrayMessage( BitmapTexture& texture, const BitmapUploadArray& bitmapArray )
173 {
174   return new MessageValue1< BitmapTexture, BitmapUploadArray >( &texture, &BitmapTexture::UploadBitmapArray, bitmapArray );
175 }
176
177 }  //namespace Internal
178
179 } //namespace Dali
180
181 #endif //__DALI_INTERNAL_BITMAP_TEXTURE_H__