1 #ifndef __DALI_INTERNAL_RENDER_TASK_H__
2 #define __DALI_INTERNAL_RENDER_TASK_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
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>
41 class RenderTask : public ProxyObject
45 typedef Dali::RenderTask::ScreenToFrameBufferFunction ScreenToFrameBufferFunction;
48 * Creates a new RenderTask.
49 * @param[in] isSystemLevel Whether the render-task is on the system level task list.
51 static RenderTask* New( bool isSystemLevel );
54 * @copydoc Dali::RenderTask::SetSourceActor()
56 void SetSourceActor( Actor* actor );
59 * @copydoc Dali::RenderTask::GetSourceActor()
61 Actor* GetSourceActor() const;
64 * @copydoc Dali::RenderTask::SetExclusive()
66 void SetExclusive( bool exclusive );
69 * @copydoc Dali::RenderTask::IsExclusive()
71 bool IsExclusive() const;
74 * @copydoc Dali::RenderTask::SetInputEnabled()
76 void SetInputEnabled( bool enabled );
79 * @copydoc Dali::RenderTask::GetInputEnabled()
81 bool GetInputEnabled() const;
84 * @copydoc Dali::RenderTask::SetCameraActor()
86 void SetCameraActor( CameraActor* cameraActor );
89 * @copydoc Dali::RenderTask::GetCameraActor()
91 CameraActor* GetCameraActor() const;
94 * @copydoc Dali::RenderTask::SetTargetFrameBuffer()
96 void SetTargetFrameBuffer( Dali::FrameBufferImage frameBuffer );
99 * @copydoc Dali::RenderTask::GetTargetFrameBuffer
101 Dali::FrameBufferImage GetTargetFrameBuffer() const;
104 * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
106 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
109 * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
111 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
114 * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
116 void SetScreenToFrameBufferMappingActor( Actor* mappingActor );
119 * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
121 Actor* GetScreenToFrameBufferMappingActor() const;
124 * @copydoc Dali::RenderTask::SetViewportPosition
126 void SetViewportPosition(const Vector2& value);
129 * @copydoc Dali::RenderTask::GetCurrentViewportPosition
131 Vector2 GetCurrentViewportPosition() const;
134 * @copydoc Dali::RenderTask::SetViewportSize
136 void SetViewportSize(const Vector2& value);
139 * @copydoc Dali::RenderTask::GetCurrentViewportSize
141 Vector2 GetCurrentViewportSize() const;
144 * @copydoc Dali::RenderTask::SetViewport()
146 void SetViewport( const Viewport& viewport );
149 * @param[out] viewPort instance to copy the values into
151 void GetViewport( Viewport& viewPort ) const;
154 * @copydoc Dali::RenderTask::SetClearColor()
156 void SetClearColor( const Vector4& color );
159 * @copydoc Dali::RenderTask::GetClearColor()
161 const Vector4& GetClearColor() const;
164 * @copydoc Dali::RenderTask::SetClearEnabled()
166 void SetClearEnabled( bool enabled );
169 * @copydoc Dali::RenderTask::GetClearEnabled()
171 bool GetClearEnabled() const;
174 * @copydoc Dali::RenderTask::SetRefreshRate()
176 void SetRefreshRate( unsigned int refreshRate );
179 * @copydoc Dali::RenderTask::GetRefreshRate()
181 unsigned int GetRefreshRate() const;
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.
188 bool IsHittable( Vector2& screenCoords ) const;
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
195 bool TranslateCoordinates( Vector2& screenCoords ) const;
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.
201 bool IsSystemLevel() const;
203 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
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.
210 SceneGraph::RenderTask* CreateSceneObject();
213 * Retrieve the scene-graph RenderTask object.
214 * @return The scene-graph object, or NULL if this has been discarded.
216 SceneGraph::RenderTask* GetRenderTaskSceneObject();
219 * Discard the scene-graph RenderTask object.
221 void DiscardSceneObject();
223 public: // Implementation of ProxyObject
226 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
228 virtual bool IsSceneObjectRemovable() const;
231 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
233 virtual unsigned int GetDefaultPropertyCount() const;
236 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
238 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
241 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
243 virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
246 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
248 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
251 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
253 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
256 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
258 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
261 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
263 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
266 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
268 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
271 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
273 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
276 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
278 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
281 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
283 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
286 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
288 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
291 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
293 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
296 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
298 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
303 * Query whether a Finished signal should be emitted for this render-task.
304 * This should only be called by NotificationManager, before signals are emitted.
305 * @pre The refresh rate must be REFRESH_ONCE.
306 * @post HasFinished() will return false on subsequent calls, until the render-task is processed again.
307 * @return \e true if the refresh once render task has finished. Otherwise it returns \e false.
312 * Emit the Finished signal
314 void EmitSignalFinish();
317 * @copydoc Dali::RenderTask::FinishedSignal()
319 Dali::RenderTask::RenderTaskSignalV2& FinishedSignal();
322 * Connects a callback function with the object's signals.
323 * @param[in] object The object providing the signal.
324 * @param[in] tracker Used to disconnect the signal.
325 * @param[in] signalName The signal to connect to.
326 * @param[in] functor A newly allocated FunctorDelegate.
327 * @return True if the signal was connected.
328 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
330 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
335 * Construct a new RenderTask.
336 * @param[in] eventToUpdate Used to send messages to the update-thread.
337 * @param[in] isSystemLevel Whether the RenderTask is on the system level task list.
339 RenderTask( EventToUpdate& eventToUpdate, bool isSystemLevel );
342 * A reference counted object may only be deleted by calling Unreference()
344 virtual ~RenderTask();
347 * Helper class for connecting Nodes to the scene-graph RenderTask
349 class Connector : public ProxyObject::Observer
361 * Create the helper class
363 Connector( Type type, RenderTask& renderTask );
366 * Non-virtual destructor; not suitable as a base object.
371 * Set the actor to be observed.
372 * @param[in] actor The actor to be observed.
374 void SetActor( Actor* actor );
377 * Update the scene-graph RenderTask with a new source/camera Node.
379 void UpdateRenderTask();
381 public: // From ProxyObject::Observer
384 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
386 virtual void SceneObjectAdded( ProxyObject& proxy );
389 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
391 virtual void SceneObjectRemoved( ProxyObject& proxy );
394 * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed
396 virtual void ProxyDestroyed( ProxyObject& proxy );
401 Connector(const Connector&);
404 Connector& operator=(const Connector& rhs);
410 RenderTask& mRenderTask;
412 Actor* mActor; ///< Raw-pointer to the actor; not owned.
417 EventToUpdate& mEventToUpdate;
419 SceneGraph::RenderTask* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
421 Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
422 Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
423 Connector mMappingConnector; /// Responsible for connecting/disconnection actor node, which used to mapping screen to frame buffer coordinate
425 Vector4 mClearColor; ///< Optional clear color
427 unsigned int mRefreshRate; ///< Determines how often the task is processed.
429 unsigned int mRefreshOnceCounter;
431 Dali::FrameBufferImage mFrameBufferImage; ///< Optional off-screen render target.
433 Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
435 bool mExclusive : 1; ///< True if the render-task has exclusive access to the source Nodes.
436 bool mInputEnabled : 1; ///< True if the render-task should be considered for input handling.
437 bool mClearEnabled : 1; ///< True if the render-task should be clear the color buffer.
438 bool mIsSystemLevel : 1; ///< True if the render-task is on the system level task list.
440 // Default properties
441 typedef std::map<std::string, Property::Index> DefaultPropertyLookup;
442 static DefaultPropertyLookup* sDefaultPropertyLookup;
445 Dali::RenderTask::RenderTaskSignalV2 mSignalFinishedV2; ///< Signal emmited when the render task has been processed.
448 } // namespace Internal
450 // Helpers for public-api forwarding methods
452 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
454 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
456 BaseObject& handle = task.GetBaseObject();
458 return static_cast<Internal::RenderTask&>(handle);
461 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
463 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
465 const BaseObject& handle = task.GetBaseObject();
467 return static_cast<const Internal::RenderTask&>(handle);
472 #endif //__DALI_INTERNAL_RENDER_TASK_H__