1 #ifndef __DALI_INTERNAL_RENDER_TASK_H__
2 #define __DALI_INTERNAL_RENDER_TASK_H__
5 * Copyright (c) 2018 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.
53 static RenderTask* New();
56 * @copydoc Dali::RenderTask::SetSourceActor()
58 void SetSourceActor( Actor* actor );
61 * @copydoc Dali::RenderTask::GetSourceActor()
63 Actor* GetSourceActor() const;
66 * @copydoc Dali::RenderTask::SetExclusive()
68 void SetExclusive( bool exclusive );
71 * @copydoc Dali::RenderTask::IsExclusive()
73 bool IsExclusive() const;
76 * @copydoc Dali::RenderTask::SetInputEnabled()
78 void SetInputEnabled( bool enabled );
81 * @copydoc Dali::RenderTask::GetInputEnabled()
83 bool GetInputEnabled() const;
86 * @copydoc Dali::RenderTask::SetCameraActor()
88 void SetCameraActor( CameraActor* cameraActor );
91 * @copydoc Dali::RenderTask::GetCameraActor()
93 CameraActor* GetCameraActor() const;
96 * @copydoc Dali::RenderTask::SetTargetFrameBuffer()
98 void SetTargetFrameBuffer( FrameBufferImagePtr frameBuffer );
101 * @copydoc Dali::RenderTask::GetTargetFrameBuffer
103 FrameBufferImage* GetTargetFrameBuffer() const;
106 * @copydoc Dali::RenderTask::SetFrameBuffer()
108 void SetFrameBuffer( FrameBufferPtr frameBuffer );
111 * @copydoc Dali::RenderTask::GetFrameBuffer
113 FrameBuffer* GetFrameBuffer() const;
116 * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
118 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
121 * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
123 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
126 * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
128 void SetScreenToFrameBufferMappingActor( Actor* mappingActor );
131 * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
133 Actor* GetScreenToFrameBufferMappingActor() const;
136 * @copydoc Dali::RenderTask::SetViewportPosition
138 void SetViewportPosition(const Vector2& value);
141 * @copydoc Dali::RenderTask::GetCurrentViewportPosition
143 Vector2 GetCurrentViewportPosition() const;
146 * @copydoc Dali::RenderTask::SetViewportSize
148 void SetViewportSize(const Vector2& value);
151 * @copydoc Dali::RenderTask::GetCurrentViewportSize
153 Vector2 GetCurrentViewportSize() const;
156 * @copydoc Dali::RenderTask::SetViewport()
158 void SetViewport( const Viewport& viewport );
161 * @param[out] viewPort instance to copy the values into
163 void GetViewport( Viewport& viewPort ) const;
166 * @copydoc Dali::RenderTask::SetClearColor()
168 void SetClearColor( const Vector4& color );
171 * @copydoc Dali::RenderTask::GetClearColor()
173 const Vector4& GetClearColor() const;
176 * Indicate whether GL sync is required for native render target.
177 * @param[in] requiresSync whether GL sync is required.
179 void SetSyncRequired( bool requiresSync );
182 * Query whether the sync object is required for native render target.
183 * @return True if the sync object is required, false otherwise.
185 bool IsSyncRequired() const;
188 * @copydoc Dali::RenderTask::SetClearEnabled()
190 void SetClearEnabled( bool enabled );
193 * @copydoc Dali::RenderTask::GetClearEnabled()
195 bool GetClearEnabled() const;
198 * @copydoc Dali::RenderTask::SetCullMode()
200 void SetCullMode( bool mode );
203 * @copydoc Dali::RenderTask::GetCullMode()
205 bool GetCullMode() const;
208 * @copydoc Dali::RenderTask::SetRefreshRate()
210 void SetRefreshRate( uint32_t refreshRate );
213 * @copydoc Dali::RenderTask::GetRefreshRate()
215 uint32_t GetRefreshRate() const;
218 * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
219 * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
220 * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
222 bool IsHittable( Vector2& screenCoords ) const;
225 * Translates screen coordinates to render task coordinates for offscreen render tasks
226 * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
227 * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
229 bool TranslateCoordinates( Vector2& screenCoords ) const;
232 * @copydoc Dali::RenderTask::WorldToViewport()
234 bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
237 * @copydoc Dali::RenderTask::ViewportToLocal()
239 bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float &localX, float &localY) const;
241 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
244 * Create the scene-graph RenderTask object.
245 * @pre CreateSceneObject has not already been called.
246 * @return A newly allocated scene-graph object; the caller takes ownership.
248 SceneGraph::RenderTask* CreateSceneObject();
251 * Retrieve the scene-graph RenderTask object.
252 * @return The scene-graph object, or NULL if this has been discarded.
254 SceneGraph::RenderTask* GetRenderTaskSceneObject();
257 * Discard the scene-graph RenderTask object.
259 void DiscardSceneObject();
261 public: // Implementation of Object
264 * @copydoc Dali::Internal::Object::SetDefaultProperty()
266 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
269 * @copydoc Dali::Internal::Object::GetDefaultProperty()
271 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
274 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
276 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
279 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
281 virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType, bool animationStarted );
284 * @copydoc Dali::Internal::Object::GetSceneObject()
286 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
289 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
291 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
294 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
296 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
301 * Query whether a Finished signal should be emitted for this render-task.
302 * This should only be called by NotificationManager, before signals are emitted.
303 * @pre The refresh rate must be REFRESH_ONCE.
304 * @post HasFinished() will return false on subsequent calls, until the render-task is processed again.
305 * @return \e true if the refresh once render task has finished. Otherwise it returns \e false.
310 * Emit the Finished signal
312 void EmitSignalFinish();
315 * @copydoc Dali::RenderTask::FinishedSignal()
317 Dali::RenderTask::RenderTaskSignalType& FinishedSignal();
320 * Connects a callback function with the object's signals.
321 * @param[in] object The object providing the signal.
322 * @param[in] tracker Used to disconnect the signal.
323 * @param[in] signalName The signal to connect to.
324 * @param[in] functor A newly allocated FunctorDelegate.
325 * @return True if the signal was connected.
326 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
328 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
333 * Construct a new RenderTask.
338 * A reference counted object may only be deleted by calling Unreference()
340 virtual ~RenderTask();
343 * Helper class for connecting Nodes to the scene-graph RenderTask
345 class Connector : public Object::Observer
357 * Create the helper class
359 Connector( Type type, RenderTask& renderTask );
362 * Non-virtual destructor; not suitable as a base object.
367 * Set the actor to be observed.
368 * @param[in] actor The actor to be observed.
370 void SetActor( Actor* actor );
373 * Update the scene-graph RenderTask with a new source/camera Node.
375 void UpdateRenderTask();
377 public: // From Object::Observer
380 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
382 virtual void SceneObjectAdded( Object& object );
385 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
387 virtual void SceneObjectRemoved( Object& object );
390 * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed
392 virtual void ObjectDestroyed( Object& object );
397 Connector(const Connector&);
400 Connector& operator=(const Connector& rhs);
406 RenderTask& mRenderTask;
408 Actor* mActor; ///< Raw-pointer to the actor; not owned.
409 const SceneGraph::Camera* mCamera; ///< Raw-pointer to camera scene-graph object; not owned.
414 SceneGraph::RenderTask* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
416 Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
417 Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
418 Connector mMappingConnector; /// Responsible for connecting/disconnecting actor node, which used to mapping screen to frame buffer coordinate
420 Vector4 mClearColor; ///< Optional clear color
422 Vector2 mViewportPosition; ///< The cached viewport position
423 Vector2 mViewportSize; ///< The cached viewport size
425 uint32_t mRefreshRate; ///< Determines how often the task is processed.
427 uint32_t mRefreshOnceCounter;
429 FrameBufferImagePtr mFrameBufferImage; ///< Optional off-screen render target.
430 FrameBufferPtr mFrameBuffer;
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 mCullMode : 1; ///< True if the render-task's actors should be culled
439 bool mRequiresSync : 1; ///< True if the GL sync is required to track the render of.
442 Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
445 } // namespace Internal
447 // Helpers for public-api forwarding methods
449 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
451 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
453 BaseObject& handle = task.GetBaseObject();
455 return static_cast<Internal::RenderTask&>(handle);
458 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
460 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
462 const BaseObject& handle = task.GetBaseObject();
464 return static_cast<const Internal::RenderTask&>(handle);
469 #endif //__DALI_INTERNAL_RENDER_TASK_H__