License conversion from Flora to Apache 2.0
[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/proxy-object.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 class Actor;
34 class CameraActor;
35 class EventToUpdate;
36
37 namespace SceneGraph
38 {
39 class RenderTask;
40 }
41
42 class RenderTask : public ProxyObject
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    * @copydoc Dali::RenderTask::SetClearEnabled()
166    */
167   void SetClearEnabled( bool enabled );
168
169   /**
170    * @copydoc Dali::RenderTask::GetClearEnabled()
171    */
172   bool GetClearEnabled() const;
173
174   /**
175    * @copydoc Dali::RenderTask::SetRefreshRate()
176    */
177   void SetRefreshRate( unsigned int refreshRate );
178
179   /**
180    * @copydoc Dali::RenderTask::GetRefreshRate()
181    */
182   unsigned int GetRefreshRate() const;
183
184   /**
185    * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
186    * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
187    * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
188    */
189   bool IsHittable( Vector2& screenCoords ) const;
190
191   /**
192    * Translates screen coordinates to render task coordinates for offscreen render tasks
193    * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
194    * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
195    */
196   bool TranslateCoordinates( Vector2& screenCoords ) const;
197
198   /**
199    * Query whether the RenderTask is on the system level render-task list.
200    * @return true, if on the system level task list, false otherwise.
201    */
202   bool IsSystemLevel() const;
203
204 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
205
206   /**
207    * Create the scene-graph RenderTask object.
208    * @pre CreateSceneObject has not already been called.
209    * @return A newly allocated scene-graph object; the caller takes ownership.
210    */
211   SceneGraph::RenderTask* CreateSceneObject();
212
213   /**
214    * Retrieve the scene-graph RenderTask object.
215    * @return The scene-graph object, or NULL if this has been discarded.
216    */
217   SceneGraph::RenderTask* GetRenderTaskSceneObject();
218
219   /**
220    * Discard the scene-graph RenderTask object.
221    */
222   void DiscardSceneObject();
223
224 public: // Implementation of ProxyObject
225
226   /**
227    * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
228    */
229   virtual bool IsSceneObjectRemovable() const;
230
231   /**
232    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
233    */
234   virtual unsigned int GetDefaultPropertyCount() const;
235
236   /**
237    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
238    */
239   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
240
241   /**
242    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
243    */
244   virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
245
246   /**
247    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
248    */
249   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
250
251   /**
252    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
253    */
254   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
255
256   /**
257    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
258    */
259   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
260
261   /**
262    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
263    */
264   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
265
266   /**
267    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
268    */
269   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
270
271   /**
272    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
273    */
274   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
275
276   /**
277    * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
278    */
279   virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
280
281   /**
282    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
283    */
284   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
285
286   /**
287    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
288    */
289   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
290
291   /**
292    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
293    */
294   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
295
296   /**
297    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
298    */
299   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
300
301   /**
302    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
303    */
304   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
305
306 public: //signals
307
308   /**
309    * Query whether a Finished signal should be emitted for this render-task.
310    * This should only be called by NotificationManager, before signals are emitted.
311    * @pre The refresh rate must be REFRESH_ONCE.
312    * @post HasFinished() will return false on subsequent calls, until the render-task is processed again.
313    * @return \e true if the refresh once render task has finished. Otherwise it returns \e false.
314    */
315   bool HasFinished();
316
317   /**
318    * Emit the Finished signal
319    */
320   void EmitSignalFinish();
321
322   /**
323    * @copydoc Dali::RenderTask::FinishedSignal()
324    */
325   Dali::RenderTask::RenderTaskSignalV2& FinishedSignal();
326
327   /**
328    * Connects a callback function with the object's signals.
329    * @param[in] object The object providing the signal.
330    * @param[in] tracker Used to disconnect the signal.
331    * @param[in] signalName The signal to connect to.
332    * @param[in] functor A newly allocated FunctorDelegate.
333    * @return True if the signal was connected.
334    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
335    */
336   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
337
338 protected:
339
340   /**
341    * Construct a new RenderTask.
342    * @param[in] eventToUpdate Used to send messages to the update-thread.
343    * @param[in] isSystemLevel Whether the RenderTask is on the system level task list.
344    */
345   RenderTask( EventToUpdate& eventToUpdate, bool isSystemLevel );
346
347   /**
348    * A reference counted object may only be deleted by calling Unreference()
349    */
350   virtual ~RenderTask();
351
352   /**
353    * Helper class for connecting Nodes to the scene-graph RenderTask
354    */
355   class Connector : public ProxyObject::Observer
356   {
357   public:
358
359     enum Type
360     {
361       SOURCE_CONNECTOR,
362       CAMERA_CONNECTOR,
363       MAPPING_CONNECTOR
364     };
365
366     /**
367      * Create the helper class
368      */
369     Connector( Type type, RenderTask& renderTask );
370
371     /**
372      * Non-virtual destructor; not suitable as a base object.
373      */
374     ~Connector();
375
376     /**
377      * Set the actor to be observed.
378      * @param[in] actor The actor to be observed.
379      */
380     void SetActor( Actor* actor );
381
382     /**
383      * Update the scene-graph RenderTask with a new source/camera Node.
384      */
385     void UpdateRenderTask();
386
387   public: // From ProxyObject::Observer
388
389     /**
390      * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
391      */
392     virtual void SceneObjectAdded( ProxyObject& proxy );
393
394     /**
395      * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
396      */
397     virtual void SceneObjectRemoved( ProxyObject& proxy );
398
399     /**
400      * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed
401      */
402     virtual void ProxyDestroyed( ProxyObject& proxy );
403
404   private:
405
406     // Undefined
407     Connector(const Connector&);
408
409     // Undefined
410     Connector& operator=(const Connector& rhs);
411
412   public:
413
414     const Type mType;
415
416     RenderTask& mRenderTask;
417
418     Actor* mActor; ///< Raw-pointer to the actor; not owned.
419   };
420
421 private:
422
423   EventToUpdate& mEventToUpdate;
424
425   SceneGraph::RenderTask* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
426
427   Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
428   Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
429   Connector mMappingConnector; /// Responsible for connecting/disconnection actor node, which used to mapping screen to frame buffer coordinate
430
431   Vector4 mClearColor;       ///< Optional clear color
432
433   unsigned int mRefreshRate; ///< Determines how often the task is processed.
434
435   unsigned int mRefreshOnceCounter;
436
437   Dali::FrameBufferImage mFrameBufferImage;  ///< Optional off-screen render target.
438
439   Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
440
441   bool mExclusive     : 1; ///< True if the render-task has exclusive access to the source Nodes.
442   bool mInputEnabled  : 1; ///< True if the render-task should be considered for input handling.
443   bool mClearEnabled  : 1; ///< True if the render-task should be clear the color buffer.
444   bool mIsSystemLevel : 1; ///< True if the render-task is on the system level task list.
445
446   // Default properties
447   typedef std::map<std::string, Property::Index> DefaultPropertyLookup;
448   static DefaultPropertyLookup* sDefaultPropertyLookup;
449
450   //Signals
451   Dali::RenderTask::RenderTaskSignalV2  mSignalFinishedV2; ///< Signal emmited when the render task has been processed.
452 };
453
454 } // namespace Internal
455
456 // Helpers for public-api forwarding methods
457
458 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
459 {
460   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
461
462   BaseObject& handle = task.GetBaseObject();
463
464   return static_cast<Internal::RenderTask&>(handle);
465 }
466
467 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
468 {
469   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
470
471   const BaseObject& handle = task.GetBaseObject();
472
473   return static_cast<const Internal::RenderTask&>(handle);
474 }
475
476 } // namespace Dali
477
478 #endif //__DALI_INTERNAL_RENDER_TASK_H__