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.
18 * @file FUiEffects_EffectImpl.h
19 * @brief This is the header file for the _EffectImpl class.
22 #ifndef _FUI_EFFECTS_INTERNAL_EFFECT_IMPL_H_
23 #define _FUI_EFFECTS_INTERNAL_EFFECT_IMPL_H_
27 #include <FBaseRtITimerEventListener.h>
28 #include <FUiEffects_ParserEffectParser.h>
29 #include <FUiEffects_RendererEffectRenderer.h>
30 #include <FUiEffects_EffectTimer.h>
32 namespace Tizen { namespace Ui {
37 namespace Tizen { namespace Base { namespace Collection {
39 }}} // Tizen::Base::Collection
41 namespace Tizen { namespace Graphics {
46 namespace Tizen { namespace Ui { namespace Effects
50 class IEffectEventListener;
51 class IEffectResourceProvider;
52 class _EffectInstance;
55 typedef std::set<Effect*> EffectsSet;
57 typedef void* EGLSurface;
58 typedef std::map<const Tizen::Ui::Control*, EGLSurface> RenderControlsMap;
59 typedef std::pair<const Tizen::Ui::Control*, EGLSurface> RenderControlsMapPair;
61 typedef std::map<const Effect*, const Tizen::Ui::Control*> EffectsControlsMap;
62 typedef std::set<const Tizen::Ui::Control*> ControlsSet;
65 : public Tizen::Base::Runtime::ITimerEventListener
66 , public Tizen::Ui::Effects::_Runtime::IEffectModelListener
67 , virtual public Tizen::Base::Runtime::IEventListener
72 * Binds the effect to Tizen::UI::Control for rendering effect.
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.
82 result SetRenderTarget(const Tizen::Ui::Control* pControl);
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
98 result Start(const Tizen::Base::Collection::IList& effectStartInfo);
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
113 * Informs an effect of a TouchPress event
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
125 result FeedTouchPressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
128 * Informs an effect of a TouchMove event
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
140 result FeedTouchMoveEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
143 * Informs an effect of a TouchRelease event
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
155 result FeedTouchReleaseEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
158 * Informs an effect of a TouchDoublePress event
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
170 result FeedTouchDoublePressEvent(const Tizen::Ui::TouchEventInfo& touchEventInfo, const Tizen::Graphics::Point& offset);
173 * Updates the effect's bitmap which is used as a graphical surface in scripts
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
184 result SetBitmap(long bitmapId, const Tizen::Graphics::Bitmap& bitmap);
187 * Gets the current state of the effect specified
191 * @return @c true if the effect is running; @c false, otherwise
192 * @exception E_SUCCESS The effect state is successfully retrieved
195 bool IsRunning(void) const;
202 * @return Type of effect
203 * @exception E_SUCCESS The effect type is successfully retrieved
206 EffectType GetType(void) const;
209 * Gets the name of an effect
213 * @return The name of the effect specified
214 * @exception E_SUCCESS The effect name is successfully retrieved
217 Tizen::Base::String GetName(void) const;
220 * Sets the IEffectsEventListener instance to get notified when the state of the effect is changed
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
229 void SetEffectEventListener(IEffectEventListener* pListener);
232 * Gets the IEffectsEventListener instance.
236 * @return The event listener for specified effect.
238 IEffectEventListener* GetEffectEventListener(void) const;
241 * Sets the IEffectsResourceProvider instance to get notified when resources are needed by the effect
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
250 void SetResourceProvider(IEffectResourceProvider* pProvider);
253 * Gets the IEffectsResourceProvider instance.
257 * @return The resource provider for specified effect.
259 IEffectResourceProvider* GetResourceProvider(void) const;
268 _EffectImpl(Effect& effect);
275 virtual ~_EffectImpl(void);
277 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
278 _EffectImpl(const _EffectImpl& rhs);
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);
284 * Finds OpenGLES surface by Control's pointer
288 * @return EGLSurface OpenGL surface created for given control, EGL_NO_SURFACE if not found
289 * @param [in] Control UI Control
292 EGLSurface FindGlesSurface(const Tizen::Ui::Control* pControl) const;
295 * Stops Effect Computing
299 * @param [in] effect Effect instance
300 * @exception E_SYSTEM
303 void EffectModelTimerStop(void);
306 * Implementation of ITimerEventListener::OnTimerExpired method - Triggering Effect Computing and Rendering
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
315 void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
318 * Implementation of IEffectModelListener::OnEffectStarted method
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"
329 void OnEffectStarted(void);
332 * Implementation of IEffectModelListener::OnEffectFinished method
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"
345 void OnEffectFinished(EffectResult effectResult, const Tizen::Ui::Effects::_Runtime::LastShownBitmapIdCollection& bitmapsTargetId); //TODO: List of bitmaps
348 * Implementation of IEffectModelListener::OnBitmapRequested method
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"
362 bool OnBitmapRequested(long bitmapId);
365 * Creates a new effect from specialised effect file
369 * @return True if effect was initialised successfully and false otherwise
370 * @see EffectManager::CreateEffect()
373 void InitializeEffect(void);
376 * Updates information about screen size if it was changed
383 void UpdateScreen(void);
386 * Removes a pair (effect*, control*) from a accordingly container and deletes GL surface if it does not need more
391 void ReleaseRenderTarget(const Control& control);
394 * Tries set a new render target for an effect.
395 * Releases old render target if successful (calls function ReleaseRenderTarget)
400 result SetRenderTargetInternal(const Tizen::Ui::Control& control, const Tizen::Ui::Control& controlOld);
405 static EffectsSet __effects;
406 static RenderControlsMap __renderControls;
407 static EffectsControlsMap __effectsControlsMapRegistered;
408 static ControlsSet __controlsSetPerforming;
409 static long __effectsCount;
412 * @brief Model instance
415 std::unique_ptr<_Runtime::IEffectModelManager> __pModel;
419 * @brief Renderer instance
422 _Renderer::EffectRendererUniquePtr __pRenderer;
425 * @brief Event Listener
428 IEffectEventListener* __pEventListener;
431 * @brief Resource Provider
434 IEffectResourceProvider* __pResourceProvider;
437 * @brief Timer for model updates
440 _EffectTimer __modelTimer;
443 * @brief Internal usage
446 bool __renderTargetSet;
448 friend class _EffectManagerImpl;
452 }}} // Tizen::Ui::Effects
454 #endif // _FUI_EFFECTS_INTERNAL_EFFECT_IMPL_H_