Make PixelData flag that we release buffer after texture upload
[platform/core/uifw/dali-core.git] / dali / integration-api / pixel-data-integ.h
1 #ifndef DALI_PIXEL_DATA_INTEG_H
2 #define DALI_PIXEL_DATA_INTEG_H
3
4 /*
5  * Copyright (c) 2024 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>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/images/pixel-data.h>
26 #include <dali/public-api/images/pixel.h>
27
28 namespace Dali::Integration
29 {
30 /**
31  * Struct to keep the buffer pointer and the allocation method.
32  *
33  * @note Need to find a better solution - one library should not
34  * be freeing data from a different source with potentially
35  * different allocators.
36  */
37 struct PixelDataBuffer
38 {
39   uint8_t* buffer;
40   uint32_t bufferSize;
41   uint32_t width;
42   uint32_t height;
43   uint32_t stride;
44
45   PixelDataBuffer(uint8_t* buffer,
46                   uint32_t bufferSize,
47                   uint32_t width,
48                   uint32_t height,
49                   uint32_t stride = 0)
50   : buffer(buffer),
51     bufferSize(bufferSize),
52     width(width),
53     height(height),
54     stride(stride)
55   {
56   }
57 };
58
59 /**
60  * Release the buffer from a pixel data object, zero it in the pixel data object.
61  * @param[in] pixelData The pixel data object to take the buffer from
62  */
63 DALI_CORE_API void ReleasePixelDataBuffer(Dali::PixelData pixelData);
64
65 /**
66  * Get the buffer from a pixel data object.
67  * @param[in] pixelData The pixel data object to get the buffer from
68  * @return the buffer of pixelData.
69  */
70 DALI_CORE_API PixelDataBuffer GetPixelDataBuffer(const Dali::PixelData& pixelData);
71
72 /**
73  * Creates a PixelData object which will release the buffer automatically after upload to texture.
74  * @return The pixel data object.
75  */
76 DALI_CORE_API Dali::PixelData NewPixelDataWithReleaseAfterUpload(uint8_t*                   buffer,
77                                                                  uint32_t                   bufferSize,
78                                                                  uint32_t                   width,
79                                                                  uint32_t                   height,
80                                                                  uint32_t                   stride,
81                                                                  Pixel::Format              pixelFormat,
82                                                                  PixelData::ReleaseFunction releaseFunction);
83
84 /**
85  * Get whether we need to release pixel data after texture upload or not.
86  * @note This function can be called from another thread. Be careful about thread safety.
87  * @param[in] pixelData The pixel data object to get the release policy.
88  * @return True if we need to release pixel data after texture upload. False otherwise.
89  */
90 DALI_CORE_API bool IsPixelDataReleaseAfterUpload(const Dali::PixelData& pixelData);
91
92 } // namespace Dali::Integration
93
94 #endif // DALI_PIXEL_DATA_INTEG_H