[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-impl.h
1 #ifndef DALI_INTERNAL_RENDER_TASK_H
2 #define DALI_INTERNAL_RENDER_TASK_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
25
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>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 class Actor;
35 class CameraActor;
36 class EventThreadServices;
37 class RenderTaskList;
38
39 namespace SceneGraph
40 {
41 class RenderTaskList;
42 class RenderTask;
43 class Camera;
44 } // namespace SceneGraph
45
46 using RenderTaskPtr = IntrusivePtr<RenderTask>;
47
48 class RenderTask : public Object
49 {
50 public:
51   using ScreenToFrameBufferFunction = Dali::RenderTask::ScreenToFrameBufferFunction;
52
53   /**
54    * Creates a new RenderTask.
55    *
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
61    */
62   static RenderTaskPtr New(Actor* sourceActor, CameraActor* cameraActor, RenderTaskList& renderTaskList, bool isOverlayTask = false);
63
64   /**
65    * @copydoc Dali::RenderTask::SetSourceActor()
66    */
67   void SetSourceActor(Actor* actor);
68
69   /**
70    * @copydoc Dali::RenderTask::GetSourceActor()
71    */
72   Actor* GetSourceActor() const;
73
74   Actor* GetStopperActor() const;
75
76   /**
77    * @copydoc Dali::RenderTask::SetExclusive()
78    */
79   void SetExclusive(bool exclusive);
80
81   /**
82    * @copydoc Dali::RenderTask::IsExclusive()
83    */
84   bool IsExclusive() const;
85
86   /**
87    * @copydoc Dali::RenderTask::SetInputEnabled()
88    */
89   void SetInputEnabled(bool enabled);
90
91   /**
92    * @copydoc Dali::RenderTask::GetInputEnabled()
93    */
94   bool GetInputEnabled() const;
95
96   /**
97    * @copydoc Dali::RenderTask::SetCameraActor()
98    */
99   void SetCameraActor(CameraActor* cameraActor);
100
101   /**
102    * @copydoc Dali::RenderTask::GetCameraActor()
103    */
104   CameraActor* GetCameraActor() const;
105
106   /**
107    * @copydoc Dali::RenderTask::SetFrameBuffer()
108    */
109   void SetFrameBuffer(FrameBufferPtr frameBuffer);
110
111   /**
112    * @copydoc Dali::RenderTask::GetFrameBuffer
113    */
114   FrameBuffer* GetFrameBuffer() const;
115
116   /**
117    * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
118    */
119   void SetScreenToFrameBufferFunction(ScreenToFrameBufferFunction conversionFunction);
120
121   /**
122    * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
123    */
124   ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
125
126   /**
127    * @copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
128    */
129   void SetScreenToFrameBufferMappingActor(Dali::Actor& mappingActor);
130
131   /**
132    * @copydoc Dali::RenderTask::GetScreenToFrameBufferMappingActor
133    */
134   Dali::Actor GetScreenToFrameBufferMappingActor() const;
135
136   /**
137    * @copydoc Dali::RenderTask::SetViewportGuideActor
138    */
139   void SetViewportGuideActor(Actor* actor);
140
141   /**
142    * @copydoc Dali::RenderTask::GetViewportGuideActor
143    */
144   Actor* GetViewportGuideActor() const;
145
146   /**
147    * @copydoc Dali::RenderTask::ResetViewportGuideActor
148    */
149   void ResetViewportGuideActor();
150
151   /**
152    * @copydoc Dali::RenderTask::SetViewportPosition
153    */
154   void SetViewportPosition(const Vector2& value);
155
156   /**
157    * @copydoc Dali::RenderTask::GetCurrentViewportPosition
158    */
159   Vector2 GetCurrentViewportPosition() const;
160
161   /**
162    * @copydoc Dali::RenderTask::SetViewportSize
163    */
164   void SetViewportSize(const Vector2& value);
165
166   /**
167    * @copydoc Dali::RenderTask::GetCurrentViewportSize
168    */
169   Vector2 GetCurrentViewportSize() const;
170
171   /**
172    * @copydoc Dali::RenderTask::SetViewport()
173    */
174   void SetViewport(const Viewport& viewport);
175
176   /**
177    * @param[out] viewPort instance to copy the values into
178    */
179   void GetViewport(Viewport& viewPort) const;
180
181   /**
182    * @copydoc Dali::RenderTask::SetClearColor()
183    */
184   void SetClearColor(const Vector4& color);
185
186   /**
187    * @copydoc Dali::RenderTask::GetClearColor()
188    */
189   const Vector4& GetClearColor() const;
190
191   /**
192    * Indicate whether GL sync is required for native render target.
193    * @param[in] requiresSync whether GL sync is required.
194    */
195   void SetSyncRequired(bool requiresSync);
196
197   /**
198    * Query whether the sync object is required for native render target.
199    * @return True if the sync object is required, false otherwise.
200    */
201   bool IsSyncRequired() const;
202
203   /**
204    * @copydoc Dali::RenderTask::SetClearEnabled()
205    */
206   void SetClearEnabled(bool enabled);
207
208   /**
209    * @copydoc Dali::RenderTask::GetClearEnabled()
210    */
211   bool GetClearEnabled() const;
212
213   /**
214    * @copydoc Dali::RenderTask::SetCullMode()
215    */
216   void SetCullMode(bool mode);
217
218   /**
219    * @copydoc Dali::RenderTask::GetCullMode()
220    */
221   bool GetCullMode() const;
222
223   /**
224    * @copydoc Dali::RenderTask::SetRefreshRate()
225    */
226   void SetRefreshRate(uint32_t refreshRate);
227
228   /**
229    * @copydoc Dali::RenderTask::GetRefreshRate()
230    */
231   uint32_t GetRefreshRate() const;
232
233   /**
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.
237    */
238   bool IsHittable(Vector2& screenCoords) const;
239
240   /**
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
244    */
245   bool TranslateCoordinates(Vector2& screenCoords) const;
246
247   /**
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
251    */
252   void GetHittableViewport(Viewport& viewPort) const;
253
254   /**
255    * @copydoc Dali::RenderTask::WorldToViewport()
256    */
257   bool WorldToViewport(const Vector3& position, float& viewportX, float& viewportY) const;
258
259   /**
260    * @copydoc Dali::RenderTask::ViewportToLocal()
261    */
262   bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float& localX, float& localY) const;
263
264   /**
265    * @copydoc Dali::RenderTask::SetRenderPassTag()
266    */
267   void SetRenderPassTag(uint32_t renderPassTag);
268
269   /**
270    * @copydoc Dali::RenderTask::GetRenderPassTag()
271    */
272   uint32_t GetRenderPassTag() const;
273
274   /**
275    * @copydoc Dali::RenderTask::SetOrderIndex()
276    */
277   void SetOrderIndex(int32_t orderIndex);
278
279   /**
280    * @copydoc Dali::RenderTask::GetOrderIndex()
281    */
282   int32_t GetOrderIndex() const;
283
284   /**
285    * @copydoc Dali::RenderTask::GetRenderTaskId()
286    */
287   uint32_t GetRenderTaskId() const;
288
289   void RenderUntil(Actor* actor);
290
291 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
292   /**
293    * Retrieve the scene-graph RenderTask object.
294    * @return The scene-graph object
295    */
296   const SceneGraph::RenderTask* GetRenderTaskSceneObject() const;
297
298   /**
299    * Remove the scene-graph RenderTask object.
300    * @param[in] renderTaskList The render task list.
301    */
302   void RemoveRenderTaskSceneObject(RenderTaskList& renderTaskList);
303
304   /**
305    * Retrieve the render task list RenderTask object belongs to.
306    * @return The render task list
307    */
308   RenderTaskList& GetRenderTaskList() const;
309
310 public: // Implementation of Object
311   /**
312    * @copydoc Dali::Internal::Object::SetDefaultProperty()
313    */
314   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
315
316   /**
317    * @copydoc Dali::Internal::Object::GetDefaultProperty()
318    */
319   Property::Value GetDefaultProperty(Property::Index index) const override;
320
321   /**
322    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
323    */
324   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
325
326   /**
327    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
328    */
329   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
330
331   /**
332    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
333    */
334   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
335
336   /**
337    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
338    */
339   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
340
341 public: // signals
342   /**
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.
348    */
349   bool HasFinished();
350
351   /**
352    * Emit the Finished signal
353    */
354   void EmitSignalFinish();
355
356   /**
357    * @copydoc Dali::RenderTask::FinishedSignal()
358    */
359   Dali::RenderTask::RenderTaskSignalType& FinishedSignal();
360
361   /**
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.
369    */
370   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
371
372 protected:
373   /**
374    * Constructor.
375    *
376    * @param[in] sceneObject The scene graph object
377    * @param[in] renderTaskList The render task list
378    */
379   RenderTask(const SceneGraph::RenderTask* sceneObject, RenderTaskList& renderTaskList);
380
381   /**
382    * A reference counted object may only be deleted by calling Unreference()
383    */
384   ~RenderTask() override;
385
386 private: // not copyable
387   RenderTask()                  = delete;
388   RenderTask(const RenderTask&) = delete;
389   RenderTask& operator=(const RenderTask&) = delete;
390
391 private:
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
398
399   Vector4 mClearColor; ///< Optional clear color
400
401   Vector2 mViewportPosition; ///< The cached viewport position
402   Vector2 mViewportSize;     ///< The cached viewport size
403
404   uint32_t mRefreshRate; ///< Determines how often the task is processed.
405
406   uint32_t mRefreshOnceCounter;
407
408   FrameBufferPtr mFrameBuffer;
409
410   Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
411
412   uint32_t mRenderPassTag{0u};
413   int32_t mOrderIndex{0u};
414
415   uint32_t mRenderTaskId{0u};
416
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.
422
423   // Signals
424   Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
425 };
426
427 } // namespace Internal
428
429 // Helpers for public-api forwarding methods
430
431 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
432 {
433   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
434
435   BaseObject& handle = task.GetBaseObject();
436
437   return static_cast<Internal::RenderTask&>(handle);
438 }
439
440 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
441 {
442   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
443
444   const BaseObject& handle = task.GetBaseObject();
445
446   return static_cast<const Internal::RenderTask&>(handle);
447 }
448
449 } // namespace Dali
450
451 #endif // DALI_INTERNAL_RENDER_TASK_H