Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / FUiEffects_EffectImpl.h
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        FUiEffects_EffectImpl.h
19  * @brief               This is the header file for the _EffectImpl class.
20  */
21
22 #ifndef _FUI_EFFECTS_INTERNAL_EFFECT_IMPL_H_
23 #define _FUI_EFFECTS_INTERNAL_EFFECT_IMPL_H_
24
25 #include <map>
26 #include <set>
27 #include <FBaseRtITimerEventListener.h>
28 #include <FUiEffects_ParserEffectParser.h>
29 #include <FUiEffects_RendererEffectRenderer.h>
30 #include <FUiEffects_EffectTimer.h>
31
32 namespace Tizen { namespace Ui {
33 class Control;
34 class TouchEventInfo;
35 }} // Tizen::Ui
36
37 namespace Tizen { namespace Base { namespace Collection {
38 class IList;
39 }}} // Tizen::Base::Collection
40
41 namespace Tizen { namespace Graphics {
42 class Point;
43 class Bitmap;
44 }} // Tizen::Graphics
45
46 namespace Tizen { namespace Ui { namespace Effects
47 {
48
49 class Effect;
50 class IEffectEventListener;
51 class IEffectResourceProvider;
52 class _EffectInstance;
53 class _EffectImpl;
54
55 typedef std::set<Effect*> EffectsSet;
56
57 typedef void* EGLSurface;
58 typedef std::map<const Tizen::Ui::Control*, EGLSurface> RenderControlsMap;
59 typedef std::pair<const Tizen::Ui::Control*, EGLSurface> RenderControlsMapPair;
60
61 typedef std::map<const Effect*, const Tizen::Ui::Control*> EffectsControlsMap;
62 typedef std::set<const Tizen::Ui::Control*> ControlsSet;
63
64 class _EffectImpl
65         : public Tizen::Base::Runtime::ITimerEventListener
66         , public Tizen::Ui::Effects::_Runtime::IEffectModelListener
67         , virtual public Tizen::Base::Runtime::IEventListener
68 {
69 public:
70
71         /**
72          * Binds the effect to Tizen::UI::Control for rendering effect.
73          *
74          * @since 2.0
75          *
76          * @return        An error code
77          * @param [in] control           Tizen::UI::Control whose content is filled by the effect
78          * @exception  E_SUCCESS                        The specified effect is bound with @c control successfully.
79          * @exception  E_OPERATION_FAILED       The system has failed to initialize the 3D system.
80          * @exception  E_INVALID_STATE          The specified effect has already started.
81          */
82         result SetRenderTarget(const Tizen::Ui::Control* pControl);
83
84         /**
85          * Starts Effect
86          *
87          * @since 2.0
88          *
89          * @return              An error code
90          * @param [in]  effectStartInfo         List of input arguments to be passed to OnEffectStarted function of the scripts.
91          *                                      All arguments should be represented in float data type
92          * @exception   E_INVALID_STATE     The effect specified started already
93          * @exception   E_OPERATION_FAILED      The system failed to start the effect specified.
94          *                                                                      The effect has a runtime error in script or the render target for this effect is not available
95          * @exception   E_SUCCESS                       The effect specified was successfully started
96          *
97          */
98         result Start(const Tizen::Base::Collection::IList& effectStartInfo);
99
100         /**
101          * Stops Effect
102          *
103          * @since 2.0
104          *
105          * @return              An error code
106          * @exception   E_INVALID_STATE The effect specified didn't start yet
107          * @exception   E_SUCCESS               The effect specified was successfully stopped
108          *
109          */
110         result Stop(void);
111
112         /**
113          * Informs an effect of a TouchPress event
114          *
115          * @since 2.0
116          *
117          * @return              An error code
118          * @param [in]  touchEventInfo          The touch event information
119          * @param [in]  offset                          The effect manager will regard the touch position in @c touchEventInfo translated by the @c offset
120          * @exception   E_INVALID_STATE     The effect specified didn't start yet
121          * @exception   E_OPERATION_FAILED      There was a runtime error in the OnTouchPressed script function or the effect is time-based
122          * @exception   E_SUCCESS                       Effect with such ID was successfully fed with TouchPress
123          *
124          */
125         result FeedTouchPressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
126
127         /**
128          * Informs an effect of a TouchMove event
129          *
130          * @since 2.0
131          *
132          * @return              An error code
133          * @param [in]  touchEventInfo          The touch event information
134          * @param [in]  offset                          The effect manager will regard the touch position in @c touchEventInfo translated by the @c offset
135          * @exception   E_INVALID_STATE     The effect specified didn't start yet
136          * @exception   E_OPERATION_FAILED      There was a runtime error in the OnTouchPressed script function or the effect is time-based
137          * @exception   E_SUCCESS                       Effect with such ID was successfully fed with TouchMove
138          *
139          */
140         result FeedTouchMoveEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
141
142         /**
143          * Informs an effect of a TouchRelease event
144          *
145          * @since 2.0
146          *
147          * @return              An error code
148          * @param [in]  touchEventInfo          The touch event information
149          * @param [in]  offset                          The effect manager will regard the touch position in @c touchEventInfo translated by the @c offset
150          * @exception   E_INVALID_STATE     The effect specified didn't start yet
151          * @exception   E_OPERATION_FAILED      There was a runtime error in the OnTouchPressed script function or the effect is time-based
152          * @exception   E_SUCCESS                       Effect with such ID was successfully fed with TouchRelease
153          *
154          */
155         result FeedTouchReleaseEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
156
157         /**
158          * Informs an effect of a TouchDoublePress event
159          *
160          * @since 2.0
161          *
162          * @return              An error code
163          * @param [in]  touchEventInfo          The touch event information
164          * @param [in]  offset                          The effect manager will regard the touch position in @c touchEventInfo translated by the @c offset
165          * @exception   E_INVALID_STATE     The effect specified didn't start yet
166          * @exception   E_OPERATION_FAILED      There was a runtime error in the OnTouchPressed script function or the effect is time-based
167          * @exception   E_SUCCESS                       Effect with such ID was successfully fed with TouchDoublePress
168          *
169          */
170         result FeedTouchDoublePressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
171
172         /**
173          * Updates the effect's bitmap which is used as a graphical surface in scripts
174          *
175          * @since 2.0
176          *
177          * @return              An error code
178          * @param [in]  bitmapId                        Id of a bitmap to be updated
179          * @param [in]  bitmap                          Bitmap content
180          * @exception   E_OPERATION_FAILED      Updating bitmap contents failed
181          * @exception   E_SUCCESS                       Bitmap was successfully updated
182          *
183          */
184         result SetBitmap(long bitmapId, const Tizen::Graphics::Bitmap& bitmap);
185
186         /**
187          * Gets the current state of the effect specified
188          *
189          * @since 2.0
190          *
191          * @return              @c true if the effect is running; @c false, otherwise
192          * @exception   E_SUCCESS               The effect state is successfully retrieved
193          *
194          */
195         bool IsRunning(void) const;
196
197         /**
198          * Gets Effect type
199          *
200          * @since 2.0
201          *
202          * @return              Type of effect
203          * @exception   E_SUCCESS               The effect type is successfully retrieved
204          *
205          */
206         EffectType GetType(void) const;
207
208         /**
209          * Gets the name of an effect
210          *
211          * @since 2.0
212          *
213          * @return              The name of the effect specified
214          * @exception   E_SUCCESS               The effect name is successfully retrieved
215          *
216          */
217         Tizen::Base::String GetName(void) const;
218
219         /**
220          * Sets the IEffectsEventListener instance to get notified when the state of the effect is changed
221          *
222          * @since 2.0
223          *
224          * @return              An error code
225          * @param [in]  pListener               The event listener to be set
226          * @exception   E_SUCCESS               The effect listener was successfully set
227          *
228          */
229         void SetEffectEventListener(IEffectEventListener* pListener);
230
231         /**
232          * Gets the IEffectsEventListener instance.
233          *
234          * @since 2.0
235          *
236          * @return        The event listener for specified effect.
237          */
238         IEffectEventListener* GetEffectEventListener(void) const;
239
240         /**
241          * Sets the IEffectsResourceProvider instance to get notified when resources are needed by the effect
242          *
243          * @since 2.0
244          *
245          * @return              An error code
246          * @param [in]  pProvider               The resource provider to provide the effect with bitmap resources
247          * @exception   E_SUCCESS               The effect resource provider was successfully set
248          *
249          */
250         void SetResourceProvider(IEffectResourceProvider* pProvider);
251
252         /**
253          * Gets the IEffectsResourceProvider instance.
254          *
255          * @since 2.0
256          *
257          * @return        The resource provider for specified effect.
258          */
259         IEffectResourceProvider* GetResourceProvider(void) const;
260
261 private:
262
263         /**
264          * The constructor
265          *
266          * @since 2.0
267          */
268         _EffectImpl(Effect& effect);
269
270         /**
271          * The destructor
272          *
273          * @since 2.0
274          */
275         virtual ~_EffectImpl(void);
276
277         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
278         _EffectImpl(const _EffectImpl& rhs);
279
280         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
281         _EffectImpl& operator=(const _EffectImpl& rhs);
282
283         /**
284          * Finds OpenGLES surface by Control's pointer
285          *
286          * @since 2.0
287          *
288          * @return              EGLSurface      OpenGL surface created for given control, EGL_NO_SURFACE if not found
289          * @param [in]  Control         UI Control
290          *
291          */
292         EGLSurface FindGlesSurface(const Tizen::Ui::Control* pControl) const;
293
294         /**
295          * Stops Effect Computing
296          *
297          * @since 2.0
298          *
299          * @param [in]  effect          Effect instance
300          * @exception   E_SYSTEM
301          *
302          */
303         void EffectModelTimerStop(void);
304
305         /**
306          * Implementation of ITimerEventListener::OnTimerExpired method - Triggering Effect Computing and Rendering
307          *
308          * @since 2.0
309          *
310          * @param [in]  timer   Tizen::Ui::Runtime::Timer instance
311          * @exception   E_FILE_NOT_FOUND        Effect with such ID doesn't exist
312          * @exception   E_SYSTEM
313          *
314          */
315         void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
316
317         /**
318          * Implementation of IEffectModelListener::OnEffectStarted method
319          *
320          * @since 2.0
321          *
322          * @param [in]  effectId        Id of an effect that requires handling
323          * @exception   E_FILE_NOT_FOUND        Effect with such ID doesn't exist
324          * @exception   E_NOT_JOINED    EventListener is not assigned
325          * @exception   E_SYSTEM
326          * @see                 IEffectModelListener in "FUiEffects_RuntimeIEffectModelListener.h"
327          *
328          */
329         void OnEffectStarted(void);
330
331         /**
332          * Implementation of IEffectModelListener::OnEffectFinished method
333          *
334          * @since 2.0
335          *
336          * @param [in]  effectId        Id of an effect that requires handling
337          * @param [in]  effectResult    One of possible options of Effect finishing
338          * @param [in]  bitmapId        Bitmap(s) which acts as Target after Effect finishing
339          * @exception   E_FILE_NOT_FOUND        Effect with such ID doesn't exist
340          * @exception   E_NOT_JOINED    EventListener is not assigned
341          * @exception   E_SYSTEM
342          * @see                 IEffectModelListener in "FUiEffects_RuntimeIEffectModelListener.h"
343          *
344          */
345         void OnEffectFinished(EffectResult effectResult, const Tizen::Ui::Effects::_Runtime::LastShownBitmapIdCollection& bitmapsTargetId); //TODO: List of bitmaps
346
347         /**
348          * Implementation of IEffectModelListener::OnBitmapRequested method
349          *
350          * @since 2.0
351          *
352          * @return              true    If User in C++ Application in IEffectResourceProvider::OnBitmapRequested implementation returns E_SUCCESS
353          *                              false   If User in C++ Application in IEffectResourceProvider::OnBitmapRequested implementation doesn't return E_SUCCESS
354          * @param [in]  effectId        Id of an effect that requires handling
355          * @param [in]  bitmapId        Bitmap that has to be updated
356          * @exception   E_FILE_NOT_FOUND        Effect with such ID doesn't exist
357          * @exception   E_NOT_JOINED    ResourceProvider is not assigned
358          * @exception   E_SYSTEM
359          * @see                 IEffectModelListener in "FUiEffects_RuntimeIEffectModelListener.h"
360          *
361          */
362         bool OnBitmapRequested(long bitmapId);
363
364         /**
365          * Creates a new effect from specialised  effect file
366          *
367          * @since 2.0
368          *
369          * @return              True if effect was initialised successfully and false otherwise
370          * @see                 EffectManager::CreateEffect()
371          *
372          */
373         void InitializeEffect(void);
374
375         /**
376          * Updates information about screen size if it was changed
377          *
378          * @since 2.0
379          *
380          * @see                 SetScreen()
381          *
382          */
383         void UpdateScreen(void);
384
385         /**
386          * Removes a pair (effect*, control*) from a accordingly container and deletes GL surface if it does not need more
387          *
388          * @since 2.0
389          *
390          */
391         void ReleaseRenderTarget(const Control& control);
392
393         /**
394          * Tries set a new render target for an effect.
395          * Releases old render target if successful (calls function ReleaseRenderTarget)
396          *
397          * @since 2.0
398          *
399          */
400         result SetRenderTargetInternal(const Tizen::Ui::Control& control, const Tizen::Ui::Control& controlOld);
401
402 private:
403         Effect* __pEffect;
404
405         static EffectsSet __effects;
406         static RenderControlsMap __renderControls;
407         static EffectsControlsMap __effectsControlsMapRegistered;
408         static ControlsSet __controlsSetPerforming;
409         static long __effectsCount;
410
411         /**
412          * @brief               Model instance
413          *
414          */
415         std::unique_ptr<_Runtime::IEffectModelManager> __pModel;
416
417
418         /**
419          * @brief               Renderer instance
420          *
421          */
422         _Renderer::EffectRendererUniquePtr __pRenderer;
423
424         /**
425          * @brief               Event Listener
426          *
427          */
428         IEffectEventListener* __pEventListener;
429
430         /**
431          * @brief               Resource Provider
432          *
433          */
434         IEffectResourceProvider* __pResourceProvider;
435
436         /**
437          * @brief               Timer for model updates
438          *
439          */
440         _EffectTimer __modelTimer;
441
442         /**
443          * @brief               Internal usage
444          *
445          */
446         bool __renderTargetSet;
447
448         friend class _EffectManagerImpl;
449         friend class Effect;
450 }; // _EffectImpl
451
452 }}} // Tizen::Ui::Effects
453
454 #endif // _FUI_EFFECTS_INTERNAL_EFFECT_IMPL_H_