2 * Copyright (c) 2022 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 "toolkit-window-impl.h"
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
28 #include <dali/integration-api/adaptor-framework/adaptor.h>
29 #include <toolkit-adaptor-impl.h>
31 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
37 /********************************************************************************
38 * Stub for Dali::Internal::Adaptor::Window
39 ********************************************************************************/
45 Window::Window(const PositionSize& positionSize)
46 : SceneHolder(positionSize),
49 mRotationAngle(90), // dummy angle for test coverage
51 mVisibilityChangedSignal()
55 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
57 return new Window(positionSize);
60 Dali::Window::WindowPosition Window::GetPosition() const
62 PositionSize positionSize = mRenderSurface.GetPositionSize();
64 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
67 PositionSize Window::GetPositionSize() const
69 return mRenderSurface.GetPositionSize();
72 Dali::Window::WindowSize Window::GetSize() const
74 PositionSize positionSize = mRenderSurface.GetPositionSize();
76 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
79 void Window::SetPositionSize(PositionSize positionSize)
81 mRenderSurface.MoveResize(positionSize);
83 Uint16Pair newSize(positionSize.width, positionSize.height);
84 Dali::Window handle(this);
85 mResizeSignal.Emit(handle, newSize);
88 } // namespace Adaptor
89 } // namespace Internal
91 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
93 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
94 BaseObject& object = window.GetBaseObject();
95 return static_cast<Internal::Adaptor::Window&>(object);
98 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
100 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
101 const BaseObject& object = window.GetBaseObject();
102 return static_cast<const Internal::Adaptor::Window&>(object);
113 Window::Window(const Window& copy) = default;
115 Window& Window::operator=(const Window& rhs) = default;
117 Window::Window(Window&& rhs) = default;
119 Window& Window::operator=(Window&& rhs) = default;
121 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, bool isTransparent)
123 return New(windowPosition, name, "", isTransparent);
126 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent)
128 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(windowPosition, name, className, isTransparent);
130 Dali::Window result(window);
132 // This will also emit the window created signals
133 AdaptorImpl::GetImpl(AdaptorImpl::Get()).AddWindow(window);
138 Window Window::DownCast(BaseHandle handle)
140 Internal::Adaptor::Window* windowImpl = nullptr;
141 if(Dali::Adaptor::IsAvailable())
143 windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>(handle.GetObjectPtr());
145 return Dali::Window(windowImpl);
148 Window::Window(Internal::Adaptor::Window* window)
153 Integration::Scene Window::GetScene()
155 return GetImplementation(*this).GetScene();
158 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
160 return GetImplementation(*this).GetRenderSurface();
163 void Window::Add(Actor actor)
165 GetImplementation(*this).Add(actor);
168 void Window::Remove(Actor actor)
170 GetImplementation(*this).Remove(actor);
173 Dali::Layer Window::GetRootLayer() const
175 return GetImplementation(*this).GetRootLayer();
178 void Window::SetBackgroundColor(const Vector4& color)
180 GetImplementation(*this).SetBackgroundColor(color);
183 Vector4 Window::GetBackgroundColor() const
185 return GetImplementation(*this).GetBackgroundColor();
190 GetImplementation(*this).mFocusChangeSignal.Emit(*this, true);
195 GetImplementation(*this).mVisibilityChangedSignal.Emit(*this, false);
196 GetImplementation(*this).mVisible = false;
199 bool Window::IsVisible() const
201 return GetImplementation(*this).mVisible;
204 FocusChangeSignalType& Window::FocusChangeSignal()
206 return GetImplementation(*this).mFocusChangeSignal;
209 ResizeSignalType& Window::ResizeSignal()
211 return GetImplementation(*this).mResizeSignal;
214 Window::KeyEventSignalType& Window::KeyEventSignal()
216 return GetImplementation(*this).KeyEventSignal();
219 Window::TouchEventSignalType& Window::TouchedSignal()
221 return GetImplementation(*this).TouchedSignal();
224 Dali::RenderTaskList Window::GetRenderTaskList()
226 return GetImplementation(*this).GetRenderTaskList();
229 namespace DevelWindow
231 Window Get(Actor actor)
233 Internal::Adaptor::Window* windowImpl = nullptr;
235 if(Dali::Adaptor::IsAvailable())
237 windowImpl = static_cast<Internal::Adaptor::Window*>(AdaptorImpl::GetImpl(AdaptorImpl::Get()).GetWindow(actor));
240 return Dali::Window(windowImpl);
243 void SetPositionSize(Window window, PositionSize positionSize)
245 GetImplementation(window).SetPositionSize(positionSize);
248 int GetPhysicalOrientation(Window window)
250 return GetImplementation(window).mRotationAngle;
253 void AddFrameRenderedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
255 CallbackBase::Execute(*callback, frameId);
258 void AddFramePresentedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
260 CallbackBase::Execute(*callback, frameId);
263 EventProcessingFinishedSignalType& EventProcessingFinishedSignal(Window window)
265 return GetImplementation(window).GetScene().EventProcessingFinishedSignal();
268 KeyEventGeneratedSignalType& KeyEventGeneratedSignal(Window window)
270 return GetImplementation(window).KeyEventGeneratedSignal();
273 WheelEventSignalType& WheelEventSignal(Window window)
275 return GetImplementation(window).WheelEventSignal();
278 WheelEventGeneratedSignalType& WheelEventGeneratedSignal(Window window)
280 return GetImplementation(window).WheelEventGeneratedSignal();
283 VisibilityChangedSignalType& VisibilityChangedSignal(Window window)
285 return GetImplementation(window).mVisibilityChangedSignal;
288 } // namespace DevelWindow