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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
42 class RenderTask : public ProxyObject
46 typedef Dali::RenderTask::ScreenToFrameBufferFunction ScreenToFrameBufferFunction;
49 * Creates a new RenderTask.
50 * @param[in] isSystemLevel Whether the render-task is on the system level task list.
52 static RenderTask* New( bool isSystemLevel );
55 * @copydoc Dali::RenderTask::SetSourceActor()
57 void SetSourceActor( Actor* actor );
60 * @copydoc Dali::RenderTask::GetSourceActor()
62 Actor* GetSourceActor() const;
65 * @copydoc Dali::RenderTask::SetExclusive()
67 void SetExclusive( bool exclusive );
70 * @copydoc Dali::RenderTask::IsExclusive()
72 bool IsExclusive() const;
75 * @copydoc Dali::RenderTask::SetInputEnabled()
77 void SetInputEnabled( bool enabled );
80 * @copydoc Dali::RenderTask::GetInputEnabled()
82 bool GetInputEnabled() const;
85 * @copydoc Dali::RenderTask::SetCameraActor()
87 void SetCameraActor( CameraActor* cameraActor );
90 * @copydoc Dali::RenderTask::GetCameraActor()
92 CameraActor* GetCameraActor() const;
95 * @copydoc Dali::RenderTask::SetTargetFrameBuffer()
97 void SetTargetFrameBuffer( Dali::FrameBufferImage frameBuffer );
100 * @copydoc Dali::RenderTask::GetTargetFrameBuffer
102 Dali::FrameBufferImage GetTargetFrameBuffer() const;
105 * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
107 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
110 * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
112 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
115 * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
117 void SetScreenToFrameBufferMappingActor( Actor* mappingActor );
120 * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
122 Actor* GetScreenToFrameBufferMappingActor() const;
125 * @copydoc Dali::RenderTask::SetViewportPosition
127 void SetViewportPosition(const Vector2& value);
130 * @copydoc Dali::RenderTask::GetCurrentViewportPosition
132 Vector2 GetCurrentViewportPosition() const;
135 * @copydoc Dali::RenderTask::SetViewportSize
137 void SetViewportSize(const Vector2& value);
140 * @copydoc Dali::RenderTask::GetCurrentViewportSize
142 Vector2 GetCurrentViewportSize() const;
145 * @copydoc Dali::RenderTask::SetViewport()
147 void SetViewport( const Viewport& viewport );
150 * @param[out] viewPort instance to copy the values into
152 void GetViewport( Viewport& viewPort ) const;
155 * @copydoc Dali::RenderTask::SetClearColor()
157 void SetClearColor( const Vector4& color );
160 * @copydoc Dali::RenderTask::GetClearColor()
162 const Vector4& GetClearColor() const;
165 * @copydoc Dali::RenderTask::SetClearEnabled()
167 void SetClearEnabled( bool enabled );
170 * @copydoc Dali::RenderTask::GetClearEnabled()
172 bool GetClearEnabled() const;
175 * @copydoc Dali::RenderTask::SetCullMode()
177 void SetCullMode( bool mode );
180 * @copydoc Dali::RenderTask::GetCullMode()
182 bool GetCullMode() const;
185 * @copydoc Dali::RenderTask::SetRefreshRate()
187 void SetRefreshRate( unsigned int refreshRate );
190 * @copydoc Dali::RenderTask::GetRefreshRate()
192 unsigned int GetRefreshRate() const;
195 * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
196 * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
197 * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
199 bool IsHittable( Vector2& screenCoords ) const;
202 * Translates screen coordinates to render task coordinates for offscreen render tasks
203 * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
204 * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
206 bool TranslateCoordinates( Vector2& screenCoords ) const;
209 * Query whether the RenderTask is on the system level render-task list.
210 * @return true, if on the system level task list, false otherwise.
212 bool IsSystemLevel() const;
214 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
217 * Create the scene-graph RenderTask object.
218 * @pre CreateSceneObject has not already been called.
219 * @return A newly allocated scene-graph object; the caller takes ownership.
221 SceneGraph::RenderTask* CreateSceneObject();
224 * Retrieve the scene-graph RenderTask object.
225 * @return The scene-graph object, or NULL if this has been discarded.
227 SceneGraph::RenderTask* GetRenderTaskSceneObject();
230 * Discard the scene-graph RenderTask object.
232 void DiscardSceneObject();
234 public: // Implementation of ProxyObject
237 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
239 virtual unsigned int GetDefaultPropertyCount() const;
242 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
244 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
247 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
249 virtual const char* GetDefaultPropertyName(Property::Index index) const;
252 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
254 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
257 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
259 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
262 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
264 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
267 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
269 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
272 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
274 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
277 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
279 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
282 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
284 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
287 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
289 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
292 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
294 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
297 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
299 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
304 * Query whether a Finished signal should be emitted for this render-task.
305 * This should only be called by NotificationManager, before signals are emitted.
306 * @pre The refresh rate must be REFRESH_ONCE.
307 * @post HasFinished() will return false on subsequent calls, until the render-task is processed again.
308 * @return \e true if the refresh once render task has finished. Otherwise it returns \e false.
313 * Emit the Finished signal
315 void EmitSignalFinish();
318 * @copydoc Dali::RenderTask::FinishedSignal()
320 Dali::RenderTask::RenderTaskSignalType& FinishedSignal();
323 * Connects a callback function with the object's signals.
324 * @param[in] object The object providing the signal.
325 * @param[in] tracker Used to disconnect the signal.
326 * @param[in] signalName The signal to connect to.
327 * @param[in] functor A newly allocated FunctorDelegate.
328 * @return True if the signal was connected.
329 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
331 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
336 * Construct a new RenderTask.
337 * @param[in] eventToUpdate Used to send messages to the update-thread.
338 * @param[in] isSystemLevel Whether the RenderTask is on the system level task list.
340 RenderTask( EventToUpdate& eventToUpdate, bool isSystemLevel );
343 * A reference counted object may only be deleted by calling Unreference()
345 virtual ~RenderTask();
348 * Helper class for connecting Nodes to the scene-graph RenderTask
350 class Connector : public ProxyObject::Observer
362 * Create the helper class
364 Connector( Type type, RenderTask& renderTask );
367 * Non-virtual destructor; not suitable as a base object.
372 * Set the actor to be observed.
373 * @param[in] actor The actor to be observed.
375 void SetActor( Actor* actor );
378 * Update the scene-graph RenderTask with a new source/camera Node.
380 void UpdateRenderTask();
382 public: // From ProxyObject::Observer
385 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
387 virtual void SceneObjectAdded( ProxyObject& proxy );
390 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
392 virtual void SceneObjectRemoved( ProxyObject& proxy );
395 * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed
397 virtual void ProxyDestroyed( ProxyObject& proxy );
402 Connector(const Connector&);
405 Connector& operator=(const Connector& rhs);
411 RenderTask& mRenderTask;
413 Actor* mActor; ///< Raw-pointer to the actor; not owned.
418 EventToUpdate& mEventToUpdate;
420 SceneGraph::RenderTask* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
422 Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
423 Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
424 Connector mMappingConnector; /// Responsible for connecting/disconnection actor node, which used to mapping screen to frame buffer coordinate
426 Vector4 mClearColor; ///< Optional clear color
428 unsigned int mRefreshRate; ///< Determines how often the task is processed.
430 unsigned int mRefreshOnceCounter;
432 Dali::FrameBufferImage mFrameBufferImage; ///< Optional off-screen render target.
434 Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
436 bool mExclusive : 1; ///< True if the render-task has exclusive access to the source Nodes.
437 bool mInputEnabled : 1; ///< True if the render-task should be considered for input handling.
438 bool mClearEnabled : 1; ///< True if the render-task should be clear the color buffer.
439 bool mCullMode : 1; ///< True if the render-task's actors should be culled
440 bool mIsSystemLevel : 1; ///< True if the render-task is on the system level task list.
443 Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
446 } // namespace Internal
448 // Helpers for public-api forwarding methods
450 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
452 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
454 BaseObject& handle = task.GetBaseObject();
456 return static_cast<Internal::RenderTask&>(handle);
459 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
461 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
463 const BaseObject& handle = task.GetBaseObject();
465 return static_cast<const Internal::RenderTask&>(handle);
470 #endif //__DALI_INTERNAL_RENDER_TASK_H__