From 4d2a2f4459c0a97de94d48b186cfaeaca67e21e2 Mon Sep 17 00:00:00 2001 From: shawnlin Date: Tue, 14 Apr 2020 14:34:16 +0800 Subject: [PATCH] Fixed incorrect size and position of a snapshot starting window in waterfall device. The dst frame was calculated from scaling the cropped snapshot which copped out the system decorations(letterboxes, nav bar and sometimes status bar). But the src frame was set to the original uncropped snapshot which caused this issue. Now set the src frame to the cropped snapshot and we could just offset the dst frame to (0, 0) since we use a matrix to tranlate from a cropped frame to a scaled cropped frame. Bug: 151740296 Test: atest TaskSnapshotSurfaceTest Test: Enable waterfall overlay, launch an app and lock then unlock device Change-Id: I0ddc8aa480264d2e6d0e59bf4dc9bd09aa3e3041 --- .../server/wm/TaskSnapshotSurface.java | 16 ++++++---------- .../server/wm/TaskSnapshotSurfaceTest.java | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java index 14e5c6cbf28d4..24cd7d1fa5289 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java @@ -217,6 +217,7 @@ class TaskSnapshotSurface implements StartingSurface { = topFullscreenOpaqueWindow.mAttrs.insetsFlags.behavior; layoutParams.insetsFlags.appearance = topFullscreenOpaqueWindow.mAttrs.insetsFlags.appearance; + layoutParams.layoutInDisplayCutoutMode = attrs.layoutInDisplayCutoutMode; layoutParams.setFitInsetsTypes(attrs.getFitInsetsTypes()); layoutParams.setFitInsetsSides(attrs.getFitInsetsSides()); layoutParams.setFitInsetsIgnoringVisibility(attrs.isFitInsetsIgnoringVisibility()); @@ -374,15 +375,15 @@ class TaskSnapshotSurface implements StartingSurface { frame = calculateSnapshotFrame(crop); mTransaction.setWindowCrop(mChildSurfaceControl, crop); mTransaction.setPosition(mChildSurfaceControl, frame.left, frame.top); + mTmpSnapshotSize.set(crop); mTmpDstFrame.set(frame); } else { frame = null; + mTmpSnapshotSize.set(0, 0, buffer.getWidth(), buffer.getHeight()); mTmpDstFrame.set(mFrame); } - mTmpDstFrame.offsetTo(0, 0); // Scale the mismatch dimensions to fill the task bounds - mTmpSnapshotSize.set(0, 0, buffer.getWidth(), buffer.getHeight()); mSnapshotMatrix.setRectToRect(mTmpSnapshotSize, mTmpDstFrame, Matrix.ScaleToFit.FILL); mTransaction.setMatrix(mChildSurfaceControl, mSnapshotMatrix, mTmpFloat9); @@ -435,16 +436,11 @@ class TaskSnapshotSurface implements StartingSurface { (float) mSnapshot.getSnapshot().getHeight() / mSnapshot.getTaskSize().y; // Rescale the frame from snapshot to window coordinate space - final Rect frame = new Rect( - (int) (crop.left / scaleX + 0.5f), - (int) (crop.top / scaleY + 0.5f), - (int) (crop.right / scaleX + 0.5f), - (int) (crop.bottom / scaleY + 0.5f) + final Rect frame = new Rect(0, 0, + (int) (crop.width() / scaleX + 0.5f), + (int) (crop.height() / scaleY + 0.5f) ); - // By default, offset it to to top/left corner - frame.offsetTo((int) (-crop.left / scaleX), (int) (-crop.top / scaleY)); - // However, we also need to make space for the navigation bar on the left side. final int colorViewLeftInset = getColorViewLeftInset(mStableInsets.left, mContentInsets.left); diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java index 67d4016dbd730..4907bdc5e1f0d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java @@ -180,12 +180,18 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { assertEquals(new Rect(0, 0, 90, 100), mSurface.calculateSnapshotCrop()); } + @Test + public void testCalculateSnapshotCrop_waterfall() { + setupSurface(100, 100, new Rect(5, 10, 5, 10), 0, 0, new Rect(0, 0, 100, 100)); + assertEquals(new Rect(5, 0, 95, 90), mSurface.calculateSnapshotCrop()); + } + @Test public void testCalculateSnapshotFrame() { setupSurface(100, 100); final Rect insets = new Rect(0, 10, 0, 10); mSurface.setFrames(new Rect(0, 0, 100, 100), insets, insets); - assertEquals(new Rect(0, -10, 100, 70), + assertEquals(new Rect(0, 0, 100, 80), mSurface.calculateSnapshotFrame(new Rect(0, 10, 100, 90))); } @@ -194,10 +200,19 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { setupSurface(100, 100); final Rect insets = new Rect(10, 10, 0, 0); mSurface.setFrames(new Rect(0, 0, 100, 100), insets, insets); - assertEquals(new Rect(0, -10, 90, 80), + assertEquals(new Rect(10, 0, 100, 90), mSurface.calculateSnapshotFrame(new Rect(10, 10, 100, 100))); } + @Test + public void testCalculateSnapshotFrame_waterfall() { + setupSurface(100, 100, new Rect(5, 10, 5, 10), 0, 0, new Rect(0, 0, 100, 100)); + final Rect insets = new Rect(0, 10, 0, 10); + mSurface.setFrames(new Rect(5, 0, 95, 100), insets, insets); + assertEquals(new Rect(0, 0, 90, 90), + mSurface.calculateSnapshotFrame(new Rect(5, 0, 95, 90))); + } + @Test public void testDrawStatusBarBackground() { setupSurface(100, 100);