From 9474421a56c8bf66086a9d253013687eb5207331 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Mon, 21 Sep 2015 19:01:47 -0700 Subject: [PATCH] Fixed issue with stack size when rotating screen. Stack bounds needs to be adjusted when the screen is rotated so it occupies the same bounds on screen. Change-Id: Id00031f2e1275f2d095f6e6b2e76b5b5d5c13864 --- .../com/android/server/wm/DisplayContent.java | 32 ++++++++++++++++++- .../core/java/com/android/server/wm/Task.java | 27 ++-------------- .../java/com/android/server/wm/TaskStack.java | 17 ++++++++-- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index b503554ce15ea..cb0dba8330952 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -100,7 +100,8 @@ class DisplayContent { Region mTouchExcludeRegion = new Region(); /** Save allocating when calculating rects */ - Rect mTmpRect = new Rect(); + private Rect mTmpRect = new Rect(); + private Rect mTmpRect2 = new Rect(); /** For gathering Task objects in order. */ final ArrayList mTmpTaskHistory = new ArrayList(); @@ -442,6 +443,35 @@ class DisplayContent { } } + 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); + } + static int deltaRotation(int oldRotation, int newRotation) { int delta = newRotation - oldRotation; if (delta < 0) delta += 4; diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 637de2caf67d6..4541dd6030b6b 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -271,31 +271,8 @@ class Task implements DimLayer.DimLayerUser { // Device rotation changed. We don't want the task to move around on the screen when // this happens, so update the task bounds so it stays in the same place. - final int rotationDelta = DisplayContent.deltaRotation(mRotation, newRotation); - displayContent.getLogicalDisplayRect(mTmpRect); - switch (rotationDelta) { - case Surface.ROTATION_0: - mTmpRect2.set(mBounds); - break; - case Surface.ROTATION_90: - mTmpRect2.top = mTmpRect.bottom - mBounds.right; - mTmpRect2.left = mBounds.top; - mTmpRect2.right = mTmpRect2.left + mBounds.height(); - mTmpRect2.bottom = mTmpRect2.top + mBounds.width(); - break; - case Surface.ROTATION_180: - mTmpRect2.top = mTmpRect.bottom - mBounds.bottom; - mTmpRect2.left = mTmpRect.right - mBounds.right; - mTmpRect2.right = mTmpRect2.left + mBounds.width(); - mTmpRect2.bottom = mTmpRect2.top + mBounds.height(); - break; - case Surface.ROTATION_270: - mTmpRect2.top = mBounds.left; - mTmpRect2.left = mTmpRect.right - mBounds.bottom; - mTmpRect2.right = mTmpRect2.left + mBounds.height(); - mTmpRect2.bottom = mTmpRect2.top + mBounds.width(); - break; - } + mTmpRect2.set(mBounds); + displayContent.rotateBounds(mRotation, newRotation, mTmpRect2); setBounds(mTmpRect2, mOverrideConfig); } diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java index 571540fade62d..31069dff6cd18 100644 --- a/services/core/java/com/android/server/wm/TaskStack.java +++ b/services/core/java/com/android/server/wm/TaskStack.java @@ -30,6 +30,7 @@ import android.util.Slog; import android.util.SparseArray; import android.view.DisplayInfo; +import android.view.Surface; import com.android.server.EventLogTags; import java.io.PrintWriter; @@ -57,6 +58,7 @@ public class TaskStack implements DimLayer.DimLayerUser { /** For comparison with DisplayContent bounds. */ private Rect mTmpRect = new Rect(); + private Rect TmpRect2 = new Rect(); /** Content limits relative to the DisplayContent this sits in. */ private Rect mBounds = new Rect(); @@ -64,6 +66,9 @@ public class TaskStack implements DimLayer.DimLayerUser { /** Whether mBounds is fullscreen */ private boolean mFullscreen = true; + // Device rotation as of the last time {@link #mBounds} was set. + int mRotation; + /** Support for non-zero {@link android.view.animation.Animation#getBackgroundColor()} */ DimLayer mAnimationBackgroundSurface; @@ -152,8 +157,10 @@ public class TaskStack implements DimLayer.DimLayerUser { private boolean setBounds(Rect bounds) { boolean oldFullscreen = mFullscreen; + int rotation = Surface.ROTATION_0; if (mDisplayContent != null) { mDisplayContent.getLogicalDisplayRect(mTmpRect); + rotation = mDisplayContent.getDisplayInfo().rotation; if (bounds == null) { bounds = mTmpRect; mFullscreen = true; @@ -171,12 +178,13 @@ public class TaskStack implements DimLayer.DimLayerUser { // Can't set to fullscreen if we don't have a display to get bounds from... return false; } - if (mBounds.equals(bounds) && oldFullscreen == mFullscreen) { + if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) { return false; } mAnimationBackgroundSurface.setBounds(bounds); mBounds.set(bounds); + mRotation = rotation; return true; } @@ -188,8 +196,13 @@ public class TaskStack implements DimLayer.DimLayerUser { if (mDisplayContent != null) { if (bounds != null) { setBounds(bounds); + } else if (mFullscreen) { + setBounds(null); } else { - setBounds(mFullscreen ? null : mBounds); + TmpRect2.set(mBounds); + mDisplayContent.rotateBounds( + mRotation, mDisplayContent.getDisplayInfo().rotation, TmpRect2); + setBounds(TmpRect2); } for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { mTasks.get(taskNdx).updateDisplayInfo(mDisplayContent);