Added memory pool logging
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.h
1 #ifndef DALI_INTERNAL_PIXEL_DATA_H
2 #define DALI_INTERNAL_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 // INTERNAL INCLUDES
22 #include <dali/devel-api/images/pixel-data-devel.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/images/pixel-data.h>
25 #include <dali/public-api/object/base-object.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class PixelData;
32 using PixelDataPtr = IntrusivePtr<PixelData>;
33
34 class PixelData : public BaseObject
35 {
36 public:
37   /**
38    * @brief Create a PixelData object.
39    *
40    * @param [in] buffer           The raw pixel data.
41    * @param [in] bufferSize       The size of the buffer in bytes
42    * @param [in] width            Buffer width in pixels
43    * @param [in] height           Buffer height in pixels
44    * @param [in] stride           Buffer stride in pixels, 0 means the buffer is tightly packed
45    * @param [in] pixelFormat      The pixel format
46    * @param [in] releaseFunction  The function used to release the memory.
47    */
48   static PixelDataPtr New(uint8_t*                         buffer,
49                           uint32_t                         bufferSize,
50                           uint32_t                         width,
51                           uint32_t                         height,
52                           uint32_t                         stride,
53                           Pixel::Format                    pixelFormat,
54                           Dali::PixelData::ReleaseFunction releaseFunction);
55
56   /**
57    * @brief Constructor.
58    *
59    * @param [in] buffer           The raw pixel data.
60    * @param [in] bufferSize       The size of the buffer in bytes
61    * @param [in] width            Buffer width in pixels
62    * @param [in] height           Buffer height in pixels
63    * @param [in] stride           Buffer stride in pixels, 0 means the buffer is tightly packed
64    * @param [in] pixelFormat      The pixel format
65    * @param [in] releaseFunction  The function used to release the memory.
66    */
67   PixelData(uint8_t*                         buffer,
68             uint32_t                         bufferSize,
69             uint32_t                         width,
70             uint32_t                         height,
71             uint32_t                         stride,
72             Pixel::Format                    pixelFormat,
73             Dali::PixelData::ReleaseFunction releaseFunction);
74
75 protected:
76   /**
77    * @brief Destructor.
78    *
79    * Release the pixel buffer if exists.
80    */
81   ~PixelData() override;
82
83 public:
84   /**
85    * Get the width of the buffer in pixels.
86    * @return The width of the buffer in pixels
87    */
88   uint32_t GetWidth() const;
89
90   /**
91    * Get the height of the buffer in pixels
92    * @return The height of the buffer in pixels
93    */
94   uint32_t GetHeight() const;
95
96   /**
97    * Get the pixel format
98    * @return The pixel format
99    */
100   Pixel::Format GetPixelFormat() const;
101
102   /**
103    * Get the pixel buffer if it's present.
104    * @return The buffer if exists, or NULL if there is no pixel buffer.
105    */
106   uint8_t* GetBuffer() const;
107
108   /**
109    * Get the size of the buffer in bytes
110    * @return The size of the buffer
111    */
112   uint32_t GetBufferSize() const;
113
114   /**
115    * Return the buffer pointer and reset the internal buffer to zero.
116    * @return The buffer pointer and associated data.
117    */
118   DevelPixelData::PixelDataBuffer ReleaseBuffer();
119
120   /**
121    * @copydoc PixelData::GetStride()
122    */
123   uint32_t GetStride() const;
124
125   /**
126    * Class method to get the total currently allocated size of pixel buffers
127    */
128   static uint32_t GetTotalAllocatedSize()
129   {
130 #if defined(DEBUG_ENABLED)
131     return gPixelDataAllocationTotal;
132 #else
133     return 0;
134 #endif
135   }
136
137 private:
138   /*
139    * Undefined copy constructor.
140    */
141   PixelData(const PixelData& other);
142
143   /*
144    * Undefined assignment operator.
145    */
146   PixelData& operator=(const PixelData& other);
147
148 private:
149   uint8_t*                         mBuffer;          ///< The raw pixel data
150   uint32_t                         mBufferSize;      ///< Buffer size in bytes
151   uint32_t                         mWidth;           ///< Buffer width in pixels
152   uint32_t                         mHeight;          ///< Buffer height in pixels
153   uint32_t                         mStride;          ///< Buffer stride in pixels, 0 means the buffer is tightly packed
154   Pixel::Format                    mPixelFormat;     ///< Pixel format
155   Dali::PixelData::ReleaseFunction mReleaseFunction; ///< Function for releasing memory
156
157 #if defined(DEBUG_ENABLED)
158   static uint32_t gPixelDataAllocationTotal;
159 #endif
160 };
161
162 } // namespace Internal
163
164 /**
165  * Helper methods for public API
166  */
167 inline Internal::PixelData& GetImplementation(Dali::PixelData& handle)
168 {
169   DALI_ASSERT_ALWAYS(handle && "handle is empty");
170
171   BaseObject& object = handle.GetBaseObject();
172
173   return static_cast<Internal::PixelData&>(object);
174 }
175
176 inline const Internal::PixelData& GetImplementation(const Dali::PixelData& handle)
177 {
178   DALI_ASSERT_ALWAYS(handle && "handle is empty");
179
180   const BaseObject& object = handle.GetBaseObject();
181
182   return static_cast<const Internal::PixelData&>(object);
183 }
184
185 } // namespace Dali
186
187 #endif // __DALI_INTERNAL_PIXEL_DATA_H__