Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrpBufferInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrpBufferInfo.cpp
20  * @brief       This is the implementation file for internal BufferInfo class.
21  *
22  */
23
24 #include <new>
25
26 #include <FGrpBufferInfo.h>
27
28 #include <FBaseSysLog.h>
29
30 #include "FGrp_BufferInfoImpl.h"
31
32
33 using namespace Tizen::Base;
34
35
36 namespace Tizen { namespace Graphics
37 {
38
39 BufferInfo::BufferInfo(void)
40         : width(0)
41         , height(0)
42         , pitch(0)
43         , bitsPerPixel(0)
44         , pixelFormat(PIXEL_FORMAT_MIN)
45         , pPixels(null)
46         , __pImpl(null)
47 {
48         __pImpl = new (std::nothrow) _BufferInfoImpl;
49
50         SysTryReturnVoidResult(NID_GRP, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
51 }
52
53 BufferInfo::BufferInfo(const BufferInfo& rhs)
54         : width(rhs.width)
55         , height(rhs.height)
56         , pitch(rhs.pitch)
57         , bitsPerPixel(rhs.bitsPerPixel)
58         , pixelFormat(rhs.pixelFormat)
59         , pPixels(rhs.pPixels)
60         , __pImpl(null)
61 {
62         if (_BufferInfoImpl::GetInstance(rhs) != null)
63         {
64                 __pImpl = new (std::nothrow) _BufferInfoImpl(*_BufferInfoImpl::GetInstance(rhs));
65
66                 SysTryReturnVoidResult(NID_GRP, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
67         }
68 }
69
70 BufferInfo::~BufferInfo(void)
71 {
72         if (__pImpl)
73         {
74                 delete __pImpl;
75                 __pImpl = null;
76         }
77 }
78
79 BufferInfo&
80 BufferInfo::operator =(const BufferInfo& rhs)
81 {
82         if (this == &rhs)
83         {
84                 return *this;
85         }
86
87         this->width = rhs.width;
88         this->height = rhs.height;
89         this->pitch = rhs.pitch;
90         this->bitsPerPixel = rhs.bitsPerPixel;
91         this->pixelFormat = rhs.pixelFormat;
92         this->pPixels = rhs.pPixels;
93
94         if (this->__pImpl && _BufferInfoImpl::GetInstance(rhs))
95         {
96                 *(this->__pImpl) = *_BufferInfoImpl::GetInstance(rhs);
97         }
98
99         return *this;
100 }
101
102 bool
103 BufferInfo::Equals(const Tizen::Base::Object& rhs) const
104 {
105         if (&rhs == null)
106         {
107                 return false;
108         }
109
110         const BufferInfo* pBufferInfo = dynamic_cast <const BufferInfo*>(&rhs);
111
112         if (pBufferInfo == null)
113         {
114                 return false;
115         }
116
117         return ((this->width == pBufferInfo->width &&
118                         this->height == pBufferInfo->height &&
119                         this->pitch == pBufferInfo->pitch &&
120                         this->bitsPerPixel == pBufferInfo->bitsPerPixel &&
121                         this->pixelFormat == pBufferInfo->pixelFormat &&
122                         this->pPixels == pBufferInfo->pPixels) ? true : false);
123 }
124
125 int
126 BufferInfo::GetHashCode(void) const
127 {
128         return ((((this->width & 0xFF) << 24) |
129                 ((this->height & 0xFF) << 16) |
130                 ((this->pitch & 0xF) << 12) |
131                 ((this->bitsPerPixel & 0xF) << 8) |
132                 ((this->pixelFormat & 0xF) << 4)) ^
133                 (reinterpret_cast<int>(this->pPixels)));
134 }
135
136 }} // Tizen::Graphics