1 #ifndef DALI_INTERNAL_RENDER_TASK_H
2 #define DALI_INTERNAL_RENDER_TASK_H
5 * Copyright (c) 2023 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/object/weak-handle.h>
24 #include <dali/public-api/render-tasks/render-task.h>
26 #include <dali/internal/event/common/object-impl.h>
27 #include <dali/internal/event/events/actor-observer.h>
28 #include <dali/internal/event/rendering/frame-buffer-impl.h>
36 class EventThreadServices;
44 } // namespace SceneGraph
46 using RenderTaskPtr = IntrusivePtr<RenderTask>;
48 class RenderTask : public Object
51 using ScreenToFrameBufferFunction = Dali::RenderTask::ScreenToFrameBufferFunction;
54 * Creates a new RenderTask.
56 * @param[in] sourceActor The source actor.
57 * @param[in] cameraActor The camera actor.
58 * @param[in] renderTaskList The render task list.
59 * @param[in] isOverlayTask True if this render task is overlay task. default is false.
60 * @return The created render task
62 static RenderTaskPtr New(Actor* sourceActor, CameraActor* cameraActor, RenderTaskList& renderTaskList, bool isOverlayTask = false);
65 * @copydoc Dali::RenderTask::SetSourceActor()
67 void SetSourceActor(Actor* actor);
70 * @copydoc Dali::RenderTask::GetSourceActor()
72 Actor* GetSourceActor() const;
74 Actor* GetStopperActor() const;
77 * @copydoc Dali::RenderTask::SetExclusive()
79 void SetExclusive(bool exclusive);
82 * @copydoc Dali::RenderTask::IsExclusive()
84 bool IsExclusive() const;
87 * @copydoc Dali::RenderTask::SetInputEnabled()
89 void SetInputEnabled(bool enabled);
92 * @copydoc Dali::RenderTask::GetInputEnabled()
94 bool GetInputEnabled() const;
97 * @copydoc Dali::RenderTask::SetCameraActor()
99 void SetCameraActor(CameraActor* cameraActor);
102 * @copydoc Dali::RenderTask::GetCameraActor()
104 CameraActor* GetCameraActor() 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(Dali::Actor& mappingActor);
132 * @copydoc Dali::RenderTask::GetScreenToFrameBufferMappingActor
134 Dali::Actor GetScreenToFrameBufferMappingActor() const;
137 * @copydoc Dali::RenderTask::SetViewportGuideActor
139 void SetViewportGuideActor(Actor* actor);
142 * @copydoc Dali::RenderTask::GetViewportGuideActor
144 Actor* GetViewportGuideActor() const;
147 * @copydoc Dali::RenderTask::ResetViewportGuideActor
149 void ResetViewportGuideActor();
152 * @copydoc Dali::RenderTask::SetViewportPosition
154 void SetViewportPosition(const Vector2& value);
157 * @copydoc Dali::RenderTask::GetCurrentViewportPosition
159 Vector2 GetCurrentViewportPosition() const;
162 * @copydoc Dali::RenderTask::SetViewportSize
164 void SetViewportSize(const Vector2& value);
167 * @copydoc Dali::RenderTask::GetCurrentViewportSize
169 Vector2 GetCurrentViewportSize() const;
172 * @copydoc Dali::RenderTask::SetViewport()
174 void SetViewport(const Viewport& viewport);
177 * @param[out] viewPort instance to copy the values into
179 void GetViewport(Viewport& viewPort) const;
182 * @copydoc Dali::RenderTask::SetClearColor()
184 void SetClearColor(const Vector4& color);
187 * @copydoc Dali::RenderTask::GetClearColor()
189 const Vector4& GetClearColor() const;
192 * Indicate whether GL sync is required for native render target.
193 * @param[in] requiresSync whether GL sync is required.
195 void SetSyncRequired(bool requiresSync);
198 * Query whether the sync object is required for native render target.
199 * @return True if the sync object is required, false otherwise.
201 bool IsSyncRequired() const;
204 * @copydoc Dali::RenderTask::SetClearEnabled()
206 void SetClearEnabled(bool enabled);
209 * @copydoc Dali::RenderTask::GetClearEnabled()
211 bool GetClearEnabled() const;
214 * @copydoc Dali::RenderTask::SetCullMode()
216 void SetCullMode(bool mode);
219 * @copydoc Dali::RenderTask::GetCullMode()
221 bool GetCullMode() const;
224 * @copydoc Dali::RenderTask::SetRefreshRate()
226 void SetRefreshRate(uint32_t refreshRate);
229 * @copydoc Dali::RenderTask::GetRefreshRate()
231 uint32_t GetRefreshRate() const;
234 * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
235 * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
236 * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
238 bool IsHittable(Vector2& screenCoords) const;
241 * Translates screen coordinates to render task coordinates for offscreen render tasks
242 * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
243 * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
245 bool TranslateCoordinates(Vector2& screenCoords) const;
248 * @brief Get Viewport when we need to be used with translated screen coordinated when render task is offscreen.
249 * It will be used when we hit-test.
250 * @param[out] viewPort instance to copy the values into
252 void GetHittableViewport(Viewport& viewPort) const;
255 * @copydoc Dali::RenderTask::WorldToViewport()
257 bool WorldToViewport(const Vector3& position, float& viewportX, float& viewportY) const;
260 * @copydoc Dali::RenderTask::ViewportToLocal()
262 bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float& localX, float& localY) const;
265 * @copydoc Dali::RenderTask::SetRenderPassTag()
267 void SetRenderPassTag(uint32_t renderPassTag);
270 * @copydoc Dali::RenderTask::GetRenderPassTag()
272 uint32_t GetRenderPassTag() const;
275 * @copydoc Dali::RenderTask::SetOrderIndex()
277 void SetOrderIndex(int32_t orderIndex);
280 * @copydoc Dali::RenderTask::GetOrderIndex()
282 int32_t GetOrderIndex() const;
285 * @copydoc Dali::RenderTask::GetRenderTaskId()
287 uint32_t GetRenderTaskId() const;
289 void RenderUntil(Actor* actor);
291 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
293 * Retrieve the scene-graph RenderTask object.
294 * @return The scene-graph object
296 const SceneGraph::RenderTask* GetRenderTaskSceneObject() const;
299 * Remove the scene-graph RenderTask object.
300 * @param[in] renderTaskList The render task list.
302 void RemoveRenderTaskSceneObject(RenderTaskList& renderTaskList);
305 * Retrieve the render task list RenderTask object belongs to.
306 * @return The render task list
308 RenderTaskList& GetRenderTaskList() const;
310 public: // Implementation of Object
312 * @copydoc Dali::Internal::Object::SetDefaultProperty()
314 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
317 * @copydoc Dali::Internal::Object::GetDefaultProperty()
319 Property::Value GetDefaultProperty(Property::Index index) const override;
322 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
324 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
327 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
329 void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
332 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
334 const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
337 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
339 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
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);
376 * @param[in] sceneObject The scene graph object
377 * @param[in] renderTaskList The render task list
379 RenderTask(const SceneGraph::RenderTask* sceneObject, RenderTaskList& renderTaskList);
382 * A reference counted object may only be deleted by calling Unreference()
384 ~RenderTask() override;
386 private: // not copyable
387 RenderTask() = delete;
388 RenderTask(const RenderTask&) = delete;
389 RenderTask& operator=(const RenderTask&) = delete;
392 ActorObserver mSourceActor; ///< Source actor
393 ActorObserver mCameraActor; ///< Camera actor
394 ActorObserver mViewportGuideActor; ///< Actor to matching viewport of this render task to this Actor.
395 ActorObserver mStopperActor; ///< A child of mSourceActor. Actor to stop rendering.
396 WeakHandle<Dali::Actor> mInputMappingActor; /// used to mapping screen to frame buffer coordinate, not kept alive by rendertask
397 RenderTaskList& mRenderTaskList; ///< The render task list
399 Vector4 mClearColor; ///< Optional clear color
401 Vector2 mViewportPosition; ///< The cached viewport position
402 Vector2 mViewportSize; ///< The cached viewport size
404 uint32_t mRefreshRate; ///< Determines how often the task is processed.
406 uint32_t mRefreshOnceCounter;
408 FrameBufferPtr mFrameBuffer;
410 Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
412 uint32_t mRenderPassTag{0u};
413 int32_t mOrderIndex{0u};
415 uint32_t mRenderTaskId{0u};
417 bool mExclusive : 1; ///< True if the render-task has exclusive access to the source Nodes.
418 bool mInputEnabled : 1; ///< True if the render-task should be considered for input handling.
419 bool mClearEnabled : 1; ///< True if the render-task should be clear the color buffer.
420 bool mCullMode : 1; ///< True if the render-task's actors should be culled
421 bool mRequiresSync : 1; ///< True if the GL sync is required to track the render of.
424 Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
427 } // namespace Internal
429 // Helpers for public-api forwarding methods
431 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
433 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
435 BaseObject& handle = task.GetBaseObject();
437 return static_cast<Internal::RenderTask&>(handle);
440 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
442 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
444 const BaseObject& handle = task.GetBaseObject();
446 return static_cast<const Internal::RenderTask&>(handle);
451 #endif // DALI_INTERNAL_RENDER_TASK_H