Merge "Remove the actor from exclusive list in RenderTaskList when the actor is destr...
[platform/core/uifw/dali-core.git] / dali / public-api / render-tasks / render-task.h
1 #ifndef __DALI_RENDER_TASK_H__
2 #define __DALI_RENDER_TASK_H__
3
4 /*
5  * Copyright (c) 2015 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/math/viewport.h>
23 #include <dali/public-api/object/handle.h>
24 #include <dali/public-api/object/property-index-ranges.h>
25 #include <dali/public-api/signals/dali-signal.h>
26
27 namespace Dali
28 {
29 /**
30  * @addtogroup dali_core_render_tasks
31  * @{
32  */
33
34 class Actor;
35 class CameraActor;
36 class FrameBufferImage;
37 struct Vector4;
38
39 namespace Internal DALI_INTERNAL
40 {
41 class RenderTask;
42 }
43
44 /**
45  * @brief RenderTasks describe how the Dali scene should be rendered.
46  *
47  * The Stage::GetRenderTaskList() method provides access to an ordered list of render-tasks.
48  *
49  * Each RenderTask must specify the source actors to be rendered, and a camera actor from
50  * which the scene is viewed.
51  *
52  * RenderTasks may optionally target a frame-buffer, otherwise the default GL surface is used;
53  * typically this is a window provided by the native system.
54  *
55  * By default Dali provides a single RenderTask, which renders the entire actor hierachy using
56  * a default camera actor and GL surface. If stereoscopic rendering is enabled, Dali will create
57  * two additional render tasks, on for each eye. Each render task will have its own camera parented
58  * to the default camera actor.
59  *
60  * The first RenderTask used for input handling will be the last one rendered, which also has input enabled,
61  * and has a valid source & camera actor; see SetInputEnabled().
62  *
63  * If none of the actors are hit in the last RenderTask rendered, then input handling will continue
64  * with the second last RenderTask rendered, and so on.
65  *
66  * All RenderTasks which target a frame-buffer (i.e. off screen) will be rendered before all RenderTasks
67  * which target the default GL surface. This allows the user to render intermediate targets which are used
68  * later when targetting the screen.
69  *
70  * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the
71  * screen->frame-buffer coordinate conversion is successful; see SetScreenToFrameBufferFunction().
72  *
73  * If the refresh rate id REFRESH_ONCE and a "Finish" signal is connected, it will be emitted when the RenderTask is completed.
74  * Note that all connected signals must be disconnected before the object is destroyed. This is typically done in the
75  * object destructor, and requires either the Dali::Connection object or Dali::RenderTask handle to be stored.
76  *
77  * Signals
78  * | %Signal Name | Method                |
79  * |--------------|-----------------------|
80  * | finished     | @ref FinishedSignal() |
81  */
82 class DALI_IMPORT_API RenderTask : public Handle
83 {
84 public:
85
86   /**
87    * @brief An enumeration of properties belonging to the RenderTask class.
88    */
89   struct Property
90   {
91     enum
92     {
93       VIEWPORT_POSITION = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "viewport-position", type Vector2
94       VIEWPORT_SIZE,                                           ///< name "viewport-size",     type Vector2
95       CLEAR_COLOR,                                             ///< name "clear-color",       type Vector4
96     };
97   };
98
99   /**
100    * @brief Typedef for signals sent by this class.
101    */
102   typedef Signal< void (RenderTask& source) > RenderTaskSignalType;
103
104   /**
105    * @brief A pointer to a function for converting screen to frame-buffer coordinates.
106    * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
107    * @return True if the conversion was successful, otherwise coordinates should be unmodified.
108    */
109   typedef bool (* ScreenToFrameBufferFunction)( Vector2& coordinates );
110
111   /**
112    * @brief A pointer to a function for converting screen to frame-buffer coordinates.
113    * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
114    * @return True if the conversion was successful, otherwise coordinates should be unmodified.
115    */
116   typedef bool (* const ConstScreenToFrameBufferFunction)( Vector2& coordinates );
117
118   /**
119    * @brief The default conversion function returns false for any screen coordinates.
120    *
121    * This effectively disables hit-testing for RenderTasks rendering to a frame buffer.
122    * See also FULLSCREEN_FRAMEBUFFER_FUNCTION below.
123    */
124   static ConstScreenToFrameBufferFunction DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION;
125
126   /**
127    * @brief This conversion function outputs the (unmodified) screen coordinates as frame-buffer coordinates.
128    *
129    * Therefore the contents of an off-screen image is expected to be rendered "full screen".
130    */
131   static ConstScreenToFrameBufferFunction FULLSCREEN_FRAMEBUFFER_FUNCTION;
132
133   /**
134    * @brief The refresh-rate of the RenderTask.
135    */
136   enum RefreshRate
137   {
138     REFRESH_ONCE   = 0, ///< Process once only e.g. take a snap-shot of the scene.
139     REFRESH_ALWAYS = 1  ///< Process every frame.
140   };
141
142   static const bool         DEFAULT_EXCLUSIVE;     ///< false
143   static const bool         DEFAULT_INPUT_ENABLED; ///< true
144   static const Vector4      DEFAULT_CLEAR_COLOR;   ///< Color::BLACK
145   static const bool         DEFAULT_CLEAR_ENABLED; ///< false
146   static const bool         DEFAULT_CULL_MODE;     ///< true
147   static const unsigned int DEFAULT_REFRESH_RATE;  ///< REFRESH_ALWAYS
148
149   /**
150    * @brief Create an empty RenderTask handle.
151    *
152    * This can be initialised with RenderTaskList::CreateRenderTask().
153    */
154   RenderTask();
155
156   /**
157    * @brief Downcast a handle to RenderTask handle.
158    *
159    * If handle points to a RenderTask the
160    * downcast produces valid handle. If not the returned handle is left uninitialized.
161    * @param[in] handle A handle to an object.
162    * @return A handle to a RenderTask or an uninitialized handle.
163    */
164   static RenderTask DownCast( BaseHandle handle );
165
166   /**
167    * @brief Destructor
168    *
169    * This is non-virtual since derived Handle types must not contain data or virtual methods.
170    */
171   ~RenderTask();
172
173   /**
174    * @brief This copy constructor is required for (smart) pointer semantics.
175    *
176    * @param [in] handle A reference to the copied handle
177    */
178   RenderTask(const RenderTask& handle);
179
180   /**
181    * @brief This assignment operator is required for (smart) pointer semantics.
182    *
183    * @param [in] rhs  A reference to the copied handle
184    * @return A reference to this
185    */
186   RenderTask& operator=(const RenderTask& rhs);
187
188   /**
189    * @brief Set the actors to be rendered.
190    * @param[in] actor This actor and its children will be rendered.
191    * If actor is an empty handle, then nothing will be rendered.
192    */
193   void SetSourceActor( Actor actor );
194
195   /**
196    * @brief Retrieve the actors to be rendered.
197    * @return This actor and its children will be rendered.
198    */
199   Actor GetSourceActor() const;
200
201   /**
202    * @brief Set whether the RenderTask has exclusive access to the source actors; the default is false.
203    * @param[in] exclusive True if the source actors will only be rendered by this render-task.
204    */
205   void SetExclusive( bool exclusive );
206
207   /**
208    * @brief Query whether the RenderTask has exclusive access to the source actors.
209    * @return True if the source actors will only be rendered by this render-task.
210    */
211   bool IsExclusive() const;
212
213   /**
214    * @brief Set whether the render-task should be considered for input handling; the default is true.
215    *
216    * The task used for input handling will be last task in the RenderTaskList which has input enabled,
217    * and has a valid source & camera actor.
218    * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the screen->frame-buffer
219    * coordinate conversion is successful; see also SetScreenToFrameBufferFunction().
220    * @param[in] enabled True if the render-task should be considered for input handling.
221    */
222   void SetInputEnabled( bool enabled );
223
224   /**
225    * @brief Query whether the render-task should be considered for input handling.
226    * @return True if the render-task should be considered for input handling.
227    */
228   bool GetInputEnabled() const;
229
230   /**
231    * @brief Set the actor from which the scene is viewed.
232    * @param[in] cameraActor The scene is viewed from the perspective of this actor.
233    */
234   void SetCameraActor( CameraActor cameraActor );
235
236   /**
237    * @brief Retrieve the actor from which the scene is viewed.
238    * @return The scene is viewed from the perspective of this actor.
239    */
240   CameraActor GetCameraActor() const;
241
242   /**
243    * @brief Set the frame-buffer used as a render target.
244    * @param[in] frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable.
245    */
246   void SetTargetFrameBuffer( FrameBufferImage frameBuffer );
247
248   /**
249    * @brief Retrieve the frame-buffer used as a render target.
250    * @return A valid frame-buffer handle, or an uninitialised handle if off-screen rendering is disabled.
251    */
252   FrameBufferImage GetTargetFrameBuffer() const;
253
254   /**
255    * @brief Set the function used to convert screen coordinates to frame-buffer coordinates.
256    *
257    * This is useful for hit-testing actors which are rendered off-screen.
258    * @param[in] conversionFunction The conversion function.
259    */
260   void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
261
262   /**
263    * @brief Retrieve the function used to convert screen coordinates to frame-buffer coordinates.
264    * @return The conversion function.
265    */
266   ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
267
268   /**
269    * @brief Set the actor used to convert screen coordinates to frame-buffer coordinates.
270    *
271    * The local coordinates of the actor are mapped as frame-buffer coordinates.
272    * This is useful for hit-testing actors which are rendered off-screen.
273    * Note: The mapping actor needs to be rendered by the default render task to make the mapping work properly.
274    * @param[in] mappingActor The actor used for conversion.
275    */
276   void SetScreenToFrameBufferMappingActor( Actor mappingActor );
277
278   /**
279    * @brief Retrieve the actor used to convert screen coordinates to frame-buffer coordinates.
280    * @return The actor used for conversion.
281    */
282   Actor GetScreenToFrameBufferMappingActor() const;
283
284   /**
285    * @brief Set the GL viewport position used when rendering.
286    *
287    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
288    * By default this will match the target window or frame-buffer size.
289    * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
290    * @param[in] position The viewports position (x,y)
291    */
292   void SetViewportPosition( Vector2 position );
293
294   /**
295    * @brief Retrieve the GL viewport position used when rendering.
296    * @return The viewport.
297    */
298   Vector2 GetCurrentViewportPosition() const;
299
300   /**
301    * @brief Set the GL viewport size used when rendering.
302    *
303    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
304    * By default this will match the target window or frame-buffer size.
305    * @param[in] size The viewports size (width,height)
306    */
307   void SetViewportSize( Vector2 size );
308
309   /**
310    * @brief Retrieve the GL viewport size used when rendering.
311    * @return The viewport.
312    */
313   Vector2 GetCurrentViewportSize() const;
314
315   /**
316    * @brief Set the GL viewport used when rendering.
317    *
318    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
319    * By default this will match the target window or frame-buffer size.
320    * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
321    * @param[in] viewport The new viewport.
322    */
323   void SetViewport( Viewport viewport );
324
325   /**
326    * @brief Retrieve the GL viewport used when rendering.
327    * @return The viewport.
328    */
329   Viewport GetViewport() const;
330
331   /**
332    * @brief Set the clear color used when SetClearEnabled(true) is used.
333    * @param[in] color The new clear color.
334    */
335   void SetClearColor( const Vector4& color );
336
337   /**
338    * @brief Retrieve the clear color used when SetClearEnabled(true) is used.
339    * @note This property can be animated; the return value may not match the value written with SetClearColor().
340    * @return The clear color.
341    */
342   Vector4 GetClearColor() const;
343
344   /**
345    * @brief Set whether the render-task will clear the results of previous render-tasks.
346    *
347    * The default is false.
348    *
349    * @note The default GL surface is cleared automatically at the
350    * beginning of each frame; this setting is only useful when 2+
351    * render-tasks are used, and the result of the first task needs to
352    * be (partially) cleared before rendering the second.
353    *
354    * @param[in] enabled True if the render-task should clear.
355    */
356   void SetClearEnabled( bool enabled );
357
358   /**
359    * @brief Query whether the render-task will clear the results of previous render-tasks.
360    * @return True if the render-task should clear.
361    */
362   bool GetClearEnabled() const;
363
364   /**
365    * @brief Set whether the render task will cull the actors to the camera's view frustum.
366    *
367    * Note that this will only affect image actors that use the default vertex shader.
368    * The default mode is to cull actors.
369    * @param[in] cullMode True if the renderers should be culled.
370    */
371   void SetCullMode( bool cullMode );
372
373   /**
374    * @brief Get the cull mode.
375    *
376    * @return True if the render task should cull the actors to the camera's view frustum
377    */
378   bool GetCullMode() const;
379
380   /**
381    * @brief Set the refresh-rate of the RenderTask.
382    *
383    * The default is REFRESH_ALWAYS (1), meaning that the RenderTask
384    * will be processed every frame if the scene graph is changing.  It
385    * may be desirable to process less frequently. For example,
386    * SetRefreshRate(3) will process once every 3 frames if the scene
387    * graph is changing.  If the scene graph is not changing, then the
388    * render task will not be rendered, regardless of this value.
389    *
390    * The REFRESH_ONCE value means that the RenderTask will be
391    * processed once only, to take a snap-shot of the scene.
392    * Repeatedly calling SetRefreshRate(REFRESH_ONCE) will cause more
393    * snap-shots to be taken.
394    *
395    * @param[in] refreshRate The new refresh rate.
396    */
397   void SetRefreshRate( unsigned int refreshRate );
398
399   /**
400    * @brief Query the refresh-rate of the RenderTask.
401    * @return The refresh-rate.
402    */
403   unsigned int GetRefreshRate() const;
404
405 public: // Signals
406
407   /**
408    * @brief If the refresh rate is REFRESH_ONCE, connect to this signal to be notified when a RenderTask has finished.
409    */
410   RenderTaskSignalType& FinishedSignal();
411
412 public: // Not intended for application developers
413
414   /**
415    * @brief This constructor is used by Dali New() methods.
416    * @param [in] renderTask A pointer to a newly allocated render-task
417    */
418   explicit DALI_INTERNAL RenderTask( Internal::RenderTask* renderTask );
419 };
420
421 /**
422  * @}
423  */
424 } // namespace Dali
425
426 #endif //__DALI_RENDER_TASK_H__