Supports to re-calculate window position and size for window rotation 94/273894/5
authorWonsik Jung <sidein@samsung.com>
Fri, 15 Apr 2022 08:53:39 +0000 (17:53 +0900)
committerWonsik Jung <sidein@samsung.com>
Thu, 21 Apr 2022 05:20:28 +0000 (14:20 +0900)
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: I65ce5ca5452e84faf732bb64071ed1977444de7f

dali/internal/window-system/common/rotation-event.h
dali/internal/window-system/common/window-impl.cpp
dali/internal/window-system/common/window-render-surface.cpp
dali/internal/window-system/common/window-render-surface.h
dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp
dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h

index 3ad8de5..4179fd7 100644 (file)
@@ -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
 };
index 1c99009..fc5a81d 100644 (file)
@@ -180,7 +180,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);
@@ -652,11 +652,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);
@@ -712,11 +715,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);
@@ -894,6 +900,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;
@@ -901,14 +909,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));
@@ -1120,7 +1128,7 @@ void Window::EnableFloatingMode(bool enable)
 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
 {
   Rect<int> newRect;
-  int screenWidth, screenHeight;
+  int       screenWidth, screenHeight;
 
   WindowSystem::GetScreenSize(screenWidth, screenHeight);
 
index 7d53976..a0523d3 100644 (file)
@@ -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;
@@ -228,7 +227,7 @@ void WindowRenderSurface::RequestRotation(int angle, int width, int height)
 
   mWindowBase->SetWindowRotationAngle(mWindowRotationAngle);
 
-  DALI_LOG_INFO(gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: angle = %d screen rotation = %d\n", mWindowRotationAngle, mScreenRotationAngle);
+  DALI_LOG_RELEASE_INFO("angle = %d screen rotation = %d, flag = %d\n", mWindowRotationAngle, mScreenRotationAngle, mWindowRotationFinished);
 }
 
 WindowBase* WindowRenderSurface::GetWindowBase()
@@ -582,7 +581,7 @@ bool WindowRenderSurface::PreRender(bool resizingSurface, const std::vector<Rect
       mWindowBase->ResizeEglWindow(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();
index 2c81fe8..5d248c0 100644 (file)
@@ -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
index 21f55fe..32d87c0 100644 (file)
@@ -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<WindowBaseEcoreWl2*>(data);
@@ -730,6 +730,8 @@ WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surf
   mWindowRotationAngle(0),
   mScreenRotationAngle(0),
   mSupportedPreProtation(0),
+  mScreenWidth(0),
+  mScreenHeight(0),
   mNotificationChangeState(0),
   mScreenOffModeChangeState(0),
   mBrightnessChangeState(0),
@@ -1003,34 +1005,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);
   }
@@ -1070,9 +1061,14 @@ void WindowBaseEcoreWl2::OnConfiguration(void* data, int type, void* event)
 
     if(windowMoved || windowResized)
     {
-      Dali::PositionSize newPositionSize(ev->x, ev->y, newWidth, newHeight);
-      mWindowPositionSize = newPositionSize;
-      DALI_LOG_RELEASE_INFO("Update position & resize signal by server, x[%d] y[%d] w[%d] h[%d]\n", newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height);
+      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);
     }
 
@@ -1696,22 +1692,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)
@@ -1783,17 +1866,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;
 
@@ -2583,6 +2656,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)
index 159e230..06caf19 100644 (file)
@@ -560,6 +560,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;
@@ -576,7 +594,7 @@ private:
 #ifdef OVER_TIZEN_VERSION_7
   zwp_input_panel_v1* mWlInputPanel;
 #else
-  wl_input_panel* mWlInputPanel;
+  wl_input_panel*         mWlInputPanel;
 #endif
   wl_output* mWlOutput;
 #ifdef OVER_TIZEN_VERSION_7
@@ -594,8 +612,10 @@ private:
 
   std::vector<std::string> mSupportedAuxiliaryHints;
 
+  // It is based on the default system coordinates.
   Dali::PositionSize mWindowPositionSize;
-  AuxiliaryHints     mAuxiliaryHints;
+
+  AuxiliaryHints mAuxiliaryHints;
 
   WindowType mType;
   int        mNotificationLevel;
@@ -604,6 +624,8 @@ private:
   int        mWindowRotationAngle;
   int        mScreenRotationAngle;
   int        mSupportedPreProtation;
+  int        mScreenWidth;
+  int        mScreenHeight;
 
   uint32_t          mNotificationChangeState;
   uint32_t          mScreenOffModeChangeState;