2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FGrp_CoordinateSystem.cpp
20 * @brief This is the implementation file for _CoordinateSystem class.
28 #include <FBaseErrors.h>
29 #include <FBaseResult.h>
31 #include <FBaseInternalTypes.h>
32 #include <FApp_AppInfo.h>
33 #include <FBaseSysLog.h>
35 #include "FGrp_CoordinateSystem.h"
36 #include "FGrp_CoordinateSystemImpl.h"
37 #include "FGrp_Screen.h"
39 using namespace Tizen::Base;
42 namespace Tizen { namespace Graphics
45 _CoordinateSystem _CoordinateSystem::__instance;
46 _CoordinateSystem* _CoordinateSystem::__pTheInstance = null;
50 _CoordinateSystem::__InitCoordinateSystem(void)
52 if (__instance.__pImpl == null)
54 result r = __instance.__Initialize(_Screen::GetWidth(), BASE_SCREEN_SIZE_DEFAULT, Dimension(_Screen::GetWidth(), _Screen::GetHeight()), BASE_SCREEN_SIZE_DEFAULT);
56 SysAssertf(!IsFailed(r), "[%s] Propagating.", GetErrorMessage(r));
59 __pTheInstance = &__instance;
63 _CoordinateSystem::GetInstance(void)
65 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
67 if (__pTheInstance == null)
69 pthread_once(&once_block, __InitCoordinateSystem);
72 return __pTheInstance;
76 _CoordinateSystem::SetTransformEnabled(bool enabled)
80 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
82 __pImpl->SetTransformEnabled(enabled);
89 _CoordinateSystem::IsTransformEnabled(void) const
93 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
95 return __pImpl->IsTransformEnabled();
103 _ICoordinateSystemTransformer*
104 _CoordinateSystem::GetTransformer(void)
106 result r = E_SUCCESS;
108 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
110 return __pImpl->GetTransformer();
118 _ICoordinateSystemTransformer*
119 _CoordinateSystem::GetInverseTransformer(void)
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.");
124 return __pImpl->GetInverseTransformer();
132 _ICoordinateSystemTransformer*
133 _CoordinateSystem::GetTransformerN(const Dimension& srcDim, const Dimension& trgDim)
135 _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(srcDim, trgDim);
137 if (pXformer == null)
139 result r = GetLastResult();
141 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
147 _ICoordinateSystemTransformer*
148 _CoordinateSystem::GetTransformerN(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
150 _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
152 if (pXformer == null)
154 result r = GetLastResult();
156 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
163 _ICoordinateSystemTransformer*
164 _CoordinateSystem::GetTransformerN(_LogicalResolution logicalResolution, _PhysicalResolution physicalResolution)
166 _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(logicalResolution, BASE_SCREEN_SIZE_NORMAL, physicalResolution, BASE_SCREEN_SIZE_NORMAL);
168 if (pXformer == null)
170 result r = GetLastResult();
172 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
178 _ICoordinateSystemTransformer*
179 _CoordinateSystem::GetTransformerN(_LogicalResolution sourceLogicalResolution, _LogicalResolution destLogicalResolution)
181 _PhysicalResolution physicalResolution = RESOLUTION_PHYSICAL_DEFAULT;
183 switch (destLogicalResolution)
185 case RESOLUTION_LOGICAL_240:
186 physicalResolution = RESOLUTION_PHYSICAL_WQVGA;
188 case RESOLUTION_LOGICAL_320:
189 physicalResolution = RESOLUTION_PHYSICAL_HVGA;
191 case RESOLUTION_LOGICAL_480:
192 physicalResolution = RESOLUTION_PHYSICAL_WVGA;
194 case RESOLUTION_LOGICAL_720:
195 physicalResolution = RESOLUTION_PHYSICAL_HD;
197 case RESOLUTION_LOGICAL_800:
198 physicalResolution = RESOLUTION_PHYSICAL_WXGA;
200 case RESOLUTION_LOGICAL_1080:
201 physicalResolution = RESOLUTION_PHYSICAL_HD1080;
203 case RESOLUTION_LOGICAL_1600:
204 physicalResolution = RESOLUTION_PHYSICAL_WQXGA;
207 physicalResolution = RESOLUTION_PHYSICAL_NONE;
211 return _CoordinateSystem::GetTransformerN(sourceLogicalResolution, physicalResolution);
214 _ICoordinateSystemTransformer*
215 _CoordinateSystem::GetTransformerN(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize, _PhysicalResolution physicalResolution, _BaseScreenSize physicalBaseScreenSize)
217 _ICoordinateSystemTransformer* pXformer = _CoordinateSystemImpl::GetTransformerN(logicalResolution, logicalBaseScreenSize, physicalResolution, physicalBaseScreenSize);
219 if (pXformer == null)
221 result r = GetLastResult();
223 SysLog(NID_GRP, "[%s] Propagating.", GetErrorMessage(r));
230 _CoordinateSystem::_CoordinateSystem(void)
235 _CoordinateSystem::~_CoordinateSystem(void)
241 _CoordinateSystem::Initialize(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize)
243 _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
245 result r = pInstance->__Initialize(logicalResolution, logicalBaseScreenSize);
247 SysTryReturn(NID_GRP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
253 _CoordinateSystem::Initialize(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
255 _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
257 result r = pInstance->__Initialize(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
259 SysTryReturn(NID_GRP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
265 _CoordinateSystem::Reset(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize)
267 result r = E_SUCCESS;
269 std::auto_ptr<_CoordinateSystemImpl> pImpl(new _CoordinateSystemImpl());
271 SysTryReturnResult(NID_GRP, pImpl.get() != null, E_OUT_OF_MEMORY, "Insufficient memory.");
273 r = pImpl->Initialize(logicalResolution, logicalBaseScreenSize);
275 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
278 __pImpl = pImpl.release();
284 _CoordinateSystem::Reset(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
286 result r = E_SUCCESS;
288 std::auto_ptr<_CoordinateSystemImpl> pImpl(new _CoordinateSystemImpl());
290 SysTryReturnResult(NID_GRP, pImpl.get() != null, E_OUT_OF_MEMORY, "Insufficient memory.");
292 r = pImpl->Initialize(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
294 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
297 __pImpl = pImpl.release();
303 _CoordinateSystem::GetNativeLogicalResolution(void) const
305 result r = E_SUCCESS;
307 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
309 return __pImpl->GetNativeLogicalResolution();
314 return RESOLUTION_LOGICAL_NONE;
318 _CoordinateSystem::GetNativeLogicalBaseScreenSize(void) const
320 result r = E_SUCCESS;
322 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
324 return __pImpl->GetNativeLogicalBaseScreenSize();
329 return BASE_SCREEN_SIZE_NONE;
333 _CoordinateSystem::GetLogicalBaseScreenSize(void) const
335 result r = E_SUCCESS;
337 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
339 return __pImpl->GetLogicalBaseScreenSize();
344 return BASE_SCREEN_SIZE_NONE;
348 _CoordinateSystem::GetLogicalResolutionInt(void) const
350 result r = E_SUCCESS;
352 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
354 return __pImpl->GetLogicalResolutionInt();
363 _CoordinateSystem::GetLogicalResolution(void) const
365 result r = E_SUCCESS;
367 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
369 return __pImpl->GetLogicalResolution();
374 return RESOLUTION_LOGICAL_NONE;
378 _CoordinateSystem::GetPhysicalResolution(void) const
380 result r = E_SUCCESS;
382 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
384 return __pImpl->GetPhysicalResolution();
389 return RESOLUTION_PHYSICAL_NONE;
393 _CoordinateSystem::GetPhysicalResolutionDim(void) const
395 result r = E_SUCCESS;
397 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
399 return __pImpl->GetPhysicalResolutionDim();
404 return Dimension(0,0);
408 _CoordinateSystem::GetPhysicalBaseScreenSize(void) const
410 result r = E_SUCCESS;
412 SysTryCatch(NID_GRP, __pImpl, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance has not been initialized yet.");
414 return __pImpl->GetPhysicalBaseScreenSize();
419 return BASE_SCREEN_SIZE_NONE;
423 _CoordinateSystem::__Initialize(_LogicalResolution logicalResolution, _BaseScreenSize logicalBaseScreenSize)
425 result r = Reset(logicalResolution, logicalBaseScreenSize);
427 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
433 _CoordinateSystem::__Initialize(int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize)
435 result r = Reset(srcResolution, srcBaseScreenSize, destResolution, destBaseScreenSize);
437 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
442 }} // Tizen::Graphics
444 // temporary test code for tizen 2.0
445 namespace Tizen { namespace Graphics
449 _SetLogicalRes480(void)
451 _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
453 pInstance->Reset(RESOLUTION_LOGICAL_480, BASE_SCREEN_SIZE_NORMAL);
457 _SetLogicalRes720(void)
459 _CoordinateSystem* pInstance = _CoordinateSystem::GetInstance();
461 pInstance->Reset(RESOLUTION_LOGICAL_720, BASE_SCREEN_SIZE_NORMAL);
464 }} // Tizen::Graphics