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 @SINCE_1_0.0
39 typedef Rect<unsigned int> RectArea; ///< rectangular area (x,y,w,h) @SINCE_1_0.0
43 * @brief BufferImage represents an image resource as a pixel data buffer.
45 * Its pixel buffer data is provided by the application developer.
47 * If the pixel format of the pixel buffer contains an alpha channel,
48 * then the image is considered to be have transparent pixels without
49 * regard for the actual content of the channel, and will be blended.
53 class DALI_IMPORT_API BufferImage : public Image
57 * @brief Constructor which creates an uninitialized BufferImage object.
59 * Use BufferImage::New(...) to create an initialised object.
65 * @brief Create a new BufferImage.
67 * Also a pixel buffer for image data is allocated.
68 * Dali has ownership of the buffer.
69 * For better performance and portability use power of two dimensions.
70 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
72 * @param [in] width Image width in pixels
73 * @param [in] height Image height in pixels
74 * @param [in] pixelformat The pixel format (rgba 32 bit by default)
75 * @return A handle to a new instance of BufferImage
76 * @pre width & height are greater than zero
77 * @note default resource management policies are Immediate and Never
80 static BufferImage New(unsigned int width,
82 Pixel::Format pixelformat=Pixel::RGBA8888);
85 * @DEPRECATED_1_1.3. Use New( unsigned int width, unsigned int height ) instead.
87 * @brief Create a new BufferImage.
89 * Also a pixel buffer for image data is allocated.
90 * Dali has ownership of the buffer.
91 * For better performance and portability use power of two dimensions.
92 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
95 * @remarks ReleasePolicy is an experimental feature and might not be supported in the next release.
96 * We do recommend not to use this method.
97 * Please refer the Remarks of ReleasePolicy for more information.
98 * @param [in] width Image width in pixels
99 * @param [in] height Image height in pixels
100 * @param [in] pixelFormat The pixel format
101 * @param [in] releasePolicy Optionally release memory when image is not visible on screen.
102 * @return A handle to a new instance of BufferImage
103 * @pre width & height are greater than zero
105 static BufferImage New(unsigned int width,
107 Pixel::Format pixelFormat,
108 ReleasePolicy releasePolicy);
111 * @brief Create a new BufferImage, which uses an external data source.
113 * The PixelBuffer has to be allocated by application.
115 * The application holds ownership of the buffer. It must not
116 * destroy the PixelBuffer on a staged image if it has called
117 * Update() and hasn't received a Image::UploadedSignal, or if it has just
118 * added it to the stage and has not received a Image::UploadedSignal.
120 * For better performance and portability use power of two dimensions.
121 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
124 * @param [in] pixelBuffer Pixel buffer. has to be allocated by application.
125 * @param [in] width Image width in pixels
126 * @param [in] height Image height in pixels
127 * @param [in] pixelFormat The pixel format (rgba 32 bit by default)
128 * @param [in] stride The internal stride of the pixelbuffer in pixels
129 * @return A handle to a new instance of BufferImage
130 * @pre width & height are greater than zero
132 static BufferImage New(PixelBuffer* pixelBuffer,
135 Pixel::Format pixelFormat=Pixel::RGBA8888,
136 unsigned int stride=0);
139 * @DEPRECATED_1_1.3. Use New( PixelBuffer* pixelBuffer, unsigned int width, unsigned int height ) instead.
141 * @brief Create a new BufferImage, which uses an external data source.
143 * The PixelBuffer has to be allocated by application.
145 * The application holds ownership of the buffer. It must not
146 * destroy the PixelBuffer on a staged image if it has called
147 * Update() and hasn't received a Image::UploadedSignal, or if it has just
148 * added it to the stage and has not received a Image::UploadedSignal.
150 * For better performance and portability use power of two dimensions.
151 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
154 * @remarks ReleasePolicy is an experimental feature and might not be supported in the next release.
155 * We do recommend not to use this method.
156 * Please refer the Remarks of ReleasePolicy for more information.
157 * @param [in] pixelBuffer Pixel buffer. has to be allocated by application.
158 * @param [in] width Image width in pixels
159 * @param [in] height Image height in pixels
160 * @param [in] pixelFormat The pixel format
161 * @param [in] stride The internal stride of the pixelbuffer in pixels
162 * @param [in] releasePolicy Optionally relase memory when image is not visible on screen.
163 * @return A handle to a new instance of BufferImage
164 * @pre width & height are greater than zero
165 * @note in case releasePolicy is Image::UNUSED, application has to call
166 * BufferImage::Update() whenever image is re-added to the stage
169 static BufferImage New(PixelBuffer* pixelBuffer,
172 Pixel::Format pixelFormat,
174 ReleasePolicy releasePolicy);
177 * @brief Downcast a handle to BufferImage handle.
179 * If handle points to a BufferImage the downcast produces valid
180 * handle. If not the returned handle is left uninitialized.
183 * @param[in] handle Handle to an object
184 * @return Handle to a BufferImage or an uninitialized handle
186 static BufferImage DownCast( BaseHandle handle );
191 * This is non-virtual since derived Handle types must not contain data or virtual methods.
197 * @brief This copy constructor is required for (smart) pointer semantics.
200 * @param [in] handle A reference to the copied handle
202 BufferImage(const BufferImage& handle);
205 * @brief This assignment operator is required for (smart) pointer semantics.
208 * @param [in] rhs A reference to the copied handle
209 * @return A reference to this
211 BufferImage& operator=(const BufferImage& rhs);
214 * @brief White pixel as image data.
216 * Can be used to create solid color actors.
218 * @return 1 white pixel with 32 bit colordepth
220 static const BufferImage WHITE();
224 * @brief Returns the pixel buffer of the Image.
226 * The application can write to the buffer to modify its contents.
228 * Whilst the image is on stage, after writing to the buffer the
229 * application should call Update() and wait for the
230 * Image::UploadedSignal() method before writing again.
233 * @return The pixel buffer
235 PixelBuffer* GetBuffer();
238 * @brief Returns buffer size in bytes.
241 * @return The buffer size in bytes
243 unsigned int GetBufferSize() const;
246 * @brief Returns buffer stride (in bytes).
249 * @return The buffer stride
251 unsigned int GetBufferStride() const;
254 * @brief Returns the pixel format of the contained buffer
257 * @return The pixel format
259 Pixel::Format GetPixelFormat() const;
262 * @brief Inform Dali that the contents of the buffer have changed.
264 * Image::UploadedSignal will be sent in response if the image is on stage
265 * and the image data has been successfully copied to graphics
266 * memory. To avoid visual tearing, the application should wait for
267 * the Image::UploadedSignal before modifying the data.
269 * The application must not destroy an external PixelBuffer on a staged
270 * image after calling this method until the Image::UploadedSignal has been
271 * successfully received.
274 * @note BufferImage::Update might not work with BGR/BGRA formats!
275 * @note Some GPUs may not support Non power of two buffer updates (for
276 * example C110/SGX540)
282 * @param [in] updateArea Area that has changed in buffer
284 void Update( RectArea updateArea );
287 * @brief Returns whether BufferImage uses external data source or not.
289 * If not, dali holds ownership of the PixelBuffer, otherwise the application
290 * is responsible for freeing it.
292 * The application must not destroy an external PixelBuffer on a staged image
293 * if it has called Update() and hasn't received a Image::UploadedSignal.
296 * @return true if application owns data, false otherwise
298 bool IsDataExternal() const;
300 public: // Not intended for application developers
302 explicit DALI_INTERNAL BufferImage(Internal::BufferImage*);
310 #endif // __DALI_BUFFER_IMAGE_H__