Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_VisualElementSurfaceImpl.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        FUiAnim_VisualElementSurfaceImpl.cpp
20  * @brief       This file contains implementation of _VisualElementSurfaceImpl class
21  *
22  * This file contains implementation _VisualElementSurfaceImpl class.
23  */
24
25 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseErrorDefine.h>
28 #include <FGrpBufferInfo.h>
29 #include <FUiAnimVisualElementSurface.h>
30
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"
36
37 using namespace std;
38 using namespace Tizen::Base;
39 using namespace Tizen::Graphics;
40
41 namespace Tizen { namespace Ui { namespace Animations
42 {
43
44 VisualElementSurface*
45 _VisualElementSurfaceImpl::CreateSurfaceN(const Handle handle, const Tizen::Graphics::Dimension& size)
46 {
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.");
49
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.");
52
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();
56
57         return pSurface.release();
58 }
59
60 VisualElementSurface*
61 _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(const DisplayContext& displayContext, const Handle handle, const Tizen::Graphics::Dimension& size)
62 {
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.");
65
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.");
68
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.");
71
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.");
74
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));
79
80         pSurface->__pVisualElementSurfaceImpl =  pImpl.release();
81
82         return pSurface.release();
83 }
84
85 _VisualElementSurfaceImpl*
86 _VisualElementSurfaceImpl::CreateInstanceN(const DisplayContext& displayContext, const Tizen::Graphics::Dimension& size)
87 {
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);
89
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.");
92
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.");
95
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));
100
101         return pVisualElementSurfaceImpl;
102
103 CATCH:
104         delete pVisualElementSurfaceImpl;
105         return null;
106 }
107
108 _VisualElementSurfaceImpl::_VisualElementSurfaceImpl(const Dimension& size)
109         : __refCount(1)
110         , __logicalSize(size)
111 {
112 }
113
114 result
115 _VisualElementSurfaceImpl::SetImage(const String& fileName)
116 {
117         return E_SUCCESS;
118 }
119
120 _VisualElementSurfaceImpl::~_VisualElementSurfaceImpl(void)
121 {
122 }
123
124 void
125 _VisualElementSurfaceImpl::AddRef(void)
126 {
127         __refCount++;
128 }
129
130 bool
131 _VisualElementSurfaceImpl::Release(void)
132 {
133         if (likely(__refCount >= 1))
134         {
135                 __refCount--;
136                 if (likely(__refCount == 0))
137                 {
138                         delete this;
139                         return true;
140                 }
141         }
142
143         return false;
144 }
145
146 int
147 _VisualElementSurfaceImpl::GetReferenceCount(void) const
148 {
149         return __refCount;
150 }
151
152 result
153 _VisualElementSurfaceImpl::GetBufferInfo(BufferInfo& bufferInfo) const
154 {
155         return E_SUCCESS;
156 }
157
158 Dimension
159 _VisualElementSurfaceImpl::GetPhysicalSize(void) const
160 {
161         return Dimension();
162 }
163
164 bool
165 _VisualElementSurfaceImpl::Equals(const Tizen::Base::Object& obj) const
166 {
167         const VisualElementSurface* pSurface = dynamic_cast< const VisualElementSurface* >(&obj);
168         if (pSurface == null)
169         {
170                 return false;
171         }
172
173         const _VisualElementSurfaceImpl* pSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pSurface);
174         if (pSurfaceImpl == this)
175         {
176                 return true;
177         }
178
179         return (this == pSurfaceImpl);
180 }
181
182 int
183 _VisualElementSurfaceImpl::GetHashCode(void) const
184 {
185         return reinterpret_cast< int >(this);
186 }
187
188 }}}             // Tizen::Ui::Animations
189