1 #ifndef __DALI_RENDER_TASK_H__
2 #define __DALI_RENDER_TASK_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @addtogroup CAPI_DALI_RENDER_TASKS_MODULE
27 #include <dali/public-api/math/viewport.h>
28 #include <dali/public-api/object/constrainable.h>
29 #include <dali/public-api/signals/dali-signal-v2.h>
31 namespace Dali DALI_IMPORT_API
36 class FrameBufferImage;
39 namespace Internal DALI_INTERNAL
45 * @brief RenderTasks describe how the Dali scene should be rendered.
47 * The Stage::GetRenderTaskList() method provides access to an ordered list of render-tasks.
49 * Each RenderTask must specify the source actors to be rendered, and a camera actor from
50 * which the scene is viewed.
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.
55 * By default Dali provides a single RenderTask, which renders the entire actor hierachy using
56 * a default camera actor and GL surface.
58 * The first RenderTask used for input handling will be the last one rendered, which also has input enabled,
59 * and has a valid source & camera actor; see SetInputEnabled().
61 * If none of the actors are hit in the last RenderTask rendered, then input handling will continue
62 * with the second last RenderTask rendered, and so on.
64 * All RenderTasks which target a frame-buffer (i.e. off screen) will be rendered before all RenderTasks
65 * which target the default GL surface. This allows the user to render intermediate targets which are used
66 * later when targetting the screen.
68 * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the
69 * screen->frame-buffer coordinate conversion is successful; see SetScreenToFrameBufferFunction().
71 * If the refresh rate id REFRESH_ONCE and a "Finish" signal is connected, it will be emitted when the RenderTask is completed.
72 * Note that all connected signals must be disconnected before the object is destroyed. This is typically done in the
73 * object destructor, and requires either the Dali::Connection object or Dali::RenderTask handle to be stored.
75 class RenderTask : public Constrainable
79 * @brief Typedef for signals sent by this class.
81 typedef SignalV2< void (RenderTask& source) > RenderTaskSignalV2;
84 static const Property::Index VIEWPORT_POSITION; ///< Property 0, name "viewport-position", type VECTOR2
85 static const Property::Index VIEWPORT_SIZE; ///< Property 1, name "viewport-size", type VECTOR2
86 static const Property::Index CLEAR_COLOR; ///< Property 2, name "clear-color", type VECTOR4
89 static const char* const SIGNAL_FINISHED; ///< Name for Finished signal
92 * @brief A pointer to a function for converting screen to frame-buffer coordinates.
93 * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
94 * @return True if the conversion was successful, otherwise coordinates should be unmodified.
96 typedef bool (* ScreenToFrameBufferFunction)( Vector2& coordinates );
99 * @brief A pointer to a function for converting screen to frame-buffer coordinates.
100 * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
101 * @return True if the conversion was successful, otherwise coordinates should be unmodified.
103 typedef bool (* const ConstScreenToFrameBufferFunction)( Vector2& coordinates );
106 * @brief The default conversion function returns false for any screen coordinates.
108 * This effectively disables hit-testing for RenderTasks rendering to a frame buffer.
109 * See also FULLSCREEN_FRAMEBUFFER_FUNCTION below.
111 static ConstScreenToFrameBufferFunction DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION;
114 * @brief This conversion function outputs the (unmodified) screen coordinates as frame-buffer coordinates.
116 * Therefore the contents of an off-screen image is expected to be rendered "full screen".
118 static ConstScreenToFrameBufferFunction FULLSCREEN_FRAMEBUFFER_FUNCTION;
121 * @brief The refresh-rate of the RenderTask.
125 REFRESH_ONCE = 0, ///< Process once only e.g. take a snap-shot of the scene.
126 REFRESH_ALWAYS = 1 ///< Process every frame.
129 static const bool DEFAULT_EXCLUSIVE; ///< false
130 static const bool DEFAULT_INPUT_ENABLED; ///< true
131 static const Vector4 DEFAULT_CLEAR_COLOR; ///< Color::BLACK
132 static const bool DEFAULT_CLEAR_ENABLED; ///< false
133 static const unsigned int DEFAULT_REFRESH_RATE; ///< REFRESH_ALWAYS
136 * @brief Create an empty RenderTask handle.
138 * This can be initialised with RenderTaskList::CreateRenderTask().
143 * @brief Downcast a handle to RenderTask handle.
145 * If handle points to a RenderTask the
146 * downcast produces valid handle. If not the returned handle is left uninitialized.
147 * @param[in] handle A handle to an object.
148 * @return A handle to a RenderTask or an uninitialized handle.
150 static RenderTask DownCast( BaseHandle handle );
153 * @brief Virtual destructor.
155 virtual ~RenderTask();
158 * @copydoc Dali::BaseHandle::operator=
160 using BaseHandle::operator=;
163 * @brief Set the actors to be rendered.
164 * @param[in] actor This actor and its children will be rendered.
165 * If actor is an empty handle, then nothing will be rendered.
167 void SetSourceActor( Actor actor );
170 * @brief Retrieve the actors to be rendered.
171 * @return This actor and its children will be rendered.
173 Actor GetSourceActor() const;
176 * @brief Set whether the RenderTask has exclusive access to the source actors; the default is false.
177 * @param[in] exclusive True if the source actors will only be rendered by this render-task.
179 void SetExclusive( bool exclusive );
182 * @brief Query whether the RenderTask has exclusive access to the source actors.
183 * @return True if the source actors will only be rendered by this render-task.
185 bool IsExclusive() const;
188 * @brief Set whether the render-task should be considered for input handling; the default is true.
190 * The task used for input handling will be last task in the RenderTaskList which has input enabled,
191 * and has a valid source & camera actor.
192 * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the screen->frame-buffer
193 * coordinate conversion is successful; see also SetScreenToFrameBufferFunction().
194 * @param[in] enabled True if the render-task should be considered for input handling.
196 void SetInputEnabled( bool enabled );
199 * @brief Query whether the render-task should be considered for input handling.
200 * @return True if the render-task should be considered for input handling.
202 bool GetInputEnabled() const;
205 * @brief Set the actor from which the scene is viewed.
206 * @param[in] cameraActor The scene is viewed from the perspective of this actor.
208 void SetCameraActor( CameraActor cameraActor );
211 * @brief Retrieve the actor from which the scene is viewed.
212 * @return The scene is viewed from the perspective of this actor.
214 CameraActor GetCameraActor() const;
217 * @brief Set the frame-buffer used as a render target.
218 * @param[in] frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable.
220 void SetTargetFrameBuffer( FrameBufferImage frameBuffer );
223 * @brief Retrieve the frame-buffer used as a render target.
224 * @return A valid frame-buffer handle, or an uninitialised handle if off-screen rendering is disabled.
226 FrameBufferImage GetTargetFrameBuffer() const;
229 * @brief Set the function used to convert screen coordinates to frame-buffer coordinates.
231 * This is useful for hit-testing actors which are rendered off-screen.
232 * @param[in] conversionFunction The conversion function.
234 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
237 * @brief Retrieve the function used to convert screen coordinates to frame-buffer coordinates.
238 * @return The conversion function.
240 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
243 * @brief Set the actor used to convert screen coordinates to frame-buffer coordinates.
245 * The local coordinates of the actor are mapped as frame-buffer coordinates.
246 * This is useful for hit-testing actors which are rendered off-screen.
247 * Note: The mapping actor needs to be rendered by the default render task to make the mapping work properly.
248 * @param[in] mappingActor The actor used for conversion.
250 void SetScreenToFrameBufferMappingActor( Actor mappingActor );
253 * @brief Retrieve the actor used to convert screen coordinates to frame-buffer coordinates.
254 * @return The actor used for conversion.
256 Actor GetScreenToFrameBufferMappingActor() const;
259 * @brief Set the GL viewport position used when rendering.
261 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
262 * By default this will match the target window or frame-buffer size.
263 * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
264 * @param[in] position The viewports position (x,y)
266 void SetViewportPosition( Vector2 position );
269 * @brief Retrieve the GL viewport position used when rendering.
270 * @return The viewport.
272 Vector2 GetCurrentViewportPosition() const;
275 * @brief Set the GL viewport size used when rendering.
277 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
278 * By default this will match the target window or frame-buffer size.
279 * @param[in] size The viewports size (width,height)
281 void SetViewportSize( Vector2 size );
284 * @brief Retrieve the GL viewport size used when rendering.
285 * @return The viewport.
287 Vector2 GetCurrentViewportSize() const;
290 * @brief Set the GL viewport used when rendering.
292 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
293 * By default this will match the target window or frame-buffer size.
294 * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
295 * @param[in] viewport The new viewport.
297 void SetViewport( Viewport viewport );
300 * @brief Retrieve the GL viewport used when rendering.
301 * @return The viewport.
303 Viewport GetViewport() const;
306 * @brief Set the clear color used when SetClearEnabled(true) is used.
307 * @param[in] color The new clear color.
309 void SetClearColor( const Vector4& color );
312 * @brief Retrieve the clear color used when SetClearEnabled(true) is used.
313 * @note This property can be animated; the return value may not match the value written with SetClearColor().
314 * @return The clear color.
316 Vector4 GetClearColor() const;
319 * @brief Set whether the render-task will clear the results of previous render-tasks.
321 * The default is false.
323 * @note The default GL surface is cleared automatically at the
324 * beginning of each frame; this setting is only useful when 2+
325 * render-tasks are used, and the result of the first task needs to
326 * be (partially) cleared before rendering the second.
328 * @param[in] enabled True if the render-task should clear.
330 void SetClearEnabled( bool enabled );
333 * @brief Query whether the render-task will clear the results of previous render-tasks.
334 * @return True if the render-task should clear.
336 bool GetClearEnabled() const;
339 * @brief Set the refresh-rate of the RenderTask.
341 * The default is REFRESH_ALWAYS (1), meaning that the RenderTask will be processed every frame.
342 * It may be desirable to process less frequently e.g. SetRefreshRate(3) will process once every 3 frames.
343 * The REFRESH_ONCE value means that the RenderTask will be processed once only, to take a snap-shot of the scene.
344 * Repeatedly calling SetRefreshRate(REFRESH_ONCE) will cause more snap-shots to be taken.
345 * @param[in] refreshRate The new refresh rate.
347 void SetRefreshRate( unsigned int refreshRate );
350 * @brief Query the refresh-rate of the RenderTask.
351 * @return The refresh-rate.
353 unsigned int GetRefreshRate() const;
358 * @brief If the refresh rate is REFRESH_ONCE, connect to this signal to be notified when a RenderTask has finished.
360 RenderTaskSignalV2& FinishedSignal();
362 public: // Not intended for application developers
365 * @brief This constructor is used by Dali New() methods.
366 * @param [in] renderTask A pointer to a newly allocated render-task
368 explicit DALI_INTERNAL RenderTask( Internal::RenderTask* renderTask );
376 #endif //__DALI_RENDER_TASK_H__