From 7cdd65e8a34f05218cc2e721a61424214f88316f Mon Sep 17 00:00:00 2001 From: Wonsik Jung Date: Wed, 13 Apr 2022 21:57:20 +0900 Subject: [PATCH] [Tizen] Supports to re-calculate window position and size for window rotation Supports to re-calculate window position and size when partial size window is rotated. It is needed when the rotated window is resized or moved. Because window system APIs work on the default coordinate system and application sets the window position and size on current orientation. In addtion, fix the bug invalid touch coordinate when window's size is partial. Change-Id: I34e861fa34c987db36aa15a9dec26481e80e1f04 --- .../internal/window-system/common/rotation-event.h | 2 + dali/internal/window-system/common/window-impl.cpp | 20 ++- .../window-system/common/window-render-surface.cpp | 7 +- .../window-system/common/window-render-surface.h | 5 +- .../ecore-wl2/window-base-ecore-wl2.cpp | 166 +++++++++++++++------ .../ecore-wl2/window-base-ecore-wl2.h | 22 +++ 6 files changed, 165 insertions(+), 57 deletions(-) diff --git a/dali/internal/window-system/common/rotation-event.h b/dali/internal/window-system/common/rotation-event.h index 3ad8de5..4179fd7 100644 --- a/dali/internal/window-system/common/rotation-event.h +++ b/dali/internal/window-system/common/rotation-event.h @@ -30,6 +30,8 @@ struct RotationEvent { int angle; ///< one of 0, 90, 180, 270 int winResize; ///< true if the window should be resized + int x; ///< converted x coordinate + int y; ///< converted y coordinate int width; ///< new window width int height; ///< new window height }; diff --git a/dali/internal/window-system/common/window-impl.cpp b/dali/internal/window-system/common/window-impl.cpp index 889ae26..86dcbd0 100644 --- a/dali/internal/window-system/common/window-impl.cpp +++ b/dali/internal/window-system/common/window-impl.cpp @@ -179,7 +179,7 @@ void Window::OnAdaptorSet(Dali::Adaptor& adaptor) // Add Window to bridge for ATSPI auto bridge = Accessibility::Bridge::GetCurrentBridge(); - if (bridge->IsUp()) + if(bridge->IsUp()) { auto rootLayer = mScene.GetRootLayer(); auto accessible = Accessibility::Accessible::Get(rootLayer, true); @@ -616,11 +616,14 @@ void Window::SetSize(Dali::Window::WindowSize size) { Uint16Pair newSize(newRect.width, newRect.height); + mWindowWidth = newRect.width; + mWindowHeight = newRect.height; + SurfaceResized(); mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize); - DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height); + DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.width, newRect.height); Dali::Window handle(this); mResizeSignal.Emit(handle, newSize); @@ -676,11 +679,14 @@ void Window::SetPositionSize(PositionSize positionSize) { Uint16Pair newSize(newRect.width, newRect.height); + mWindowWidth = newRect.width; + mWindowHeight = newRect.height; + SurfaceResized(); mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize); - DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height); + DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.width, newRect.height); Dali::Window handle(this); mResizeSignal.Emit(handle, newSize); mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize); @@ -835,6 +841,8 @@ void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) void Window::OnRotation(const RotationEvent& rotation) { + PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height); + mRotationAngle = rotation.angle; mWindowWidth = rotation.width; mWindowHeight = rotation.height; @@ -842,14 +850,14 @@ void Window::OnRotation(const RotationEvent& rotation) // Notify that the orientation is changed mOrientation->OnOrientationChange(rotation); - mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight); + mWindowSurface->RequestRotation(mRotationAngle, newPositionSize); int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360; SurfaceRotated(mWindowWidth, mWindowHeight, orientation); mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight)); - DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight); + DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): x[%d], y[%d], resize signal emit [%d x %d]\n", this, mNativeWindowId, newPositionSize.x, newPositionSize.y, mWindowWidth, mWindowHeight); // Emit signal Dali::Window handle(this); mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight)); @@ -1061,7 +1069,7 @@ void Window::EnableFloatingMode(bool enable) Rect Window::RecalculateRect(const Rect& rect) { Rect newRect; - int screenWidth, screenHeight; + int screenWidth, screenHeight; WindowSystem::GetScreenSize(screenWidth, screenHeight); diff --git a/dali/internal/window-system/common/window-render-surface.cpp b/dali/internal/window-system/common/window-render-surface.cpp index 22901c2..3261edb 100644 --- a/dali/internal/window-system/common/window-render-surface.cpp +++ b/dali/internal/window-system/common/window-render-surface.cpp @@ -211,7 +211,7 @@ void WindowRenderSurface::SetTransparency(bool transparent) mWindowBase->SetTransparency(transparent); } -void WindowRenderSurface::RequestRotation(int angle, int width, int height) +void WindowRenderSurface::RequestRotation(int angle, PositionSize positionSize) { if(!mPostRenderTrigger) { @@ -219,8 +219,7 @@ void WindowRenderSurface::RequestRotation(int angle, int width, int height) TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER)); } - mPositionSize.width = width; - mPositionSize.height = height; + mPositionSize = positionSize; mWindowRotationAngle = angle; mWindowRotationFinished = false; @@ -546,7 +545,7 @@ bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vectorResizeEglWindow(positionSize); mResizeFinished = true; - DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: Set resize, x: %d, y: %d, w: %d, h:%d\n", positionSize.x, positionSize.y, positionSize.width, positionSize.height); + DALI_LOG_RELEASE_INFO("WindowRenderSurface::PreRender: Set resize, totalAngle: %d, x: %d, y: %d, w: %d, h:%d\n", totalAngle, positionSize.x, positionSize.y, positionSize.width, positionSize.height); } SetFullSwapNextFrame(); diff --git a/dali/internal/window-system/common/window-render-surface.h b/dali/internal/window-system/common/window-render-surface.h index 4c0ff2f..b1194ca 100644 --- a/dali/internal/window-system/common/window-render-surface.h +++ b/dali/internal/window-system/common/window-render-surface.h @@ -97,10 +97,9 @@ public: // API /** * Request surface rotation * @param[in] angle A new angle of the surface - * @param[in] width A new width of the surface - * @param[in] height A new height of the surface + * @param[in] positionSize A new position and size of the surface */ - void RequestRotation(int angle, int width, int height); + void RequestRotation(int angle, PositionSize positionSize); /** * @brief Gets the window base object diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp index 2c80a4d..fc0e36c 100644 --- a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp +++ b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp @@ -449,9 +449,9 @@ static Eina_Bool EcoreEventDataSend(void* data, int type, void* event) } /** -* Called when the source window sends us about the selected content. -* For example, when item is selected in the clipboard. -*/ + * Called when the source window sends us about the selected content. + * For example, when item is selected in the clipboard. + */ static Eina_Bool EcoreEventDataReceive(void* data, int type, void* event) { WindowBaseEcoreWl2* windowBase = static_cast(data); @@ -732,6 +732,8 @@ WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surf mWindowRotationAngle(0), mScreenRotationAngle(0), mSupportedPreProtation(0), + mScreenWidth(0), + mScreenHeight(0), mNotificationChangeState(0), mScreenOffModeChangeState(0), mBrightnessChangeState(0), @@ -1005,34 +1007,23 @@ void WindowBaseEcoreWl2::OnRotation(void* data, int type, void* event) if(ev->w == 0 || ev->h == 0) { - // Use previous client side window's size. - if(mWindowRotationAngle == 90 || mWindowRotationAngle == 270) - { - ev->w = mWindowPositionSize.height; - ev->h = mWindowPositionSize.width; - } - else - { - ev->w = mWindowPositionSize.width; - ev->h = mWindowPositionSize.height; - } + // When rotation event does not have the window width or height, + // previous DALi side window's size are used. + ev->w = mWindowPositionSize.width; + ev->h = mWindowPositionSize.height; } mWindowRotationAngle = ev->angle; - if(ev->angle == 0 || ev->angle == 180) - { - rotationEvent.width = ev->w; - rotationEvent.height = ev->h; - } - else - { - rotationEvent.width = ev->h; - rotationEvent.height = ev->w; - } + mWindowPositionSize.width = ev->w; + mWindowPositionSize.height = ev->h; - mWindowPositionSize.width = rotationEvent.width; - mWindowPositionSize.height = rotationEvent.height; + PositionSize newPositionSize = RecalculatePositionSizeToCurrentOrientation(mWindowPositionSize); + + rotationEvent.x = newPositionSize.x; + rotationEvent.y = newPositionSize.y; + rotationEvent.width = newPositionSize.width; + rotationEvent.height = newPositionSize.height; mRotationSignal.Emit(rotationEvent); } @@ -1072,7 +1063,14 @@ void WindowBaseEcoreWl2::OnConfiguration(void* data, int type, void* event) if(windowMoved || windowResized) { - Dali::PositionSize newPositionSize(ev->x, ev->y, newWidth, newHeight); + mWindowPositionSize.x = ev->x; + mWindowPositionSize.y = ev->y; + mWindowPositionSize.width = newWidth; + mWindowPositionSize.height = newHeight; + DALI_LOG_RELEASE_INFO("Update position & resize signal by server, current angle [%d] x[%d] y[%d] w[%d] h[%d]\n", mWindowRotationAngle, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height); + + Dali::PositionSize newPositionSize = RecalculatePositionSizeToCurrentOrientation(mWindowPositionSize); + DALI_LOG_RELEASE_INFO("emit signal to update window's position and size, x[%d] y[%d] w[%d] h[%d]\n", newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height); mUpdatePositionSizeSignal.Emit(newPositionSize); } @@ -1687,22 +1685,109 @@ bool WindowBaseEcoreWl2::IsEglWindowRotationSupported() return false; } +PositionSize WindowBaseEcoreWl2::RecalculatePositionSizeToSystem(PositionSize positionSize) +{ + PositionSize newPositionSize; + + if(mWindowRotationAngle == 90) + { + newPositionSize.x = positionSize.y; + newPositionSize.y = mScreenHeight - (positionSize.x + positionSize.width); + newPositionSize.width = positionSize.height; + newPositionSize.height = positionSize.width; + } + else if(mWindowRotationAngle == 180) + { + newPositionSize.x = mScreenWidth - (positionSize.x + positionSize.width); + newPositionSize.y = mScreenHeight - (positionSize.y + positionSize.height); + newPositionSize.width = positionSize.width; + newPositionSize.height = positionSize.height; + } + else if(mWindowRotationAngle == 270) + { + newPositionSize.x = mScreenWidth - (positionSize.y + positionSize.height); + newPositionSize.y = positionSize.x; + newPositionSize.width = positionSize.height; + newPositionSize.height = positionSize.width; + } + else + { + newPositionSize.x = positionSize.x; + newPositionSize.y = positionSize.y; + newPositionSize.width = positionSize.width; + newPositionSize.height = positionSize.height; + } + + DALI_LOG_RELEASE_INFO("input coord x[%d], y[%d], w{%d], h[%d], screen w[%d], h[%d]\n", positionSize.x, positionSize.y, positionSize.width, positionSize.height, mScreenWidth, mScreenHeight); + DALI_LOG_RELEASE_INFO("recalc coord x[%d], y[%d], w{%d], h[%d]\n", newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height); + + return newPositionSize; +} + +PositionSize WindowBaseEcoreWl2::RecalculatePositionSizeToCurrentOrientation(PositionSize positionSize) +{ + PositionSize newPositionSize; + + if(mWindowRotationAngle == 90) + { + newPositionSize.x = mScreenHeight - (positionSize.y + positionSize.height); + newPositionSize.y = positionSize.x; + newPositionSize.width = positionSize.height; + newPositionSize.height = positionSize.width; + } + else if(mWindowRotationAngle == 180) + { + newPositionSize.x = mScreenWidth - (positionSize.x + positionSize.width); + newPositionSize.y = mScreenHeight - (positionSize.y + positionSize.height); + newPositionSize.width = positionSize.width; + newPositionSize.height = positionSize.height; + } + else if(mWindowRotationAngle == 270) + { + newPositionSize.x = positionSize.y; + newPositionSize.y = mScreenWidth - (positionSize.x + positionSize.width); + newPositionSize.width = positionSize.height; + newPositionSize.height = positionSize.width; + } + else + { + newPositionSize.x = positionSize.x; + newPositionSize.y = positionSize.y; + newPositionSize.width = positionSize.width; + newPositionSize.height = positionSize.height; + } + + DALI_LOG_RELEASE_INFO("input coord x[%d], y[%d], w{%d], h[%d], screen w[%d], h[%d]\n", positionSize.x, positionSize.y, positionSize.width, positionSize.height, mScreenWidth, mScreenHeight); + DALI_LOG_RELEASE_INFO("recalc by current orientation coord x[%d], y[%d], w{%d], h[%d]\n", newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height); + + return newPositionSize; +} + void WindowBaseEcoreWl2::Move(PositionSize positionSize) { - mWindowPositionSize = positionSize; - ecore_wl2_window_position_set(mEcoreWindow, positionSize.x, positionSize.y); + PositionSize newPositionSize = RecalculatePositionSizeToSystem(positionSize); + + mWindowPositionSize = newPositionSize; + DALI_LOG_RELEASE_INFO("ecore_wl2_window_position_set x[%d], y[%d]\n", newPositionSize.x, newPositionSize.y); + ecore_wl2_window_position_set(mEcoreWindow, newPositionSize.x, newPositionSize.y); } void WindowBaseEcoreWl2::Resize(PositionSize positionSize) { - mWindowPositionSize = positionSize; - ecore_wl2_window_geometry_set(mEcoreWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height); + PositionSize newPositionSize = RecalculatePositionSizeToSystem(positionSize); + + mWindowPositionSize = newPositionSize; + DALI_LOG_RELEASE_INFO("ecore_wl2_window_sync_geometry_set, x[%d], y[%d], w{%d], h[%d]\n", newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height); + ecore_wl2_window_sync_geometry_set(mEcoreWindow, ++mMoveResizeSerial, newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height); } void WindowBaseEcoreWl2::MoveResize(PositionSize positionSize) { - mWindowPositionSize = positionSize; - ecore_wl2_window_sync_geometry_set(mEcoreWindow, ++mMoveResizeSerial, positionSize.x, positionSize.y, positionSize.width, positionSize.height); + PositionSize newPositionSize = RecalculatePositionSizeToSystem(positionSize); + + mWindowPositionSize = newPositionSize; + DALI_LOG_RELEASE_INFO("ecore_wl2_window_sync_geometry_set, x[%d], y[%d], w{%d], h[%d]\n", newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height); + ecore_wl2_window_sync_geometry_set(mEcoreWindow, ++mMoveResizeSerial, newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height); } void WindowBaseEcoreWl2::SetClass(const std::string& name, const std::string& className) @@ -1754,17 +1839,7 @@ void WindowBaseEcoreWl2::Show() { if(!mVisible) { - // Ecore-wl2 has the original window size - // and he always sends the window rotation event with the swapped size. - // So, to restore, dali should set the reswapped size(original window size) to ecore-wl2 for restoring. - if(mWindowRotationAngle == 0 || mWindowRotationAngle == 180) - { - ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height); - } - else - { - ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.height, mWindowPositionSize.width); - } + ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height); } mVisible = true; @@ -2554,6 +2629,9 @@ void WindowBaseEcoreWl2::CreateWindow(PositionSize positionSize) // Set default type ecore_wl2_window_type_set(mEcoreWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL); + + // Get Screen width, height + ecore_wl2_display_screen_size_get(display, &mScreenWidth, &mScreenHeight); } void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase, bool belowParent) diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h index 3df827b..984c1de 100644 --- a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h +++ b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h @@ -536,6 +536,24 @@ private: */ void CreateWindow(PositionSize positionSize); + /** + * @brief Return the window's position and size to recalulate with the default system coordinates. + * It is used when window is moved or resized for native ecore wayland window system. + * + * @param[in] positionSize the window's current position and size with current oriented window's coordinates. + * @return the re-calculated window's position and size on the default system coordinates. + */ + PositionSize RecalculatePositionSizeToSystem(PositionSize positionSize); + + /** + * @brief Return the window's position and size to recalulate with current oriented window's coordinates. + * It is used when window is moved or resized for dali and uppler layer framework. + * + * @param[in] positionSize the window's current position and size with the default system coordinates. + * @return the re-calculated window's position and size on current oriented window's coordinates. + */ + PositionSize RecalculatePositionSizeToCurrentOrientation(PositionSize positionSize); + protected: // Undefined WindowBaseEcoreWl2(const WindowBaseEcoreWl2&) = delete; @@ -562,7 +580,9 @@ private: std::vector mSupportedAuxiliaryHints; + // It is based on the default system coordinates. Dali::PositionSize mWindowPositionSize; + AuxiliaryHints mAuxiliaryHints; WindowType mType; @@ -572,6 +592,8 @@ private: int mWindowRotationAngle; int mScreenRotationAngle; int mSupportedPreProtation; + int mScreenWidth; + int mScreenHeight; uint32_t mNotificationChangeState; uint32_t mScreenOffModeChangeState; -- 2.7.4