1 #ifndef DALI_INTERNAL_PIXEL_DATA_H
2 #define DALI_INTERNAL_PIXEL_DATA_H
5 * Copyright (c) 2024 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/integration-api/debug.h>
23 #include <dali/integration-api/pixel-data-integ.h>
24 #include <dali/public-api/images/pixel-data.h>
25 #include <dali/public-api/object/base-object.h>
32 using PixelDataPtr = IntrusivePtr<PixelData>;
34 class PixelData : public BaseObject
38 * @brief Create a PixelData object.
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 * @param [in] releaseAfterUpload Whether we release buffer after texture upload or not.
49 static PixelDataPtr New(uint8_t* buffer,
54 Pixel::Format pixelFormat,
55 Dali::PixelData::ReleaseFunction releaseFunction,
56 bool releaseAfterUpload);
61 * @param [in] buffer The raw pixel data.
62 * @param [in] bufferSize The size of the buffer in bytes
63 * @param [in] width Buffer width in pixels
64 * @param [in] height Buffer height in pixels
65 * @param [in] stride Buffer stride in pixels, 0 means the buffer is tightly packed
66 * @param [in] pixelFormat The pixel format
67 * @param [in] releaseFunction The function used to release the memory.
68 * @param [in] releaseAfterUpload Whether we release buffer after texture upload or not.
70 PixelData(uint8_t* buffer,
75 Pixel::Format pixelFormat,
76 Dali::PixelData::ReleaseFunction releaseFunction,
77 bool releaseAfterUpload);
83 * Release the pixel buffer if exists.
85 ~PixelData() override;
89 * Get the width of the buffer in pixels.
90 * @return The width of the buffer in pixels
92 uint32_t GetWidth() const;
95 * Get the height of the buffer in pixels
96 * @return The height of the buffer in pixels
98 uint32_t GetHeight() const;
101 * Get the pixel format
102 * @return The pixel format
104 Pixel::Format GetPixelFormat() const;
107 * Get the pixel buffer if it's present.
108 * @return The buffer if exists, or NULL if there is no pixel buffer.
110 uint8_t* GetBuffer() const;
113 * Get the size of the buffer in bytes
114 * @return The size of the buffer
116 uint32_t GetBufferSize() const;
119 * Release the buffer data and reset the internal buffer to zero.
121 void ReleasePixelDataBuffer();
124 * Return the buffer pointer.
125 * @return The buffer pointer.
127 Dali::Integration::PixelDataBuffer GetPixelDataBuffer() const;
130 * Get whether we need to release pixel data after texture upload or not.
131 * @note This function can be called from another thread. Be careful.
132 * @return True if we need to release pixel data after texture upload. False otherwise.
134 bool IsPixelDataReleaseAfterUpload() const
136 return mReleaseAfterUpload;
140 * @copydoc PixelData::GetStride()
142 uint32_t GetStride() const;
145 * Class method to get the total currently allocated size of pixel buffers
147 static uint32_t GetTotalAllocatedSize()
149 #if defined(DEBUG_ENABLED)
150 return gPixelDataAllocationTotal;
158 * Undefined copy constructor.
160 PixelData(const PixelData& other);
163 * Undefined assignment operator.
165 PixelData& operator=(const PixelData& other);
168 uint8_t* mBuffer; ///< The raw pixel data
169 uint32_t mBufferSize; ///< Buffer size in bytes
170 uint32_t mWidth; ///< Buffer width in pixels
171 uint32_t mHeight; ///< Buffer height in pixels
172 uint32_t mStride; ///< Buffer stride in pixels, 0 means the buffer is tightly packed
173 Pixel::Format mPixelFormat; ///< Pixel format
174 Dali::PixelData::ReleaseFunction mReleaseFunction; ///< Function for releasing memory
176 const bool mReleaseAfterUpload;
178 #if defined(DEBUG_ENABLED)
179 static uint32_t gPixelDataAllocationTotal;
183 } // namespace Internal
186 * Helper methods for public API
188 inline Internal::PixelData& GetImplementation(Dali::PixelData& handle)
190 DALI_ASSERT_ALWAYS(handle && "handle is empty");
192 BaseObject& object = handle.GetBaseObject();
194 return static_cast<Internal::PixelData&>(object);
197 inline const Internal::PixelData& GetImplementation(const Dali::PixelData& handle)
199 DALI_ASSERT_ALWAYS(handle && "handle is empty");
201 const BaseObject& object = handle.GetBaseObject();
203 return static_cast<const Internal::PixelData&>(object);
208 #endif // __DALI_INTERNAL_PIXEL_DATA_H__