Apply the new doxygen tagging rule for @SINCE
[platform/core/uifw/dali-core.git] / dali / public-api / images / buffer-image.h
1 #ifndef __DALI_BUFFER_IMAGE_H__
2 #define __DALI_BUFFER_IMAGE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/images/pixel.h>
24 #include <dali/public-api/math/rect.h>
25
26 namespace Dali
27 {
28 /**
29  * @addtogroup dali_core_images
30  * @{
31  */
32
33 namespace Internal DALI_INTERNAL
34 {
35 class BufferImage;
36 }
37
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
40
41
42 /**
43  * @brief BufferImage represents an image resource as a pixel data buffer
44  * Its pixel buffer data is provided by the application developer.
45  *
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.
49  *
50  * @SINCE_1_0.0
51  */
52 class DALI_IMPORT_API BufferImage : public Image
53 {
54 public:
55   /**
56    * @brief Constructor which creates an uninitialized BufferImage object.
57    *
58    * Use BufferImage::New(...) to create an initialised object.
59    * @SINCE_1_0.0
60    */
61   BufferImage();
62
63   /**
64    * @brief Create a new BufferImage.
65    *
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
71    *
72    * @SINCE_1_0.0
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
78    */
79   static BufferImage New(unsigned int width,
80                          unsigned int height,
81                          Pixel::Format pixelformat=Pixel::RGBA8888);
82
83   /**
84    * @deprecated DALi 1.1.3, use New( unsigned int width, unsigned int height ) instead.
85    *
86    * @brief Create a new BufferImage.
87    *
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.
92    *
93    * @SINCE_1_0.0
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
100    */
101   static BufferImage New(unsigned int  width,
102                          unsigned int  height,
103                          Pixel::Format pixelFormat,
104                          ReleasePolicy releasePolicy);
105
106   /**
107    * @brief Create a new BufferImage, which uses an external data source.
108    *
109    * The PixelBuffer has to be allocated by application.
110    *
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.
115    *
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.
118    *
119    * @SINCE_1_0.0
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
127    */
128   static BufferImage New(PixelBuffer*  pixelBuffer,
129                          unsigned int  width,
130                          unsigned int  height,
131                          Pixel::Format pixelFormat=Pixel::RGBA8888,
132                          unsigned int  stride=0);
133
134   /**
135    * @deprecated DALi 1.1.3, use New( PixelBuffer* pixelBuffer, unsigned int width, unsigned int height ) instead.
136    *
137    * @brief Create a new BufferImage, which uses an external data source.
138    *
139    * The PixelBuffer has to be allocated by application.
140    *
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.
145    *
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.
148    *
149    * @SINCE_1_0.0
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
160    *
161    */
162   static BufferImage New(PixelBuffer*  pixelBuffer,
163                          unsigned int  width,
164                          unsigned int  height,
165                          Pixel::Format pixelFormat,
166                          unsigned int  stride,
167                          ReleasePolicy releasePolicy);
168
169   /**
170    * @brief Downcast an Object handle to BufferImage.
171    *
172    * If handle points to a BufferImage the downcast produces valid
173    * handle. If not the returned handle is left uninitialized.
174    *
175    * @SINCE_1_0.0
176    * @param[in] handle to An object
177    * @return handle to a BufferImage or an uninitialized handle
178    */
179   static BufferImage DownCast( BaseHandle handle );
180
181   /**
182    * @brief Destructor
183    *
184    * This is non-virtual since derived Handle types must not contain data or virtual methods.
185    * @SINCE_1_0.0
186    */
187   ~BufferImage();
188
189   /**
190    * @brief This copy constructor is required for (smart) pointer semantics.
191    *
192    * @SINCE_1_0.0
193    * @param [in] handle A reference to the copied handle
194    */
195   BufferImage(const BufferImage& handle);
196
197   /**
198    * @brief This assignment operator is required for (smart) pointer semantics.
199    *
200    * @SINCE_1_0.0
201    * @param [in] rhs  A reference to the copied handle
202    * @return A reference to this
203    */
204   BufferImage& operator=(const BufferImage& rhs);
205
206   /**
207    * @brief White pixel as image data.
208    *
209    * Can be used to create solid color actors.
210    * @SINCE_1_0.0
211    * @return 1 white pixel with 32 bit colordepth
212    */
213   static const BufferImage WHITE();
214
215 public:
216   /**
217    * @brief Returns the pixel buffer of the Image.
218    *
219    * The application can write to the buffer to modify its contents.
220    *
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.
224    *
225    * @SINCE_1_0.0
226    * @return the pixel buffer
227    */
228   PixelBuffer* GetBuffer();
229
230   /**
231    * @brief Returns buffer size in bytes.
232    *
233    * @SINCE_1_0.0
234    * @return the buffer size in bytes
235    */
236   unsigned int GetBufferSize() const;
237
238   /**
239    * @brief Returns buffer stride (in bytes).
240    *
241    * @SINCE_1_0.0
242    * @return the buffer stride
243    */
244   unsigned int GetBufferStride() const;
245
246   /**
247    * @brief Returns the pixel format of the contained buffer
248    *
249    * @SINCE_1_0.0
250    * @return the pixel format
251    */
252   Pixel::Format GetPixelFormat() const;
253
254   /**
255    * @brief Inform Dali that the contents of the buffer have changed.
256    *
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.
261    *
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.
265    *
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)
269    * @SINCE_1_0.0
270    */
271   void Update();
272
273   /**
274    * @copydoc Update()
275    * @param [in] updateArea area that has changed in buffer
276    */
277   void Update( RectArea updateArea );
278
279   /**
280    * @brief Returns whether BufferImage uses external data source or not.
281    *
282    * If not, dali holds ownership of the PixelBuffer, otherwise the application
283    * is responsible for freeing it.
284    *
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.
287    *
288    * @SINCE_1_0.0
289    * @return true if application owns data, false otherwise
290    */
291   bool IsDataExternal() const;
292
293 public: // Not intended for application developers
294
295   explicit DALI_INTERNAL BufferImage(Internal::BufferImage*);
296 };
297
298 /**
299  * @}
300  */
301 } // namespace Dali
302
303 #endif // __DALI_BUFFER_IMAGE_H__