Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrp_BitmapUtil.h
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        FGrp_BitmapUtil.h
20  * @brief       This is the header file for _BitmapUtil namespace.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_BITMAPUTIL_H_
25 #define _FGRP_INTERNAL_BITMAPUTIL_H_
26
27 #include <FGrpBitmap.h>
28
29 #include <FBaseSysLog.h>
30
31 #include "FGrp_BitmapImpl.h"
32 #include "FGrp_BitmapCoordHolder.h"
33
34
35 namespace Tizen { namespace Graphics
36 {
37
38 namespace _BitmapUtil
39 {
40
41 unsigned long GetTimeStamp(const Tizen::Graphics::Bitmap& bitmap);
42
43 unsigned long UpdateTimeStamp(Tizen::Graphics::Bitmap& bitmap);
44
45 // the ownership of 'bitmapImpl' moves to the new Bitmap instance
46 Bitmap* CreateBitmapN(Tizen::Graphics::_BitmapImpl* bitmapImpl);
47
48 // it doesn't move the ownership of 'pBuffer'
49 Bitmap* CreateBitmapN(void* pBuffer, int width, int height, int depth);
50
51 // This function can create a raw bitmap from physical size
52 Bitmap* CreateBitmapN(Dimension physicalSize, int depth);
53
54 // This function changes the buffer of the specified bitmap to the user defined buffer
55 // The user buffer size MUST be same as the original bitmap size
56 result ChangeBuffer(Tizen::Graphics::Bitmap& srcBitmap, void* pBuffer, long bytesPerLine, void (* DestroyCallback)(void*), void* pCallbackParam);
57
58 bool SetCallback(Tizen::Graphics::Bitmap& bitmap,
59                                 void (* DestroyCallback)(void*), void* pCallbackParam,
60                                 void (* LockCallback)(void*), void* pLockParam,
61                                 void (* UnlockCallback)(void*), void* pUnlockParam);
62
63 void ResetCallback(Tizen::Graphics::Bitmap& bitmap);
64
65 } //  Tizen::Graphics::_BitmapUtil
66
67
68 class BitmapTemp
69         : public _BitmapImpl
70 {
71 public:
72         BitmapTemp(Canvas& canvas);
73         BitmapTemp(void* pBuffer, int width, int height, int depth);
74         BitmapTemp(Dimension physicalSize, int depth);
75
76         virtual ~BitmapTemp();
77
78         bool IsValid(void);
79
80 private:
81         bool __isValid;
82
83 }; // BitmapTemp
84
85 }} // Tizen::Graphics
86
87
88 namespace Tizen { namespace Graphics
89 {
90
91 class _BitmapImplHack
92         : public _BitmapImpl
93 {
94 public:
95         _Bitmap* GetBitmapEx(void) const
96         {
97                 return (this && this->_sharedItem.get()) ? this->_sharedItem->nativeBitmap.get() : 0;
98         }
99
100         _Bitmap* GetScaledBitmapEx(void) const
101         {
102                 return (this && this->_sharedItem.get()) ? this->_sharedItem->scaledNativeBitmap.get() : 0;
103         }
104
105         bool IsLazyScalingBitmap(void) const
106         {
107                 return (this && this->_sharedItem.get()) ? (this->_sharedItem->lazyScaling != 0) : false;
108         }
109
110         bool IsLazyScalingBitmap(Tizen::Graphics::Dimension& virSize, Tizen::Graphics::Dimension& phySize) const
111         {
112                 if (this->_sharedItem.get() == 0 || this->_sharedItem->lazyScaling == 0)
113                 {
114                         return false;
115                 }
116
117                 virSize.width = this->_sharedItem->coordHolder->bitmapSize.virCoord.w;
118                 virSize.height = this->_sharedItem->coordHolder->bitmapSize.virCoord.h;
119                 phySize.width = this->_sharedItem->coordHolder->bitmapSize.phyCoord.w;
120                 phySize.height = this->_sharedItem->coordHolder->bitmapSize.phyCoord.h;
121
122                 return true;
123         }
124
125         bool SetCallback(void (* DestroyCallback)(void*), void* pDestroyCallbackParam,
126                          void (* LockCallback)(void*), void* pLockCallbackParam,
127                          void (* UnlockCallback)(void*), void* pUnlockCallbackParam)
128         {
129                 if (this->_sharedItem.get() == 0)
130                 {
131                         return false;
132                 }
133
134                 return this->_SetCallback(DestroyCallback, pDestroyCallbackParam, LockCallback, pLockCallbackParam, UnlockCallback, pUnlockCallbackParam);
135         }
136
137         void ResetCallback(void)
138         {
139                 if (this->_sharedItem.get() == 0)
140                 {
141                         return;
142                 }
143
144                 this->_sharedItem->pDestroyCallbackFunc = null;
145                 this->_sharedItem->pDestroyCallbackParam = null;
146                 this->_sharedItem->pLockCallbackFunc = null;
147                 this->_sharedItem->pLockCallbackParam = null;
148                 this->_sharedItem->pUnlockCallbackFunc = null;
149                 this->_sharedItem->pUnlockCallbackParam = null;
150         }
151
152 }; // _BitmapImplHack
153
154 inline _Bitmap*
155 GetBitmapEx(const Tizen::Graphics::_BitmapImpl& bitmap)
156 {
157         const _BitmapImplHack* pBitmapImplHack = static_cast <const _BitmapImplHack*>(&bitmap);
158
159         return (pBitmapImplHack) ? pBitmapImplHack->GetBitmapEx() : null;
160 }
161
162 inline _Bitmap*
163 GetScaledBitmapEx(const Tizen::Graphics::_BitmapImpl& bitmap)
164 {
165         const _BitmapImplHack* pBitmapImplHack = static_cast <const _BitmapImplHack*>(&bitmap);
166
167         return (pBitmapImplHack) ? pBitmapImplHack->GetScaledBitmapEx() : null;
168 }
169
170 inline bool
171 IsLazyScalingBitmap(const Tizen::Graphics::_BitmapImpl& bitmap)
172 {
173         const _BitmapImplHack* pBitmapImplHack = static_cast <const _BitmapImplHack*>(&bitmap);
174
175         return (pBitmapImplHack) ? pBitmapImplHack->IsLazyScalingBitmap() : false;
176 }
177
178 inline bool
179 IsLazyScalingBitmap(const Tizen::Graphics::_BitmapImpl& bitmap, Tizen::Graphics::Dimension& virSize,
180                                         Tizen::Graphics::Dimension& phySize)
181 {
182         const _BitmapImplHack* pBitmapImplHack = static_cast <const _BitmapImplHack*>(&bitmap);
183
184         return (pBitmapImplHack) ? pBitmapImplHack->IsLazyScalingBitmap(virSize, phySize) : false;
185 }
186
187 }} // Tizen::Graphics
188
189 namespace Tizen { namespace Graphics
190 {
191
192 inline _Bitmap*
193 GetBitmapEx(const Tizen::Graphics::Bitmap& bitmap)
194 {
195         return GetBitmapEx(*_BitmapImpl::GetInstance(bitmap));
196 }
197
198 inline _Bitmap*
199 GetScaledBitmapEx(const Tizen::Graphics::Bitmap& bitmap)
200 {
201         return GetScaledBitmapEx(*_BitmapImpl::GetInstance(bitmap));
202 }
203
204 inline bool
205 IsLazyScalingBitmap(const Tizen::Graphics::Bitmap& bitmap)
206 {
207         return IsLazyScalingBitmap(*_BitmapImpl::GetInstance(bitmap));
208 }
209
210 inline bool
211 IsLazyScalingBitmap(const Tizen::Graphics::Bitmap& bitmap, Tizen::Graphics::Dimension& virSize, Tizen::Graphics::Dimension& phySize)
212 {
213         return IsLazyScalingBitmap(*_BitmapImpl::GetInstance(bitmap), virSize, phySize);
214 }
215
216 }} // Tizen::Graphics
217
218 #endif // _FGRP_INTERNAL_BITMAPUTIL_H_