2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/render-tasks/render-task.h>
22 #include <dali/public-api/common/constants.h>
23 #include <dali/public-api/rendering/frame-buffer.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/internal/event/actors/camera-actor-impl.h>
26 #include <dali/internal/event/render-tasks/render-task-impl.h>
31 static bool DefaultScreenToFrameBufferFunction( Vector2& coordinates )
36 static bool FullScreenFrameBufferFunction( Vector2& coordinates )
38 // Don't need to modify frameBufferCoords
42 RenderTask::ConstScreenToFrameBufferFunction RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION = DefaultScreenToFrameBufferFunction;
43 RenderTask::ConstScreenToFrameBufferFunction RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION = FullScreenFrameBufferFunction;
45 const bool RenderTask::DEFAULT_EXCLUSIVE = false;
46 const bool RenderTask::DEFAULT_INPUT_ENABLED = true;
47 const Vector4 RenderTask::DEFAULT_CLEAR_COLOR = Vector4( 0.0f, 0.0f, 0.0f, 1.0f ); // cannot use Color::Black because it may or may not be initialized yet
48 const bool RenderTask::DEFAULT_CLEAR_ENABLED = false;
49 const bool RenderTask::DEFAULT_CULL_MODE = true;
50 const uint32_t RenderTask::DEFAULT_REFRESH_RATE = REFRESH_ALWAYS;
52 RenderTask::RenderTask()
56 RenderTask RenderTask::DownCast( BaseHandle handle )
58 return RenderTask( dynamic_cast<Dali::Internal::RenderTask*>( handle.GetObjectPtr() ) );
61 RenderTask::~RenderTask()
65 RenderTask::RenderTask(const RenderTask& handle) = default;
67 RenderTask& RenderTask::operator=(const RenderTask& rhs) = default;
69 RenderTask::RenderTask( RenderTask&& rhs ) = default;
71 RenderTask& RenderTask::operator=( RenderTask&& rhs ) = default;
73 void RenderTask::SetSourceActor( Actor actor )
75 // NULL handle is allowed
76 Internal::Actor* actorImpl( NULL );
79 actorImpl = &GetImplementation( actor );
82 GetImplementation(*this).SetSourceActor( actorImpl );
85 Actor RenderTask::GetSourceActor() const
87 return Dali::Actor(GetImplementation(*this).GetSourceActor());
90 void RenderTask::SetExclusive( bool exclusive )
92 GetImplementation(*this).SetExclusive( exclusive );
95 bool RenderTask::IsExclusive() const
97 return GetImplementation(*this).IsExclusive();
100 void RenderTask::SetCameraActor( CameraActor cameraActor )
102 // NULL handle is allowed
103 Internal::CameraActor* actorImpl( NULL );
106 actorImpl = &GetImplementation( cameraActor );
109 GetImplementation(*this).SetCameraActor( actorImpl );
112 CameraActor RenderTask::GetCameraActor() const
114 return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
117 void RenderTask::SetFrameBuffer( FrameBuffer frameBuffer )
119 Internal::FrameBuffer* frameBufferPtr( NULL );
122 frameBufferPtr = &GetImplementation( frameBuffer );
125 GetImplementation(*this).SetFrameBuffer( frameBufferPtr );
128 FrameBuffer RenderTask::GetFrameBuffer() const
130 Internal::FrameBuffer* frameBufferPtr( GetImplementation(*this).GetFrameBuffer() );
131 return FrameBuffer( frameBufferPtr );
134 void RenderTask::SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction )
136 GetImplementation(*this).SetScreenToFrameBufferFunction( conversionFunction );
139 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
141 return GetImplementation(*this).GetScreenToFrameBufferFunction();
144 void RenderTask::SetScreenToFrameBufferMappingActor( Dali::Actor mappingActor )
146 GetImplementation(*this).SetScreenToFrameBufferMappingActor( mappingActor );
149 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
151 return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
154 void RenderTask::SetViewportPosition( Vector2 position )
156 GetImplementation(*this).SetViewportPosition( position );
159 Vector2 RenderTask::GetCurrentViewportPosition() const
161 return GetImplementation(*this).GetCurrentViewportPosition();
164 void RenderTask::SetViewportSize( Vector2 size )
166 GetImplementation(*this).SetViewportSize( size );
169 Vector2 RenderTask::GetCurrentViewportSize() const
171 return GetImplementation(*this).GetCurrentViewportSize();
174 void RenderTask::SetViewport( Viewport viewport )
176 GetImplementation(*this).SetViewport( viewport );
179 Viewport RenderTask::GetViewport() const
182 GetImplementation(*this).GetViewport( result );
186 void RenderTask::SetClearColor( const Vector4& color )
188 GetImplementation(*this).SetClearColor( color );
191 Vector4 RenderTask::GetClearColor() const
193 return GetImplementation(*this).GetClearColor();
196 void RenderTask::SetClearEnabled( bool enabled )
198 GetImplementation(*this).SetClearEnabled( enabled );
201 bool RenderTask::GetClearEnabled() const
203 return GetImplementation(*this).GetClearEnabled();
206 void RenderTask::SetCullMode( bool mode )
208 GetImplementation(*this).SetCullMode( mode );
211 bool RenderTask::GetCullMode() const
213 return GetImplementation(*this).GetCullMode();
216 void RenderTask::SetRefreshRate( uint32_t refreshRate )
218 GetImplementation(*this).SetRefreshRate( refreshRate );
221 uint32_t RenderTask::GetRefreshRate() const
223 return GetImplementation(*this).GetRefreshRate();
226 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
228 return GetImplementation(*this).FinishedSignal();
231 void RenderTask::SetInputEnabled( bool enabled )
233 GetImplementation(*this).SetInputEnabled( enabled );
236 bool RenderTask::GetInputEnabled() const
238 return GetImplementation(*this).GetInputEnabled();
241 bool RenderTask::WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const
243 return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
246 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const
250 Internal::Actor* actorImpl( &GetImplementation( actor ) );
251 return GetImplementation(*this).ViewportToLocal( actorImpl, viewportX, viewportY, localX, localY );
260 RenderTask::RenderTask( Internal::RenderTask* internal )