2 * Copyright (c) 2021 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/internal/window-system/common/window-impl.h>
22 #include <dali/devel-api/adaptor-framework/orientation.h>
23 #include <dali/integration-api/core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/window-enumerations.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/public-api/rendering/frame-buffer.h>
35 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
36 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
37 #include <dali/internal/graphics/gles/egl-graphics.h>
38 #include <dali/internal/window-system/common/event-handler.h>
39 #include <dali/internal/window-system/common/orientation-impl.h>
40 #include <dali/internal/window-system/common/render-surface-factory.h>
41 #include <dali/internal/window-system/common/window-base.h>
42 #include <dali/internal/window-system/common/window-factory.h>
43 #include <dali/internal/window-system/common/window-render-surface.h>
44 #include <dali/internal/window-system/common/window-system.h>
45 #include <dali/internal/window-system/common/window-visibility-observer.h>
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
59 } // unnamed namespace
61 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
64 return Window::New(surface, positionSize, name, className, type, isTransparent);
67 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
69 Window* window = new Window();
70 window->mIsTransparent = isTransparent;
71 window->Initialize(surface, positionSize, name, className, type);
76 : mWindowSurface(nullptr),
78 mIsTransparent(false),
79 mIsFocusAcceptable(true),
82 mWindowRotationAcknowledgement(false),
84 mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
88 mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
90 mDeleteRequestSignal(),
93 mVisibilityChangedSignal(),
94 mTransitionEffectEventSignal(),
95 mKeyboardRepeatSettingsChangedSignal(),
96 mAuxiliaryMessageSignal()
102 auto bridge = Accessibility::Bridge::GetCurrentBridge();
103 auto rootLayer = mScene.GetRootLayer();
104 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
105 bridge->RemoveTopLevelWindow(accessible);
109 mAdaptor->RemoveWindow(this);
114 mEventHandler->RemoveObserver(*this);
118 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
120 // Create a window render surface
121 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
122 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
123 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
126 mWindowBase = mWindowSurface->GetWindowBase();
129 mWindowBase->SetType(type);
131 // Initialize for Ime window type
132 if(type == WindowType::IME)
134 mWindowBase->InitializeIme();
135 mWindowSurface->InitializeImeSurface();
139 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
140 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
141 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
142 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
143 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
144 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
145 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
146 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
148 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
150 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
152 SetClass(name, className);
154 mOrientation = Orientation::New(this);
156 // Get OrientationMode
157 int screenWidth, screenHeight;
158 WindowSystem::GetScreenSize(screenWidth, screenHeight);
159 if(screenWidth > screenHeight)
161 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
165 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
168 mNativeWindowId = mWindowBase->GetNativeWindowId();
171 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
173 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
174 mEventHandler->AddObserver(*this);
176 // Add Window to bridge for ATSPI
177 auto bridge = Accessibility::Bridge::GetCurrentBridge();
178 auto rootLayer = mScene.GetRootLayer();
179 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
180 bridge->AddTopLevelWindow(accessible);
182 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
183 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
185 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
186 // The show must be called after the adaptor is initialized.
190 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
192 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
195 void Window::SetClass(std::string name, std::string className)
198 mClassName = className;
199 mWindowBase->SetClass(name, className);
202 std::string Window::GetClassName() const
209 mWindowBase->Raise();
211 mSurface->SetFullSwapNextFrame();
213 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
218 mWindowBase->Lower();
220 mSurface->SetFullSwapNextFrame();
222 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
225 void Window::Activate()
227 mWindowBase->Activate();
229 mSurface->SetFullSwapNextFrame();
231 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
234 uint32_t Window::GetLayerCount() const
236 return mScene.GetLayerCount();
239 Dali::Layer Window::GetLayer(uint32_t depth) const
241 return mScene.GetLayer(depth);
244 Dali::RenderTaskList Window::GetRenderTaskList() const
246 return mScene.GetRenderTaskList();
249 void Window::AddAvailableOrientation(WindowOrientation orientation)
251 if(IsOrientationAvailable(orientation) == false)
257 int convertedAngle = ConvertToAngle(orientation);
258 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
259 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
261 if(mAvailableAngles[i] == convertedAngle)
270 mAvailableAngles.push_back(convertedAngle);
271 SetAvailableAnlges(mAvailableAngles);
275 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
277 if(IsOrientationAvailable(orientation) == false)
282 int convertedAngle = ConvertToAngle(orientation);
283 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
284 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
285 iter != mAvailableAngles.end();
288 if(*iter == convertedAngle)
290 mAvailableAngles.erase(iter);
295 SetAvailableAnlges(mAvailableAngles);
298 void Window::SetPreferredOrientation(WindowOrientation orientation)
300 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
302 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
305 mPreferredAngle = ConvertToAngle(orientation);
306 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
307 mWindowBase->SetPreferredAngle(mPreferredAngle);
310 WindowOrientation Window::GetPreferredOrientation()
312 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
313 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
314 return preferredOrientation;
317 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
319 int angle = ConvertToAngle(orientation);
320 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
323 void Window::SetAvailableAnlges(const std::vector<int>& angles)
325 if(angles.size() > 4)
327 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
331 mWindowBase->SetAvailableAnlges(angles);
334 int Window::ConvertToAngle(WindowOrientation orientation)
336 int convertAngle = static_cast<int>(orientation);
337 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
341 case WindowOrientation::LANDSCAPE:
346 case WindowOrientation::PORTRAIT:
351 case WindowOrientation::LANDSCAPE_INVERSE:
356 case WindowOrientation::PORTRAIT_INVERSE:
361 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
371 WindowOrientation Window::ConvertToOrientation(int angle) const
373 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
374 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
380 orientation = WindowOrientation::LANDSCAPE;
385 orientation = WindowOrientation::PORTRAIT;
390 orientation = WindowOrientation::LANDSCAPE_INVERSE;
395 orientation = WindowOrientation::PORTRAIT_INVERSE;
400 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
408 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
410 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
412 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
418 Dali::Any Window::GetNativeHandle() const
420 return mWindowSurface->GetNativeWindow();
423 void Window::SetAcceptFocus(bool accept)
425 mIsFocusAcceptable = accept;
427 mWindowBase->SetAcceptFocus(accept);
430 bool Window::IsFocusAcceptable() const
432 return mIsFocusAcceptable;
443 Dali::Window handle(this);
444 mVisibilityChangedSignal.Emit(handle, true);
446 WindowVisibilityObserver* observer(mAdaptor);
447 observer->OnWindowShown();
450 mSurface->SetFullSwapNextFrame();
452 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
463 Dali::Window handle(this);
464 mVisibilityChangedSignal.Emit(handle, false);
466 WindowVisibilityObserver* observer(mAdaptor);
467 observer->OnWindowHidden();
470 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
473 bool Window::IsVisible() const
475 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
476 return mVisible && !mIconified;
479 unsigned int Window::GetSupportedAuxiliaryHintCount() const
481 return mWindowBase->GetSupportedAuxiliaryHintCount();
484 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
486 return mWindowBase->GetSupportedAuxiliaryHint(index);
489 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
491 return mWindowBase->AddAuxiliaryHint(hint, value);
494 bool Window::RemoveAuxiliaryHint(unsigned int id)
496 return mWindowBase->RemoveAuxiliaryHint(id);
499 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
501 return mWindowBase->SetAuxiliaryHintValue(id, value);
504 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
506 return mWindowBase->GetAuxiliaryHintValue(id);
509 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
511 return mWindowBase->GetAuxiliaryHintId(hint);
514 void Window::SetInputRegion(const Rect<int>& inputRegion)
516 Rect<int> convertRegion = RecalculateRect(inputRegion);
518 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window (%p), WinId (%d), SetInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
520 mWindowBase->SetInputRegion(convertRegion);
523 void Window::SetType(WindowType type)
525 mWindowBase->SetType(type);
528 WindowType Window::GetType() const
530 return mWindowBase->GetType();
533 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
535 WindowType type = mWindowBase->GetType();
536 if(type != WindowType::NOTIFICATION)
538 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
539 return WindowOperationResult::INVALID_OPERATION;
542 return mWindowBase->SetNotificationLevel(level);
545 WindowNotificationLevel Window::GetNotificationLevel() const
547 WindowType type = mWindowBase->GetType();
548 if(type != WindowType::NOTIFICATION)
550 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
551 return WindowNotificationLevel::NONE;
554 return mWindowBase->GetNotificationLevel();
557 void Window::SetOpaqueState(bool opaque)
559 mOpaqueState = opaque;
561 mWindowBase->SetOpaqueState(opaque);
563 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
566 bool Window::IsOpaqueState() const
571 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
573 return mWindowBase->SetScreenOffMode(screenOffMode);
576 WindowScreenOffMode Window::GetScreenOffMode() const
578 return mWindowBase->GetScreenOffMode();
581 WindowOperationResult Window::SetBrightness(int brightness)
583 if(brightness < 0 || brightness > 100)
585 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
586 return WindowOperationResult::INVALID_OPERATION;
589 return mWindowBase->SetBrightness(brightness);
592 int Window::GetBrightness() const
594 return mWindowBase->GetBrightness();
597 void Window::SetSize(Dali::Window::WindowSize size)
599 PositionSize oldRect = mSurface->GetPositionSize();
601 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
603 PositionSize newRect = mSurface->GetPositionSize();
605 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
606 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
608 Uint16Pair newSize(newRect.width, newRect.height);
612 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
614 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
616 Dali::Window handle(this);
617 mResizeSignal.Emit(handle, newSize);
619 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
622 mSurface->SetFullSwapNextFrame();
624 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
627 Dali::Window::WindowSize Window::GetSize() const
629 PositionSize positionSize = mSurface->GetPositionSize();
631 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
634 void Window::SetPosition(Dali::Window::WindowPosition position)
636 PositionSize oldRect = mSurface->GetPositionSize();
638 mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
640 mSurface->SetFullSwapNextFrame();
642 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
645 Dali::Window::WindowPosition Window::GetPosition() const
647 PositionSize positionSize = mSurface->GetPositionSize();
649 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
652 PositionSize Window::GetPositionSize() const
654 return mSurface->GetPositionSize();
657 void Window::SetPositionSize(PositionSize positionSize)
659 PositionSize oldRect = mSurface->GetPositionSize();
661 mWindowSurface->MoveResize(positionSize);
663 PositionSize newRect = mSurface->GetPositionSize();
665 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
666 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
668 Uint16Pair newSize(newRect.width, newRect.height);
672 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
674 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
675 Dali::Window handle(this);
676 mResizeSignal.Emit(handle, newSize);
677 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
680 mSurface->SetFullSwapNextFrame();
682 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
685 Dali::Layer Window::GetRootLayer() const
687 return mScene.GetRootLayer();
690 void Window::SetTransparency(bool transparent)
692 mWindowSurface->SetTransparency(transparent);
695 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
697 return mWindowBase->GrabKey(key, grabMode);
700 bool Window::UngrabKey(Dali::KEY key)
702 return mWindowBase->UngrabKey(key);
705 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
707 return mWindowBase->GrabKeyList(key, grabMode, result);
710 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
712 return mWindowBase->UngrabKeyList(key, result);
715 void Window::OnIconifyChanged(bool iconified)
723 Dali::Window handle(this);
724 mVisibilityChangedSignal.Emit(handle, false);
726 WindowVisibilityObserver* observer(mAdaptor);
727 observer->OnWindowHidden();
730 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
738 Dali::Window handle(this);
739 mVisibilityChangedSignal.Emit(handle, true);
741 WindowVisibilityObserver* observer(mAdaptor);
742 observer->OnWindowShown();
745 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
748 mSurface->SetFullSwapNextFrame();
751 void Window::OnFocusChanged(bool focusIn)
753 Dali::Window handle(this);
754 mFocusChangeSignal.Emit(handle, focusIn);
756 mSurface->SetFullSwapNextFrame();
758 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
762 bridge->WindowFocused(handle);
766 bridge->WindowUnfocused(handle);
771 void Window::OnOutputTransformed()
773 PositionSize positionSize = mSurface->GetPositionSize();
775 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
776 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
778 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
779 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
782 void Window::OnDeleteRequest()
784 mDeleteRequestSignal.Emit();
787 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
789 Dali::Window handle(this);
790 mTransitionEffectEventSignal.Emit(handle, state, type);
793 void Window::OnKeyboardRepeatSettingsChanged()
795 Dali::Window handle(this);
796 mKeyboardRepeatSettingsChangedSignal.Emit();
799 void Window::OnWindowRedrawRequest()
801 mAdaptor->RenderOnce();
804 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
806 SetPositionSize(positionSize);
809 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
811 FeedTouchPoint(point, timeStamp);
814 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
816 FeedWheelEvent(wheelEvent);
819 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
821 FeedKeyEvent(keyEvent);
824 void Window::OnRotation(const RotationEvent& rotation)
826 mRotationAngle = rotation.angle;
827 mWindowWidth = rotation.width;
828 mWindowHeight = rotation.height;
830 // Notify that the orientation is changed
831 mOrientation->OnOrientationChange(rotation);
833 mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
835 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
836 SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
838 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
840 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
842 Dali::Window handle(this);
843 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
845 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
848 void Window::OnPause()
852 mEventHandler->Pause();
856 void Window::OnResume()
860 mEventHandler->Resume();
863 mSurface->SetFullSwapNextFrame();
866 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
868 mAuxiliaryMessageSignal.Emit(key, value, options);
871 void Window::OnAccessibilityEnabled()
873 auto bridge = Accessibility::Bridge::GetCurrentBridge();
874 auto rootLayer = mScene.GetRootLayer();
875 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
876 bridge->AddTopLevelWindow(accessible);
879 void Window::OnAccessibilityDisabled()
881 auto bridge = Accessibility::Bridge::GetCurrentBridge();
882 auto rootLayer = mScene.GetRootLayer();
883 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
884 bridge->RemoveTopLevelWindow(accessible);
887 void Window::RecalculateTouchPosition(Integration::Point& point)
889 Vector2 position = point.GetScreenPosition();
890 Vector2 convertedPosition;
892 switch(mRotationAngle)
896 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
897 convertedPosition.y = position.x;
902 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
903 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
908 convertedPosition.x = position.y;
909 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
914 convertedPosition = position;
919 point.SetScreenPosition(convertedPosition);
922 Dali::Window Window::Get(Dali::Actor actor)
924 Internal::Adaptor::Window* windowImpl = nullptr;
926 if(Internal::Adaptor::Adaptor::IsAvailable())
928 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
929 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
932 return Dali::Window(windowImpl);
936 return Dali::Window();
939 void Window::SetParent(Dali::Window& parent)
941 if(DALI_UNLIKELY(parent))
943 mParentWindow = parent;
944 Dali::Window self = Dali::Window(this);
945 // check circular parent window setting
946 if(Dali::DevelWindow::GetParent(parent) == self)
948 Dali::DevelWindow::Unparent(parent);
950 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
954 void Window::SetParent(Dali::Window& parent, bool belowParent)
956 if(DALI_UNLIKELY(parent))
958 mParentWindow = parent;
959 Dali::Window self = Dali::Window(this);
960 // check circular parent window setting
961 if(Dali::DevelWindow::GetParent(parent) == self)
963 Dali::DevelWindow::Unparent(parent);
965 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
969 void Window::Unparent()
971 mWindowBase->SetParent(nullptr, false);
972 mParentWindow.Reset();
975 Dali::Window Window::GetParent()
977 return mParentWindow;
980 WindowOrientation Window::GetCurrentOrientation() const
982 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
983 return ConvertToOrientation(mRotationAngle);
986 int Window::GetPhysicalOrientation() const
988 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
991 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
993 Dali::Vector<float>::SizeType count = orientations.Count();
994 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
996 if(IsOrientationAvailable(orientations[index]) == false)
998 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1003 int convertedAngle = ConvertToAngle(orientations[index]);
1005 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1007 if(mAvailableAngles[i] == convertedAngle)
1016 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1017 mAvailableAngles.push_back(convertedAngle);
1020 SetAvailableAnlges(mAvailableAngles);
1023 int32_t Window::GetNativeId() const
1025 return mWindowBase->GetNativeWindowId();
1028 void Window::RequestMoveToServer()
1030 mWindowBase->RequestMoveToServer();
1033 void Window::RequestResizeToServer(WindowResizeDirection direction)
1035 mWindowBase->RequestResizeToServer(direction);
1038 void Window::EnableFloatingMode(bool enable)
1040 mWindowBase->EnableFloatingMode(enable);
1043 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1046 int screenWidth, screenHeight;
1048 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1050 if(mRotationAngle == 90)
1053 newRect.y = screenHeight - (rect.x + rect.width);
1054 newRect.width = rect.height;
1055 newRect.height = rect.width;
1057 else if(mRotationAngle == 180)
1059 newRect.x = screenWidth - (rect.x + rect.width);
1060 newRect.y = screenHeight - (rect.y + rect.height);
1061 newRect.width = rect.width;
1062 newRect.height = rect.height;
1064 else if(mRotationAngle == 270)
1066 newRect.x = screenWidth - (rect.y + rect.height);
1068 newRect.width = rect.height;
1069 newRect.height = rect.width;
1075 newRect.width = rect.width;
1076 newRect.height = rect.height;
1081 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1083 Rect<int> convertRegion = RecalculateRect(inputRegion);
1085 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IncludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1086 mWindowBase->IncludeInputRegion(convertRegion);
1089 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1091 Rect<int> convertRegion = RecalculateRect(inputRegion);
1093 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), ExcludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1094 mWindowBase->ExcludeInputRegion(convertRegion);
1097 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1099 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1100 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1101 mWindowRotationAcknowledgement = needAcknowledgement;
1104 void Window::SendRotationCompletedAcknowledgement()
1106 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1107 if(mWindowRotationAcknowledgement)
1109 SetRotationCompletedAcknowledgement();
1113 bool Window::IsWindowRotating() const
1115 return mWindowSurface->IsWindowRotating();
1118 } // namespace Adaptor
1120 } // namespace Internal