[dali_1.3.53] Merge branch 'devel/master'
[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   GetImplementation(*this).SetScreenToFrameBufferMappingActor( mappingActor );
168 }
169
170 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
171 {
172   return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
173 }
174
175 void RenderTask::SetViewportPosition( Vector2 position )
176 {
177   GetImplementation(*this).SetViewportPosition( position );
178 }
179
180 Vector2 RenderTask::GetCurrentViewportPosition() const
181 {
182   return GetImplementation(*this).GetCurrentViewportPosition();
183 }
184
185 void RenderTask::SetViewportSize( Vector2 size )
186 {
187   GetImplementation(*this).SetViewportSize( size );
188 }
189
190 Vector2 RenderTask::GetCurrentViewportSize() const
191 {
192   return GetImplementation(*this).GetCurrentViewportSize();
193 }
194
195 void RenderTask::SetViewport( Viewport viewport )
196 {
197   GetImplementation(*this).SetViewport( viewport );
198 }
199
200 Viewport RenderTask::GetViewport() const
201 {
202   Viewport result;
203   GetImplementation(*this).GetViewport( result );
204   return result;
205 }
206
207 void RenderTask::SetClearColor( const Vector4& color )
208 {
209   GetImplementation(*this).SetClearColor( color );
210 }
211
212 Vector4 RenderTask::GetClearColor() const
213 {
214   return GetImplementation(*this).GetClearColor();
215 }
216
217 void RenderTask::SetClearEnabled( bool enabled )
218 {
219   GetImplementation(*this).SetClearEnabled( enabled );
220 }
221
222 bool RenderTask::GetClearEnabled() const
223 {
224   return GetImplementation(*this).GetClearEnabled();
225 }
226
227 void RenderTask::SetCullMode( bool mode )
228 {
229   GetImplementation(*this).SetCullMode( mode );
230 }
231
232 bool RenderTask::GetCullMode() const
233 {
234   return GetImplementation(*this).GetCullMode();
235 }
236
237 void RenderTask::SetRefreshRate( uint32_t refreshRate )
238 {
239   GetImplementation(*this).SetRefreshRate( refreshRate );
240 }
241
242 uint32_t RenderTask::GetRefreshRate() const
243 {
244   return GetImplementation(*this).GetRefreshRate();
245 }
246
247 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
248 {
249   return GetImplementation(*this).FinishedSignal();
250 }
251
252 void RenderTask::SetInputEnabled( bool enabled )
253 {
254   GetImplementation(*this).SetInputEnabled( enabled );
255 }
256
257 bool RenderTask::GetInputEnabled() const
258 {
259   return GetImplementation(*this).GetInputEnabled();
260 }
261
262 bool RenderTask::WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const
263 {
264   return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
265 }
266
267 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const
268 {
269   if( actor )
270   {
271     Internal::Actor* actorImpl( &GetImplementation( actor ) );
272     return GetImplementation(*this).ViewportToLocal( actorImpl, viewportX, viewportY, localX, localY );
273   }
274   else
275   {
276     return false;
277   }
278 }
279
280
281 RenderTask::RenderTask( Internal::RenderTask* internal )
282 : Handle(internal)
283 {
284 }
285
286 } // namespace Dali