d0726dced4ba93909fd85b05d5b5da8a7205f0f5
[platform/core/uifw/dali-core.git] / dali / public-api / render-tasks / render-task.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/render-tasks/render-task.h>
20
21 // INTERNAL INCLUDES
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>
27
28 namespace Dali
29 {
30
31 static bool DefaultScreenToFrameBufferFunction( Vector2& coordinates )
32 {
33   return false;
34 }
35
36 static bool FullScreenFrameBufferFunction( Vector2& coordinates )
37 {
38   // Don't need to modify frameBufferCoords
39   return true;
40 }
41
42 RenderTask::ConstScreenToFrameBufferFunction RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION = DefaultScreenToFrameBufferFunction;
43 RenderTask::ConstScreenToFrameBufferFunction RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION        = FullScreenFrameBufferFunction;
44
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;
51
52 RenderTask::RenderTask()
53 {
54 }
55
56 RenderTask RenderTask::DownCast( BaseHandle handle )
57 {
58   return RenderTask( dynamic_cast<Dali::Internal::RenderTask*>( handle.GetObjectPtr() ) );
59 }
60
61 RenderTask::~RenderTask()
62 {
63 }
64
65 RenderTask::RenderTask(const RenderTask& handle) = default;
66
67 RenderTask& RenderTask::operator=(const RenderTask& rhs) = default;
68
69 RenderTask::RenderTask( RenderTask&& rhs ) =  default;
70
71 RenderTask& RenderTask::operator=( RenderTask&& rhs ) =  default;
72
73 void RenderTask::SetSourceActor( Actor actor )
74 {
75   // NULL handle is allowed
76   Internal::Actor* actorImpl( nullptr );
77   if ( actor )
78   {
79     actorImpl = &GetImplementation( actor );
80   }
81
82   GetImplementation(*this).SetSourceActor( actorImpl );
83 }
84
85 Actor RenderTask::GetSourceActor() const
86 {
87   return Dali::Actor(GetImplementation(*this).GetSourceActor());
88 }
89
90 void RenderTask::SetExclusive( bool exclusive )
91 {
92   GetImplementation(*this).SetExclusive( exclusive );
93 }
94
95 bool RenderTask::IsExclusive() const
96 {
97   return GetImplementation(*this).IsExclusive();
98 }
99
100 void RenderTask::SetCameraActor( CameraActor cameraActor )
101 {
102   // NULL handle is allowed
103   Internal::CameraActor* actorImpl( nullptr );
104   if ( cameraActor )
105   {
106     actorImpl = &GetImplementation( cameraActor );
107   }
108
109   GetImplementation(*this).SetCameraActor( actorImpl );
110 }
111
112 CameraActor RenderTask::GetCameraActor() const
113 {
114   return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
115 }
116
117 void RenderTask::SetFrameBuffer( FrameBuffer frameBuffer )
118 {
119   Internal::FrameBuffer* frameBufferPtr( nullptr );
120   if( frameBuffer )
121   {
122     frameBufferPtr = &GetImplementation( frameBuffer );
123   }
124
125   GetImplementation(*this).SetFrameBuffer( frameBufferPtr );
126 }
127
128 FrameBuffer RenderTask::GetFrameBuffer() const
129 {
130   Internal::FrameBuffer* frameBufferPtr( GetImplementation(*this).GetFrameBuffer() );
131   return FrameBuffer( frameBufferPtr );
132 }
133
134 void RenderTask::SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction )
135 {
136   GetImplementation(*this).SetScreenToFrameBufferFunction( conversionFunction );
137 }
138
139 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
140 {
141   return GetImplementation(*this).GetScreenToFrameBufferFunction();
142 }
143
144 void RenderTask::SetScreenToFrameBufferMappingActor( Dali::Actor mappingActor )
145 {
146   GetImplementation(*this).SetScreenToFrameBufferMappingActor( mappingActor );
147 }
148
149 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
150 {
151   return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
152 }
153
154 void RenderTask::SetViewportPosition( Vector2 position )
155 {
156   GetImplementation(*this).SetViewportPosition( position );
157 }
158
159 Vector2 RenderTask::GetCurrentViewportPosition() const
160 {
161   return GetImplementation(*this).GetCurrentViewportPosition();
162 }
163
164 void RenderTask::SetViewportSize( Vector2 size )
165 {
166   GetImplementation(*this).SetViewportSize( size );
167 }
168
169 Vector2 RenderTask::GetCurrentViewportSize() const
170 {
171   return GetImplementation(*this).GetCurrentViewportSize();
172 }
173
174 void RenderTask::SetViewport( Viewport viewport )
175 {
176   GetImplementation(*this).SetViewport( viewport );
177 }
178
179 Viewport RenderTask::GetViewport() const
180 {
181   Viewport result;
182   GetImplementation(*this).GetViewport( result );
183   return result;
184 }
185
186 void RenderTask::SetClearColor( const Vector4& color )
187 {
188   GetImplementation(*this).SetClearColor( color );
189 }
190
191 Vector4 RenderTask::GetClearColor() const
192 {
193   return GetImplementation(*this).GetClearColor();
194 }
195
196 void RenderTask::SetClearEnabled( bool enabled )
197 {
198   GetImplementation(*this).SetClearEnabled( enabled );
199 }
200
201 bool RenderTask::GetClearEnabled() const
202 {
203   return GetImplementation(*this).GetClearEnabled();
204 }
205
206 void RenderTask::SetCullMode( bool mode )
207 {
208   GetImplementation(*this).SetCullMode( mode );
209 }
210
211 bool RenderTask::GetCullMode() const
212 {
213   return GetImplementation(*this).GetCullMode();
214 }
215
216 void RenderTask::SetRefreshRate( uint32_t refreshRate )
217 {
218   GetImplementation(*this).SetRefreshRate( refreshRate );
219 }
220
221 uint32_t RenderTask::GetRefreshRate() const
222 {
223   return GetImplementation(*this).GetRefreshRate();
224 }
225
226 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
227 {
228   return GetImplementation(*this).FinishedSignal();
229 }
230
231 void RenderTask::SetInputEnabled( bool enabled )
232 {
233   GetImplementation(*this).SetInputEnabled( enabled );
234 }
235
236 bool RenderTask::GetInputEnabled() const
237 {
238   return GetImplementation(*this).GetInputEnabled();
239 }
240
241 bool RenderTask::WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const
242 {
243   return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
244 }
245
246 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const
247 {
248   if( actor )
249   {
250     Internal::Actor* actorImpl( &GetImplementation( actor ) );
251     return GetImplementation(*this).ViewportToLocal( actorImpl, viewportX, viewportY, localX, localY );
252   }
253   else
254   {
255     return false;
256   }
257 }
258
259
260 RenderTask::RenderTask( Internal::RenderTask* internal )
261 : Handle(internal)
262 {
263 }
264
265 } // namespace Dali