Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / FUiEffectsEffect.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  * @file        FUiEffectsEffect.cpp
19  * @brief       This file contains implementation of Effect class.
20  */
21
22 #include <FUiEffectsEffect.h>
23
24 #include <iostream>
25 #include <fstream>
26 #include <string>
27
28 #include <FBaseColIList.h>
29 #include <FBaseSysLog.h>
30 #include <FBaseErrors.h>
31 #include <FUiTouchEventInfo.h>
32
33 #include <FUiEffectsEffectManager.h>
34 #include <FUiEffectsEffectTouchInfo.h>
35 #include <FUiEffectsIEffectEventListener.h>
36 #include <FUiEffectsIEffectResourceProvider.h>
37
38 #include "FUiEffects_EffectManagerImpl.h"
39 #include <FUiEffects_LoggingProfiler.h>
40 #include "FUiEffects_EffectErrorMessages.h"
41 #include <FUiEffects_RuntimeIEffectModelListener.h>
42 #include <FUiEffects_ParserEffectParser.h>
43 #include <FUiEffects_EffectImpl.h>
44
45 using namespace Tizen::Ui::Controls;
46 using namespace Tizen::Base::Runtime;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Base::Collection;
49
50 using namespace Tizen::Ui::Effects::_Runtime;
51 using namespace Tizen::Ui::Effects::_Renderer;
52 using namespace Tizen::Ui::Effects::_Parser;
53 using namespace Tizen::Ui::Effects;
54 using namespace Tizen::Ui::Effects::_Utils;
55 using namespace std;
56
57 using namespace Tizen::Graphics;
58 using namespace Tizen::Base;
59
60 namespace Tizen { namespace Ui { namespace Effects
61 {
62
63 result
64 Effect::Start(void)
65 {
66         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
67
68         SetLastResult(E_SUCCESS);
69
70         ArrayList emptyList;
71         result r = emptyList.Construct();
72         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
73
74         r = __pEffectImpl->Start(emptyList);
75         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
76         return r;
77 }
78
79 result
80 Effect::Start(const Tizen::Base::Collection::IList& effectStartInfo)
81 {
82         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
83
84         SetLastResult(E_SUCCESS);
85         result r = __pEffectImpl->Start(effectStartInfo);
86         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
87         return r;
88 }
89
90 result
91 Effect::Stop(void)
92 {
93         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
94
95         SetLastResult(E_SUCCESS);
96         result r = __pEffectImpl->Stop();
97         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
98         return r;
99 }
100
101 result
102 Effect::SetRenderTarget(Tizen::Ui::Control* pControl)
103 {
104         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
105
106         SetLastResult(E_SUCCESS);
107         result r = __pEffectImpl->SetRenderTarget(pControl);
108         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
109
110         return r;
111 }
112
113 result
114 Effect::FeedTouchPressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Point& offset)
115 {
116         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
117
118         SetLastResult(E_SUCCESS);
119         result r = __pEffectImpl->FeedTouchPressEvent(touchEventInfo, offset);
120         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121         return r;
122 }
123
124 result
125 Effect::FeedTouchPressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo)
126 {
127         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
128
129         SetLastResult(E_SUCCESS);
130         result r = __pEffectImpl->FeedTouchPressEvent(touchEventInfo, Point(0, 0));
131         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
132         return r;
133 }
134
135 result
136 Effect::FeedTouchMoveEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Point& offset)
137 {
138         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
139
140         SetLastResult(E_SUCCESS);
141         result r = __pEffectImpl->FeedTouchMoveEvent(touchEventInfo, offset);
142         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
143         return r;
144 }
145
146 result
147 Effect::FeedTouchMoveEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo)
148 {
149         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
150
151         SetLastResult(E_SUCCESS);
152         result r = __pEffectImpl->FeedTouchMoveEvent(touchEventInfo, Point(0, 0));
153         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154         return r;
155 }
156
157 result
158 Effect::FeedTouchReleaseEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Point& offset)
159 {
160         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
161
162         SetLastResult(E_SUCCESS);
163         result r = __pEffectImpl->FeedTouchReleaseEvent(touchEventInfo, offset);
164         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
165         return r;
166 }
167
168 result
169 Effect::FeedTouchReleaseEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo)
170 {
171         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
172
173         SetLastResult(E_SUCCESS);
174         result r = __pEffectImpl->FeedTouchReleaseEvent(touchEventInfo, Point(0, 0));
175         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
176         return r;
177 }
178
179 result
180 Effect::FeedTouchDoublePressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Point& offset)
181 {
182         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
183
184         SetLastResult(E_SUCCESS);
185         result r = __pEffectImpl->FeedTouchDoublePressEvent(touchEventInfo, offset);
186         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
187         return r;
188 }
189
190 result
191 Effect::FeedTouchDoublePressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo)
192 {
193         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
194
195         SetLastResult(E_SUCCESS);
196         result r = __pEffectImpl->FeedTouchDoublePressEvent(touchEventInfo, Point(0, 0));
197         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
198         return r;
199 }
200
201 result
202 Effect::SetBitmap(long bitmapId, const Tizen::Graphics::Bitmap& bitmap)
203 {
204         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
205
206         SetLastResult(E_SUCCESS);
207         result r = __pEffectImpl->SetBitmap(bitmapId, bitmap);
208         SysTryReturn(NID_UI_EFFECT, !(r == E_OUT_OF_MEMORY), E_OPERATION_FAILED, E_OPERATION_FAILED, "[%s] Propagating.", GetErrorMessage(r));
209         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
210         return r;
211 }
212
213 bool
214 Effect::IsRunning(void) const
215 {
216         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
217
218         SetLastResult(E_SUCCESS);
219         bool isRunning = __pEffectImpl->IsRunning();
220         result r = GetLastResult();
221         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, isRunning, r, "[%s] Propagating.", GetErrorMessage(r));
222         return isRunning;
223 }
224
225 EffectType
226 Effect::GetType(void) const
227 {
228         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
229
230         SetLastResult(E_SUCCESS);
231         EffectType effectType = __pEffectImpl->GetType();
232         result r = GetLastResult();
233         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, effectType, r, "[%s] Propagating.", GetErrorMessage(r));
234         return effectType;
235 }
236
237 String
238 Effect::GetName(void) const
239 {
240         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
241
242         SetLastResult(E_SUCCESS);
243         String effectName = __pEffectImpl->GetName();
244         result r = GetLastResult();
245         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, effectName, r, "[%s] Propagating.", GetErrorMessage(r));
246         return effectName;
247 }
248
249 void
250 Effect::SetEffectEventListener(IEffectEventListener* pListener)
251 {
252         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
253
254         SetLastResult(E_SUCCESS);
255         __pEffectImpl->SetEffectEventListener(pListener);
256         result r = GetLastResult();
257         SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
258 }
259
260 IEffectEventListener*
261 Effect::GetEffectEventListener(void) const
262 {
263         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
264
265         SetLastResult(E_SUCCESS);
266         IEffectEventListener* listener = null;
267         listener = __pEffectImpl->GetEffectEventListener();
268         result r = GetLastResult();
269         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, listener, r, "[%s] Propagating.", GetErrorMessage(r));
270         return listener;
271 }
272
273 void
274 Effect::SetResourceProvider(IEffectResourceProvider* pProvider)
275 {
276         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
277
278         SetLastResult(E_SUCCESS);
279         __pEffectImpl->SetResourceProvider(pProvider);
280         result r = GetLastResult();
281         SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
282 }
283
284 IEffectResourceProvider*
285 Effect::GetResourceProvider(void) const
286 {
287         SysAssertf(__pEffectImpl != null, _UiEffectError::INTERNAL_ERROR);
288
289         SetLastResult(E_SUCCESS);
290         IEffectResourceProvider* provider = null;
291         provider = __pEffectImpl->GetResourceProvider();
292         result r = GetLastResult();
293         SysTryReturn(NID_UI_EFFECT, r == E_SUCCESS, provider, r, "[%s] Propagating.", GetErrorMessage(r));
294         return provider;
295 }
296
297 Effect::Effect(void)
298         : __pEffectImpl(null)
299 {
300         __pEffectImpl = new (std::nothrow) _EffectImpl(*this);
301         SysTryReturnVoidResult(NID_UI_EFFECT, __pEffectImpl != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
302
303         __pEffectImpl->InitializeEffect();
304 }
305
306
307 Effect::~Effect(void)
308 {
309         if (__pEffectImpl != null)
310         {
311                 delete __pEffectImpl;
312                 __pEffectImpl = null;
313         }
314 }
315
316 }}} // Tizen::Ui::Effects