Merge "Fixed not updating waterfall insets in DisplayCutout.inset()" into rvc-dev am: faff9bd887 am: 8d9fa7833d

Change-Id: I671d25b647b779fa335ea5a41c827951e42926c1
This commit is contained in:
Automerger Merge Worker
2020-02-25 06:29:33 +00:00
2 changed files with 39 additions and 19 deletions

View File

@@ -554,26 +554,12 @@ public final class DisplayCutout {
*/
public DisplayCutout inset(int insetLeft, int insetTop, int insetRight, int insetBottom) {
if (insetLeft == 0 && insetTop == 0 && insetRight == 0 && insetBottom == 0
|| isBoundsEmpty()) {
|| (isBoundsEmpty() && mWaterfallInsets.equals(Insets.NONE))) {
return this;
}
Rect safeInsets = new Rect(mSafeInsets);
// Note: it's not really well defined what happens when the inset is negative, because we
// don't know if the safe inset needs to expand in general.
if (insetTop > 0 || safeInsets.top > 0) {
safeInsets.top = atLeastZero(safeInsets.top - insetTop);
}
if (insetBottom > 0 || safeInsets.bottom > 0) {
safeInsets.bottom = atLeastZero(safeInsets.bottom - insetBottom);
}
if (insetLeft > 0 || safeInsets.left > 0) {
safeInsets.left = atLeastZero(safeInsets.left - insetLeft);
}
if (insetRight > 0 || safeInsets.right > 0) {
safeInsets.right = atLeastZero(safeInsets.right - insetRight);
}
Rect safeInsets = insetInsets(insetLeft, insetTop, insetRight, insetBottom,
new Rect(mSafeInsets));
// If we are not cutting off part of the cutout by insetting it on bottom/right, and we also
// don't move it around, we can avoid the allocation and copy of the instance.
@@ -581,6 +567,9 @@ public final class DisplayCutout {
return this;
}
Rect waterfallInsets = insetInsets(insetLeft, insetTop, insetRight, insetBottom,
mWaterfallInsets.toRect());
Rect[] bounds = mBounds.getRects();
for (int i = 0; i < bounds.length; ++i) {
if (!bounds[i].equals(ZERO_RECT)) {
@@ -588,7 +577,27 @@ public final class DisplayCutout {
}
}
return new DisplayCutout(safeInsets, mWaterfallInsets, bounds, false /* copyArguments */);
return new DisplayCutout(safeInsets, Insets.of(waterfallInsets), bounds,
false /* copyArguments */);
}
private Rect insetInsets(int insetLeft, int insetTop, int insetRight, int insetBottom,
Rect insets) {
// Note: it's not really well defined what happens when the inset is negative, because we
// don't know if the safe inset needs to expand in general.
if (insetTop > 0 || insets.top > 0) {
insets.top = atLeastZero(insets.top - insetTop);
}
if (insetBottom > 0 || insets.bottom > 0) {
insets.bottom = atLeastZero(insets.bottom - insetBottom);
}
if (insetLeft > 0 || insets.left > 0) {
insets.left = atLeastZero(insets.left - insetLeft);
}
if (insetRight > 0 || insets.right > 0) {
insets.right = atLeastZero(insets.right - insetRight);
}
return insets;
}
/**

View File

@@ -229,6 +229,16 @@ public class DisplayCutoutTest {
assertEquals(cutout.getSafeInsetBottom(), 96);
}
@Test
public void inset_insets_withWaterfallCutout() throws Exception {
DisplayCutout cutout = createCutoutWaterfallOnly(Insets.of(0, 10, 0, 10)).inset(1, 2, 3, 4);
assertEquals(cutout.getSafeInsetLeft(), 0);
assertEquals(cutout.getSafeInsetTop(), 8);
assertEquals(cutout.getSafeInsetRight(), 0);
assertEquals(cutout.getSafeInsetBottom(), 6);
}
@Test
public void inset_insets_consumeInset() throws Exception {
DisplayCutout cutout = mCutoutTop.inset(0, 1000, 0, 0);
@@ -457,7 +467,8 @@ public class DisplayCutoutTest {
private static DisplayCutout createCutoutWaterfallOnly(Insets waterfallInsets) {
return new DisplayCutout(
Insets.of(20, 0, 20, 0),
Insets.of(waterfallInsets.left, waterfallInsets.top, waterfallInsets.right,
waterfallInsets.bottom),
ZERO_RECT,
ZERO_RECT,
ZERO_RECT,