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
This commit is contained in:
shawnlin
2020-04-14 14:34:16 +08:00
parent 3002b11fb6
commit 4d2a2f4459
2 changed files with 23 additions and 12 deletions

View File

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

View File

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