1 #ifndef __DALI_INTERNAL_RENDER_TASK_H__
2 #define __DALI_INTERNAL_RENDER_TASK_H__
5 * Copyright (c) 2018 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 #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>
37 class EventThreadServices;
46 using RenderTaskPtr = IntrusivePtr<RenderTask>;
48 class RenderTask : public Object
52 using ScreenToFrameBufferFunction = Dali::RenderTask::ScreenToFrameBufferFunction;
55 * Creates a new RenderTask.
57 static RenderTaskPtr New( Actor* sourceActor, CameraActor* cameraActor, SceneGraph::RenderTaskList& parentSceneObject );
60 * @copydoc Dali::RenderTask::SetSourceActor()
62 void SetSourceActor( Actor* actor );
65 * @copydoc Dali::RenderTask::GetSourceActor()
67 Actor* GetSourceActor() const;
70 * @copydoc Dali::RenderTask::SetExclusive()
72 void SetExclusive( bool exclusive );
75 * @copydoc Dali::RenderTask::IsExclusive()
77 bool IsExclusive() const;
80 * @copydoc Dali::RenderTask::SetInputEnabled()
82 void SetInputEnabled( bool enabled );
85 * @copydoc Dali::RenderTask::GetInputEnabled()
87 bool GetInputEnabled() const;
90 * @copydoc Dali::RenderTask::SetCameraActor()
92 void SetCameraActor( CameraActor* cameraActor );
95 * @copydoc Dali::RenderTask::GetCameraActor()
97 CameraActor* GetCameraActor() const;
100 * @copydoc Dali::RenderTask::SetTargetFrameBuffer()
102 void SetTargetFrameBuffer( FrameBufferImagePtr frameBuffer );
105 * @copydoc Dali::RenderTask::GetTargetFrameBuffer
107 FrameBufferImage* GetTargetFrameBuffer() const;
110 * @copydoc Dali::RenderTask::SetFrameBuffer()
112 void SetFrameBuffer( FrameBufferPtr frameBuffer );
115 * @copydoc Dali::RenderTask::GetFrameBuffer
117 FrameBuffer* GetFrameBuffer() const;
120 * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
122 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
125 * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
127 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
130 * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
132 void SetScreenToFrameBufferMappingActor( Dali::Actor& mappingActor );
135 * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
137 Dali::Actor GetScreenToFrameBufferMappingActor() const;
140 * @copydoc Dali::RenderTask::SetViewportPosition
142 void SetViewportPosition(const Vector2& value);
145 * @copydoc Dali::RenderTask::GetCurrentViewportPosition
147 Vector2 GetCurrentViewportPosition() const;
150 * @copydoc Dali::RenderTask::SetViewportSize
152 void SetViewportSize(const Vector2& value);
155 * @copydoc Dali::RenderTask::GetCurrentViewportSize
157 Vector2 GetCurrentViewportSize() const;
160 * @copydoc Dali::RenderTask::SetViewport()
162 void SetViewport( const Viewport& viewport );
165 * @param[out] viewPort instance to copy the values into
167 void GetViewport( Viewport& viewPort ) const;
170 * @copydoc Dali::RenderTask::SetClearColor()
172 void SetClearColor( const Vector4& color );
175 * @copydoc Dali::RenderTask::GetClearColor()
177 const Vector4& GetClearColor() const;
180 * Indicate whether GL sync is required for native render target.
181 * @param[in] requiresSync whether GL sync is required.
183 void SetSyncRequired( bool requiresSync );
186 * Query whether the sync object is required for native render target.
187 * @return True if the sync object is required, false otherwise.
189 bool IsSyncRequired() const;
192 * @copydoc Dali::RenderTask::SetClearEnabled()
194 void SetClearEnabled( bool enabled );
197 * @copydoc Dali::RenderTask::GetClearEnabled()
199 bool GetClearEnabled() const;
202 * @copydoc Dali::RenderTask::SetCullMode()
204 void SetCullMode( bool mode );
207 * @copydoc Dali::RenderTask::GetCullMode()
209 bool GetCullMode() const;
212 * @copydoc Dali::RenderTask::SetRefreshRate()
214 void SetRefreshRate( uint32_t refreshRate );
217 * @copydoc Dali::RenderTask::GetRefreshRate()
219 uint32_t GetRefreshRate() const;
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.
226 bool IsHittable( Vector2& screenCoords ) const;
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
233 bool TranslateCoordinates( Vector2& screenCoords ) const;
236 * @copydoc Dali::RenderTask::WorldToViewport()
238 bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
241 * @copydoc Dali::RenderTask::ViewportToLocal()
243 bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float &localX, float &localY) const;
245 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
248 * Retrieve the scene-graph RenderTask object.
249 * @return The scene-graph object
251 const SceneGraph::RenderTask& GetRenderTaskSceneObject() const;
253 public: // Implementation of Object
256 * @copydoc Dali::Internal::Object::SetDefaultProperty()
258 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
261 * @copydoc Dali::Internal::Object::GetDefaultProperty()
263 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
266 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
268 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
271 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
273 virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType );
276 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
278 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
281 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
283 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
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.
297 * Emit the Finished signal
299 void EmitSignalFinish();
302 * @copydoc Dali::RenderTask::FinishedSignal()
304 Dali::RenderTask::RenderTaskSignalType& FinishedSignal();
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.
315 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
322 * @param sceneObject the scene graph object
324 RenderTask( const SceneGraph::RenderTask* sceneObject );
327 * A reference counted object may only be deleted by calling Unreference()
329 virtual ~RenderTask();
331 private: // not copyable
333 RenderTask() = delete;
334 RenderTask( const RenderTask& ) = delete;
335 RenderTask& operator=( const RenderTask& ) = delete;
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
343 Vector4 mClearColor; ///< Optional clear color
345 Vector2 mViewportPosition; ///< The cached viewport position
346 Vector2 mViewportSize; ///< The cached viewport size
348 uint32_t mRefreshRate; ///< Determines how often the task is processed.
350 uint32_t mRefreshOnceCounter;
352 FrameBufferImagePtr mFrameBufferImage; ///< Optional off-screen render target.
353 FrameBufferPtr mFrameBuffer;
356 Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
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.
365 Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
368 } // namespace Internal
370 // Helpers for public-api forwarding methods
372 inline Internal::RenderTask& GetImplementation(Dali::RenderTask& task)
374 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
376 BaseObject& handle = task.GetBaseObject();
378 return static_cast<Internal::RenderTask&>(handle);
381 inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& task)
383 DALI_ASSERT_ALWAYS(task && "RenderTask handle is empty");
385 const BaseObject& handle = task.GetBaseObject();
387 return static_cast<const Internal::RenderTask&>(handle);
392 #endif //__DALI_INTERNAL_RENDER_TASK_H__