b9396910e37f026fab13c6b1a82002114a13d1e1
[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) 2022 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    * @return The created render task
60    */
61   static RenderTaskPtr New(Actor* sourceActor, CameraActor* cameraActor, RenderTaskList& renderTaskList);
62
63   /**
64    * @copydoc Dali::RenderTask::SetSourceActor()
65    */
66   void SetSourceActor(Actor* actor);
67
68   /**
69    * @copydoc Dali::RenderTask::GetSourceActor()
70    */
71   Actor* GetSourceActor() const;
72
73   /**
74    * @copydoc Dali::RenderTask::SetExclusive()
75    */
76   void SetExclusive(bool exclusive);
77
78   /**
79    * @copydoc Dali::RenderTask::IsExclusive()
80    */
81   bool IsExclusive() const;
82
83   /**
84    * @copydoc Dali::RenderTask::SetInputEnabled()
85    */
86   void SetInputEnabled(bool enabled);
87
88   /**
89    * @copydoc Dali::RenderTask::GetInputEnabled()
90    */
91   bool GetInputEnabled() const;
92
93   /**
94    * @copydoc Dali::RenderTask::SetCameraActor()
95    */
96   void SetCameraActor(CameraActor* cameraActor);
97
98   /**
99    * @copydoc Dali::RenderTask::GetCameraActor()
100    */
101   CameraActor* GetCameraActor() const;
102
103   /**
104     * @copydoc Dali::RenderTask::SetFrameBuffer()
105     */
106   void SetFrameBuffer(FrameBufferPtr frameBuffer);
107
108   /**
109     * @copydoc Dali::RenderTask::GetFrameBuffer
110     */
111   FrameBuffer* GetFrameBuffer() const;
112
113   /**
114    * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
115    */
116   void SetScreenToFrameBufferFunction(ScreenToFrameBufferFunction conversionFunction);
117
118   /**
119    * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
120    */
121   ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
122
123   /**
124    * @copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
125    */
126   void SetScreenToFrameBufferMappingActor(Dali::Actor& mappingActor);
127
128   /**
129    * @copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
130    */
131   Dali::Actor GetScreenToFrameBufferMappingActor() const;
132
133   /**
134    * @copydoc Dali::RenderTask::SetViewportGuideActor
135    */
136   void SetViewportGuideActor(Actor* actor);
137
138   /**
139    * @copydoc Dali::RenderTask::GetViewportGuideActor
140    */
141   Actor* GetViewportGuideActor() const;
142
143   /**
144    * @copydoc Dali::RenderTask::ResetViewportGuideActor
145    */
146   void ResetViewportGuideActor();
147
148   /**
149    * @copydoc Dali::RenderTask::SetViewportPosition
150    */
151   void SetViewportPosition(const Vector2& value);
152
153   /**
154    * @copydoc Dali::RenderTask::GetCurrentViewportPosition
155    */
156   Vector2 GetCurrentViewportPosition() const;
157
158   /**
159    * @copydoc Dali::RenderTask::SetViewportSize
160    */
161   void SetViewportSize(const Vector2& value);
162
163   /**
164    * @copydoc Dali::RenderTask::GetCurrentViewportSize
165    */
166   Vector2 GetCurrentViewportSize() const;
167
168   /**
169    * @copydoc Dali::RenderTask::SetViewport()
170    */
171   void SetViewport(const Viewport& viewport);
172
173   /**
174    * @param[out] viewPort instance to copy the values into
175    */
176   void GetViewport(Viewport& viewPort) const;
177
178   /**
179    * @copydoc Dali::RenderTask::SetClearColor()
180    */
181   void SetClearColor(const Vector4& color);
182
183   /**
184    * @copydoc Dali::RenderTask::GetClearColor()
185    */
186   const Vector4& GetClearColor() const;
187
188   /**
189    * Indicate whether GL sync is required for native render target.
190    * @param[in] requiresSync whether GL sync is required.
191    */
192   void SetSyncRequired(bool requiresSync);
193
194   /**
195    * Query whether the sync object is required for native render target.
196    * @return True if the sync object is required, false otherwise.
197    */
198   bool IsSyncRequired() const;
199
200   /**
201    * @copydoc Dali::RenderTask::SetClearEnabled()
202    */
203   void SetClearEnabled(bool enabled);
204
205   /**
206    * @copydoc Dali::RenderTask::GetClearEnabled()
207    */
208   bool GetClearEnabled() const;
209
210   /**
211    * @copydoc Dali::RenderTask::SetCullMode()
212    */
213   void SetCullMode(bool mode);
214
215   /**
216    * @copydoc Dali::RenderTask::GetCullMode()
217    */
218   bool GetCullMode() const;
219
220   /**
221    * @copydoc Dali::RenderTask::SetRefreshRate()
222    */
223   void SetRefreshRate(uint32_t refreshRate);
224
225   /**
226    * @copydoc Dali::RenderTask::GetRefreshRate()
227    */
228   uint32_t GetRefreshRate() const;
229
230   /**
231    * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
232    * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
233    * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
234    */
235   bool IsHittable(Vector2& screenCoords) const;
236
237   /**
238    * Translates screen coordinates to render task coordinates for offscreen render tasks
239    * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
240    * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
241    */
242   bool TranslateCoordinates(Vector2& screenCoords) const;
243
244   /**
245    * @copydoc Dali::RenderTask::WorldToViewport()
246    */
247   bool WorldToViewport(const Vector3& position, float& viewportX, float& viewportY) const;
248
249   /**
250    * @copydoc Dali::RenderTask::ViewportToLocal()
251    */
252   bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float& localX, float& localY) const;
253
254 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
255   /**
256    * Retrieve the scene-graph RenderTask object.
257    * @return The scene-graph object
258    */
259   const SceneGraph::RenderTask& GetRenderTaskSceneObject() const;
260
261   /**
262    * Retrieve the render task list RenderTask object belongs to.
263    * @return The render task list
264    */
265   RenderTaskList& GetRenderTaskList() const;
266
267 public: // Implementation of Object
268   /**
269    * @copydoc Dali::Internal::Object::SetDefaultProperty()
270    */
271   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
272
273   /**
274    * @copydoc Dali::Internal::Object::GetDefaultProperty()
275    */
276   Property::Value GetDefaultProperty(Property::Index index) const override;
277
278   /**
279    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
280    */
281   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
282
283   /**
284    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
285    */
286   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
287
288   /**
289    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
290    */
291   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
292
293   /**
294    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
295    */
296   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
297
298 public: //signals
299   /**
300    * Query whether a Finished signal should be emitted for this render-task.
301    * This should only be called by NotificationManager, before signals are emitted.
302    * @pre The refresh rate must be REFRESH_ONCE.
303    * @post HasFinished() will return false on subsequent calls, until the render-task is processed again.
304    * @return \e true if the refresh once render task has finished. Otherwise it returns \e false.
305    */
306   bool HasFinished();
307
308   /**
309    * Emit the Finished signal
310    */
311   void EmitSignalFinish();
312
313   /**
314    * @copydoc Dali::RenderTask::FinishedSignal()
315    */
316   Dali::RenderTask::RenderTaskSignalType& FinishedSignal();
317
318   /**
319    * Connects a callback function with the object's signals.
320    * @param[in] object The object providing the signal.
321    * @param[in] tracker Used to disconnect the signal.
322    * @param[in] signalName The signal to connect to.
323    * @param[in] functor A newly allocated FunctorDelegate.
324    * @return True if the signal was connected.
325    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
326    */
327   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
328
329 protected:
330   /**
331    * Constructor.
332    *
333    * @param[in] sceneObject The scene graph object
334    * @param[in] renderTaskList The render task list
335    */
336   RenderTask(const SceneGraph::RenderTask* sceneObject, RenderTaskList& renderTaskList);
337
338   /**
339    * A reference counted object may only be deleted by calling Unreference()
340    */
341   ~RenderTask() override;
342
343 private: // not copyable
344   RenderTask()                  = delete;
345   RenderTask(const RenderTask&) = delete;
346   RenderTask& operator=(const RenderTask&) = delete;
347
348 private:
349   ActorObserver           mSourceActor;        ///< Source actor
350   ActorObserver           mCameraActor;        ///< Camera actor
351   ActorObserver           mViewportGuideActor; ///< Actor to matching viewport of this render task to this Actor.
352   WeakHandle<Dali::Actor> mInputMappingActor;  /// used to mapping screen to frame buffer coordinate, not kept alive by rendertask
353   RenderTaskList&         mRenderTaskList;     ///< The render task list
354
355   Vector4 mClearColor; ///< Optional clear color
356
357   Vector2 mViewportPosition; ///< The cached viewport position
358   Vector2 mViewportSize;     ///< The cached viewport size
359
360   uint32_t mRefreshRate; ///< Determines how often the task is processed.
361
362   uint32_t mRefreshOnceCounter;
363
364   FrameBufferPtr mFrameBuffer;
365
366   Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
367
368   bool mExclusive : 1;    ///< True if the render-task has exclusive access to the source Nodes.
369   bool mInputEnabled : 1; ///< True if the render-task should be considered for input handling.
370   bool mClearEnabled : 1; ///< True if the render-task should be clear the color buffer.
371   bool mCullMode : 1;     ///< True if the render-task's actors should be culled
372   bool mRequiresSync : 1; ///< True if the GL sync is required to track the render of.
373
374   //Signals
375   Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
376 };
377
378 } // namespace Internal
379
380 // Helpers for public-api forwarding methods
381
382 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
383 {
384   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
385
386   BaseObject& handle = task.GetBaseObject();
387
388   return static_cast<Internal::RenderTask&>(handle);
389 }
390
391 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
392 {
393   DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
394
395   const BaseObject& handle = task.GetBaseObject();
396
397   return static_cast<const Internal::RenderTask&>(handle);
398 }
399
400 } // namespace Dali
401
402 #endif // DALI_INTERNAL_RENDER_TASK_H