Make pip size spec calculations more precise

Improve the procision of the new pip size spec calculations
by making sure we are as close to the requested aspect ratio
as possible.
Also make sure to use rounding instead of casting to integer.

Update the PipSizeSpecHandlerTest to reflect the changes as well.

Bug: 283500710
Test: atest WMShellUnitTests:PipSizeSpecHandlerTest
Test: atest PinnedStackTests
Change-Id: Iec0f9df11720584de46c839f5b30559bd8d22222
This commit is contained in:
Ikram Gabiyev
2023-06-02 13:44:24 -07:00
parent cec1c35e34
commit b5fd71549f
2 changed files with 17 additions and 18 deletions

View File

@@ -135,14 +135,14 @@ public class PipSizeSpecHandler {
maxWidth = (int) (mOptimizedAspectRatio * shorterLength
+ shorterLength * (aspectRatio - mOptimizedAspectRatio) / (1
+ aspectRatio));
maxHeight = (int) (maxWidth / aspectRatio);
maxHeight = Math.round(maxWidth / aspectRatio);
} else {
if (aspectRatio > 1f) {
maxWidth = shorterLength;
maxHeight = (int) (maxWidth / aspectRatio);
maxHeight = Math.round(maxWidth / aspectRatio);
} else {
maxHeight = shorterLength;
maxWidth = (int) (maxHeight * aspectRatio);
maxWidth = Math.round(maxHeight * aspectRatio);
}
}
@@ -165,10 +165,9 @@ public class PipSizeSpecHandler {
Size maxSize = this.getMaxSize(aspectRatio);
int defaultWidth = Math.max((int) (maxSize.getWidth() * mDefaultSizePercent),
int defaultWidth = Math.max(Math.round(maxSize.getWidth() * mDefaultSizePercent),
minSize.getWidth());
int defaultHeight = Math.max((int) (maxSize.getHeight() * mDefaultSizePercent),
minSize.getHeight());
int defaultHeight = Math.round(defaultWidth / aspectRatio);
return new Size(defaultWidth, defaultHeight);
}
@@ -188,16 +187,16 @@ public class PipSizeSpecHandler {
Size maxSize = this.getMaxSize(aspectRatio);
int minWidth = (int) (maxSize.getWidth() * mMinimumSizePercent);
int minHeight = (int) (maxSize.getHeight() * mMinimumSizePercent);
int minWidth = Math.round(maxSize.getWidth() * mMinimumSizePercent);
int minHeight = Math.round(maxSize.getHeight() * mMinimumSizePercent);
// make sure the calculated min size is not smaller than the allowed default min size
if (aspectRatio > 1f) {
minHeight = (int) Math.max(minHeight, mDefaultMinSize);
minWidth = (int) (minHeight * aspectRatio);
minHeight = Math.max(minHeight, mDefaultMinSize);
minWidth = Math.round(minHeight * aspectRatio);
} else {
minWidth = (int) Math.max(minWidth, mDefaultMinSize);
minHeight = (int) (minWidth / aspectRatio);
minWidth = Math.max(minWidth, mDefaultMinSize);
minHeight = Math.round(minWidth / aspectRatio);
}
return new Size(minWidth, minHeight);
}

View File

@@ -106,21 +106,21 @@ public class PipSizeSpecHandlerTest extends ShellTestCase {
sExpectedDefaultSizes = new HashMap<>();
sExpectedMinSizes = new HashMap<>();
sExpectedMaxSizes.put(16f / 9, new Size(1000, 562));
sExpectedDefaultSizes.put(16f / 9, new Size(600, 337));
sExpectedMinSizes.put(16f / 9, new Size(499, 281));
sExpectedMaxSizes.put(16f / 9, new Size(1000, 563));
sExpectedDefaultSizes.put(16f / 9, new Size(600, 338));
sExpectedMinSizes.put(16f / 9, new Size(501, 282));
sExpectedMaxSizes.put(4f / 3, new Size(892, 669));
sExpectedDefaultSizes.put(4f / 3, new Size(535, 401));
sExpectedMinSizes.put(4f / 3, new Size(445, 334));
sExpectedMinSizes.put(4f / 3, new Size(447, 335));
sExpectedMaxSizes.put(3f / 4, new Size(669, 892));
sExpectedDefaultSizes.put(3f / 4, new Size(401, 535));
sExpectedMinSizes.put(3f / 4, new Size(334, 445));
sExpectedMinSizes.put(3f / 4, new Size(335, 447));
sExpectedMaxSizes.put(9f / 16, new Size(562, 999));
sExpectedDefaultSizes.put(9f / 16, new Size(337, 599));
sExpectedMinSizes.put(9f / 16, new Size(281, 499));
sExpectedMinSizes.put(9f / 16, new Size(281, 500));
}
private void forEveryTestCaseCheck(Map<Float, Size> expectedSizes,