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