Ensure BaseHandle class move noexcept (core public-api)
[platform/core/uifw/dali-core.git] / dali / public-api / images / pixel-data.h
1 #ifndef DALI_PIXEL_DATA_H
2 #define DALI_PIXEL_DATA_H
3
4 /*
5  * Copyright (c) 2022 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 // EXTERNAL INCLUDES
22 #include <cstdint> // uint8_t, uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/images/pixel.h>
26 #include <dali/public-api/object/base-handle.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_images
32  * @{
33  */
34
35 namespace Internal
36 {
37 class PixelData;
38 }
39
40 /**
41  * @brief The PixelData object holds a pixel buffer .
42  * The PixelData takes over the ownership of the pixel buffer.
43  * The buffer memory must NOT be released outside of this class, instead, the PixelData object will release it automatically when the reference count falls to zero.
44  *
45  * @SINCE_1_1.43
46  */
47 class DALI_CORE_API PixelData : public BaseHandle
48 {
49 public:
50   /**
51    * @brief Enumeration for Function to release the pixel buffer.
52    * @SINCE_1_1.43
53    */
54   enum ReleaseFunction
55   {
56     FREE,         ///< Use free function to release the pixel buffer     @SINCE_1_1.43
57     DELETE_ARRAY, ///< Use delete[] operator to release the pixel buffer @SINCE_1_1.43
58   };
59
60   /**
61    * @brief Creates a PixelData object.
62    *
63    * @SINCE_1_1.43
64    * @param[in] buffer          The raw pixel data
65    * @param[in] bufferSize      The size of the buffer in bytes
66    * @param[in] width           Buffer width in pixels
67    * @param[in] height          Buffer height in pixels
68    * @param[in] pixelFormat     The pixel format
69    * @param[in] releaseFunction The function used to release the memory
70    * @return A handle to the PixelData
71    */
72   static PixelData New(uint8_t*        buffer,
73                        uint32_t        bufferSize,
74                        uint32_t        width,
75                        uint32_t        height,
76                        Pixel::Format   pixelFormat,
77                        ReleaseFunction releaseFunction);
78
79   /**
80    * @brief Creates a PixelData object.
81    *
82    * @SINCE_2_1.10
83    * @param[in] buffer          The raw pixel data
84    * @param[in] bufferSize      The size of the buffer in bytes
85    * @param[in] width           Buffer width in pixels
86    * @param[in] height          Buffer height in pixels
87    * @param[in] stride          Buffer stride in pixels, 0 means the buffer is tightly packed
88    * @param[in] pixelFormat     The pixel format
89    * @param[in] releaseFunction The function used to release the memory
90    * @return A handle to the PixelData
91    */
92   static PixelData New(uint8_t*        buffer,
93                        uint32_t        bufferSize,
94                        uint32_t        width,
95                        uint32_t        height,
96                        uint32_t        stride,
97                        Pixel::Format   pixelFormat,
98                        ReleaseFunction releaseFunction);
99   /**
100    * @brief Creates an empty handle.
101    * Use PixelData::New() to create an initialized object.
102    *
103    * @SINCE_1_1.43
104    */
105   PixelData();
106
107   /**
108    * @brief Destructor.
109    *
110    * @SINCE_1_1.43
111    */
112   ~PixelData();
113
114   /**
115    * @brief This copy constructor is required for (smart) pointer semantics.
116    *
117    * @SINCE_1_1.43
118    * @param[in] handle A reference to the copied handle
119    */
120   PixelData(const PixelData& handle);
121
122   /**
123    * @brief This assignment operator is required for (smart) pointer semantics.
124    *
125    * @SINCE_1_1.43
126    * @param[in] rhs A reference to the copied handle
127    * @return A reference to this object
128    */
129   PixelData& operator=(const PixelData& rhs);
130
131   /**
132    * @brief Move constructor.
133    *
134    * @SINCE_1_9.22
135    * @param[in] rhs A reference to the moved handle
136    */
137   PixelData(PixelData&& rhs) noexcept;
138
139   /**
140    * @brief Move assignment operator.
141    *
142    * @SINCE_1_9.22
143    * @param[in] rhs A reference to the moved handle
144    * @return A reference to this handle
145    */
146   PixelData& operator=(PixelData&& rhs) noexcept;
147
148   /**
149    * @brief Gets the width of the buffer in pixels.
150    *
151    * @SINCE_1_1.43
152    * @return The width of the buffer in pixels
153    */
154   uint32_t GetWidth() const;
155
156   /**
157    * @brief Gets the height of the buffer in pixels.
158    *
159    * @SINCE_1_1.43
160    * @return The height of the buffer in pixels
161    */
162   uint32_t GetHeight() const;
163
164   /**
165    * @brief Gets the pixel format.
166    *
167    * @SINCE_1_1.43
168    * @return The pixel format
169    */
170   Pixel::Format GetPixelFormat() const;
171
172   /**
173    * @brief Gets the stride of the buffer in pixels.
174    *
175    * @SINCE_2_1.10
176    * @return The stride of the buffer in pixels. 0 means the buffer is tightly packed.
177    */
178   uint32_t GetStride() const;
179
180   /**
181    * Class method to get the total currently allocated size of pixel buffers
182    */
183   static uint32_t GetTotalAllocatedSize();
184
185 public:
186   /**
187    * @brief The constructor.
188    * @note  Not intended for application developers.
189    * @SINCE_1_1.43
190    * @param[in] pointer A pointer to a newly allocated PixelData
191    */
192   explicit DALI_INTERNAL PixelData(Internal::PixelData* pointer);
193 };
194
195 /**
196  * @}
197  */
198 } // namespace Dali
199
200 #endif // DALI_PIXEL_DATA_H