Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / graphics / FGrp_CoordinateSystem.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        FGrp_CoordinateSystem.cpp
20  * @brief       This is the implementation file for _CoordinateSystem class.
21  *
22  */
23
24 #include <new>
25 #include <memory>
26 #include <pthread.h>
27
28 #include <FBaseErrors.h>
29 #include <FBaseResult.h>
30
31 #include <FBaseInternalTypes.h>
32 #include <FApp_AppInfo.h>
33 #include <FBaseSysLog.h>
34
35 #include "FGrp_CoordinateSystem.h"
36 #include "FGrp_CoordinateSystemImpl.h"
37 #include "FGrp_Screen.h"
38
39 using namespace Tizen::Base;
40
41
42 namespace Tizen { namespace Graphics
43 {
44
45 _CoordinateSystem _CoordinateSystem::__instance;
46 _CoordinateSystem* _CoordinateSystem::__pTheInstance = null;
47
48
49 void
50 _CoordinateSystem::__InitCoordinateSystem(void)
51 {
52         if (__instance.__pImpl == null)
53         {
54                 result r = __instance.__Initialize(_Screen::GetWidth(), BASE_SCREEN_SIZE_DEFAULT, Dimension(_Screen::GetWidth(), _Screen::GetHeight()), BASE_SCREEN_SIZE_DEFAULT);
55
56                 SysAssertf(!IsFailed(r), "[%s] Propagating.", GetErrorMessage(r));
57         }
58
59         __pTheInstance = &__instance;
60 }
61
62 _CoordinateSystem*
63 _CoordinateSystem::GetInstance(void)
64 {
65         static pthread_once_t once_block = PTHREAD_ONCE_INIT;
66
67         if (__pTheInstance == null)
68         {
69                 pthread_once(&once_block, __InitCoordinateSystem);
70         }
71
72         return __pTheInstance;
73 }
74
75 void
76 _CoordinateSystem::SetTransformEnabled(bool enabled)
77 {
78         result r = E_SUCCESS;
79
80         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
81
82         __pImpl->SetTransformEnabled(enabled);
83
84 CATCH:
85         SetLastResult(r);
86 }
87
88 bool
89 _CoordinateSystem::IsTransformEnabled(void) const
90 {
91         result r = E_SUCCESS;
92
93         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
94
95         return __pImpl->IsTransformEnabled();
96
97 CATCH:
98         SetLastResult(r);
99
100         return false;
101 }
102
103 _ICoordinateSystemTransformer*
104 _CoordinateSystem::GetTransformer(void)
105 {
106         result r = E_SUCCESS;
107
108         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
109
110         return __pImpl->GetTransformer();
111
112 CATCH:
113         SetLastResult(r);
114
115         return null;
116 }
117
118 _ICoordinateSystemTransformer*
119 _CoordinateSystem::GetInverseTransformer(void)
120 {
121         result r = E_SUCCESS;
122         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
123
124         return __pImpl->GetInverseTransformer();
125
126 CATCH:
127         SetLastResult(r);
128
129         return null;
130 }
131
132 _ICoordinateSystemTransformer*
133 _CoordinateSystem::GetTransformerN(const Dimension& srcDim, const Dimension& trgDim)
134 {
135         _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(srcDim, trgDim);
136
137         if (pXformer == null)
138         {
139                 result r = GetLastResult();
140
141                 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
142         }
143
144         return pXformer;
145 }
146
147 _ICoordinateSystemTransformer*
148 _CoordinateSystem::GetTransformerN(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
149 {
150         _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
151
152         if (pXformer == null)
153         {
154                 result r = GetLastResult();
155
156                 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
157         }
158
159         return pXformer;
160 }
161
162
163 _ICoordinateSystemTransformer*
164 _CoordinateSystem::GetTransformerN(_LogicalResolution logicalResolution, _PhysicalResolution physicalResolution)
165 {
166         _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(logicalResolution, BASE_SCREEN_SIZE_NORMAL, physicalResolution, BASE_SCREEN_SIZE_NORMAL);
167
168         if (pXformer == null)
169         {
170                 result r = GetLastResult();
171
172                 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
173         }
174
175         return pXformer;
176 }
177
178 _ICoordinateSystemTransformer*
179 _CoordinateSystem::GetTransformerN(_LogicalResolution sourceLogicalResolution, _LogicalResolution destLogicalResolution)
180 {
181         _PhysicalResolution physicalResolution = RESOLUTION_PHYSICAL_DEFAULT;
182
183         switch (destLogicalResolution)
184         {
185         case RESOLUTION_LOGICAL_240:
186                 physicalResolution = RESOLUTION_PHYSICAL_WQVGA;
187                 break;
188         case RESOLUTION_LOGICAL_320:
189                 physicalResolution = RESOLUTION_PHYSICAL_HVGA;
190                 break;
191         case RESOLUTION_LOGICAL_480:
192                 physicalResolution = RESOLUTION_PHYSICAL_WVGA;
193                 break;
194         case RESOLUTION_LOGICAL_720:
195                 physicalResolution = RESOLUTION_PHYSICAL_HD;
196                 break;
197         case RESOLUTION_LOGICAL_800:
198                 physicalResolution = RESOLUTION_PHYSICAL_WXGA;
199                 break;
200         case RESOLUTION_LOGICAL_1080:
201                 physicalResolution = RESOLUTION_PHYSICAL_HD1080;
202                 break;
203         case RESOLUTION_LOGICAL_1600:
204                 physicalResolution = RESOLUTION_PHYSICAL_WQXGA;
205                 break;
206         default:
207                 physicalResolution = RESOLUTION_PHYSICAL_NONE;
208                 break;
209         }
210
211         return _CoordinateSystem::GetTransformerN(sourceLogicalResolution, physicalResolution);
212 }
213
214 _ICoordinateSystemTransformer*
215 _CoordinateSystem::GetTransformerN(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize, _PhysicalResolution physicalResolution, _BaseScreenSize physicalBaseScreenSize)
216 {
217         _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(logicalResolution, logicalBaseScreenSize, physicalResolution, physicalBaseScreenSize);
218
219         if (pXformer == null)
220         {
221                 result r = GetLastResult();
222
223                 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
224         }
225
226         return pXformer;
227 }
228
229
230 _CoordinateSystem::_CoordinateSystem(void)
231         : __pImpl(null)
232 {
233 }
234
235 _CoordinateSystem::~_CoordinateSystem(void)
236 {
237         delete __pImpl;
238 }
239
240 result
241 _CoordinateSystem::Initialize(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize)
242 {
243         _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
244
245         result r = pInstance->__Initialize(logicalResolution, logicalBaseScreenSize);
246
247         SysTryReturn(NID_GRP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
248
249         return r;
250 }
251
252 result
253 _CoordinateSystem::Initialize(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
254 {
255         _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
256
257         result r = pInstance->__Initialize(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
258
259         SysTryReturn(NID_GRP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
260
261         return r;
262 }
263
264 result
265 _CoordinateSystem::Reset(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize)
266 {
267         result r = E_SUCCESS;
268
269         std::auto_ptr<_CoordinateSystemImpl> pImpl(new _CoordinateSystemImpl());
270
271         SysTryReturnResult(NID_GRP, pImpl.get() != null, E_OUT_OF_MEMORY, "Insufficient memory.");
272
273         r = pImpl->Initialize(logicalResolution, logicalBaseScreenSize);
274
275         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
276
277         delete __pImpl;
278         __pImpl = pImpl.release();
279
280         return E_SUCCESS;
281 }
282
283 result
284 _CoordinateSystem::Reset(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
285 {
286         result r = E_SUCCESS;
287
288         std::auto_ptr<_CoordinateSystemImpl> pImpl(new _CoordinateSystemImpl());
289
290         SysTryReturnResult(NID_GRP, pImpl.get() != null, E_OUT_OF_MEMORY, "Insufficient memory.");
291
292         r = pImpl->Initialize(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
293
294         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
295
296         delete __pImpl;
297         __pImpl = pImpl.release();
298
299         return E_SUCCESS;
300 }
301
302 _LogicalResolution
303 _CoordinateSystem::GetNativeLogicalResolution(void) const
304 {
305         result r = E_SUCCESS;
306
307         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
308
309         return __pImpl->GetNativeLogicalResolution();
310
311 CATCH:
312         SetLastResult(r);
313
314         return RESOLUTION_LOGICAL_NONE;
315 }
316
317 _BaseScreenSize
318 _CoordinateSystem::GetNativeLogicalBaseScreenSize(void) const
319 {
320         result r = E_SUCCESS;
321
322         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
323
324         return __pImpl->GetNativeLogicalBaseScreenSize();
325
326 CATCH:
327         SetLastResult(r);
328
329         return BASE_SCREEN_SIZE_NONE;
330 }
331
332 _BaseScreenSize
333 _CoordinateSystem::GetLogicalBaseScreenSize(void) const
334 {
335         result r = E_SUCCESS;
336
337         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
338
339         return __pImpl->GetLogicalBaseScreenSize();
340
341 CATCH:
342         SetLastResult(r);
343
344         return BASE_SCREEN_SIZE_NONE;
345 }
346
347 int
348 _CoordinateSystem::GetLogicalResolutionInt(void) const
349 {
350         result r = E_SUCCESS;
351
352         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
353
354         return __pImpl->GetLogicalResolutionInt();
355
356 CATCH:
357         SetLastResult(r);
358
359         return 0;
360 }
361
362 _LogicalResolution
363 _CoordinateSystem::GetLogicalResolution(void) const
364 {
365         result r = E_SUCCESS;
366
367         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
368
369         return __pImpl->GetLogicalResolution();
370
371 CATCH:
372         SetLastResult(r);
373
374         return RESOLUTION_LOGICAL_NONE;
375 }
376
377 _PhysicalResolution
378 _CoordinateSystem::GetPhysicalResolution(void) const
379 {
380         result r = E_SUCCESS;
381
382         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
383
384         return __pImpl->GetPhysicalResolution();
385
386 CATCH:
387         SetLastResult(r);
388
389         return RESOLUTION_PHYSICAL_NONE;
390 }
391
392 Dimension
393 _CoordinateSystem::GetPhysicalResolutionDim(void) const
394 {
395         result r = E_SUCCESS;
396
397         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
398
399         return __pImpl->GetPhysicalResolutionDim();
400
401 CATCH:
402         SetLastResult(r);
403
404         return Dimension(0,0);
405 }
406
407 _BaseScreenSize
408 _CoordinateSystem::GetPhysicalBaseScreenSize(void) const
409 {
410         result r = E_SUCCESS;
411
412         SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
413
414         return __pImpl->GetPhysicalBaseScreenSize();
415
416 CATCH:
417         SetLastResult(r);
418
419         return BASE_SCREEN_SIZE_NONE;
420 }
421
422 result
423 _CoordinateSystem::__Initialize(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize)
424 {
425         result r = Reset(logicalResolution, logicalBaseScreenSize);
426
427         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
428
429         return E_SUCCESS;
430 }
431
432 result
433 _CoordinateSystem::__Initialize(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
434 {
435         result r = Reset(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
436
437         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
438
439         return E_SUCCESS;
440 }
441
442 }} // Tizen::Graphics
443
444 // temporary test code for tizen 2.0
445 namespace Tizen { namespace Graphics
446 {
447
448 void
449 _SetLogicalRes480(void)
450 {
451         _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
452
453         pInstance->Reset(RESOLUTION_LOGICAL_480, BASE_SCREEN_SIZE_NORMAL);
454 }
455
456 void
457 _SetLogicalRes720(void)
458 {
459         _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
460
461         pInstance->Reset(RESOLUTION_LOGICAL_720, BASE_SCREEN_SIZE_NORMAL);
462 }
463
464 }} // Tizen::Graphics
465
466