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);