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