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 initialized object.
65 * @brief Creates 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 * @brief Creates a new BufferImage, which uses an external data source.
87 * The PixelBuffer has to be allocated by application.
89 * The application holds ownership of the buffer. It must not
90 * destroy the PixelBuffer on a staged image if it has called
91 * Update() and hasn't received a Image::UploadedSignal, or if it has just
92 * added it to the stage and has not received a Image::UploadedSignal.
94 * For better performance and portability use power of two dimensions.
95 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
98 * @param[in] pixelBuffer Pixel buffer has to be allocated by application
99 * @param[in] width Image width in pixels
100 * @param[in] height Image height in pixels
101 * @param[in] pixelFormat The pixel format (rgba 32 bit by default)
102 * @param[in] stride The internal stride of the pixelbuffer in pixels
103 * @return A handle to a new instance of BufferImage
104 * @pre width & height are greater than zero
106 static BufferImage New(PixelBuffer* pixelBuffer,
109 Pixel::Format pixelFormat=Pixel::RGBA8888,
110 unsigned int stride=0);
113 * @brief Downcasts a handle to BufferImage handle.
115 * If the handle points to a BufferImage, the downcast produces valid handle.
116 * If not, the returned handle is left uninitialized.
119 * @param[in] handle Handle to an object
120 * @return Handle to a BufferImage or an uninitialized handle
122 static BufferImage DownCast( BaseHandle handle );
127 * This is non-virtual since derived Handle types must not contain data or virtual methods.
133 * @brief This copy constructor is required for (smart) pointer semantics.
136 * @param[in] handle A reference to the copied handle
138 BufferImage(const BufferImage& handle);
141 * @brief This assignment operator is required for (smart) pointer semantics.
144 * @param[in] rhs A reference to the copied handle
145 * @return A reference to this
147 BufferImage& operator=(const BufferImage& rhs);
150 * @brief White pixel as image data.
152 * Can be used to create solid color actors.
154 * @return 1 white pixel with 32 bit colordepth
156 static const BufferImage WHITE();
160 * @brief Returns the pixel buffer of the Image.
162 * The application can write to the buffer to modify its contents.
164 * Whilst the image is on stage, after writing to the buffer the
165 * application should call Update() and wait for the
166 * Image::UploadedSignal() method before writing again.
169 * @return The pixel buffer
171 PixelBuffer* GetBuffer();
174 * @brief Returns buffer size in bytes.
177 * @return The buffer size in bytes
179 unsigned int GetBufferSize() const;
182 * @brief Returns buffer stride (in bytes).
185 * @return The buffer stride
187 unsigned int GetBufferStride() const;
190 * @brief Returns the pixel format of the contained buffer
193 * @return The pixel format
195 Pixel::Format GetPixelFormat() const;
198 * @brief Inform Dali that the contents of the buffer have changed.
200 * Image::UploadedSignal will be sent in response if the image is on stage
201 * and the image data has been successfully copied to graphics
202 * memory. To avoid visual tearing, the application should wait for
203 * the Image::UploadedSignal before modifying the data.
205 * The application must not destroy an external PixelBuffer on a staged
206 * image after calling this method until the Image::UploadedSignal has been
207 * successfully received.
210 * @note BufferImage::Update might not work with BGR/BGRA formats!
211 * @note Some GPUs may not support Non power of two buffer updates (for
212 * example C110/SGX540)
218 * @param[in] updateArea Area that has changed in buffer
220 void Update( RectArea updateArea );
223 * @brief Returns whether BufferImage uses external data source or not.
225 * If not, dali holds ownership of the PixelBuffer, otherwise the application
226 * is responsible for freeing it.
228 * The application must not destroy an external PixelBuffer on a staged image
229 * if it has called Update() and hasn't received a Image::UploadedSignal.
232 * @return @c true if application owns data, @c false otherwise
234 bool IsDataExternal() const;
236 public: // Not intended for application developers
238 explicit DALI_INTERNAL BufferImage(Internal::BufferImage*);
246 #endif // __DALI_BUFFER_IMAGE_H__