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