Merge "Make pip size spec calculations more precise" into udc-dev

This commit is contained in:
Ikram Gabiyev
2023-06-05 17:40:13 +00:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 18 deletions

View File

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

View File

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