1 #ifndef __DALI_INTERNAL_RENDER_TASK_H__
2 #define __DALI_INTERNAL_RENDER_TASK_H__
5 * Copyright (c) 2017 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/internal/event/images/frame-buffer-image-impl.h>
25 #include <dali/internal/event/common/object-impl.h>
26 #include <dali/internal/event/rendering/frame-buffer-impl.h>
36 class EventThreadServices;
44 class RenderTask : public Object
48 typedef Dali::RenderTask::ScreenToFrameBufferFunction ScreenToFrameBufferFunction;
51 * Creates a new RenderTask.
52 * @param[in] isSystemLevel Whether the render-task is on the system level task list.
54 static RenderTask* New( bool isSystemLevel );
57 * @copydoc Dali::RenderTask::SetSourceActor()
59 void SetSourceActor( Actor* actor );
62 * @copydoc Dali::RenderTask::GetSourceActor()
64 Actor* GetSourceActor() const;
67 * @copydoc Dali::RenderTask::SetExclusive()
69 void SetExclusive( bool exclusive );
72 * @copydoc Dali::RenderTask::IsExclusive()
74 bool IsExclusive() const;
77 * @copydoc Dali::RenderTask::SetInputEnabled()
79 void SetInputEnabled( bool enabled );
82 * @copydoc Dali::RenderTask::GetInputEnabled()
84 bool GetInputEnabled() const;
87 * @copydoc Dali::RenderTask::SetCameraActor()
89 void SetCameraActor( CameraActor* cameraActor );
92 * @copydoc Dali::RenderTask::GetCameraActor()
94 CameraActor* GetCameraActor() const;
97 * @copydoc Dali::RenderTask::SetTargetFrameBuffer()
99 void SetTargetFrameBuffer( FrameBufferImagePtr frameBuffer );
102 * @copydoc Dali::RenderTask::GetTargetFrameBuffer
104 FrameBufferImage* GetTargetFrameBuffer() const;
107 * @copydoc Dali::RenderTask::SetFrameBuffer()
109 void SetFrameBuffer( FrameBufferPtr frameBuffer );
112 * @copydoc Dali::RenderTask::GetFrameBuffer
114 FrameBuffer* GetFrameBuffer() const;
117 * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
119 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
122 * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
124 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
127 * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
129 void SetScreenToFrameBufferMappingActor( Actor* mappingActor );
132 * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
134 Actor* GetScreenToFrameBufferMappingActor() const;
137 * @copydoc Dali::RenderTask::SetViewportPosition
139 void SetViewportPosition(const Vector2& value);
142 * @copydoc Dali::RenderTask::GetCurrentViewportPosition
144 Vector2 GetCurrentViewportPosition() const;
147 * @copydoc Dali::RenderTask::SetViewportSize
149 void SetViewportSize(const Vector2& value);
152 * @copydoc Dali::RenderTask::GetCurrentViewportSize
154 Vector2 GetCurrentViewportSize() const;
157 * @copydoc Dali::RenderTask::SetViewport()
159 void SetViewport( const Viewport& viewport );
162 * @param[out] viewPort instance to copy the values into
164 void GetViewport( Viewport& viewPort ) const;
167 * @copydoc Dali::RenderTask::SetClearColor()
169 void SetClearColor( const Vector4& color );
172 * @copydoc Dali::RenderTask::GetClearColor()
174 const Vector4& GetClearColor() const;
177 * Indicate whether GL sync is required for native render target.
178 * @param[in] requiresSync whether GL sync is required.
180 void SetSyncRequired( bool requiresSync );
183 * Query whether the sync object is required for native render target.
184 * @return True if the sync object is required, false otherwise.
186 bool IsSyncRequired() const;
189 * @copydoc Dali::RenderTask::SetClearEnabled()
191 void SetClearEnabled( bool enabled );
194 * @copydoc Dali::RenderTask::GetClearEnabled()
196 bool GetClearEnabled() const;
199 * @copydoc Dali::RenderTask::SetCullMode()
201 void SetCullMode( bool mode );
204 * @copydoc Dali::RenderTask::GetCullMode()
206 bool GetCullMode() const;
209 * @copydoc Dali::RenderTask::SetRefreshRate()
211 void SetRefreshRate( unsigned int refreshRate );
214 * @copydoc Dali::RenderTask::GetRefreshRate()
216 unsigned int GetRefreshRate() const;
219 * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
220 * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
221 * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
223 bool IsHittable( Vector2& screenCoords ) const;
226 * Translates screen coordinates to render task coordinates for offscreen render tasks
227 * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
228 * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
230 bool TranslateCoordinates( Vector2& screenCoords ) const;
233 * Query whether the RenderTask is on the system level render-task list.
234 * @return true, if on the system level task list, false otherwise.
236 bool IsSystemLevel() const;
239 * @copydoc Dali::RenderTask::WorldToViewport()
241 bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
244 * @copydoc Dali::RenderTask::ViewportToLocal()
246 bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float &localX, float &localY) const;
248 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
251 * Create the scene-graph RenderTask object.
252 * @pre CreateSceneObject has not already been called.
253 * @return A newly allocated scene-graph object; the caller takes ownership.
255 SceneGraph::RenderTask* CreateSceneObject();
258 * Retrieve the scene-graph RenderTask object.
259 * @return The scene-graph object, or NULL if this has been discarded.
261 SceneGraph::RenderTask* GetRenderTaskSceneObject();
264 * Discard the scene-graph RenderTask object.
266 void DiscardSceneObject();
268 public: // Implementation of Object
271 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
273 virtual unsigned int GetDefaultPropertyCount() const;
276 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
278 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
281 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
283 virtual const char* GetDefaultPropertyName(Property::Index index) const;
286 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
288 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
291 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
293 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
296 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
298 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
301 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
303 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
306 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
308 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
311 * @copydoc Dali::Internal::Object::SetDefaultProperty()
313 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
316 * @copydoc Dali::Internal::Object::GetDefaultProperty()
318 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
321 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
323 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
326 * @copydoc Dali::Internal::Object::GetSceneObject()
328 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
331 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
333 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
336 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
338 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
343 * Query whether a Finished signal should be emitted for this render-task.
344 * This should only be called by NotificationManager, before signals are emitted.
345 * @pre The refresh rate must be REFRESH_ONCE.
346 * @post HasFinished() will return false on subsequent calls, until the render-task is processed again.
347 * @return \e true if the refresh once render task has finished. Otherwise it returns \e false.
352 * Emit the Finished signal
354 void EmitSignalFinish();
357 * @copydoc Dali::RenderTask::FinishedSignal()
359 Dali::RenderTask::RenderTaskSignalType& FinishedSignal();
362 * Connects a callback function with the object's signals.
363 * @param[in] object The object providing the signal.
364 * @param[in] tracker Used to disconnect the signal.
365 * @param[in] signalName The signal to connect to.
366 * @param[in] functor A newly allocated FunctorDelegate.
367 * @return True if the signal was connected.
368 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
370 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
375 * Construct a new RenderTask.
376 * @param[in] isSystemLevel Whether the RenderTask is on the system level task list.
378 RenderTask( bool isSystemLevel );
381 * A reference counted object may only be deleted by calling Unreference()
383 virtual ~RenderTask();
386 * Helper class for connecting Nodes to the scene-graph RenderTask
388 class Connector : public Object::Observer
400 * Create the helper class
402 Connector( Type type, RenderTask& renderTask );
405 * Non-virtual destructor; not suitable as a base object.
410 * Set the actor to be observed.
411 * @param[in] actor The actor to be observed.
413 void SetActor( Actor* actor );
416 * Update the scene-graph RenderTask with a new source/camera Node.
418 void UpdateRenderTask();
420 public: // From Object::Observer
423 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
425 virtual void SceneObjectAdded( Object& object );
428 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
430 virtual void SceneObjectRemoved( Object& object );
433 * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed
435 virtual void ObjectDestroyed( Object& object );
440 Connector(const Connector&);
443 Connector& operator=(const Connector& rhs);
449 RenderTask& mRenderTask;
451 Actor* mActor; ///< Raw-pointer to the actor; not owned.
452 const SceneGraph::Camera* mCamera; ///< Raw-pointer to camera scene-graph object; not owned.
457 SceneGraph::RenderTask* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
459 Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
460 Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
461 Connector mMappingConnector; /// Responsible for connecting/disconnecting actor node, which used to mapping screen to frame buffer coordinate
463 Vector4 mClearColor; ///< Optional clear color
465 Vector2 mViewportPosition; ///< The cached viewport position
466 Vector2 mViewportSize; ///< The cached viewport size
468 unsigned int mRefreshRate; ///< Determines how often the task is processed.
470 unsigned int mRefreshOnceCounter;
472 FrameBufferImagePtr mFrameBufferImage; ///< Optional off-screen render target.
473 FrameBufferPtr mFrameBuffer;
476 Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
478 bool mExclusive : 1; ///< True if the render-task has exclusive access to the source Nodes.
479 bool mInputEnabled : 1; ///< True if the render-task should be considered for input handling.
480 bool mClearEnabled : 1; ///< True if the render-task should be clear the color buffer.
481 bool mCullMode : 1; ///< True if the render-task's actors should be culled
482 bool mIsSystemLevel : 1; ///< True if the render-task is on the system level task list.
483 bool mRequiresSync : 1; ///< True if the GL sync is required to track the render of.
486 Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
489 } // namespace Internal
491 // Helpers for public-api forwarding methods
493 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
495 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
497 BaseObject& handle = task.GetBaseObject();
499 return static_cast<Internal::RenderTask&>(handle);
502 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
504 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
506 const BaseObject& handle = task.GetBaseObject();
508 return static_cast<const Internal::RenderTask&>(handle);
513 #endif //__DALI_INTERNAL_RENDER_TASK_H__