Update doxygen comments
[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_rendering_effects
31  * @{
32  */
33
34 class Actor;
35 class CameraActor;
36 class FrameBufferImage;
37 class FrameBuffer;
38 struct Vector4;
39
40 namespace Internal DALI_INTERNAL
41 {
42 class RenderTask;
43 }
44
45 /**
46  * @brief RenderTasks describe how the Dali scene should be rendered.
47  *
48  * The Stage::GetRenderTaskList() method provides access to an ordered list of render-tasks.
49  *
50  * Each RenderTask must specify the source actors to be rendered, and a camera actor from
51  * which the scene is viewed.
52  *
53  * RenderTasks may optionally target a frame-buffer, otherwise the default GL surface is used;
54  * typically this is a window provided by the native system.
55  *
56  * By default Dali provides a single RenderTask, which renders the entire actor hierachy using
57  * a default camera actor and GL surface. If stereoscopic rendering is enabled, Dali will create
58  * two additional render tasks, on for each eye. Each render task will have its own camera parented
59  * to the default camera actor.
60  *
61  * The first RenderTask used for input handling will be the last one rendered, which also has input enabled,
62  * and has a valid source & camera actor; see SetInputEnabled().
63  *
64  * If none of the actors are hit in the last RenderTask rendered, then input handling will continue
65  * with the second last RenderTask rendered, and so on.
66  *
67  * All RenderTasks which target a frame-buffer (i.e. off screen) will be rendered before all RenderTasks
68  * which target the default GL surface. This allows the user to render intermediate targets which are used
69  * later when targeting the screen.
70  *
71  * A RenderTask targeting a frame-buffer can still be hit-tested, provided that the
72  * screen->frame-buffer coordinate conversion is successful; see SetScreenToFrameBufferFunction().
73  *
74  * If the refresh rate id REFRESH_ONCE and a "Finish" signal is connected, it will be emitted when the RenderTask is completed.
75  * Note that all connected signals must be disconnected before the object is destroyed. This is typically done in the
76  * object destructor, and requires either the Dali::Connection object or Dali::RenderTask handle to be stored.
77  *
78  * Signals
79  * | %Signal Name | Method                |
80  * |--------------|-----------------------|
81  * | finished     | @ref FinishedSignal() |
82  * @SINCE_1_0.0
83  */
84 class DALI_IMPORT_API RenderTask : public Handle
85 {
86 public:
87
88   /**
89    * @brief Enumeration for instances of properties belonging to the RenderTask class.
90    * @SINCE_1_0.0
91    */
92   struct Property
93   {
94     /**
95      * @brief Enumeration for instances of properties belonging to the RenderTask class.
96      * @SINCE_1_0.0
97      */
98     enum
99     {
100       /**
101        * @brief name "viewportPosition", type Vector2
102        * @SINCE_1_0.0
103        */
104       VIEWPORT_POSITION = DEFAULT_OBJECT_PROPERTY_START_INDEX,
105       /**
106        * @brief name "viewportSize", type Vector2
107        * @SINCE_1_0.0
108        */
109       VIEWPORT_SIZE,
110       /**
111        * @brief name "clearColor", type Vector4
112        * @SINCE_1_0.0
113        */
114       CLEAR_COLOR,
115       /**
116        * @brief name "requiresSync", type BOOLEAN
117        * @details By default, the sync object is not created.
118        *  When native image source is used as render target, in order to track when the render to pixmap is completed, the GL sync should be enabled.
119        *  Thus the RENDER_ONCE finished signal can be emit at the correct timing.
120        * @SINCE_1_1.29
121        * @note The use of GL sync might cause deadlock with multiple access to the single pixmap happening in the same time.
122        */
123       REQUIRES_SYNC,
124     };
125   };
126
127   /**
128    * @brief Typedef for signals sent by this class.
129    * @SINCE_1_0.0
130    */
131   typedef Signal< void (RenderTask& source) > RenderTaskSignalType;
132
133   /**
134    * @brief A pointer to a function for converting screen to frame-buffer coordinates.
135    * @SINCE_1_0.0
136    * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen
137    * @return True if the conversion was successful, otherwise coordinates should be unmodified
138    */
139   typedef bool (* ScreenToFrameBufferFunction)( Vector2& coordinates );
140
141   /**
142    * @brief A pointer to a function for converting screen to frame-buffer coordinates.
143    * @SINCE_1_0.0
144    * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen
145    * @return True if the conversion was successful, otherwise coordinates should be unmodified
146    */
147   typedef bool (* const ConstScreenToFrameBufferFunction)( Vector2& coordinates );
148
149   /**
150    * @brief The default conversion function returns false for any screen coordinates.
151    *
152    * This effectively disables hit-testing for RenderTasks rendering to a frame buffer.
153    * See also FULLSCREEN_FRAMEBUFFER_FUNCTION below.
154    */
155   static ConstScreenToFrameBufferFunction DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION;
156
157   /**
158    * @brief This conversion function outputs the (unmodified) screen coordinates as frame-buffer coordinates.
159    *
160    * Therefore the contents of an off-screen image is expected to be rendered "full screen".
161    */
162   static ConstScreenToFrameBufferFunction FULLSCREEN_FRAMEBUFFER_FUNCTION;
163
164   /**
165    * @brief Enumeration for the refresh-rate of the RenderTask.
166    * @SINCE_1_0.0
167    */
168   enum RefreshRate
169   {
170     REFRESH_ONCE   = 0, ///< Process once only e.g. take a snap-shot of the scene. @SINCE_1_0.0
171     REFRESH_ALWAYS = 1  ///< Process every frame. @SINCE_1_0.0
172   };
173
174   static const bool         DEFAULT_EXCLUSIVE;     ///< false
175   static const bool         DEFAULT_INPUT_ENABLED; ///< true
176   static const Vector4      DEFAULT_CLEAR_COLOR;   ///< Color::BLACK
177   static const bool         DEFAULT_CLEAR_ENABLED; ///< false
178   static const bool         DEFAULT_CULL_MODE;     ///< true
179   static const unsigned int DEFAULT_REFRESH_RATE;  ///< REFRESH_ALWAYS
180
181   /**
182    * @brief Creates an empty RenderTask handle.
183    *
184    * This can be initialised with RenderTaskList::CreateRenderTask().
185    * @SINCE_1_0.0
186    */
187   RenderTask();
188
189   /**
190    * @brief Downcasts a handle to RenderTask handle.
191    *
192    * If handle points to a RenderTask, the
193    * downcast produces valid handle. If not, the returned handle is left uninitialized.
194    * @SINCE_1_0.0
195    * @param[in] handle A handle to an object
196    * @return A handle to a RenderTask or an uninitialized handle
197    */
198   static RenderTask DownCast( BaseHandle handle );
199
200   /**
201    * @brief Destructor.
202    *
203    * This is non-virtual since derived Handle types must not contain data or virtual methods.
204    * @SINCE_1_0.0
205    */
206   ~RenderTask();
207
208   /**
209    * @brief This copy constructor is required for (smart) pointer semantics.
210    *
211    * @SINCE_1_0.0
212    * @param[in] handle A reference to the copied handle
213    */
214   RenderTask(const RenderTask& handle);
215
216   /**
217    * @brief This assignment operator is required for (smart) pointer semantics.
218    *
219    * @SINCE_1_0.0
220    * @param[in] rhs A reference to the copied handle
221    * @return A reference to this
222    */
223   RenderTask& operator=(const RenderTask& rhs);
224
225   /**
226    * @brief Sets the actors to be rendered.
227    * @SINCE_1_0.0
228    * @param[in] actor This actor and its children will be rendered.
229    * If actor is an empty handle, then nothing will be rendered
230    */
231   void SetSourceActor( Actor actor );
232
233   /**
234    * @brief Retrieves the actors to be rendered.
235    * @SINCE_1_0.0
236    * @return This actor and its children will be rendered
237    */
238   Actor GetSourceActor() const;
239
240   /**
241    * @brief Sets whether the RenderTask has exclusive access to the source actors; the default is false.
242    * @SINCE_1_0.0
243    * @param[in] exclusive True if the source actors will only be rendered by this render-task
244    */
245   void SetExclusive( bool exclusive );
246
247   /**
248    * @brief Queries whether the RenderTask has exclusive access to the source actors.
249    * @SINCE_1_0.0
250    * @return True if the source actors will only be rendered by this render-task
251    */
252   bool IsExclusive() const;
253
254   /**
255    * @brief Sets whether the render-task should be considered for input handling; the default is true.
256    *
257    * The task used for input handling will be last task in the RenderTaskList which has input enabled,
258    * and has a valid source & camera actor.
259    * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the screen->frame-buffer
260    * coordinate conversion is successful; see also SetScreenToFrameBufferFunction().
261    * @SINCE_1_0.0
262    * @param[in] enabled True if the render-task should be considered for input handling
263    */
264   void SetInputEnabled( bool enabled );
265
266   /**
267    * @brief Queries whether the render-task should be considered for input handling.
268    * @SINCE_1_0.0
269    * @return True if the render-task should be considered for input handling
270    */
271   bool GetInputEnabled() const;
272
273   /**
274    * @brief Sets the actor from which the scene is viewed.
275    * @SINCE_1_0.0
276    * @param[in] cameraActor The scene is viewed from the perspective of this actor
277    */
278   void SetCameraActor( CameraActor cameraActor );
279
280   /**
281    * @brief Retrieves the actor from which the scene is viewed.
282    * @SINCE_1_0.0
283    * @return The scene is viewed from the perspective of this actor
284    */
285   CameraActor GetCameraActor() const;
286
287   /**
288    * @brief Sets the frame-buffer used as a render target.
289    * @SINCE_1_0.0
290    * @param[in] frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable
291    */
292   void SetTargetFrameBuffer( FrameBufferImage frameBuffer );
293
294   /**
295    * @brief Retrieves the frame-buffer used as a render target.
296    * @SINCE_1_0.0
297    * @return A valid frame-buffer handle, or an uninitialised handle if off-screen rendering is disabled
298    */
299   FrameBufferImage GetTargetFrameBuffer() const;
300
301   /**
302    * @brief Sets the frame-buffer used as a render target.
303    * @SINCE_1_1.38
304    * @param[in] frameBuffer er A valid FrameBuffer handle to enable off-screen rendering, or an uninitialized handle to disable it
305    */
306   void SetFrameBuffer( FrameBuffer frameBuffer );
307
308   /**
309    * @brief Retrieves the frame-buffer used as a render target.
310    * @SINCE_1_1.38
311    * @return The framebuffer
312    */
313   FrameBuffer GetFrameBuffer() const;
314
315   /**
316    * @brief Sets the function used to convert screen coordinates to frame-buffer coordinates.
317    *
318    * This is useful for hit-testing actors which are rendered off-screen.
319    * @SINCE_1_0.0
320    * @param[in] conversionFunction The conversion function
321    */
322   void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
323
324   /**
325    * @brief Retrieves the function used to convert screen coordinates to frame-buffer coordinates.
326    * @SINCE_1_0.0
327    * @return The conversion function
328    */
329   ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
330
331   /**
332    * @brief Sets the actor used to convert screen coordinates to frame-buffer coordinates.
333    *
334    * The local coordinates of the actor are mapped as frame-buffer coordinates.
335    * This is useful for hit-testing actors which are rendered off-screen.
336    * @SINCE_1_0.0
337    * @param[in] mappingActor The actor used for conversion
338    * @note The mapping actor needs to be rendered by the default render task to make the mapping work properly.
339    */
340   void SetScreenToFrameBufferMappingActor( Actor mappingActor );
341
342   /**
343    * @brief Retrieves the actor used to convert screen coordinates to frame-buffer coordinates.
344    * @SINCE_1_0.0
345    * @return The actor used for conversion
346    */
347   Actor GetScreenToFrameBufferMappingActor() const;
348
349   /**
350    * @brief Sets the GL viewport position used when rendering.
351    *
352    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
353    * By default this will match the target window or frame-buffer size.
354    * @SINCE_1_0.0
355    * @param[in] position The viewports position (x,y)
356    * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
357    */
358   void SetViewportPosition( Vector2 position );
359
360   /**
361    * @brief Retrieves the GL viewport position used when rendering.
362    * @SINCE_1_0.0
363    * @return The viewport
364    */
365   Vector2 GetCurrentViewportPosition() const;
366
367   /**
368    * @brief Sets the GL viewport size used when rendering.
369    *
370    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
371    * By default this will match the target window or frame-buffer size.
372    * @SINCE_1_0.0
373    * @param[in] size The viewports size (width,height)
374    */
375   void SetViewportSize( Vector2 size );
376
377   /**
378    * @brief Retrieves the GL viewport size used when rendering.
379    * @SINCE_1_0.0
380    * @return The viewport
381    */
382   Vector2 GetCurrentViewportSize() const;
383
384   /**
385    * @brief Sets the GL viewport used when rendering.
386    *
387    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
388    * By default this will match the target window or frame-buffer size.
389    * @SINCE_1_0.0
390    * @param[in] viewport The new viewport
391    * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
392    */
393   void SetViewport( Viewport viewport );
394
395   /**
396    * @brief Retrieves the GL viewport used when rendering.
397    * @SINCE_1_0.0
398    * @return The viewport
399    */
400   Viewport GetViewport() const;
401
402   /**
403    * @brief Sets the clear color used when SetClearEnabled(true) is used.
404    * @SINCE_1_0.0
405    * @param[in] color The new clear color
406    */
407   void SetClearColor( const Vector4& color );
408
409   /**
410    * @brief Retrieves the clear color used when SetClearEnabled(true) is used.
411    * @SINCE_1_0.0
412    * @return The clear color
413    * @note This property can be animated; the return value may not match the value written with SetClearColor().
414    */
415   Vector4 GetClearColor() const;
416
417   /**
418    * @brief Sets whether the render-task will clear the results of previous render-tasks.
419    *
420    * The default is false.
421    *
422    * @SINCE_1_0.0
423    * @param[in] enabled True if the render-task should clear
424    * @note The default GL surface is cleared automatically at the
425    * beginning of each frame; this setting is only useful when 2+
426    * render-tasks are used, and the result of the first task needs to
427    * be (partially) cleared before rendering the second.
428    *
429    */
430   void SetClearEnabled( bool enabled );
431
432   /**
433    * @brief Queries whether the render-task will clear the results of previous render-tasks.
434    * @SINCE_1_0.0
435    * @return True if the render-task should clear
436    */
437   bool GetClearEnabled() const;
438
439   /**
440    * @brief Sets whether the render task will cull the actors to the camera's view frustum.
441    *
442    * @SINCE_1_0.0
443    * @param[in] cullMode True if the renderers should be culled
444    * @note The default mode is to cull actors.
445    * @note If the shader uses @ref Shader::Hint::MODIFIES_GEOMETRY then culling optimizations are disabled.
446    * @see Shader::Hint
447    */
448   void SetCullMode( bool cullMode );
449
450   /**
451    * @brief Gets the cull mode.
452    *
453    * @SINCE_1_0.0
454    * @return True if the render task should cull the actors to the camera's view frustum
455    */
456   bool GetCullMode() const;
457
458   /**
459    * @brief Sets the refresh-rate of the RenderTask.
460    *
461    * The default is REFRESH_ALWAYS (1), meaning that the RenderTask
462    * will be processed every frame if the scene graph is changing.  It
463    * may be desirable to process less frequently. For example,
464    * SetRefreshRate(3) will process once every 3 frames if the scene
465    * graph is changing. If the scene graph is not changing, then the
466    * render task will not be rendered, regardless of this value.
467    *
468    * The REFRESH_ONCE value means that the RenderTask will be
469    * processed once only, to take a snap-shot of the scene.
470    * Repeatedly calling SetRefreshRate(REFRESH_ONCE) will cause more
471    * snap-shots to be taken.
472    *
473    * @SINCE_1_0.0
474    * @param[in] refreshRate The new refresh rate
475    */
476   void SetRefreshRate( unsigned int refreshRate );
477
478   /**
479    * @brief Queries the refresh-rate of the RenderTask.
480    * @SINCE_1_0.0
481    * @return The refresh-rate
482    */
483   unsigned int GetRefreshRate() const;
484
485   /*
486    * @brief Gets viewport coordinates for given world position.
487    *
488    * @SINCE_1_1.13
489    * @param[in] position The world position
490    * @param[out] viewportX The viewport x position
491    * @param[out] viewportY The viewport y position
492    * @return true if the position has a screen coordinate
493    */
494   bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
495
496   /*
497    * @brief Gets actor local coordinates for given viewport coordinates.
498    *
499    * @SINCE_1_1.13
500    * @param[in] actor The actor describing local coordinate system
501    * @param[in] viewportX The viewport x position
502    * @param[in] viewportY The viewport y position
503    * @param[out] localX The local x position
504    * @param[out] localY The local y position
505    * @return true if the screen position has a local coordinate
506    */
507   bool ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const;
508
509 public: // Signals
510
511   /**
512    * @brief If the refresh rate is REFRESH_ONCE, connect to this signal to be notified when a RenderTask has finished.
513    * @SINCE_1_0.0
514    * @return The signal to connect to
515    */
516   RenderTaskSignalType& FinishedSignal();
517
518 public: // Not intended for application developers
519
520   /// @cond internal
521   /**
522    * @brief This constructor is used by Dali New() methods.
523    * @SINCE_1_0.0
524    * @param[in] renderTask A pointer to a newly allocated render-task
525    */
526   explicit DALI_INTERNAL RenderTask( Internal::RenderTask* renderTask );
527   /// @endcond
528 };
529
530 /**
531  * @}
532  */
533 } // namespace Dali
534
535 #endif //__DALI_RENDER_TASK_H__