1 #ifndef DALI_BUFFER_IMAGE_H
2 #define DALI_BUFFER_IMAGE_H
5 * Copyright (c) 2019 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 uint8_t PixelBuffer; ///< pixel data buffer @SINCE_1_0.0
39 typedef Rect<uint32_t> RectArea; ///< rectangular area (x,y,w,h) @SINCE_1_0.0
45 * @brief BufferImage represents an image resource as a pixel data buffer.
47 * Its pixel buffer data is provided by the application developer.
49 * If the pixel format of the pixel buffer contains an alpha channel,
50 * then the image is considered to be have transparent pixels without
51 * regard for the actual content of the channel, and will be blended.
55 class DALI_CORE_API BufferImage : public Image
62 * @brief Constructor which creates an uninitialized BufferImage object.
64 * Use BufferImage::New(...) to create an initialized object.
67 BufferImage() DALI_DEPRECATED_API;
72 * @brief Creates a new BufferImage.
74 * Also a pixel buffer for image data is allocated.
75 * Dali has ownership of the buffer.
76 * For better performance and portability use power of two dimensions.
77 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
79 * @param[in] width Image width in pixels
80 * @param[in] height Image height in pixels
81 * @param[in] pixelformat The pixel format (rgba 32 bit by default)
82 * @return A handle to a new instance of BufferImage
83 * @pre width & height are greater than zero
84 * @note default resource management policies are Immediate and Never
87 static BufferImage New(uint32_t width,
89 Pixel::Format pixelformat=Pixel::RGBA8888) DALI_DEPRECATED_API;
94 * @brief Creates a new BufferImage, which uses an external data source.
96 * The PixelBuffer has to be allocated by application.
98 * The application holds ownership of the buffer. It must not
99 * destroy the PixelBuffer on a staged image if it has called
100 * Update() and hasn't received a Image::UploadedSignal, or if it has just
101 * added it to the stage and has not received a Image::UploadedSignal.
103 * For better performance and portability use power of two dimensions.
104 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
107 * @param[in] pixelBuffer Pixel buffer has to be allocated by application
108 * @param[in] width Image width in pixels
109 * @param[in] height Image height in pixels
110 * @param[in] pixelFormat The pixel format (rgba 32 bit by default)
111 * @param[in] stride The internal stride of the pixelbuffer in pixels
112 * @return A handle to a new instance of BufferImage
113 * @pre width & height are greater than zero
115 static BufferImage New(PixelBuffer* pixelBuffer,
118 Pixel::Format pixelFormat=Pixel::RGBA8888,
119 uint32_t stride=0) DALI_DEPRECATED_API;
124 * @brief Downcasts a handle to BufferImage handle.
126 * If the handle points to a BufferImage, the downcast produces valid handle.
127 * If not, the returned handle is left uninitialized.
130 * @param[in] handle Handle to an object
131 * @return Handle to a BufferImage or an uninitialized handle
133 static BufferImage DownCast( BaseHandle handle ) DALI_DEPRECATED_API;
140 * This is non-virtual since derived Handle types must not contain data or virtual methods.
143 ~BufferImage() DALI_DEPRECATED_API;
148 * @brief This copy constructor is required for (smart) pointer semantics.
151 * @param[in] handle A reference to the copied handle
153 BufferImage(const BufferImage& handle) DALI_DEPRECATED_API;
158 * @brief This assignment operator is required for (smart) pointer semantics.
161 * @param[in] rhs A reference to the copied handle
162 * @return A reference to this
164 BufferImage& operator=(const BufferImage& rhs) DALI_DEPRECATED_API;
169 * @brief White pixel as image data.
171 * Can be used to create solid color actors.
173 * @return 1 white pixel with 32 bit colordepth
175 static const BufferImage WHITE() DALI_DEPRECATED_API;
182 * @brief Returns the pixel buffer of the Image.
184 * The application can write to the buffer to modify its contents.
186 * Whilst the image is on stage, after writing to the buffer the
187 * application should call Update() and wait for the
188 * Image::UploadedSignal() method before writing again.
191 * @return The pixel buffer
193 PixelBuffer* GetBuffer() DALI_DEPRECATED_API;
198 * @brief Returns buffer size in bytes.
201 * @return The buffer size in bytes
203 uint32_t GetBufferSize() const DALI_DEPRECATED_API;
208 * @brief Returns buffer stride (in bytes).
211 * @return The buffer stride
213 uint32_t GetBufferStride() const DALI_DEPRECATED_API;
218 * @brief Returns the pixel format of the contained buffer
221 * @return The pixel format
223 Pixel::Format GetPixelFormat() const DALI_DEPRECATED_API;
228 * @brief Inform Dali that the contents of the buffer have changed.
230 * Image::UploadedSignal will be sent in response if the image is on stage
231 * and the image data has been successfully copied to graphics
232 * memory. To avoid visual tearing, the application should wait for
233 * the Image::UploadedSignal before modifying the data.
235 * The application must not destroy an external PixelBuffer on a staged
236 * image after calling this method until the Image::UploadedSignal has been
237 * successfully received.
240 * @note BufferImage::Update might not work with BGR/BGRA formats!
241 * @note Some GPUs may not support Non power of two buffer updates (for
242 * example C110/SGX540)
244 void Update() DALI_DEPRECATED_API;
250 * @param[in] updateArea Area that has changed in buffer
252 void Update( RectArea updateArea ) DALI_DEPRECATED_API;
257 * @brief Returns whether BufferImage uses external data source or not.
259 * If not, dali holds ownership of the PixelBuffer, otherwise the application
260 * is responsible for freeing it.
262 * The application must not destroy an external PixelBuffer on a staged image
263 * if it has called Update() and hasn't received a Image::UploadedSignal.
266 * @return @c true if application owns data, @c false otherwise
268 bool IsDataExternal() const DALI_DEPRECATED_API;
270 public: // Not intended for application developers
272 explicit DALI_INTERNAL BufferImage(Internal::BufferImage*);
280 #endif // DALI_BUFFER_IMAGE_H