1 #ifndef __DALI_BUFFER_IMAGE_H__
2 #define __DALI_BUFFER_IMAGE_H__
5 * Copyright (c) 2015 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 <dali/public-api/images/image.h>
23 #include <dali/public-api/images/pixel.h>
24 #include <dali/public-api/math/rect.h>
29 * @addtogroup dali_core_images
33 namespace Internal DALI_INTERNAL
38 typedef unsigned char PixelBuffer; ///< pixel data buffer
39 typedef Rect<unsigned int> RectArea; ///< rectangular area (x,y,w,h)
43 * @brief BufferImage represents an image resource as a pixel data buffer
44 * Its pixel buffer data is provided by the application developer.
46 * If the pixel format of the pixel buffer contains an alpha channel,
47 * then the image is considered to be have transparent pixels without
48 * regard for the actual content of the channel, and will be blended.
51 class DALI_IMPORT_API BufferImage : public Image
55 * @brief Constructor which creates an uninitialized BufferImage object.
57 * Use BufferImage::New(...) to create an initialised object.
62 * @brief Create a new BufferImage.
64 * Also a pixel buffer for image data is allocated.
65 * Dali has ownership of the buffer.
66 * For better performance and portability use power of two dimensions.
67 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
68 * @note: default resource management policies are Immediate and Never
70 * @pre width & height are greater than zero
71 * @param [in] width image width in pixels
72 * @param [in] height image height in pixels
73 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
74 * @return a handle to a new instance of BufferImage
76 static BufferImage New(unsigned int width,
78 Pixel::Format pixelformat=Pixel::RGBA8888);
81 * @deprecated DALi 1.1.3, use New( unsigned int width, unsigned int height ) instead.
83 * @brief Create a new BufferImage.
85 * Also a pixel buffer for image data is allocated.
86 * Dali has ownership of the buffer.
87 * For better performance and portability use power of two dimensions.
88 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
90 * @pre width & height are greater than zero
91 * @param [in] width Image width in pixels
92 * @param [in] height Image height in pixels
93 * @param [in] pixelFormat The pixel format
94 * @param [in] releasePolicy Optionally release memory when image is not visible on screen.
95 * @return a handle to a new instance of BufferImage
97 static BufferImage New(unsigned int width,
99 Pixel::Format pixelFormat,
100 ReleasePolicy releasePolicy);
103 * @brief Create a new BufferImage, which uses an external data source.
105 * The PixelBuffer has to be allocated by application.
107 * The application holds ownership of the buffer. It must not
108 * destroy the PixelBuffer on a staged image if it has called
109 * Update() and hasn't received a SignalUploaded, or if it has just
110 * added it to the stage and has not received a SignalUploaded.
112 * For better performance and portability use power of two dimensions.
113 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
115 * @pre width & height are greater than zero
116 * @param [in] pixelBuffer pixel buffer. has to be allocated by application.
117 * @param [in] width image width in pixels
118 * @param [in] height image height in pixels
119 * @param [in] pixelFormat the pixel format (rgba 32 bit by default)
120 * @param [in] stride the internal stride of the pixelbuffer in pixels
121 * @return a handle to a new instance of BufferImage
123 static BufferImage New(PixelBuffer* pixelBuffer,
126 Pixel::Format pixelFormat=Pixel::RGBA8888,
127 unsigned int stride=0);
130 * @deprecated DALi 1.1.3, use New( PixelBuffer* pixelBuffer, unsigned int width, unsigned int height ) instead.
132 * @brief Create a new BufferImage, which uses an external data source.
134 * The PixelBuffer has to be allocated by application.
136 * The application holds ownership of the buffer. It must not
137 * destroy the PixelBuffer on a staged image if it has called
138 * Update() and hasn't received a SignalUploaded, or if it has just
139 * added it to the stage and has not received a SignalUploaded.
141 * For better performance and portability use power of two dimensions.
142 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
144 * @note in case releasePolicy is "Unused", application has to call
145 * BufferImage::Update() whenever image is re-added to the stage
147 * @pre width & height are greater than zero
148 * @param [in] pixelBuffer pixel buffer. has to be allocated by application.
149 * @param [in] width image width in pixels
150 * @param [in] height image height in pixels
151 * @param [in] pixelFormat the pixel format
152 * @param [in] stride the internal stride of the pixelbuffer in pixels
153 * @param [in] releasePolicy optionally relase memory when image is not visible on screen.
154 * @return a handle to a new instance of BufferImage
156 static BufferImage New(PixelBuffer* pixelBuffer,
159 Pixel::Format pixelFormat,
161 ReleasePolicy releasePolicy);
164 * @brief Downcast an Object handle to BufferImage.
166 * If handle points to a BufferImage the downcast produces valid
167 * handle. If not the returned handle is left uninitialized.
169 * @param[in] handle to An object
170 * @return handle to a BufferImage or an uninitialized handle
172 static BufferImage DownCast( BaseHandle handle );
177 * This is non-virtual since derived Handle types must not contain data or virtual methods.
182 * @brief This copy constructor is required for (smart) pointer semantics.
184 * @param [in] handle A reference to the copied handle
186 BufferImage(const BufferImage& handle);
189 * @brief This assignment operator is required for (smart) pointer semantics.
191 * @param [in] rhs A reference to the copied handle
192 * @return A reference to this
194 BufferImage& operator=(const BufferImage& rhs);
197 * @brief White pixel as image data.
199 * Can be used to create solid color actors.
200 * @return 1 white pixel with 32 bit colordepth
202 static const BufferImage WHITE();
206 * @brief Returns the pixel buffer of the Image.
208 * The application can write to the buffer to modify its contents.
210 * Whilst the image is on stage, after writing to the buffer the
211 * application should call Update() and wait for the
212 * SignalUploaded() method before writing again.
214 * @return the pixel buffer
216 PixelBuffer* GetBuffer();
219 * @brief Returns buffer size in bytes.
221 * @return the buffer size in bytes
223 unsigned int GetBufferSize() const;
226 * @brief Returns buffer stride (in bytes).
228 * @return the buffer stride
230 unsigned int GetBufferStride() const;
233 * @brief Returns the pixel format of the contained buffer
235 * @return the pixel format
237 Pixel::Format GetPixelFormat() const;
240 * @brief Inform Dali that the contents of the buffer have changed.
242 * SignalUploaded will be sent in response if the image is on stage
243 * and the image data has been successfully copied to graphics
244 * memory. To avoid visual tearing, the application should wait for
245 * the SignalUploaded before modifying the data.
247 * The application must not destroy an external PixelBuffer on a staged
248 * image after calling this method until the SignalUploaded has been
249 * successfully received.
251 * @note: BufferImage::Update might not work with BGR/BGRA formats!
252 * @note: Some GPUs may not support Non power of two buffer updates (for
253 * example C110/SGX540)
259 * @param [in] updateArea area that has changed in buffer
261 void Update( RectArea updateArea );
264 * @brief Returns whether BufferImage uses external data source or not.
266 * If not, dali holds ownership of the PixelBuffer, otherwise the application
267 * is responsible for freeing it.
269 * The application must not destroy an external PixelBuffer on a staged image
270 * if it has called Update() and hasn't received a SignalUploaded.
272 * @return true if application owns data, false otherwise
274 bool IsDataExternal() const;
276 public: // Not intended for application developers
278 explicit DALI_INTERNAL BufferImage(Internal::BufferImage*);
286 #endif // __DALI_BUFFER_IMAGE_H__