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