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()
55 RenderTask RenderTask::DownCast(BaseHandle handle)
57 return RenderTask(dynamic_cast<Dali::Internal::RenderTask*>(handle.GetObjectPtr()));
60 RenderTask::~RenderTask()
64 RenderTask::RenderTask(const RenderTask& handle) = default;
66 RenderTask& RenderTask::operator=(const RenderTask& rhs) = default;
68 RenderTask::RenderTask(RenderTask&& rhs) = default;
70 RenderTask& RenderTask::operator=(RenderTask&& rhs) = default;
72 void RenderTask::SetSourceActor(Actor actor)
74 // NULL handle is allowed
75 Internal::Actor* actorImpl(nullptr);
78 actorImpl = &GetImplementation(actor);
81 GetImplementation(*this).SetSourceActor(actorImpl);
84 Actor RenderTask::GetSourceActor() const
86 return Dali::Actor(GetImplementation(*this).GetSourceActor());
89 void RenderTask::SetExclusive(bool exclusive)
91 GetImplementation(*this).SetExclusive(exclusive);
94 bool RenderTask::IsExclusive() const
96 return GetImplementation(*this).IsExclusive();
99 void RenderTask::SetCameraActor(CameraActor cameraActor)
101 // NULL handle is allowed
102 Internal::CameraActor* actorImpl(nullptr);
105 actorImpl = &GetImplementation(cameraActor);
108 GetImplementation(*this).SetCameraActor(actorImpl);
111 CameraActor RenderTask::GetCameraActor() const
113 return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
116 void RenderTask::SetFrameBuffer(FrameBuffer frameBuffer)
118 Internal::FrameBuffer* frameBufferPtr(nullptr);
121 frameBufferPtr = &GetImplementation(frameBuffer);
124 GetImplementation(*this).SetFrameBuffer(frameBufferPtr);
127 FrameBuffer RenderTask::GetFrameBuffer() const
129 Internal::FrameBuffer* frameBufferPtr(GetImplementation(*this).GetFrameBuffer());
130 return FrameBuffer(frameBufferPtr);
133 void RenderTask::SetScreenToFrameBufferFunction(ScreenToFrameBufferFunction conversionFunction)
135 GetImplementation(*this).SetScreenToFrameBufferFunction(conversionFunction);
138 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
140 return GetImplementation(*this).GetScreenToFrameBufferFunction();
143 void RenderTask::SetScreenToFrameBufferMappingActor(Dali::Actor mappingActor)
145 GetImplementation(*this).SetScreenToFrameBufferMappingActor(mappingActor);
148 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
150 return GetImplementation(*this).GetScreenToFrameBufferMappingActor();
153 void RenderTask::SetViewportPosition(Vector2 position)
155 GetImplementation(*this).SetViewportPosition(position);
158 Vector2 RenderTask::GetCurrentViewportPosition() const
160 return GetImplementation(*this).GetCurrentViewportPosition();
163 void RenderTask::SetViewportSize(Vector2 size)
165 GetImplementation(*this).SetViewportSize(size);
168 Vector2 RenderTask::GetCurrentViewportSize() const
170 return GetImplementation(*this).GetCurrentViewportSize();
173 void RenderTask::SetViewport(Viewport viewport)
175 GetImplementation(*this).SetViewport(viewport);
178 Viewport RenderTask::GetViewport() const
181 GetImplementation(*this).GetViewport(result);
185 void RenderTask::SetClearColor(const Vector4& color)
187 GetImplementation(*this).SetClearColor(color);
190 Vector4 RenderTask::GetClearColor() const
192 return GetImplementation(*this).GetClearColor();
195 void RenderTask::SetClearEnabled(bool enabled)
197 GetImplementation(*this).SetClearEnabled(enabled);
200 bool RenderTask::GetClearEnabled() const
202 return GetImplementation(*this).GetClearEnabled();
205 void RenderTask::SetCullMode(bool mode)
207 GetImplementation(*this).SetCullMode(mode);
210 bool RenderTask::GetCullMode() const
212 return GetImplementation(*this).GetCullMode();
215 void RenderTask::SetRefreshRate(uint32_t refreshRate)
217 GetImplementation(*this).SetRefreshRate(refreshRate);
220 uint32_t RenderTask::GetRefreshRate() const
222 return GetImplementation(*this).GetRefreshRate();
225 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
227 return GetImplementation(*this).FinishedSignal();
230 void RenderTask::SetInputEnabled(bool enabled)
232 GetImplementation(*this).SetInputEnabled(enabled);
235 bool RenderTask::GetInputEnabled() const
237 return GetImplementation(*this).GetInputEnabled();
240 bool RenderTask::WorldToViewport(const Vector3& position, float& viewportX, float& viewportY) const
242 return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
245 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float& localX, float& localY) const
249 Internal::Actor* actorImpl(&GetImplementation(actor));
250 return GetImplementation(*this).ViewportToLocal(actorImpl, viewportX, viewportY, localX, localY);
258 RenderTask::RenderTask(Internal::RenderTask* internal)