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