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