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