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
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.
52 class DALI_IMPORT_API BufferImage : public Image
56 * @brief Constructor which creates an uninitialized BufferImage object.
58 * Use BufferImage::New(...) to create an initialised object.
64 * @brief Create a new BufferImage.
66 * Also a pixel buffer for image data is allocated.
67 * Dali has ownership of the buffer.
68 * For better performance and portability use power of two dimensions.
69 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
70 * @note: default resource management policies are Immediate and Never
73 * @param [in] width image width in pixels
74 * @param [in] height image height in pixels
75 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
76 * @return a handle to a new instance of BufferImage
77 * @pre width & height are greater than zero
79 static BufferImage New(unsigned int width,
81 Pixel::Format pixelformat=Pixel::RGBA8888);
84 * @DEPRECATED_1_1.3. Use New( unsigned int width, unsigned int height ) instead.
86 * @brief Create a new BufferImage.
88 * Also a pixel buffer for image data is allocated.
89 * Dali has ownership of the buffer.
90 * For better performance and portability use power of two dimensions.
91 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
94 * @param [in] width Image width in pixels
95 * @param [in] height Image height in pixels
96 * @param [in] pixelFormat The pixel format
97 * @param [in] releasePolicy Optionally release memory when image is not visible on screen.
98 * @return a handle to a new instance of BufferImage
99 * @pre width & height are greater than zero
101 static BufferImage New(unsigned int width,
103 Pixel::Format pixelFormat,
104 ReleasePolicy releasePolicy);
107 * @brief Create a new BufferImage, which uses an external data source.
109 * The PixelBuffer has to be allocated by application.
111 * The application holds ownership of the buffer. It must not
112 * destroy the PixelBuffer on a staged image if it has called
113 * Update() and hasn't received a SignalUploaded, or if it has just
114 * added it to the stage and has not received a SignalUploaded.
116 * For better performance and portability use power of two dimensions.
117 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
120 * @param [in] pixelBuffer pixel buffer. has to be allocated by application.
121 * @param [in] width image width in pixels
122 * @param [in] height image height in pixels
123 * @param [in] pixelFormat the pixel format (rgba 32 bit by default)
124 * @param [in] stride the internal stride of the pixelbuffer in pixels
125 * @return a handle to a new instance of BufferImage
126 * @pre width & height are greater than zero
128 static BufferImage New(PixelBuffer* pixelBuffer,
131 Pixel::Format pixelFormat=Pixel::RGBA8888,
132 unsigned int stride=0);
135 * @DEPRECATED_1_1.3. Use New( PixelBuffer* pixelBuffer, unsigned int width, unsigned int height ) instead.
137 * @brief Create a new BufferImage, which uses an external data source.
139 * The PixelBuffer has to be allocated by application.
141 * The application holds ownership of the buffer. It must not
142 * destroy the PixelBuffer on a staged image if it has called
143 * Update() and hasn't received a SignalUploaded, or if it has just
144 * added it to the stage and has not received a SignalUploaded.
146 * For better performance and portability use power of two dimensions.
147 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
150 * @param [in] pixelBuffer pixel buffer. has to be allocated by application.
151 * @param [in] width image width in pixels
152 * @param [in] height image height in pixels
153 * @param [in] pixelFormat the pixel format
154 * @param [in] stride the internal stride of the pixelbuffer in pixels
155 * @param [in] releasePolicy optionally relase memory when image is not visible on screen.
156 * @return a handle to a new instance of BufferImage
157 * @pre width & height are greater than zero
158 * @note in case releasePolicy is "Unused", application has to call
159 * BufferImage::Update() whenever image is re-added to the stage
162 static BufferImage New(PixelBuffer* pixelBuffer,
165 Pixel::Format pixelFormat,
167 ReleasePolicy releasePolicy);
170 * @brief Downcast an Object handle to BufferImage.
172 * If handle points to a BufferImage the downcast produces valid
173 * handle. If not the returned handle is left uninitialized.
176 * @param[in] handle to An object
177 * @return handle to a BufferImage or an uninitialized handle
179 static BufferImage DownCast( BaseHandle handle );
184 * This is non-virtual since derived Handle types must not contain data or virtual methods.
190 * @brief This copy constructor is required for (smart) pointer semantics.
193 * @param [in] handle A reference to the copied handle
195 BufferImage(const BufferImage& handle);
198 * @brief This assignment operator is required for (smart) pointer semantics.
201 * @param [in] rhs A reference to the copied handle
202 * @return A reference to this
204 BufferImage& operator=(const BufferImage& rhs);
207 * @brief White pixel as image data.
209 * Can be used to create solid color actors.
211 * @return 1 white pixel with 32 bit colordepth
213 static const BufferImage WHITE();
217 * @brief Returns the pixel buffer of the Image.
219 * The application can write to the buffer to modify its contents.
221 * Whilst the image is on stage, after writing to the buffer the
222 * application should call Update() and wait for the
223 * SignalUploaded() method before writing again.
226 * @return the pixel buffer
228 PixelBuffer* GetBuffer();
231 * @brief Returns buffer size in bytes.
234 * @return the buffer size in bytes
236 unsigned int GetBufferSize() const;
239 * @brief Returns buffer stride (in bytes).
242 * @return the buffer stride
244 unsigned int GetBufferStride() const;
247 * @brief Returns the pixel format of the contained buffer
250 * @return the pixel format
252 Pixel::Format GetPixelFormat() const;
255 * @brief Inform Dali that the contents of the buffer have changed.
257 * SignalUploaded will be sent in response if the image is on stage
258 * and the image data has been successfully copied to graphics
259 * memory. To avoid visual tearing, the application should wait for
260 * the SignalUploaded before modifying the data.
262 * The application must not destroy an external PixelBuffer on a staged
263 * image after calling this method until the SignalUploaded has been
264 * successfully received.
266 * @note: BufferImage::Update might not work with BGR/BGRA formats!
267 * @note: Some GPUs may not support Non power of two buffer updates (for
268 * example C110/SGX540)
275 * @param [in] updateArea area that has changed in buffer
277 void Update( RectArea updateArea );
280 * @brief Returns whether BufferImage uses external data source or not.
282 * If not, dali holds ownership of the PixelBuffer, otherwise the application
283 * is responsible for freeing it.
285 * The application must not destroy an external PixelBuffer on a staged image
286 * if it has called Update() and hasn't received a SignalUploaded.
289 * @return true if application owns data, false otherwise
291 bool IsDataExternal() const;
293 public: // Not intended for application developers
295 explicit DALI_INTERNAL BufferImage(Internal::BufferImage*);
303 #endif // __DALI_BUFFER_IMAGE_H__