2 * Copyright (c) 2018 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/images/frame-buffer-image-impl.h>
27 #include <dali/internal/event/render-tasks/render-task-impl.h>
32 static bool DefaultScreenToFrameBufferFunction( Vector2& coordinates )
37 static bool FullScreenFrameBufferFunction( Vector2& coordinates )
39 // Don't need to modify frameBufferCoords
43 RenderTask::ConstScreenToFrameBufferFunction RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION = DefaultScreenToFrameBufferFunction;
44 RenderTask::ConstScreenToFrameBufferFunction RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION = FullScreenFrameBufferFunction;
46 const bool RenderTask::DEFAULT_EXCLUSIVE = false;
47 const bool RenderTask::DEFAULT_INPUT_ENABLED = true;
48 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
49 const bool RenderTask::DEFAULT_CLEAR_ENABLED = false;
50 const bool RenderTask::DEFAULT_CULL_MODE = true;
51 const uint32_t RenderTask::DEFAULT_REFRESH_RATE = REFRESH_ALWAYS;
53 RenderTask::RenderTask()
57 RenderTask RenderTask::DownCast( BaseHandle handle )
59 return RenderTask( dynamic_cast<Dali::Internal::RenderTask*>( handle.GetObjectPtr() ) );
62 RenderTask::~RenderTask()
66 RenderTask::RenderTask(const RenderTask& handle)
71 RenderTask& RenderTask::operator=(const RenderTask& rhs)
73 BaseHandle::operator=(rhs);
77 void RenderTask::SetSourceActor( Actor actor )
79 // NULL handle is allowed
80 Internal::Actor* actorImpl( NULL );
83 actorImpl = &GetImplementation( actor );
86 GetImplementation(*this).SetSourceActor( actorImpl );
89 Actor RenderTask::GetSourceActor() const
91 return Dali::Actor(GetImplementation(*this).GetSourceActor());
94 void RenderTask::SetExclusive( bool exclusive )
96 GetImplementation(*this).SetExclusive( exclusive );
99 bool RenderTask::IsExclusive() const
101 return GetImplementation(*this).IsExclusive();
104 void RenderTask::SetCameraActor( CameraActor cameraActor )
106 // NULL handle is allowed
107 Internal::CameraActor* actorImpl( NULL );
110 actorImpl = &GetImplementation( cameraActor );
113 GetImplementation(*this).SetCameraActor( actorImpl );
116 CameraActor RenderTask::GetCameraActor() const
118 return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
121 void RenderTask::SetTargetFrameBuffer( Dali::FrameBufferImage frameBuffer )
123 Internal::FrameBufferImage* frameBufferPtr( NULL );
126 frameBufferPtr = &GetImplementation( frameBuffer );
129 GetImplementation(*this).SetTargetFrameBuffer( frameBufferPtr );
132 FrameBufferImage RenderTask::GetTargetFrameBuffer() const
134 Internal::FrameBufferImage* frameBufferPtr = GetImplementation(*this).GetTargetFrameBuffer();
135 return Dali::FrameBufferImage( frameBufferPtr );
138 void RenderTask::SetFrameBuffer( FrameBuffer frameBuffer )
140 Internal::FrameBuffer* frameBufferPtr( NULL );
143 frameBufferPtr = &GetImplementation( frameBuffer );
146 GetImplementation(*this).SetFrameBuffer( frameBufferPtr );
149 FrameBuffer RenderTask::GetFrameBuffer() const
151 Internal::FrameBuffer* frameBufferPtr( GetImplementation(*this).GetFrameBuffer() );
152 return FrameBuffer( frameBufferPtr );
155 void RenderTask::SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction )
157 GetImplementation(*this).SetScreenToFrameBufferFunction( conversionFunction );
160 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
162 return GetImplementation(*this).GetScreenToFrameBufferFunction();
165 void RenderTask::SetScreenToFrameBufferMappingActor( Dali::Actor mappingActor )
167 // NULL handle is allowed
168 Internal::Actor* actorImpl( NULL );
171 actorImpl = &GetImplementation( mappingActor );
174 GetImplementation(*this).SetScreenToFrameBufferMappingActor( actorImpl );
177 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
179 return Dali::Actor(GetImplementation(*this).GetScreenToFrameBufferMappingActor());
182 void RenderTask::SetViewportPosition( Vector2 position )
184 GetImplementation(*this).SetViewportPosition( position );
187 Vector2 RenderTask::GetCurrentViewportPosition() const
189 return GetImplementation(*this).GetCurrentViewportPosition();
192 void RenderTask::SetViewportSize( Vector2 size )
194 GetImplementation(*this).SetViewportSize( size );
197 Vector2 RenderTask::GetCurrentViewportSize() const
199 return GetImplementation(*this).GetCurrentViewportSize();
202 void RenderTask::SetViewport( Viewport viewport )
204 GetImplementation(*this).SetViewport( viewport );
207 Viewport RenderTask::GetViewport() const
210 GetImplementation(*this).GetViewport( result );
214 void RenderTask::SetClearColor( const Vector4& color )
216 GetImplementation(*this).SetClearColor( color );
219 Vector4 RenderTask::GetClearColor() const
221 return GetImplementation(*this).GetClearColor();
224 void RenderTask::SetClearEnabled( bool enabled )
226 GetImplementation(*this).SetClearEnabled( enabled );
229 bool RenderTask::GetClearEnabled() const
231 return GetImplementation(*this).GetClearEnabled();
234 void RenderTask::SetCullMode( bool mode )
236 GetImplementation(*this).SetCullMode( mode );
239 bool RenderTask::GetCullMode() const
241 return GetImplementation(*this).GetCullMode();
244 void RenderTask::SetRefreshRate( uint32_t refreshRate )
246 GetImplementation(*this).SetRefreshRate( refreshRate );
249 uint32_t RenderTask::GetRefreshRate() const
251 return GetImplementation(*this).GetRefreshRate();
254 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
256 return GetImplementation(*this).FinishedSignal();
259 void RenderTask::SetInputEnabled( bool enabled )
261 GetImplementation(*this).SetInputEnabled( enabled );
264 bool RenderTask::GetInputEnabled() const
266 return GetImplementation(*this).GetInputEnabled();
269 bool RenderTask::WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const
271 return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
274 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const
278 Internal::Actor* actorImpl( &GetImplementation( actor ) );
279 return GetImplementation(*this).ViewportToLocal( actorImpl, viewportX, viewportY, localX, localY );
288 RenderTask::RenderTask( Internal::RenderTask* internal )