Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_VisualElementSharedData.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_VisualElementSharedData.cpp
20  * @brief       This file contains implementation of _VisualElementSharedData class
21  *
22  * This file contains implementation _VisualElementSharedData class.
23  */
24
25 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseString.h>
28 #include <FUiAnimVisualElementSurface.h>
29
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiAnim_VisualElementSharedData.h"
32 #include "FUiAnim_VisualElementSurfaceImpl.h"
33 #include "FUiAnim_INativeNode.h"
34 #include "FUiAnim_NativeLayer.h"
35
36 using namespace std;
37
38 namespace Tizen { namespace Ui { namespace Animations
39 {
40
41 _VisualElementSharedData::_VisualElementSharedData(void)
42         : invalidatedNativeProps(-1)
43         , surfaceChanged(false)
44         , pNativeNode(null)
45         , pSurface(null)
46         , invalidatedRegion(0.0f, 0.0f, 0.0f, 0.0f)
47         , drawOnPresentation(false)
48         , needSurface(true)
49         , redrawOnResize(false)
50         , isSurfaceOpaque(true)
51         , fixedSurfaceSize(false)
52         , invalidationLockCount(0)
53         , updateRegion(0.0f, 0.0f, 0.0f, 0.0f)
54         , pAnimationProvider(null)
55         , pContentProvider(null)
56         , pEventListener(null)
57         , name("")
58         , pUserData(null)
59         , __refCount(1)
60 {
61 }
62
63 _VisualElementSharedData::~_VisualElementSharedData(void)
64 {
65         if (pSurface)
66         {
67                 delete pSurface;
68                 pSurface = null;
69         }
70
71         if (pNativeNode)
72         {
73                 delete pNativeNode;
74         }
75 }
76
77 result
78 _VisualElementSharedData::Construct(void)
79 {
80         ClearLastResult();
81         SysAssert(pNativeNode == null);
82
83         pNativeNode = _INativeNode::CreateInstanceN();
84         SysTryReturnResult(NID_UI, pNativeNode, E_OUT_OF_MEMORY, "Memory allocation failed.");
85
86         return E_SUCCESS;
87 }
88
89 void
90 _VisualElementSharedData::AddRef(void)
91 {
92         __refCount++;
93 }
94
95 void
96 _VisualElementSharedData::Release(void)
97 {
98         if (__refCount >= 1)
99         {
100                 __refCount--;
101                 if (__refCount == 0)
102                 {
103                         delete this;
104                 }
105
106                 return;
107         }
108
109         // error reference counting.........
110 }
111
112 int
113 _VisualElementSharedData::GetReferenceCount(void) const
114 {
115         return __refCount;
116 }
117
118 void
119 _VisualElementSharedData::LockInvalidate(bool lock)
120 {
121         if (lock)
122         {
123                 invalidationLockCount++;
124         }
125         else if (invalidationLockCount >= 1)
126         {
127                 invalidationLockCount--;
128         }
129 }
130
131 result
132 _VisualElementSharedData::CreateSurface(const Tizen::Graphics::Dimension& size, _NativeLayer& layer)
133 {
134         unique_ptr<VisualElementSurface> pNewSurface(_VisualElementSurfaceImpl::CreateSurfaceN((const Handle)&layer, size));
135         SysTryReturnResult(NID_UI, pNewSurface, E_OUT_OF_MEMORY, "Memory allocation failed.");
136
137         if (pSurface)
138         {
139                 delete pSurface;
140                 pSurface = null;
141         }
142
143         pSurface = pNewSurface.release();
144         return E_SUCCESS;
145 }
146
147 result
148 _VisualElementSharedData::SetImage(const Tizen::Base::String& fileName)
149 {
150         SysTryReturnResult(NID_UI, pNativeNode, E_INVALID_STATE, "The Native Node is invalid.");
151         SysTryReturnResult(NID_UI, pSurface, E_INVALID_STATE, "The Native Node is invalid.");
152
153         _VisualElementSurfaceImpl* pImpl = _VisualElementSurfaceImpl::GetInstance(*pSurface);
154         SysTryReturnResult(NID_UI, pImpl, E_SYSTEM, "A system error has been occurred.");
155         SysTryReturnResult(NID_UI, pImpl->SetImage(fileName) == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
156
157         return E_SUCCESS;
158 }
159
160 void
161 _VisualElementSharedData::RemoveSurface(_VisualElementImpl& presentation)
162 {
163         if (likely(pNativeNode))
164         {
165                 pNativeNode->Reconfigure(null, presentation, true);
166         }
167
168         delete pSurface;
169         pSurface = null;
170 }
171
172 }}}             // Tizen::Ui::Animations
173