Merge "Added memory pool logging" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/images/pixel-data-impl.h>
20
21 #include <dali/integration-api/debug.h>
22
23 #if defined(DEBUG_ENABLED)
24 Debug::Filter* gPixelDataLogFilter = Debug::Filter::New(Debug::NoLogging, false, "DALI_LOG_PIXEL_DATA_SIZE");
25 #endif
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 #if defined(DEBUG_ENABLED)
32 // Only track data allocation if debug is enabled
33 uint32_t PixelData::gPixelDataAllocationTotal{0};
34 #endif
35
36 PixelData::PixelData(uint8_t*                         buffer,
37                      uint32_t                         bufferSize,
38                      uint32_t                         width,
39                      uint32_t                         height,
40                      uint32_t                         stride,
41                      Pixel::Format                    pixelFormat,
42                      Dali::PixelData::ReleaseFunction releaseFunction)
43 : mBuffer(buffer),
44   mBufferSize(bufferSize),
45   mWidth(width),
46   mHeight(height),
47   mStride(stride),
48   mPixelFormat(pixelFormat),
49   mReleaseFunction(releaseFunction)
50 {
51   DALI_LOG_INFO(gPixelDataLogFilter, Debug::Concise, "Allocated PixelData of size %u\n", bufferSize);
52 #if defined(DEBUG_ENABLED)
53   gPixelDataAllocationTotal += mBufferSize;
54 #endif
55 }
56
57 PixelData::~PixelData()
58 {
59   if(mBuffer)
60   {
61     if(mReleaseFunction == Dali::PixelData::FREE)
62     {
63       free(mBuffer);
64     }
65     else
66     {
67       delete[] mBuffer;
68     }
69 #if defined(DEBUG_ENABLED)
70     gPixelDataAllocationTotal -= mBufferSize;
71 #endif
72   }
73 }
74
75 PixelDataPtr PixelData::New(uint8_t*                         buffer,
76                             uint32_t                         bufferSize,
77                             uint32_t                         width,
78                             uint32_t                         height,
79                             uint32_t                         stride,
80                             Pixel::Format                    pixelFormat,
81                             Dali::PixelData::ReleaseFunction releaseFunction)
82 {
83   return new PixelData(buffer, bufferSize, width, height, stride, pixelFormat, releaseFunction);
84 }
85
86 uint32_t PixelData::GetWidth() const
87 {
88   return mWidth;
89 }
90
91 uint32_t PixelData::GetHeight() const
92 {
93   return mHeight;
94 }
95
96 Pixel::Format PixelData::GetPixelFormat() const
97 {
98   return mPixelFormat;
99 }
100
101 uint8_t* PixelData::GetBuffer() const
102 {
103   return mBuffer;
104 }
105
106 uint32_t PixelData::GetBufferSize() const
107 {
108   return mBufferSize;
109 }
110
111 DevelPixelData::PixelDataBuffer PixelData::ReleaseBuffer()
112 {
113   DevelPixelData::PixelDataBuffer pixelDataBuffer(mBuffer, mBufferSize, mReleaseFunction);
114   mBuffer = nullptr;
115   return pixelDataBuffer;
116 }
117
118 uint32_t PixelData::GetStride() const
119 {
120   return mStride;
121 }
122
123 } // namespace Internal
124
125 } // namespace Dali