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