[dali_2.3.19] Merge branch 'devel/master'
[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/internal/event/actors/actor-impl.h>
23 #include <dali/internal/event/actors/camera-actor-impl.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
25 #include <dali/public-api/common/constants.h>
26 #include <dali/public-api/rendering/frame-buffer.h>
27
28 namespace Dali
29 {
30 static bool DefaultScreenToFrameBufferFunction(Vector2& coordinates)
31 {
32   return false;
33 }
34
35 static bool FullScreenFrameBufferFunction(Vector2& coordinates)
36 {
37   // Don't need to modify frameBufferCoords
38   return true;
39 }
40
41 RenderTask::ConstScreenToFrameBufferFunction RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION = DefaultScreenToFrameBufferFunction;
42 RenderTask::ConstScreenToFrameBufferFunction RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION        = FullScreenFrameBufferFunction;
43
44 const bool     RenderTask::DEFAULT_EXCLUSIVE     = false;
45 const bool     RenderTask::DEFAULT_INPUT_ENABLED = true;
46 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
47 const bool     RenderTask::DEFAULT_CLEAR_ENABLED = false;
48 const bool     RenderTask::DEFAULT_CULL_MODE     = true;
49 const uint32_t RenderTask::DEFAULT_REFRESH_RATE  = REFRESH_ALWAYS;
50
51 static constexpr int32_t MIN_ORDER_INDEX = -1000;
52 static constexpr int32_t MAX_ORDER_INDEX = 1000;
53
54 RenderTask::RenderTask() = default;
55
56 RenderTask RenderTask::DownCast(BaseHandle handle)
57 {
58   return RenderTask(dynamic_cast<Dali::Internal::RenderTask*>(handle.GetObjectPtr()));
59 }
60
61 RenderTask::~RenderTask() = default;
62
63 RenderTask::RenderTask(const RenderTask& handle) = default;
64
65 RenderTask& RenderTask::operator=(const RenderTask& rhs) = default;
66
67 RenderTask::RenderTask(RenderTask&& rhs) noexcept = default;
68
69 RenderTask& RenderTask::operator=(RenderTask&& rhs) noexcept = default;
70
71 void RenderTask::SetSourceActor(Actor actor)
72 {
73   // NULL handle is allowed
74   Internal::Actor* actorImpl(nullptr);
75   if(actor)
76   {
77     actorImpl = &GetImplementation(actor);
78   }
79
80   GetImplementation(*this).SetSourceActor(actorImpl);
81 }
82
83 Actor RenderTask::GetSourceActor() const
84 {
85   return Dali::Actor(GetImplementation(*this).GetSourceActor());
86 }
87
88 void RenderTask::SetExclusive(bool exclusive)
89 {
90   GetImplementation(*this).SetExclusive(exclusive);
91 }
92
93 bool RenderTask::IsExclusive() const
94 {
95   return GetImplementation(*this).IsExclusive();
96 }
97
98 void RenderTask::SetCameraActor(CameraActor cameraActor)
99 {
100   // NULL handle is allowed
101   Internal::CameraActor* actorImpl(nullptr);
102   if(cameraActor)
103   {
104     actorImpl = &GetImplementation(cameraActor);
105   }
106
107   GetImplementation(*this).SetCameraActor(actorImpl);
108 }
109
110 CameraActor RenderTask::GetCameraActor() const
111 {
112   return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
113 }
114
115 void RenderTask::SetFrameBuffer(FrameBuffer frameBuffer)
116 {
117   Internal::FrameBuffer* frameBufferPtr(nullptr);
118   if(frameBuffer)
119   {
120     frameBufferPtr = &GetImplementation(frameBuffer);
121   }
122
123   GetImplementation(*this).SetFrameBuffer(frameBufferPtr);
124 }
125
126 FrameBuffer RenderTask::GetFrameBuffer() const
127 {
128   Internal::FrameBuffer* frameBufferPtr(GetImplementation(*this).GetFrameBuffer());
129   return FrameBuffer(frameBufferPtr);
130 }
131
132 void RenderTask::SetScreenToFrameBufferFunction(ScreenToFrameBufferFunction conversionFunction)
133 {
134   GetImplementation(*this).SetScreenToFrameBufferFunction(conversionFunction);
135 }
136
137 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
138 {
139   return GetImplementation(*this).GetScreenToFrameBufferFunction();
140 }
141
142 void RenderTask::SetScreenToFrameBufferMappingActor(Dali::Actor mappingActor)
143 {
144   GetImplementation(*this).SetScreenToFrameBufferMappingActor(mappingActor);
145 }
146
147 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
148 {
149   return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
150 }
151
152 void RenderTask::SetViewportGuideActor(Actor actor)
153 {
154   // NULL handle is allowed
155   Internal::Actor* actorImpl(nullptr);
156   if(actor)
157   {
158     actorImpl = &GetImplementation(actor);
159   }
160
161   GetImplementation(*this).SetViewportGuideActor(actorImpl);
162 }
163
164 Actor RenderTask::GetViewportGuideActor() const
165 {
166   return Dali::Actor(GetImplementation(*this).GetViewportGuideActor());
167 }
168
169 void RenderTask::ResetViewportGuideActor()
170 {
171   GetImplementation(*this).ResetViewportGuideActor();
172 }
173
174 void RenderTask::SetViewportPosition(Vector2 position)
175 {
176   GetImplementation(*this).SetViewportPosition(position);
177 }
178
179 Vector2 RenderTask::GetCurrentViewportPosition() const
180 {
181   return GetImplementation(*this).GetCurrentViewportPosition();
182 }
183
184 void RenderTask::SetViewportSize(Vector2 size)
185 {
186   GetImplementation(*this).SetViewportSize(size);
187 }
188
189 Vector2 RenderTask::GetCurrentViewportSize() const
190 {
191   return GetImplementation(*this).GetCurrentViewportSize();
192 }
193
194 void RenderTask::SetViewport(Viewport viewport)
195 {
196   GetImplementation(*this).SetViewport(viewport);
197 }
198
199 Viewport RenderTask::GetViewport() const
200 {
201   Viewport result;
202   GetImplementation(*this).GetViewport(result);
203   return result;
204 }
205
206 void RenderTask::SetClearColor(const Vector4& color)
207 {
208   GetImplementation(*this).SetClearColor(color);
209 }
210
211 Vector4 RenderTask::GetClearColor() const
212 {
213   return GetImplementation(*this).GetClearColor();
214 }
215
216 void RenderTask::SetClearEnabled(bool enabled)
217 {
218   GetImplementation(*this).SetClearEnabled(enabled);
219 }
220
221 bool RenderTask::GetClearEnabled() const
222 {
223   return GetImplementation(*this).GetClearEnabled();
224 }
225
226 void RenderTask::SetCullMode(bool mode)
227 {
228   GetImplementation(*this).SetCullMode(mode);
229 }
230
231 bool RenderTask::GetCullMode() const
232 {
233   return GetImplementation(*this).GetCullMode();
234 }
235
236 void RenderTask::SetRefreshRate(uint32_t refreshRate)
237 {
238   GetImplementation(*this).SetRefreshRate(refreshRate);
239 }
240
241 uint32_t RenderTask::GetRefreshRate() const
242 {
243   return GetImplementation(*this).GetRefreshRate();
244 }
245
246 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
247 {
248   return GetImplementation(*this).FinishedSignal();
249 }
250
251 void RenderTask::SetInputEnabled(bool enabled)
252 {
253   GetImplementation(*this).SetInputEnabled(enabled);
254 }
255
256 bool RenderTask::GetInputEnabled() const
257 {
258   return GetImplementation(*this).GetInputEnabled();
259 }
260
261 bool RenderTask::WorldToViewport(const Vector3& position, float& viewportX, float& viewportY) const
262 {
263   return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
264 }
265
266 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float& localX, float& localY) const
267 {
268   if(actor)
269   {
270     Internal::Actor* actorImpl(&GetImplementation(actor));
271     return GetImplementation(*this).ViewportToLocal(actorImpl, viewportX, viewportY, localX, localY);
272   }
273   else
274   {
275     return false;
276   }
277 }
278
279 void RenderTask::SetRenderPassTag(uint32_t renderPassTag)
280 {
281   GetImplementation(*this).SetRenderPassTag(renderPassTag);
282 }
283
284 uint32_t RenderTask::GetRenderPassTag() const
285 {
286   return GetImplementation(*this).GetRenderPassTag();
287 }
288
289 void RenderTask::SetOrderIndex(int32_t orderIndex)
290 {
291   if(orderIndex < MIN_ORDER_INDEX || orderIndex > MAX_ORDER_INDEX)
292   {
293     DALI_LOG_ERROR("OrderIndex value can be available between [-1000, 1000].\n");
294     orderIndex = std::min(orderIndex, MAX_ORDER_INDEX);
295     orderIndex = std::max(orderIndex, MIN_ORDER_INDEX);
296   }
297   GetImplementation(*this).SetOrderIndex(orderIndex);
298 }
299
300 int32_t RenderTask::GetOrderIndex() const
301 {
302   return GetImplementation(*this).GetOrderIndex();
303 }
304
305 uint32_t RenderTask::GetRenderTaskId() const
306 {
307   return GetImplementation(*this).GetRenderTaskId();
308 }
309
310 RenderTask::RenderTask(Internal::RenderTask* internal)
311 : Handle(internal)
312 {
313 }
314
315 } // namespace Dali