Merge "Refactored NativeImageInterfaceExtension into NativeImageInterface" into devel...
[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)
66 : Handle(handle)
67 {
68 }
69
70 RenderTask& RenderTask::operator=(const RenderTask& rhs)
71 {
72   BaseHandle::operator=(rhs);
73   return *this;
74 }
75
76 RenderTask::RenderTask( RenderTask&& rhs ) =  default;
77
78 RenderTask& RenderTask::operator=( RenderTask&& rhs ) =  default;
79
80 void RenderTask::SetSourceActor( Actor actor )
81 {
82   // NULL handle is allowed
83   Internal::Actor* actorImpl( NULL );
84   if ( actor )
85   {
86     actorImpl = &GetImplementation( actor );
87   }
88
89   GetImplementation(*this).SetSourceActor( actorImpl );
90 }
91
92 Actor RenderTask::GetSourceActor() const
93 {
94   return Dali::Actor(GetImplementation(*this).GetSourceActor());
95 }
96
97 void RenderTask::SetExclusive( bool exclusive )
98 {
99   GetImplementation(*this).SetExclusive( exclusive );
100 }
101
102 bool RenderTask::IsExclusive() const
103 {
104   return GetImplementation(*this).IsExclusive();
105 }
106
107 void RenderTask::SetCameraActor( CameraActor cameraActor )
108 {
109   // NULL handle is allowed
110   Internal::CameraActor* actorImpl( NULL );
111   if ( cameraActor )
112   {
113     actorImpl = &GetImplementation( cameraActor );
114   }
115
116   GetImplementation(*this).SetCameraActor( actorImpl );
117 }
118
119 CameraActor RenderTask::GetCameraActor() const
120 {
121   return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
122 }
123
124 void RenderTask::SetFrameBuffer( FrameBuffer frameBuffer )
125 {
126   Internal::FrameBuffer* frameBufferPtr( NULL );
127   if( frameBuffer )
128   {
129     frameBufferPtr = &GetImplementation( frameBuffer );
130   }
131
132   GetImplementation(*this).SetFrameBuffer( frameBufferPtr );
133 }
134
135 FrameBuffer RenderTask::GetFrameBuffer() const
136 {
137   Internal::FrameBuffer* frameBufferPtr( GetImplementation(*this).GetFrameBuffer() );
138   return FrameBuffer( frameBufferPtr );
139 }
140
141 void RenderTask::SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction )
142 {
143   GetImplementation(*this).SetScreenToFrameBufferFunction( conversionFunction );
144 }
145
146 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
147 {
148   return GetImplementation(*this).GetScreenToFrameBufferFunction();
149 }
150
151 void RenderTask::SetScreenToFrameBufferMappingActor( Dali::Actor mappingActor )
152 {
153   GetImplementation(*this).SetScreenToFrameBufferMappingActor( mappingActor );
154 }
155
156 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
157 {
158   return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
159 }
160
161 void RenderTask::SetViewportPosition( Vector2 position )
162 {
163   GetImplementation(*this).SetViewportPosition( position );
164 }
165
166 Vector2 RenderTask::GetCurrentViewportPosition() const
167 {
168   return GetImplementation(*this).GetCurrentViewportPosition();
169 }
170
171 void RenderTask::SetViewportSize( Vector2 size )
172 {
173   GetImplementation(*this).SetViewportSize( size );
174 }
175
176 Vector2 RenderTask::GetCurrentViewportSize() const
177 {
178   return GetImplementation(*this).GetCurrentViewportSize();
179 }
180
181 void RenderTask::SetViewport( Viewport viewport )
182 {
183   GetImplementation(*this).SetViewport( viewport );
184 }
185
186 Viewport RenderTask::GetViewport() const
187 {
188   Viewport result;
189   GetImplementation(*this).GetViewport( result );
190   return result;
191 }
192
193 void RenderTask::SetClearColor( const Vector4& color )
194 {
195   GetImplementation(*this).SetClearColor( color );
196 }
197
198 Vector4 RenderTask::GetClearColor() const
199 {
200   return GetImplementation(*this).GetClearColor();
201 }
202
203 void RenderTask::SetClearEnabled( bool enabled )
204 {
205   GetImplementation(*this).SetClearEnabled( enabled );
206 }
207
208 bool RenderTask::GetClearEnabled() const
209 {
210   return GetImplementation(*this).GetClearEnabled();
211 }
212
213 void RenderTask::SetCullMode( bool mode )
214 {
215   GetImplementation(*this).SetCullMode( mode );
216 }
217
218 bool RenderTask::GetCullMode() const
219 {
220   return GetImplementation(*this).GetCullMode();
221 }
222
223 void RenderTask::SetRefreshRate( uint32_t refreshRate )
224 {
225   GetImplementation(*this).SetRefreshRate( refreshRate );
226 }
227
228 uint32_t RenderTask::GetRefreshRate() const
229 {
230   return GetImplementation(*this).GetRefreshRate();
231 }
232
233 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
234 {
235   return GetImplementation(*this).FinishedSignal();
236 }
237
238 void RenderTask::SetInputEnabled( bool enabled )
239 {
240   GetImplementation(*this).SetInputEnabled( enabled );
241 }
242
243 bool RenderTask::GetInputEnabled() const
244 {
245   return GetImplementation(*this).GetInputEnabled();
246 }
247
248 bool RenderTask::WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const
249 {
250   return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
251 }
252
253 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const
254 {
255   if( actor )
256   {
257     Internal::Actor* actorImpl( &GetImplementation( actor ) );
258     return GetImplementation(*this).ViewportToLocal( actorImpl, viewportX, viewportY, localX, localY );
259   }
260   else
261   {
262     return false;
263   }
264 }
265
266
267 RenderTask::RenderTask( Internal::RenderTask* internal )
268 : Handle(internal)
269 {
270 }
271
272 } // namespace Dali