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 FUiAnim_VisualElementSurfaceImpl.cpp
20 * @brief This file contains implementation of _VisualElementSurfaceImpl class
22 * This file contains implementation _VisualElementSurfaceImpl class.
25 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseErrorDefine.h>
28 #include <FGrpBufferInfo.h>
29 #include <FUiAnimVisualElementSurface.h>
31 #include "FUiAnim_VisualElementCoordinateSystem.h"
32 #include "FUiAnim_EflVisualElementSurfaceImpl.h"
33 #include "FUiAnim_VisualElementSurfaceImpl.h"
34 #include "FUiAnim_DisplayContextImpl.h"
35 #include "FUiAnim_EflLayer.h"
38 using namespace Tizen::Base;
39 using namespace Tizen::Graphics;
41 namespace Tizen { namespace Ui { namespace Animations
45 _VisualElementSurfaceImpl::CreateSurfaceN(const Handle handle, const Tizen::Graphics::Dimension& size)
47 SysTryReturn(NID_UI_ANIM, size.width >= 0 && size.height >= 0, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Surface size is out of range. size = (%d, %d)", size.width, size.height);
48 SysTryReturn(NID_UI_ANIM, handle != 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. The handle is invalid.");
50 unique_ptr<VisualElementSurface> pSurface(new(std::nothrow) VisualElementSurface());
51 SysTryReturn(NID_UI_ANIM, pSurface , null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
53 unique_ptr<_EflVisualElementSurfaceImpl> pImpl(new (std::nothrow) _EflVisualElementSurfaceImpl(handle, size));
54 SysTryReturn(NID_UI_ANIM, pImpl, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. The handle is invalid.");
55 pSurface->__pVisualElementSurfaceImpl = pImpl.release();
57 return pSurface.release();
61 _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(const DisplayContext& displayContext, const Handle handle, const Tizen::Graphics::Dimension& size)
63 SysTryReturn(NID_UI_ANIM, size.width >= 0 && size.height >= 0, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Surface size is out of range. size = (%d, %d)", size.width, size.height);
64 SysTryReturn(NID_UI_ANIM, handle != 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. The handle is invalid.");
66 unique_ptr<VisualElementSurface> pSurface(new(std::nothrow) VisualElementSurface());
67 SysTryReturn(NID_UI_ANIM, pSurface , null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
69 _DisplayContextImpl* pDisplayContext = const_cast<_DisplayContextImpl*>(_DisplayContextImpl::GetInstance(displayContext));
70 SysTryReturn(NID_UI_ANIM, pDisplayContext != null, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. DisplayContext is invalid.");
72 _EflLayer* pLayer = dynamic_cast<_EflLayer*>(pDisplayContext->GetNativeLayer());
73 SysTryReturn(NID_UI_ANIM, pLayer != null, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. DisplayContext is invalid.");
75 unique_ptr<_EflVisualElementSurfaceImpl> pImpl(new (std::nothrow) _EflVisualElementSurfaceImpl(reinterpret_cast<Handle>(pLayer), handle, size));
76 SysTryReturn(NID_UI_ANIM, pImpl, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. The handle is invalid.");
77 result r = GetLastResult();
78 SysTryReturn(NID_UI_ANIM, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
80 pSurface->__pVisualElementSurfaceImpl = pImpl.release();
82 return pSurface.release();
85 _VisualElementSurfaceImpl*
86 _VisualElementSurfaceImpl::CreateInstanceN(const DisplayContext& displayContext, const Tizen::Graphics::Dimension& size)
88 SysTryReturn(NID_UI_ANIM, size.width >= 0 && size.height >= 0, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Surface size is out of range. size = (%d, %d)", size.width, size.height);
90 _DisplayContextImpl* pDisplayContext = const_cast<_DisplayContextImpl*>(_DisplayContextImpl::GetInstance(displayContext));
91 SysTryReturn(NID_UI_ANIM, pDisplayContext != null, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. DisplayContext is invalid.");
93 _EflLayer* pLayer = dynamic_cast<_EflLayer*>(pDisplayContext->GetNativeLayer());
94 SysTryReturn(NID_UI_ANIM, pLayer != null, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. DisplayContext is invalid.");
96 _VisualElementSurfaceImpl* pVisualElementSurfaceImpl = new (std::nothrow) _EflVisualElementSurfaceImpl(reinterpret_cast<Handle>(pLayer), size);
97 result r = GetLastResult();
98 SysTryReturn(NID_UI_ANIM, pVisualElementSurfaceImpl != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
99 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
101 return pVisualElementSurfaceImpl;
104 delete pVisualElementSurfaceImpl;
108 _VisualElementSurfaceImpl::_VisualElementSurfaceImpl(const Dimension& size)
110 , __logicalSize(size)
115 _VisualElementSurfaceImpl::SetImage(const String& fileName)
120 _VisualElementSurfaceImpl::~_VisualElementSurfaceImpl(void)
125 _VisualElementSurfaceImpl::AddRef(void)
131 _VisualElementSurfaceImpl::Release(void)
133 if (likely(__refCount >= 1))
136 if (likely(__refCount == 0))
147 _VisualElementSurfaceImpl::GetReferenceCount(void) const
153 _VisualElementSurfaceImpl::GetBufferInfo(BufferInfo& bufferInfo) const
159 _VisualElementSurfaceImpl::GetPhysicalSize(void) const
165 _VisualElementSurfaceImpl::Equals(const Tizen::Base::Object& obj) const
167 const VisualElementSurface* pSurface = dynamic_cast< const VisualElementSurface* >(&obj);
168 if (pSurface == null)
173 const _VisualElementSurfaceImpl* pSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pSurface);
174 if (pSurfaceImpl == this)
179 return (this == pSurfaceImpl);
183 _VisualElementSurfaceImpl::GetHashCode(void) const
185 return reinterpret_cast< int >(this);
188 }}} // Tizen::Ui::Animations