2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/public-api/render-tasks/render-task.h>
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>
30 static bool DefaultScreenToFrameBufferFunction(Vector2& coordinates)
35 static bool FullScreenFrameBufferFunction(Vector2& coordinates)
37 // Don't need to modify frameBufferCoords
41 RenderTask::ConstScreenToFrameBufferFunction RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION = DefaultScreenToFrameBufferFunction;
42 RenderTask::ConstScreenToFrameBufferFunction RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION = FullScreenFrameBufferFunction;
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;
51 RenderTask::RenderTask() = default;
53 RenderTask RenderTask::DownCast(BaseHandle handle)
55 return RenderTask(dynamic_cast<Dali::Internal::RenderTask*>(handle.GetObjectPtr()));
58 RenderTask::~RenderTask() = default;
60 RenderTask::RenderTask(const RenderTask& handle) = default;
62 RenderTask& RenderTask::operator=(const RenderTask& rhs) = default;
64 RenderTask::RenderTask(RenderTask&& rhs) noexcept = default;
66 RenderTask& RenderTask::operator=(RenderTask&& rhs) noexcept = default;
68 void RenderTask::SetSourceActor(Actor actor)
70 // NULL handle is allowed
71 Internal::Actor* actorImpl(nullptr);
74 actorImpl = &GetImplementation(actor);
77 GetImplementation(*this).SetSourceActor(actorImpl);
80 Actor RenderTask::GetSourceActor() const
82 return Dali::Actor(GetImplementation(*this).GetSourceActor());
85 void RenderTask::SetExclusive(bool exclusive)
87 GetImplementation(*this).SetExclusive(exclusive);
90 bool RenderTask::IsExclusive() const
92 return GetImplementation(*this).IsExclusive();
95 void RenderTask::SetCameraActor(CameraActor cameraActor)
97 // NULL handle is allowed
98 Internal::CameraActor* actorImpl(nullptr);
101 actorImpl = &GetImplementation(cameraActor);
104 GetImplementation(*this).SetCameraActor(actorImpl);
107 CameraActor RenderTask::GetCameraActor() const
109 return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
112 void RenderTask::SetFrameBuffer(FrameBuffer frameBuffer)
114 Internal::FrameBuffer* frameBufferPtr(nullptr);
117 frameBufferPtr = &GetImplementation(frameBuffer);
120 GetImplementation(*this).SetFrameBuffer(frameBufferPtr);
123 FrameBuffer RenderTask::GetFrameBuffer() const
125 Internal::FrameBuffer* frameBufferPtr(GetImplementation(*this).GetFrameBuffer());
126 return FrameBuffer(frameBufferPtr);
129 void RenderTask::SetScreenToFrameBufferFunction(ScreenToFrameBufferFunction conversionFunction)
131 GetImplementation(*this).SetScreenToFrameBufferFunction(conversionFunction);
134 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
136 return GetImplementation(*this).GetScreenToFrameBufferFunction();
139 void RenderTask::SetScreenToFrameBufferMappingActor(Dali::Actor mappingActor)
141 GetImplementation(*this).SetScreenToFrameBufferMappingActor(mappingActor);
144 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
146 return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
149 void RenderTask::SetViewportGuideActor(Actor actor)
151 // NULL handle is allowed
152 Internal::Actor* actorImpl(nullptr);
155 actorImpl = &GetImplementation(actor);
158 GetImplementation(*this).SetViewportGuideActor(actorImpl);
161 Actor RenderTask::GetViewportGuideActor() const
163 return Dali::Actor(GetImplementation(*this).GetViewportGuideActor());
166 void RenderTask::ResetViewportGuideActor()
168 GetImplementation(*this).ResetViewportGuideActor();
171 void RenderTask::SetViewportPosition(Vector2 position)
173 GetImplementation(*this).SetViewportPosition(position);
176 Vector2 RenderTask::GetCurrentViewportPosition() const
178 return GetImplementation(*this).GetCurrentViewportPosition();
181 void RenderTask::SetViewportSize(Vector2 size)
183 GetImplementation(*this).SetViewportSize(size);
186 Vector2 RenderTask::GetCurrentViewportSize() const
188 return GetImplementation(*this).GetCurrentViewportSize();
191 void RenderTask::SetViewport(Viewport viewport)
193 GetImplementation(*this).SetViewport(viewport);
196 Viewport RenderTask::GetViewport() const
199 GetImplementation(*this).GetViewport(result);
203 void RenderTask::SetClearColor(const Vector4& color)
205 GetImplementation(*this).SetClearColor(color);
208 Vector4 RenderTask::GetClearColor() const
210 return GetImplementation(*this).GetClearColor();
213 void RenderTask::SetClearEnabled(bool enabled)
215 GetImplementation(*this).SetClearEnabled(enabled);
218 bool RenderTask::GetClearEnabled() const
220 return GetImplementation(*this).GetClearEnabled();
223 void RenderTask::SetCullMode(bool mode)
225 GetImplementation(*this).SetCullMode(mode);
228 bool RenderTask::GetCullMode() const
230 return GetImplementation(*this).GetCullMode();
233 void RenderTask::SetRefreshRate(uint32_t refreshRate)
235 GetImplementation(*this).SetRefreshRate(refreshRate);
238 uint32_t RenderTask::GetRefreshRate() const
240 return GetImplementation(*this).GetRefreshRate();
243 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
245 return GetImplementation(*this).FinishedSignal();
248 void RenderTask::SetInputEnabled(bool enabled)
250 GetImplementation(*this).SetInputEnabled(enabled);
253 bool RenderTask::GetInputEnabled() const
255 return GetImplementation(*this).GetInputEnabled();
258 bool RenderTask::WorldToViewport(const Vector3& position, float& viewportX, float& viewportY) const
260 return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
263 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float& localX, float& localY) const
267 Internal::Actor* actorImpl(&GetImplementation(actor));
268 return GetImplementation(*this).ViewportToLocal(actorImpl, viewportX, viewportY, localX, localY);
276 RenderTask::RenderTask(Internal::RenderTask* internal)