diff options
| author | 2016-10-13 02:10:26 +0000 | |
|---|---|---|
| committer | 2016-10-13 02:10:28 +0000 | |
| commit | d2753b5478690db844d33f774bbbf290731aaa4a (patch) | |
| tree | 23ade7ebba05e3377b83a368ea20fab0e089cae9 | |
| parent | b4d116f1c64d720e113ffdf6ee319e2031fd8e5f (diff) | |
| parent | 4dfb9c4bbb014ac4625dcae419b212d00f541ef0 (diff) | |
Merge "Fix bounds rotation logic"
| -rw-r--r-- | services/core/java/com/android/server/wm/DisplayContent.java | 90 | ||||
| -rw-r--r-- | services/core/java/com/android/server/wm/WindowStateAnimator.java | 20 |
2 files changed, 64 insertions, 46 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 6f7f4a97ad00..327392fb8789 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -23,6 +23,10 @@ import static android.app.ActivityManager.StackId.PINNED_STACK_ID; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; +import static android.view.Surface.ROTATION_0; +import static android.view.Surface.ROTATION_180; +import static android.view.Surface.ROTATION_270; +import static android.view.Surface.ROTATION_90; import static android.view.WindowManager.DOCKED_BOTTOM; import static android.view.WindowManager.DOCKED_INVALID; import static android.view.WindowManager.DOCKED_TOP; @@ -48,7 +52,9 @@ import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; import android.annotation.NonNull; import android.app.ActivityManager.StackId; import android.content.res.Configuration; +import android.graphics.Matrix; import android.graphics.Rect; +import android.graphics.RectF; import android.graphics.Region; import android.graphics.Region.Op; import android.hardware.display.DisplayManagerInternal; @@ -128,6 +134,8 @@ class DisplayContent extends WindowContainer<TaskStack> { /** Save allocating when calculating rects */ private final Rect mTmpRect = new Rect(); private final Rect mTmpRect2 = new Rect(); + private final RectF mTmpRectF = new RectF(); + private final Matrix mTmpMatrix = new Matrix(); private final Region mTmpRegion = new Region(); final WindowManagerService mService; @@ -353,8 +361,7 @@ class DisplayContent extends WindowContainer<TaskStack> { void getLogicalDisplayRect(Rect out) { // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. final int orientation = mDisplayInfo.rotation; - boolean rotated = (orientation == Surface.ROTATION_90 - || orientation == Surface.ROTATION_270); + boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; int width = mDisplayInfo.logicalWidth; @@ -364,6 +371,20 @@ class DisplayContent extends WindowContainer<TaskStack> { out.set(left, top, left + width, top + height); } + private void getLogicalDisplayRect(Rect out, int orientation) { + getLogicalDisplayRect(out); + + // Rotate the Rect if needed. + final int currentRotation = mDisplayInfo.rotation; + final int rotationDelta = deltaRotation(currentRotation, orientation); + if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { + createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); + mTmpRectF.set(out); + mTmpMatrix.mapRect(mTmpRectF); + mTmpRectF.round(out); + } + } + void getContentRect(Rect out) { out.set(mContentRect); } @@ -666,32 +687,16 @@ class DisplayContent extends WindowContainer<TaskStack> { } void rotateBounds(int oldRotation, int newRotation, Rect bounds) { - final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation); - getLogicalDisplayRect(mTmpRect); - switch (rotationDelta) { - case Surface.ROTATION_0: - mTmpRect2.set(bounds); - break; - case Surface.ROTATION_90: - mTmpRect2.top = mTmpRect.bottom - bounds.right; - mTmpRect2.left = bounds.top; - mTmpRect2.right = mTmpRect2.left + bounds.height(); - mTmpRect2.bottom = mTmpRect2.top + bounds.width(); - break; - case Surface.ROTATION_180: - mTmpRect2.top = mTmpRect.bottom - bounds.bottom; - mTmpRect2.left = mTmpRect.right - bounds.right; - mTmpRect2.right = mTmpRect2.left + bounds.width(); - mTmpRect2.bottom = mTmpRect2.top + bounds.height(); - break; - case Surface.ROTATION_270: - mTmpRect2.top = bounds.left; - mTmpRect2.left = mTmpRect.right - bounds.bottom; - mTmpRect2.right = mTmpRect2.left + bounds.height(); - mTmpRect2.bottom = mTmpRect2.top + bounds.width(); - break; - } - bounds.set(mTmpRect2); + getLogicalDisplayRect(mTmpRect, newRotation); + + // Compute a transform matrix to undo the coordinate space transformation, + // and present the window at the same physical position it previously occupied. + final int deltaRotation = deltaRotation(newRotation, oldRotation); + createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix); + + mTmpRectF.set(bounds); + mTmpMatrix.mapRect(mTmpRectF); + mTmpRectF.round(bounds); } static int deltaRotation(int oldRotation, int newRotation) { @@ -700,6 +705,35 @@ class DisplayContent extends WindowContainer<TaskStack> { return delta; } + static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, + Matrix outMatrix) { + // For rotations without Z-ordering we don't need the target rectangle's position. + createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, + displayHeight, outMatrix); + } + + static void createRotationMatrix(int rotation, float rectLeft, float rectTop, + float displayWidth, float displayHeight, Matrix outMatrix) { + switch (rotation) { + case ROTATION_0: + outMatrix.reset(); + break; + case ROTATION_270: + outMatrix.setRotate(270, 0, 0); + outMatrix.postTranslate(0, displayHeight); + outMatrix.postTranslate(rectTop, 0); + break; + case ROTATION_180: + outMatrix.reset(); + break; + case ROTATION_90: + outMatrix.setRotate(90, 0, 0); + outMatrix.postTranslate(displayWidth, 0); + outMatrix.postTranslate(-rectTop, rectLeft); + break; + } + } + public void dump(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); final String subPrefix = " " + prefix; diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index 65bfbf462dbe..53fb99b4effd 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -1936,24 +1936,8 @@ class WindowStateAnimator { // Compute a transform matrix to undo the coordinate space transformation, // and present the window at the same physical position it previously occupied. final int deltaRotation = DisplayContent.deltaRotation(newRotation, oldRotation); - switch (deltaRotation) { - case Surface.ROTATION_0: - transform.reset(); - break; - case Surface.ROTATION_270: - transform.setRotate(270, 0, 0); - transform.postTranslate(0, displayHeight); - transform.postTranslate(y, 0); - break; - case Surface.ROTATION_180: - transform.reset(); - break; - case Surface.ROTATION_90: - transform.setRotate(90, 0, 0); - transform.postTranslate(displayWidth, 0); - transform.postTranslate(-y, x); - break; - } + DisplayContent.createRotationMatrix(deltaRotation, x, y, displayWidth, displayHeight, + transform); // We have two cases: // 1. Windows with NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY: |