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