Merge "Performance Improvements: Remove unnecessary SwapBuffer calls" into devel...
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.cpp
1 /*
2  * Copyright (c) 2017 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 // EXTERNAL INCLUDES
22 #include <stdlib.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 PixelData::PixelData( unsigned char* buffer,
31                       unsigned int bufferSize,
32                       unsigned int width,
33                       unsigned int height,
34                       Pixel::Format pixelFormat,
35                       Dali::PixelData::ReleaseFunction releaseFunction )
36 : mBuffer( buffer ),
37   mBufferSize( bufferSize ),
38   mWidth( width ),
39   mHeight( height ),
40   mPixelFormat( pixelFormat ),
41   mReleaseFunction( releaseFunction )
42 {
43 }
44
45 PixelData::~PixelData()
46 {
47   if( mBuffer )
48   {
49     if( mReleaseFunction == Dali::PixelData::FREE)
50     {
51       free( mBuffer );
52     }
53     else
54     {
55       delete[] mBuffer;
56     }
57   }
58  }
59
60 PixelDataPtr PixelData::New(unsigned char* buffer,
61                             unsigned int bufferSize,
62                             unsigned int width,
63                             unsigned int height,
64                             Pixel::Format pixelFormat,
65                             Dali::PixelData::ReleaseFunction releaseFunction)
66 {
67   return new PixelData( buffer, bufferSize, width, height, pixelFormat, releaseFunction );
68 }
69
70 unsigned int PixelData::GetWidth() const
71 {
72   return mWidth;
73 }
74
75 unsigned int PixelData::GetHeight() const
76 {
77   return mHeight;
78 }
79
80 Pixel::Format PixelData::GetPixelFormat() const
81 {
82   return mPixelFormat;
83 }
84
85 unsigned char* PixelData::GetBuffer() const
86 {
87   return mBuffer;
88 }
89
90 unsigned int PixelData::GetBufferSize() const
91 {
92   return mBufferSize;
93 }
94
95 DevelPixelData::PixelDataBuffer PixelData::ReleaseBuffer()
96 {
97   DevelPixelData::PixelDataBuffer pixelDataBuffer(mBuffer, mBufferSize, mReleaseFunction);
98   mBuffer = NULL;
99   return pixelDataBuffer;
100 }
101
102
103 }// namespace Internal
104
105 }// namespace Dali