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 static constexpr int32_t MIN_ORDER_INDEX = -1000;
52 static constexpr int32_t MAX_ORDER_INDEX = 1000;
54 RenderTask::RenderTask() = default;
56 RenderTask RenderTask::DownCast(BaseHandle handle)
58 return RenderTask(dynamic_cast<Dali::Internal::RenderTask*>(handle.GetObjectPtr()));
61 RenderTask::~RenderTask() = default;
63 RenderTask::RenderTask(const RenderTask& handle) = default;
65 RenderTask& RenderTask::operator=(const RenderTask& rhs) = default;
67 RenderTask::RenderTask(RenderTask&& rhs) noexcept = default;
69 RenderTask& RenderTask::operator=(RenderTask&& rhs) noexcept = default;
71 void RenderTask::SetSourceActor(Actor actor)
73 // NULL handle is allowed
74 Internal::Actor* actorImpl(nullptr);
77 actorImpl = &GetImplementation(actor);
80 GetImplementation(*this).SetSourceActor(actorImpl);
83 Actor RenderTask::GetSourceActor() const
85 return Dali::Actor(GetImplementation(*this).GetSourceActor());
88 void RenderTask::SetExclusive(bool exclusive)
90 GetImplementation(*this).SetExclusive(exclusive);
93 bool RenderTask::IsExclusive() const
95 return GetImplementation(*this).IsExclusive();
98 void RenderTask::SetCameraActor(CameraActor cameraActor)
100 // NULL handle is allowed
101 Internal::CameraActor* actorImpl(nullptr);
104 actorImpl = &GetImplementation(cameraActor);
107 GetImplementation(*this).SetCameraActor(actorImpl);
110 CameraActor RenderTask::GetCameraActor() const
112 return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
115 void RenderTask::SetFrameBuffer(FrameBuffer frameBuffer)
117 Internal::FrameBuffer* frameBufferPtr(nullptr);
120 frameBufferPtr = &GetImplementation(frameBuffer);
123 GetImplementation(*this).SetFrameBuffer(frameBufferPtr);
126 FrameBuffer RenderTask::GetFrameBuffer() const
128 Internal::FrameBuffer* frameBufferPtr(GetImplementation(*this).GetFrameBuffer());
129 return FrameBuffer(frameBufferPtr);
132 void RenderTask::SetScreenToFrameBufferFunction(ScreenToFrameBufferFunction conversionFunction)
134 GetImplementation(*this).SetScreenToFrameBufferFunction(conversionFunction);
137 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
139 return GetImplementation(*this).GetScreenToFrameBufferFunction();
142 void RenderTask::SetScreenToFrameBufferMappingActor(Dali::Actor mappingActor)
144 GetImplementation(*this).SetScreenToFrameBufferMappingActor(mappingActor);
147 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
149 return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
152 void RenderTask::SetViewportGuideActor(Actor actor)
154 // NULL handle is allowed
155 Internal::Actor* actorImpl(nullptr);
158 actorImpl = &GetImplementation(actor);
161 GetImplementation(*this).SetViewportGuideActor(actorImpl);
164 Actor RenderTask::GetViewportGuideActor() const
166 return Dali::Actor(GetImplementation(*this).GetViewportGuideActor());
169 void RenderTask::ResetViewportGuideActor()
171 GetImplementation(*this).ResetViewportGuideActor();
174 void RenderTask::SetViewportPosition(Vector2 position)
176 GetImplementation(*this).SetViewportPosition(position);
179 Vector2 RenderTask::GetCurrentViewportPosition() const
181 return GetImplementation(*this).GetCurrentViewportPosition();
184 void RenderTask::SetViewportSize(Vector2 size)
186 GetImplementation(*this).SetViewportSize(size);
189 Vector2 RenderTask::GetCurrentViewportSize() const
191 return GetImplementation(*this).GetCurrentViewportSize();
194 void RenderTask::SetViewport(Viewport viewport)
196 GetImplementation(*this).SetViewport(viewport);
199 Viewport RenderTask::GetViewport() const
202 GetImplementation(*this).GetViewport(result);
206 void RenderTask::SetClearColor(const Vector4& color)
208 GetImplementation(*this).SetClearColor(color);
211 Vector4 RenderTask::GetClearColor() const
213 return GetImplementation(*this).GetClearColor();
216 void RenderTask::SetClearEnabled(bool enabled)
218 GetImplementation(*this).SetClearEnabled(enabled);
221 bool RenderTask::GetClearEnabled() const
223 return GetImplementation(*this).GetClearEnabled();
226 void RenderTask::SetCullMode(bool mode)
228 GetImplementation(*this).SetCullMode(mode);
231 bool RenderTask::GetCullMode() const
233 return GetImplementation(*this).GetCullMode();
236 void RenderTask::SetRefreshRate(uint32_t refreshRate)
238 GetImplementation(*this).SetRefreshRate(refreshRate);
241 uint32_t RenderTask::GetRefreshRate() const
243 return GetImplementation(*this).GetRefreshRate();
246 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
248 return GetImplementation(*this).FinishedSignal();
251 void RenderTask::SetInputEnabled(bool enabled)
253 GetImplementation(*this).SetInputEnabled(enabled);
256 bool RenderTask::GetInputEnabled() const
258 return GetImplementation(*this).GetInputEnabled();
261 bool RenderTask::WorldToViewport(const Vector3& position, float& viewportX, float& viewportY) const
263 return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
266 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float& localX, float& localY) const
270 Internal::Actor* actorImpl(&GetImplementation(actor));
271 return GetImplementation(*this).ViewportToLocal(actorImpl, viewportX, viewportY, localX, localY);
279 void RenderTask::SetRenderPassTag(uint32_t renderPassTag)
281 GetImplementation(*this).SetRenderPassTag(renderPassTag);
284 uint32_t RenderTask::GetRenderPassTag() const
286 return GetImplementation(*this).GetRenderPassTag();
289 void RenderTask::SetOrderIndex(int32_t orderIndex)
291 if(orderIndex < MIN_ORDER_INDEX || orderIndex > MAX_ORDER_INDEX)
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);
297 GetImplementation(*this).SetOrderIndex(orderIndex);
300 int32_t RenderTask::GetOrderIndex() const
302 return GetImplementation(*this).GetOrderIndex();
305 uint32_t RenderTask::GetRenderTaskId() const
307 return GetImplementation(*this).GetRenderTaskId();
310 RenderTask::RenderTask(Internal::RenderTask* internal)