Ensure cached values of properties animated using AnimateTo are updated
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-impl.h
1 #ifndef __DALI_INTERNAL_RENDER_TASK_H__
2 #define __DALI_INTERNAL_RENDER_TASK_H__
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/render-tasks/render-task.h>
24 #include <dali/internal/event/images/frame-buffer-image-impl.h>
25 #include <dali/internal/event/common/object-impl.h>
26 #include <dali/internal/event/rendering/frame-buffer-impl.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 class Actor;
35 class CameraActor;
36 class EventThreadServices;
37
38 namespace SceneGraph
39 {
40 class RenderTask;
41 class Camera;
42 }
43
44 class RenderTask : public Object
45 {
46 public:
47
48   typedef Dali::RenderTask::ScreenToFrameBufferFunction ScreenToFrameBufferFunction;
49
50   /**
51    * Creates a new RenderTask.
52    * @param[in] isSystemLevel Whether the render-task is on the system level task list.
53    */
54   static RenderTask* New( bool isSystemLevel );
55
56   /**
57    * @copydoc Dali::RenderTask::SetSourceActor()
58    */
59   void SetSourceActor( Actor* actor );
60
61   /**
62    * @copydoc Dali::RenderTask::GetSourceActor()
63    */
64   Actor* GetSourceActor() const;
65
66   /**
67    * @copydoc Dali::RenderTask::SetExclusive()
68    */
69   void SetExclusive( bool exclusive );
70
71   /**
72    * @copydoc Dali::RenderTask::IsExclusive()
73    */
74   bool IsExclusive() const;
75
76   /**
77    * @copydoc Dali::RenderTask::SetInputEnabled()
78    */
79   void SetInputEnabled( bool enabled );
80
81   /**
82    * @copydoc Dali::RenderTask::GetInputEnabled()
83    */
84   bool GetInputEnabled() const;
85
86   /**
87    * @copydoc Dali::RenderTask::SetCameraActor()
88    */
89   void SetCameraActor( CameraActor* cameraActor );
90
91   /**
92    * @copydoc Dali::RenderTask::GetCameraActor()
93    */
94   CameraActor* GetCameraActor() const;
95
96   /**
97    * @copydoc Dali::RenderTask::SetTargetFrameBuffer()
98    */
99   void SetTargetFrameBuffer( FrameBufferImagePtr frameBuffer );
100
101   /**
102    * @copydoc Dali::RenderTask::GetTargetFrameBuffer
103    */
104   FrameBufferImage* GetTargetFrameBuffer() const;
105
106   /**
107     * @copydoc Dali::RenderTask::SetFrameBuffer()
108     */
109    void SetFrameBuffer( FrameBufferPtr frameBuffer );
110
111    /**
112     * @copydoc Dali::RenderTask::GetFrameBuffer
113     */
114    FrameBuffer* GetFrameBuffer() const;
115
116   /**
117    * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
118    */
119   void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
120
121   /**
122    * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
123    */
124   ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
125
126   /**
127    * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
128    */
129   void SetScreenToFrameBufferMappingActor( Actor* mappingActor );
130
131   /**
132    * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
133    */
134   Actor* GetScreenToFrameBufferMappingActor() const;
135
136   /**
137    * @copydoc Dali::RenderTask::SetViewportPosition
138    */
139   void SetViewportPosition(const Vector2& value);
140
141   /**
142    * @copydoc Dali::RenderTask::GetCurrentViewportPosition
143    */
144   Vector2 GetCurrentViewportPosition() const;
145
146   /**
147    * @copydoc Dali::RenderTask::SetViewportSize
148    */
149   void SetViewportSize(const Vector2& value);
150
151   /**
152    * @copydoc Dali::RenderTask::GetCurrentViewportSize
153    */
154   Vector2 GetCurrentViewportSize() const;
155
156   /**
157    * @copydoc Dali::RenderTask::SetViewport()
158    */
159   void SetViewport( const Viewport& viewport );
160
161   /**
162    * @param[out] viewPort instance to copy the values into
163    */
164   void GetViewport( Viewport& viewPort ) const;
165
166   /**
167    * @copydoc Dali::RenderTask::SetClearColor()
168    */
169   void SetClearColor( const Vector4& color );
170
171   /**
172    * @copydoc Dali::RenderTask::GetClearColor()
173    */
174   const Vector4& GetClearColor() const;
175
176   /**
177    * Indicate whether GL sync is required for native render target.
178    * @param[in] requiresSync whether GL sync is required.
179    */
180   void SetSyncRequired( bool requiresSync );
181
182   /**
183    * Query whether the sync object is required for native render target.
184    * @return True if the sync object is required, false otherwise.
185    */
186  bool IsSyncRequired() const;
187
188   /**
189    * @copydoc Dali::RenderTask::SetClearEnabled()
190    */
191   void SetClearEnabled( bool enabled );
192
193   /**
194    * @copydoc Dali::RenderTask::GetClearEnabled()
195    */
196   bool GetClearEnabled() const;
197
198   /**
199    * @copydoc Dali::RenderTask::SetCullMode()
200    */
201   void SetCullMode( bool mode );
202
203   /**
204    * @copydoc Dali::RenderTask::GetCullMode()
205    */
206   bool GetCullMode() const;
207
208   /**
209    * @copydoc Dali::RenderTask::SetRefreshRate()
210    */
211   void SetRefreshRate( unsigned int refreshRate );
212
213   /**
214    * @copydoc Dali::RenderTask::GetRefreshRate()
215    */
216   unsigned int GetRefreshRate() const;
217
218   /**
219    * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
220    * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
221    * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
222    */
223   bool IsHittable( Vector2& screenCoords ) const;
224
225   /**
226    * Translates screen coordinates to render task coordinates for offscreen render tasks
227    * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
228    * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
229    */
230   bool TranslateCoordinates( Vector2& screenCoords ) const;
231
232   /**
233    * Query whether the RenderTask is on the system level render-task list.
234    * @return true, if on the system level task list, false otherwise.
235    */
236   bool IsSystemLevel() const;
237
238   /**
239    * @copydoc Dali::RenderTask::WorldToViewport()
240    */
241   bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
242
243   /**
244    * @copydoc Dali::RenderTask::ViewportToLocal()
245    */
246   bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float &localX, float &localY) const;
247
248 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
249
250   /**
251    * Create the scene-graph RenderTask object.
252    * @pre CreateSceneObject has not already been called.
253    * @return A newly allocated scene-graph object; the caller takes ownership.
254    */
255   SceneGraph::RenderTask* CreateSceneObject();
256
257   /**
258    * Retrieve the scene-graph RenderTask object.
259    * @return The scene-graph object, or NULL if this has been discarded.
260    */
261   SceneGraph::RenderTask* GetRenderTaskSceneObject();
262
263   /**
264    * Discard the scene-graph RenderTask object.
265    */
266   void DiscardSceneObject();
267
268 public: // Implementation of Object
269
270   /**
271    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
272    */
273   virtual unsigned int GetDefaultPropertyCount() const;
274
275   /**
276    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
277    */
278   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
279
280   /**
281    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
282    */
283   virtual const char* GetDefaultPropertyName(Property::Index index) const;
284
285   /**
286    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
287    */
288   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
289
290   /**
291    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
292    */
293   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
294
295   /**
296    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
297    */
298   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
299
300   /**
301    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
302    */
303   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
304
305   /**
306    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
307    */
308   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
309
310   /**
311    * @copydoc Dali::Internal::Object::SetDefaultProperty()
312    */
313   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
314
315   /**
316    * @copydoc Dali::Internal::Object::GetDefaultProperty()
317    */
318   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
319
320   /**
321    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
322    */
323   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
324
325   /**
326    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
327    */
328   virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value );
329
330   /**
331    * @copydoc Dali::Internal::Object::GetSceneObject()
332    */
333   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
334
335   /**
336    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
337    */
338   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
339
340   /**
341    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
342    */
343   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
344
345 public: //signals
346
347   /**
348    * Query whether a Finished signal should be emitted for this render-task.
349    * This should only be called by NotificationManager, before signals are emitted.
350    * @pre The refresh rate must be REFRESH_ONCE.
351    * @post HasFinished() will return false on subsequent calls, until the render-task is processed again.
352    * @return \e true if the refresh once render task has finished. Otherwise it returns \e false.
353    */
354   bool HasFinished();
355
356   /**
357    * Emit the Finished signal
358    */
359   void EmitSignalFinish();
360
361   /**
362    * @copydoc Dali::RenderTask::FinishedSignal()
363    */
364   Dali::RenderTask::RenderTaskSignalType& FinishedSignal();
365
366   /**
367    * Connects a callback function with the object's signals.
368    * @param[in] object The object providing the signal.
369    * @param[in] tracker Used to disconnect the signal.
370    * @param[in] signalName The signal to connect to.
371    * @param[in] functor A newly allocated FunctorDelegate.
372    * @return True if the signal was connected.
373    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
374    */
375   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
376
377 protected:
378
379   /**
380    * Construct a new RenderTask.
381    * @param[in] isSystemLevel Whether the RenderTask is on the system level task list.
382    */
383   RenderTask( bool isSystemLevel );
384
385   /**
386    * A reference counted object may only be deleted by calling Unreference()
387    */
388   virtual ~RenderTask();
389
390   /**
391    * Helper class for connecting Nodes to the scene-graph RenderTask
392    */
393   class Connector : public Object::Observer
394   {
395   public:
396
397     enum Type
398     {
399       SOURCE_CONNECTOR,
400       CAMERA_CONNECTOR,
401       MAPPING_CONNECTOR
402     };
403
404     /**
405      * Create the helper class
406      */
407     Connector( Type type, RenderTask& renderTask );
408
409     /**
410      * Non-virtual destructor; not suitable as a base object.
411      */
412     ~Connector();
413
414     /**
415      * Set the actor to be observed.
416      * @param[in] actor The actor to be observed.
417      */
418     void SetActor( Actor* actor );
419
420     /**
421      * Update the scene-graph RenderTask with a new source/camera Node.
422      */
423     void UpdateRenderTask();
424
425   public: // From Object::Observer
426
427     /**
428      * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
429      */
430     virtual void SceneObjectAdded( Object& object );
431
432     /**
433      * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
434      */
435     virtual void SceneObjectRemoved( Object& object );
436
437     /**
438      * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed
439      */
440     virtual void ObjectDestroyed( Object& object );
441
442   private:
443
444     // Undefined
445     Connector(const Connector&);
446
447     // Undefined
448     Connector& operator=(const Connector& rhs);
449
450   public:
451
452     const Type mType;
453
454     RenderTask& mRenderTask;
455
456     Actor* mActor; ///< Raw-pointer to the actor; not owned.
457     const SceneGraph::Camera* mCamera;    ///< Raw-pointer to camera scene-graph object; not owned.
458   };
459
460 private:
461
462   SceneGraph::RenderTask* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
463
464   Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
465   Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
466   Connector mMappingConnector; /// Responsible for connecting/disconnecting actor node, which used to mapping screen to frame buffer coordinate
467
468   Vector4 mClearColor;       ///< Optional clear color
469
470   Vector2 mViewportPosition; ///< The cached viewport position
471   Vector2 mViewportSize;     ///< The cached viewport size
472
473   unsigned int mRefreshRate; ///< Determines how often the task is processed.
474
475   unsigned int mRefreshOnceCounter;
476
477   FrameBufferImagePtr mFrameBufferImage;  ///< Optional off-screen render target.
478   FrameBufferPtr  mFrameBuffer;
479
480
481   Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
482
483   bool mExclusive     : 1; ///< True if the render-task has exclusive access to the source Nodes.
484   bool mInputEnabled  : 1; ///< True if the render-task should be considered for input handling.
485   bool mClearEnabled  : 1; ///< True if the render-task should be clear the color buffer.
486   bool mCullMode      : 1; ///< True if the render-task's actors should be culled
487   bool mIsSystemLevel : 1; ///< True if the render-task is on the system level task list.
488   bool mRequiresSync  : 1; ///< True if the GL sync is required to track the render of.
489
490   //Signals
491   Dali::RenderTask::RenderTaskSignalType  mSignalFinished; ///< Signal emmited when the render task has been processed.
492 };
493
494 } // namespace Internal
495
496 // Helpers for public-api forwarding methods
497
498 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
499 {
500   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
501
502   BaseObject& handle = task.GetBaseObject();
503
504   return static_cast<Internal::RenderTask&>(handle);
505 }
506
507 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
508 {
509   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
510
511   const BaseObject& handle = task.GetBaseObject();
512
513   return static_cast<const Internal::RenderTask&>(handle);
514 }
515
516 } // namespace Dali
517
518 #endif //__DALI_INTERNAL_RENDER_TASK_H__