From ef49b9f1cb989523aca0c2d27ed06c2e638fb1df Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Thu, 15 Sep 2022 07:05:20 +0000 Subject: [PATCH] Fix translateToWindow to report proper values The `translateToWindowX`and `translateToWindowY` will translate screen pointer to window coordinate, if a window has a global scale, it should multiply its `mInvGlobalScale` so we could get the proper values. For example: Global scale = 2.0f, inverse scale = 0.5f Then screen pointer is (1000, 1000) and the window frame is (0, 0). So after `translateToWindow`, it should return (500, 500) in window coordinate. Bug: b/246446831 Test: atest DragDropTest DragDropCompatTest Change-Id: If66875ebefb1ae15779603c193136cf6334517d3 --- services/core/java/com/android/server/wm/DragState.java | 4 ++-- services/core/java/com/android/server/wm/WindowState.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java index 25ff023a664bd..0b28ba2bb1465 100644 --- a/services/core/java/com/android/server/wm/DragState.java +++ b/services/core/java/com/android/server/wm/DragState.java @@ -228,8 +228,8 @@ class DragState { SurfaceControl dragSurface = null; if (!mDragResult && (ws.mSession.mPid == mPid)) { // Report unconsumed drop location back to the app that started the drag. - x = mCurrentX; - y = mCurrentY; + x = ws.translateToWindowX(mCurrentX); + y = ws.translateToWindowY(mCurrentY); if (relinquishDragSurfaceToDragSource()) { // If requested (and allowed), report the drag surface back to the app // starting the drag to handle the return animation diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index df7b8bb4ec9b0..b2b3b8c0aabf5 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -4562,7 +4562,7 @@ class WindowState extends WindowContainer implements WindowManagerP float translateToWindowX(float x) { float winX = x - mWindowFrames.mFrame.left; if (mGlobalScale != 1f) { - winX *= mGlobalScale; + winX *= mInvGlobalScale; } return winX; } @@ -4570,7 +4570,7 @@ class WindowState extends WindowContainer implements WindowManagerP float translateToWindowY(float y) { float winY = y - mWindowFrames.mFrame.top; if (mGlobalScale != 1f) { - winY *= mGlobalScale; + winY *= mInvGlobalScale; } return winY; }