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-bridge.h>
36 #include <dali/devel-api/atspi-interfaces/accessible.h>
37 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
38 #include <dali/internal/graphics/gles/egl-graphics.h>
39 #include <dali/internal/window-system/common/event-handler.h>
40 #include <dali/internal/window-system/common/orientation-impl.h>
41 #include <dali/internal/window-system/common/render-surface-factory.h>
42 #include <dali/internal/window-system/common/window-base.h>
43 #include <dali/internal/window-system/common/window-factory.h>
44 #include <dali/internal/window-system/common/window-render-surface.h>
45 #include <dali/internal/window-system/common/window-system.h>
46 #include <dali/internal/window-system/common/window-visibility-observer.h>
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
60 } // unnamed namespace
62 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
65 return Window::New(surface, positionSize, name, className, type, isTransparent);
68 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
70 Window* window = new Window();
71 window->mIsTransparent = isTransparent;
72 window->Initialize(surface, positionSize, name, className, type);
77 : mWindowSurface(nullptr),
79 mIsTransparent(false),
80 mIsFocusAcceptable(true),
83 mWindowRotationAcknowledgement(false),
85 mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
89 mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
91 mDeleteRequestSignal(),
94 mVisibilityChangedSignal(),
95 mTransitionEffectEventSignal(),
96 mKeyboardRepeatSettingsChangedSignal(),
97 mAuxiliaryMessageSignal()
103 auto bridge = Accessibility::Bridge::GetCurrentBridge();
104 auto rootLayer = mScene.GetRootLayer();
105 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
106 bridge->RemoveTopLevelWindow(accessible);
110 mAdaptor->RemoveWindow(this);
115 mEventHandler->RemoveObserver(*this);
119 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
121 // Create a window render surface
122 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
123 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
124 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
127 mWindowBase = mWindowSurface->GetWindowBase();
130 mWindowBase->SetType(type);
132 // Initialize for Ime window type
133 if(type == WindowType::IME)
135 mWindowBase->InitializeIme();
136 mWindowSurface->InitializeImeSurface();
140 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
141 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
142 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
143 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
144 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
145 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
146 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
147 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
149 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
151 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
153 SetClass(name, className);
155 mOrientation = Orientation::New(this);
157 // Get OrientationMode
158 int screenWidth, screenHeight;
159 WindowSystem::GetScreenSize(screenWidth, screenHeight);
160 if(screenWidth > screenHeight)
162 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
166 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
169 mNativeWindowId = mWindowBase->GetNativeWindowId();
172 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
174 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
175 mEventHandler->AddObserver(*this);
177 // Add Window to bridge for ATSPI
178 auto bridge = Accessibility::Bridge::GetCurrentBridge();
179 auto rootLayer = mScene.GetRootLayer();
180 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
181 bridge->AddTopLevelWindow(accessible);
183 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
184 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
186 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
187 // The show must be called after the adaptor is initialized.
191 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
193 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
196 void Window::SetClass(std::string name, std::string className)
199 mClassName = className;
200 mWindowBase->SetClass(name, className);
203 std::string Window::GetClassName() const
210 mWindowBase->Raise();
212 mSurface->SetFullSwapNextFrame();
214 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
219 mWindowBase->Lower();
221 mSurface->SetFullSwapNextFrame();
223 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
226 void Window::Activate()
228 mWindowBase->Activate();
230 mSurface->SetFullSwapNextFrame();
232 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
235 uint32_t Window::GetLayerCount() const
237 return mScene.GetLayerCount();
240 Dali::Layer Window::GetLayer(uint32_t depth) const
242 return mScene.GetLayer(depth);
245 Dali::RenderTaskList Window::GetRenderTaskList() const
247 return mScene.GetRenderTaskList();
250 void Window::AddAvailableOrientation(WindowOrientation orientation)
252 if(IsOrientationAvailable(orientation) == false)
258 int convertedAngle = ConvertToAngle(orientation);
259 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
260 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
262 if(mAvailableAngles[i] == convertedAngle)
271 mAvailableAngles.push_back(convertedAngle);
272 SetAvailableAnlges(mAvailableAngles);
276 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
278 if(IsOrientationAvailable(orientation) == false)
283 int convertedAngle = ConvertToAngle(orientation);
284 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
285 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
286 iter != mAvailableAngles.end();
289 if(*iter == convertedAngle)
291 mAvailableAngles.erase(iter);
296 SetAvailableAnlges(mAvailableAngles);
299 void Window::SetPreferredOrientation(WindowOrientation orientation)
301 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
303 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
306 mPreferredAngle = ConvertToAngle(orientation);
307 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
308 mWindowBase->SetPreferredAngle(mPreferredAngle);
311 WindowOrientation Window::GetPreferredOrientation()
313 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
314 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
315 return preferredOrientation;
318 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
320 int angle = ConvertToAngle(orientation);
321 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
324 void Window::SetAvailableAnlges(const std::vector<int>& angles)
326 if(angles.size() > 4)
328 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
332 mWindowBase->SetAvailableAnlges(angles);
335 int Window::ConvertToAngle(WindowOrientation orientation)
337 int convertAngle = static_cast<int>(orientation);
338 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
342 case WindowOrientation::LANDSCAPE:
347 case WindowOrientation::PORTRAIT:
352 case WindowOrientation::LANDSCAPE_INVERSE:
357 case WindowOrientation::PORTRAIT_INVERSE:
362 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
372 WindowOrientation Window::ConvertToOrientation(int angle) const
374 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
375 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
381 orientation = WindowOrientation::LANDSCAPE;
386 orientation = WindowOrientation::PORTRAIT;
391 orientation = WindowOrientation::LANDSCAPE_INVERSE;
396 orientation = WindowOrientation::PORTRAIT_INVERSE;
401 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
409 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
411 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
413 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
419 Dali::Any Window::GetNativeHandle() const
421 return mWindowSurface->GetNativeWindow();
424 void Window::SetAcceptFocus(bool accept)
426 mIsFocusAcceptable = accept;
428 mWindowBase->SetAcceptFocus(accept);
431 bool Window::IsFocusAcceptable() const
433 return mIsFocusAcceptable;
444 Dali::Window handle(this);
445 mVisibilityChangedSignal.Emit(handle, true);
447 WindowVisibilityObserver* observer(mAdaptor);
448 observer->OnWindowShown();
451 mSurface->SetFullSwapNextFrame();
453 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
464 Dali::Window handle(this);
465 mVisibilityChangedSignal.Emit(handle, false);
467 WindowVisibilityObserver* observer(mAdaptor);
468 observer->OnWindowHidden();
471 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
474 bool Window::IsVisible() const
476 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
477 return mVisible && !mIconified;
480 unsigned int Window::GetSupportedAuxiliaryHintCount() const
482 return mWindowBase->GetSupportedAuxiliaryHintCount();
485 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
487 return mWindowBase->GetSupportedAuxiliaryHint(index);
490 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
492 return mWindowBase->AddAuxiliaryHint(hint, value);
495 bool Window::RemoveAuxiliaryHint(unsigned int id)
497 return mWindowBase->RemoveAuxiliaryHint(id);
500 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
502 return mWindowBase->SetAuxiliaryHintValue(id, value);
505 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
507 return mWindowBase->GetAuxiliaryHintValue(id);
510 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
512 return mWindowBase->GetAuxiliaryHintId(hint);
515 void Window::SetInputRegion(const Rect<int>& inputRegion)
517 Rect<int> convertRegion = RecalculateRect(inputRegion);
519 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);
521 mWindowBase->SetInputRegion(convertRegion);
524 void Window::SetType(WindowType type)
526 mWindowBase->SetType(type);
529 WindowType Window::GetType() const
531 return mWindowBase->GetType();
534 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
536 WindowType type = mWindowBase->GetType();
537 if(type != WindowType::NOTIFICATION)
539 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
540 return WindowOperationResult::INVALID_OPERATION;
543 return mWindowBase->SetNotificationLevel(level);
546 WindowNotificationLevel Window::GetNotificationLevel() const
548 WindowType type = mWindowBase->GetType();
549 if(type != WindowType::NOTIFICATION)
551 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
552 return WindowNotificationLevel::NONE;
555 return mWindowBase->GetNotificationLevel();
558 void Window::SetOpaqueState(bool opaque)
560 mOpaqueState = opaque;
562 mWindowBase->SetOpaqueState(opaque);
564 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
567 bool Window::IsOpaqueState() const
572 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
574 return mWindowBase->SetScreenOffMode(screenOffMode);
577 WindowScreenOffMode Window::GetScreenOffMode() const
579 return mWindowBase->GetScreenOffMode();
582 WindowOperationResult Window::SetBrightness(int brightness)
584 if(brightness < 0 || brightness > 100)
586 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
587 return WindowOperationResult::INVALID_OPERATION;
590 return mWindowBase->SetBrightness(brightness);
593 int Window::GetBrightness() const
595 return mWindowBase->GetBrightness();
598 void Window::SetSize(Dali::Window::WindowSize size)
600 PositionSize oldRect = mSurface->GetPositionSize();
602 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
604 PositionSize newRect = mSurface->GetPositionSize();
606 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
607 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
609 Uint16Pair newSize(newRect.width, newRect.height);
613 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
615 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
617 Dali::Window handle(this);
618 mResizeSignal.Emit(handle, newSize);
620 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
623 mSurface->SetFullSwapNextFrame();
625 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
628 Dali::Window::WindowSize Window::GetSize() const
630 PositionSize positionSize = mSurface->GetPositionSize();
632 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
635 void Window::SetPosition(Dali::Window::WindowPosition position)
637 PositionSize oldRect = mSurface->GetPositionSize();
639 mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
641 mSurface->SetFullSwapNextFrame();
643 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
646 Dali::Window::WindowPosition Window::GetPosition() const
648 PositionSize positionSize = mSurface->GetPositionSize();
650 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
653 PositionSize Window::GetPositionSize() const
655 return mSurface->GetPositionSize();
658 void Window::SetPositionSize(PositionSize positionSize)
660 PositionSize oldRect = mSurface->GetPositionSize();
662 mWindowSurface->MoveResize(positionSize);
664 PositionSize newRect = mSurface->GetPositionSize();
666 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
667 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
669 Uint16Pair newSize(newRect.width, newRect.height);
673 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
675 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
676 Dali::Window handle(this);
677 mResizeSignal.Emit(handle, newSize);
678 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
681 mSurface->SetFullSwapNextFrame();
683 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
686 Dali::Layer Window::GetRootLayer() const
688 return mScene.GetRootLayer();
691 void Window::SetTransparency(bool transparent)
693 mWindowSurface->SetTransparency(transparent);
696 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
698 return mWindowBase->GrabKey(key, grabMode);
701 bool Window::UngrabKey(Dali::KEY key)
703 return mWindowBase->UngrabKey(key);
706 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
708 return mWindowBase->GrabKeyList(key, grabMode, result);
711 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
713 return mWindowBase->UngrabKeyList(key, result);
716 void Window::OnIconifyChanged(bool iconified)
724 Dali::Window handle(this);
725 mVisibilityChangedSignal.Emit(handle, false);
727 WindowVisibilityObserver* observer(mAdaptor);
728 observer->OnWindowHidden();
731 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
739 Dali::Window handle(this);
740 mVisibilityChangedSignal.Emit(handle, true);
742 WindowVisibilityObserver* observer(mAdaptor);
743 observer->OnWindowShown();
746 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
749 mSurface->SetFullSwapNextFrame();
752 void Window::OnFocusChanged(bool focusIn)
754 Dali::Window handle(this);
755 mFocusChangeSignal.Emit(handle, focusIn);
757 mSurface->SetFullSwapNextFrame();
759 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
763 bridge->WindowFocused(handle);
767 bridge->WindowUnfocused(handle);
772 void Window::OnOutputTransformed()
774 PositionSize positionSize = mSurface->GetPositionSize();
776 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
777 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
779 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
780 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
783 void Window::OnDeleteRequest()
785 mDeleteRequestSignal.Emit();
788 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
790 Dali::Window handle(this);
791 mTransitionEffectEventSignal.Emit(handle, state, type);
794 void Window::OnKeyboardRepeatSettingsChanged()
796 Dali::Window handle(this);
797 mKeyboardRepeatSettingsChangedSignal.Emit();
800 void Window::OnWindowRedrawRequest()
802 mAdaptor->RenderOnce();
805 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
807 SetPositionSize(positionSize);
810 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
812 FeedTouchPoint(point, timeStamp);
815 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
817 FeedWheelEvent(wheelEvent);
820 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
822 FeedKeyEvent(keyEvent);
825 void Window::OnRotation(const RotationEvent& rotation)
827 mRotationAngle = rotation.angle;
828 mWindowWidth = rotation.width;
829 mWindowHeight = rotation.height;
831 // Notify that the orientation is changed
832 mOrientation->OnOrientationChange(rotation);
834 mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
836 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
837 SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
839 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
841 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
843 Dali::Window handle(this);
844 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
846 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
849 void Window::OnPause()
853 mEventHandler->Pause();
857 void Window::OnResume()
861 mEventHandler->Resume();
864 mSurface->SetFullSwapNextFrame();
867 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
869 mAuxiliaryMessageSignal.Emit(key, value, options);
872 void Window::OnAccessibilityEnabled()
874 auto bridge = Accessibility::Bridge::GetCurrentBridge();
875 auto rootLayer = mScene.GetRootLayer();
876 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
877 bridge->AddTopLevelWindow(accessible);
880 void Window::OnAccessibilityDisabled()
882 auto bridge = Accessibility::Bridge::GetCurrentBridge();
883 auto rootLayer = mScene.GetRootLayer();
884 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
885 bridge->RemoveTopLevelWindow(accessible);
888 void Window::RecalculateTouchPosition(Integration::Point& point)
890 Vector2 position = point.GetScreenPosition();
891 Vector2 convertedPosition;
893 switch(mRotationAngle)
897 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
898 convertedPosition.y = position.x;
903 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
904 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
909 convertedPosition.x = position.y;
910 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
915 convertedPosition = position;
920 point.SetScreenPosition(convertedPosition);
923 Dali::Window Window::Get(Dali::Actor actor)
925 Internal::Adaptor::Window* windowImpl = nullptr;
927 if(Internal::Adaptor::Adaptor::IsAvailable())
929 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
930 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
933 return Dali::Window(windowImpl);
937 return Dali::Window();
940 void Window::SetParent(Dali::Window& parent)
942 if(DALI_UNLIKELY(parent))
944 mParentWindow = parent;
945 Dali::Window self = Dali::Window(this);
946 // check circular parent window setting
947 if(Dali::DevelWindow::GetParent(parent) == self)
949 Dali::DevelWindow::Unparent(parent);
951 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
955 void Window::SetParent(Dali::Window& parent, bool belowParent)
957 if(DALI_UNLIKELY(parent))
959 mParentWindow = parent;
960 Dali::Window self = Dali::Window(this);
961 // check circular parent window setting
962 if(Dali::DevelWindow::GetParent(parent) == self)
964 Dali::DevelWindow::Unparent(parent);
966 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
970 void Window::Unparent()
972 mWindowBase->SetParent(nullptr, false);
973 mParentWindow.Reset();
976 Dali::Window Window::GetParent()
978 return mParentWindow;
981 WindowOrientation Window::GetCurrentOrientation() const
983 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
984 return ConvertToOrientation(mRotationAngle);
987 int Window::GetPhysicalOrientation() const
989 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
992 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
994 Dali::Vector<float>::SizeType count = orientations.Count();
995 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
997 if(IsOrientationAvailable(orientations[index]) == false)
999 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1004 int convertedAngle = ConvertToAngle(orientations[index]);
1006 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1008 if(mAvailableAngles[i] == convertedAngle)
1017 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1018 mAvailableAngles.push_back(convertedAngle);
1021 SetAvailableAnlges(mAvailableAngles);
1024 int32_t Window::GetNativeId() const
1026 return mWindowBase->GetNativeWindowId();
1029 void Window::RequestMoveToServer()
1031 mWindowBase->RequestMoveToServer();
1034 void Window::RequestResizeToServer(WindowResizeDirection direction)
1036 mWindowBase->RequestResizeToServer(direction);
1039 void Window::EnableFloatingMode(bool enable)
1041 mWindowBase->EnableFloatingMode(enable);
1044 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1047 int screenWidth, screenHeight;
1049 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1051 if(mRotationAngle == 90)
1054 newRect.y = screenHeight - (rect.x + rect.width);
1055 newRect.width = rect.height;
1056 newRect.height = rect.width;
1058 else if(mRotationAngle == 180)
1060 newRect.x = screenWidth - (rect.x + rect.width);
1061 newRect.y = screenHeight - (rect.y + rect.height);
1062 newRect.width = rect.width;
1063 newRect.height = rect.height;
1065 else if(mRotationAngle == 270)
1067 newRect.x = screenWidth - (rect.y + rect.height);
1069 newRect.width = rect.height;
1070 newRect.height = rect.width;
1076 newRect.width = rect.width;
1077 newRect.height = rect.height;
1082 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1084 Rect<int> convertRegion = RecalculateRect(inputRegion);
1086 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);
1087 mWindowBase->IncludeInputRegion(convertRegion);
1090 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1092 Rect<int> convertRegion = RecalculateRect(inputRegion);
1094 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);
1095 mWindowBase->ExcludeInputRegion(convertRegion);
1098 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1100 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1101 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1102 mWindowRotationAcknowledgement = needAcknowledgement;
1105 void Window::SendRotationCompletedAcknowledgement()
1107 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1108 if(mWindowRotationAcknowledgement)
1110 SetRotationCompletedAcknowledgement();
1114 } // namespace Adaptor
1116 } // namespace Internal