Merge "Replace DisplayManager.getStableDisplaySize with max Display.Mode" into tm-dev am: 15cb562bcd am: 02c07a76ba am: 7c604236cc

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18485561

Change-Id: I56f1dee5d834ef91397c72a42e716edba9fd9e1b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shawn Lin
2022-05-24 04:13:18 +00:00
committed by Automerger Merge Worker
12 changed files with 140 additions and 106 deletions

View File

@@ -17,6 +17,7 @@
package android.util; package android.util;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.Display;
import com.android.internal.R; import com.android.internal.R;
@@ -53,15 +54,33 @@ public class DisplayUtils {
} }
/** /**
* Get the display size ratio based on the stable display size. * Returns the Display.Mode with maximum resolution.
*/
public static Display.Mode getMaximumResolutionDisplayMode(Display.Mode[] modes) {
if (modes == null || modes.length == 0) {
return null;
}
int maxWidth = 0;
Display.Mode target = null;
for (Display.Mode mode : modes) {
if (mode.getPhysicalWidth() > maxWidth) {
maxWidth = mode.getPhysicalWidth();
target = mode;
}
}
return target;
}
/**
* Get the display size ratio based on the physical display size.
*/ */
public static float getPhysicalPixelDisplaySizeRatio( public static float getPhysicalPixelDisplaySizeRatio(
int stableWidth, int stableHeight, int currentWidth, int currentHeight) { int physicalWidth, int physicalHeight, int currentWidth, int currentHeight) {
if (stableWidth == currentWidth && stableHeight == currentHeight) { if (physicalWidth == currentWidth && physicalHeight == currentHeight) {
return 1f; return 1f;
} }
final float widthRatio = (float) currentWidth / stableWidth; final float widthRatio = (float) currentWidth / physicalWidth;
final float heightRatio = (float) currentHeight / stableHeight; final float heightRatio = (float) currentHeight / physicalHeight;
return Math.min(widthRatio, heightRatio); return Math.min(widthRatio, heightRatio);
} }
} }

View File

@@ -203,8 +203,8 @@ public class CutoutSpecification {
public static class Parser { public static class Parser {
private final boolean mIsShortEdgeOnTop; private final boolean mIsShortEdgeOnTop;
private final float mStableDensity; private final float mStableDensity;
private final int mStableDisplayWidth; private final int mPhysicalDisplayWidth;
private final int mStableDisplayHeight; private final int mPhysicalDisplayHeight;
private final float mPhysicalPixelDisplaySizeRatio; private final float mPhysicalPixelDisplaySizeRatio;
private final Matrix mMatrix; private final Matrix mMatrix;
private Insets mInsets; private Insets mInsets;
@@ -238,25 +238,26 @@ public class CutoutSpecification {
private boolean mIsCloserToStartSide; private boolean mIsCloserToStartSide;
@VisibleForTesting(visibility = PACKAGE) @VisibleForTesting(visibility = PACKAGE)
public Parser(float stableDensity, int stableDisplayWidth, int stableDisplayHeight) { public Parser(float stableDensity, int physicalDisplayWidth,
this(stableDensity, stableDisplayWidth, stableDisplayHeight, 1f); int physicalDisplayHeight) {
this(stableDensity, physicalDisplayWidth, physicalDisplayHeight, 1f);
} }
/** /**
* The constructor of the CutoutSpecification parser to parse the specification of cutout. * The constructor of the CutoutSpecification parser to parse the specification of cutout.
* @param stableDensity the display density. * @param stableDensity the display density.
* @param stableDisplayWidth the display width. * @param physicalDisplayWidth the display width.
* @param stableDisplayHeight the display height. * @param physicalDisplayHeight the display height.
* @param physicalPixelDisplaySizeRatio the display size ratio based on stable display size. * @param physicalPixelDisplaySizeRatio the display size ratio based on stable display size.
*/ */
Parser(float stableDensity, int stableDisplayWidth, int stableDisplayHeight, Parser(float stableDensity, int physicalDisplayWidth, int physicalDisplayHeight,
float physicalPixelDisplaySizeRatio) { float physicalPixelDisplaySizeRatio) {
mStableDensity = stableDensity; mStableDensity = stableDensity;
mStableDisplayWidth = stableDisplayWidth; mPhysicalDisplayWidth = physicalDisplayWidth;
mStableDisplayHeight = stableDisplayHeight; mPhysicalDisplayHeight = physicalDisplayHeight;
mPhysicalPixelDisplaySizeRatio = physicalPixelDisplaySizeRatio; mPhysicalPixelDisplaySizeRatio = physicalPixelDisplaySizeRatio;
mMatrix = new Matrix(); mMatrix = new Matrix();
mIsShortEdgeOnTop = mStableDisplayWidth < mStableDisplayHeight; mIsShortEdgeOnTop = mPhysicalDisplayWidth < mPhysicalDisplayHeight;
} }
private void computeBoundsRectAndAddToRegion(Path p, Region inoutRegion, Rect inoutRect) { private void computeBoundsRectAndAddToRegion(Path p, Region inoutRegion, Rect inoutRect) {
@@ -281,18 +282,18 @@ public class CutoutSpecification {
private void translateMatrix() { private void translateMatrix() {
final float offsetX; final float offsetX;
if (mPositionFromRight) { if (mPositionFromRight) {
offsetX = mStableDisplayWidth; offsetX = mPhysicalDisplayWidth;
} else if (mPositionFromLeft) { } else if (mPositionFromLeft) {
offsetX = 0; offsetX = 0;
} else { } else {
offsetX = mStableDisplayWidth / 2f; offsetX = mPhysicalDisplayWidth / 2f;
} }
final float offsetY; final float offsetY;
if (mPositionFromBottom) { if (mPositionFromBottom) {
offsetY = mStableDisplayHeight; offsetY = mPhysicalDisplayHeight;
} else if (mPositionFromCenterVertical) { } else if (mPositionFromCenterVertical) {
offsetY = mStableDisplayHeight / 2f; offsetY = mPhysicalDisplayHeight / 2f;
} else { } else {
offsetY = 0; offsetY = 0;
} }
@@ -305,14 +306,14 @@ public class CutoutSpecification {
} }
private int computeSafeInsets(int gravity, Rect rect) { private int computeSafeInsets(int gravity, Rect rect) {
if (gravity == LEFT && rect.right > 0 && rect.right < mStableDisplayWidth) { if (gravity == LEFT && rect.right > 0 && rect.right < mPhysicalDisplayWidth) {
return rect.right; return rect.right;
} else if (gravity == TOP && rect.bottom > 0 && rect.bottom < mStableDisplayHeight) { } else if (gravity == TOP && rect.bottom > 0 && rect.bottom < mPhysicalDisplayHeight) {
return rect.bottom; return rect.bottom;
} else if (gravity == RIGHT && rect.left > 0 && rect.left < mStableDisplayWidth) { } else if (gravity == RIGHT && rect.left > 0 && rect.left < mPhysicalDisplayWidth) {
return mStableDisplayWidth - rect.left; return mPhysicalDisplayWidth - rect.left;
} else if (gravity == BOTTOM && rect.top > 0 && rect.top < mStableDisplayHeight) { } else if (gravity == BOTTOM && rect.top > 0 && rect.top < mPhysicalDisplayHeight) {
return mStableDisplayHeight - rect.top; return mPhysicalDisplayHeight - rect.top;
} }
return 0; return 0;
} }
@@ -415,12 +416,12 @@ public class CutoutSpecification {
if (mIsShortEdgeOnTop) { if (mIsShortEdgeOnTop) {
mIsTouchShortEdgeStart = mTmpRect.top <= 0; mIsTouchShortEdgeStart = mTmpRect.top <= 0;
mIsTouchShortEdgeEnd = mTmpRect.bottom >= mStableDisplayHeight; mIsTouchShortEdgeEnd = mTmpRect.bottom >= mPhysicalDisplayHeight;
mIsCloserToStartSide = mTmpRect.centerY() < mStableDisplayHeight / 2; mIsCloserToStartSide = mTmpRect.centerY() < mPhysicalDisplayHeight / 2;
} else { } else {
mIsTouchShortEdgeStart = mTmpRect.left <= 0; mIsTouchShortEdgeStart = mTmpRect.left <= 0;
mIsTouchShortEdgeEnd = mTmpRect.right >= mStableDisplayWidth; mIsTouchShortEdgeEnd = mTmpRect.right >= mPhysicalDisplayWidth;
mIsCloserToStartSide = mTmpRect.centerX() < mStableDisplayWidth / 2; mIsCloserToStartSide = mTmpRect.centerX() < mPhysicalDisplayWidth / 2;
} }
setEdgeCutout(newPath); setEdgeCutout(newPath);

View File

@@ -77,8 +77,8 @@ public final class DisplayCutout {
private static final Rect ZERO_RECT = new Rect(); private static final Rect ZERO_RECT = new Rect();
private static final CutoutPathParserInfo EMPTY_PARSER_INFO = new CutoutPathParserInfo( private static final CutoutPathParserInfo EMPTY_PARSER_INFO = new CutoutPathParserInfo(
0 /* displayWidth */, 0 /* stableDisplayHeight */, 0 /* displayWidth */, 0 /* physicalDisplayHeight */,
0 /* stableDisplayHeight */, 0 /* displayHeight */, 0f /* density */, 0 /* physicalDisplayHeight */, 0 /* displayHeight */, 0f /* density */,
"" /* cutoutSpec */, 0 /* ROTATION_0 */, 0f /* scale */, "" /* cutoutSpec */, 0 /* ROTATION_0 */, 0f /* scale */,
0f /* physicalPixelDisplaySizeRatio*/); 0f /* physicalPixelDisplaySizeRatio*/);
@@ -258,21 +258,21 @@ public final class DisplayCutout {
public static class CutoutPathParserInfo { public static class CutoutPathParserInfo {
private final int mDisplayWidth; private final int mDisplayWidth;
private final int mDisplayHeight; private final int mDisplayHeight;
private final int mStableDisplayWidth; private final int mPhysicalDisplayWidth;
private final int mStableDisplayHeight; private final int mPhysicalDisplayHeight;
private final float mDensity; private final float mDensity;
private final String mCutoutSpec; private final String mCutoutSpec;
private final @Rotation int mRotation; private final @Rotation int mRotation;
private final float mScale; private final float mScale;
private final float mPhysicalPixelDisplaySizeRatio; private final float mPhysicalPixelDisplaySizeRatio;
public CutoutPathParserInfo(int displayWidth, int displayHeight, int stableDisplayWidth, public CutoutPathParserInfo(int displayWidth, int displayHeight, int physicalDisplayWidth,
int stableDisplayHeight, float density, @Nullable String cutoutSpec, int physicalDisplayHeight, float density, @Nullable String cutoutSpec,
@Rotation int rotation, float scale, float physicalPixelDisplaySizeRatio) { @Rotation int rotation, float scale, float physicalPixelDisplaySizeRatio) {
mDisplayWidth = displayWidth; mDisplayWidth = displayWidth;
mDisplayHeight = displayHeight; mDisplayHeight = displayHeight;
mStableDisplayWidth = stableDisplayWidth; mPhysicalDisplayWidth = physicalDisplayWidth;
mStableDisplayHeight = stableDisplayHeight; mPhysicalDisplayHeight = physicalDisplayHeight;
mDensity = density; mDensity = density;
mCutoutSpec = cutoutSpec == null ? "" : cutoutSpec; mCutoutSpec = cutoutSpec == null ? "" : cutoutSpec;
mRotation = rotation; mRotation = rotation;
@@ -283,8 +283,8 @@ public final class DisplayCutout {
public CutoutPathParserInfo(@NonNull CutoutPathParserInfo cutoutPathParserInfo) { public CutoutPathParserInfo(@NonNull CutoutPathParserInfo cutoutPathParserInfo) {
mDisplayWidth = cutoutPathParserInfo.mDisplayWidth; mDisplayWidth = cutoutPathParserInfo.mDisplayWidth;
mDisplayHeight = cutoutPathParserInfo.mDisplayHeight; mDisplayHeight = cutoutPathParserInfo.mDisplayHeight;
mStableDisplayWidth = cutoutPathParserInfo.mStableDisplayWidth; mPhysicalDisplayWidth = cutoutPathParserInfo.mPhysicalDisplayWidth;
mStableDisplayHeight = cutoutPathParserInfo.mStableDisplayHeight; mPhysicalDisplayHeight = cutoutPathParserInfo.mPhysicalDisplayHeight;
mDensity = cutoutPathParserInfo.mDensity; mDensity = cutoutPathParserInfo.mDensity;
mCutoutSpec = cutoutPathParserInfo.mCutoutSpec; mCutoutSpec = cutoutPathParserInfo.mCutoutSpec;
mRotation = cutoutPathParserInfo.mRotation; mRotation = cutoutPathParserInfo.mRotation;
@@ -300,12 +300,12 @@ public final class DisplayCutout {
return mDisplayHeight; return mDisplayHeight;
} }
public int getStableDisplayWidth() { public int getPhysicalDisplayWidth() {
return mStableDisplayWidth; return mPhysicalDisplayWidth;
} }
public int getStableDisplayHeight() { public int getPhysicalDisplayHeight() {
return mStableDisplayHeight; return mPhysicalDisplayHeight;
} }
public float getDensity() { public float getDensity() {
@@ -342,8 +342,8 @@ public final class DisplayCutout {
result = result * 48271 + Integer.hashCode(mRotation); result = result * 48271 + Integer.hashCode(mRotation);
result = result * 48271 + Float.hashCode(mScale); result = result * 48271 + Float.hashCode(mScale);
result = result * 48271 + Float.hashCode(mPhysicalPixelDisplaySizeRatio); result = result * 48271 + Float.hashCode(mPhysicalPixelDisplaySizeRatio);
result = result * 48271 + Integer.hashCode(mStableDisplayWidth); result = result * 48271 + Integer.hashCode(mPhysicalDisplayWidth);
result = result * 48271 + Integer.hashCode(mStableDisplayHeight); result = result * 48271 + Integer.hashCode(mPhysicalDisplayHeight);
return result; return result;
} }
@@ -355,8 +355,8 @@ public final class DisplayCutout {
if (o instanceof CutoutPathParserInfo) { if (o instanceof CutoutPathParserInfo) {
CutoutPathParserInfo c = (CutoutPathParserInfo) o; CutoutPathParserInfo c = (CutoutPathParserInfo) o;
return mDisplayWidth == c.mDisplayWidth && mDisplayHeight == c.mDisplayHeight return mDisplayWidth == c.mDisplayWidth && mDisplayHeight == c.mDisplayHeight
&& mStableDisplayWidth == c.mStableDisplayWidth && mPhysicalDisplayWidth == c.mPhysicalDisplayWidth
&& mStableDisplayHeight == c.mStableDisplayHeight && mPhysicalDisplayHeight == c.mPhysicalDisplayHeight
&& mDensity == c.mDensity && mCutoutSpec.equals(c.mCutoutSpec) && mDensity == c.mDensity && mCutoutSpec.equals(c.mCutoutSpec)
&& mRotation == c.mRotation && mScale == c.mScale && mRotation == c.mRotation && mScale == c.mScale
&& mPhysicalPixelDisplaySizeRatio == c.mPhysicalPixelDisplaySizeRatio; && mPhysicalPixelDisplaySizeRatio == c.mPhysicalPixelDisplaySizeRatio;
@@ -368,8 +368,8 @@ public final class DisplayCutout {
public String toString() { public String toString() {
return "CutoutPathParserInfo{displayWidth=" + mDisplayWidth return "CutoutPathParserInfo{displayWidth=" + mDisplayWidth
+ " displayHeight=" + mDisplayHeight + " displayHeight=" + mDisplayHeight
+ " stableDisplayHeight=" + mStableDisplayWidth + " physicalDisplayWidth=" + mPhysicalDisplayWidth
+ " stableDisplayHeight=" + mStableDisplayHeight + " physicalDisplayHeight=" + mPhysicalDisplayHeight
+ " density={" + mDensity + "}" + " density={" + mDensity + "}"
+ " cutoutSpec={" + mCutoutSpec + "}" + " cutoutSpec={" + mCutoutSpec + "}"
+ " rotation={" + mRotation + "}" + " rotation={" + mRotation + "}"
@@ -750,8 +750,8 @@ public final class DisplayCutout {
} }
} }
final CutoutSpecification cutoutSpec = new CutoutSpecification.Parser( final CutoutSpecification cutoutSpec = new CutoutSpecification.Parser(
mCutoutPathParserInfo.getDensity(), mCutoutPathParserInfo.getStableDisplayWidth(), mCutoutPathParserInfo.getDensity(), mCutoutPathParserInfo.getPhysicalDisplayWidth(),
mCutoutPathParserInfo.getStableDisplayHeight(), mCutoutPathParserInfo.getPhysicalDisplayHeight(),
mCutoutPathParserInfo.getPhysicalPixelDisplaySizeRatio()) mCutoutPathParserInfo.getPhysicalPixelDisplaySizeRatio())
.parse(mCutoutPathParserInfo.getCutoutSpec()); .parse(mCutoutPathParserInfo.getCutoutSpec());
@@ -1053,11 +1053,11 @@ public final class DisplayCutout {
* @hide * @hide
*/ */
public static DisplayCutout fromResourcesRectApproximation(Resources res, public static DisplayCutout fromResourcesRectApproximation(Resources res,
String displayUniqueId, int stableDisplayWidth, int stableDisplayHeight, String displayUniqueId, int physicalDisplayWidth, int physicalDisplayHeight,
int displayWidth, int displayHeight) { int displayWidth, int displayHeight) {
return pathAndDisplayCutoutFromSpec(getDisplayCutoutPath(res, displayUniqueId), return pathAndDisplayCutoutFromSpec(getDisplayCutoutPath(res, displayUniqueId),
getDisplayCutoutApproximationRect(res, displayUniqueId), stableDisplayWidth, getDisplayCutoutApproximationRect(res, displayUniqueId), physicalDisplayWidth,
stableDisplayHeight, displayWidth, displayHeight, physicalDisplayHeight, displayWidth, displayHeight,
DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT,
getWaterfallInsets(res, displayUniqueId)).second; getWaterfallInsets(res, displayUniqueId)).second;
} }
@@ -1080,8 +1080,8 @@ public final class DisplayCutout {
* *
* @param pathSpec the spec string read from config_mainBuiltInDisplayCutout. * @param pathSpec the spec string read from config_mainBuiltInDisplayCutout.
* @param rectSpec the spec string read from config_mainBuiltInDisplayCutoutRectApproximation. * @param rectSpec the spec string read from config_mainBuiltInDisplayCutoutRectApproximation.
* @param stableDisplayWidth the stable display width. * @param physicalDisplayWidth the max physical display width the display supports.
* @param stableDisplayHeight the stable display height. * @param physicalDisplayHeight the max physical display height the display supports.
* @param displayWidth the display width. * @param displayWidth the display width.
* @param displayHeight the display height. * @param displayHeight the display height.
* @param density the display density. * @param density the display density.
@@ -1089,7 +1089,7 @@ public final class DisplayCutout {
* @return a Pair contains the cutout path and the corresponding DisplayCutout instance. * @return a Pair contains the cutout path and the corresponding DisplayCutout instance.
*/ */
private static Pair<Path, DisplayCutout> pathAndDisplayCutoutFromSpec( private static Pair<Path, DisplayCutout> pathAndDisplayCutoutFromSpec(
String pathSpec, String rectSpec, int stableDisplayWidth, int stableDisplayHeight, String pathSpec, String rectSpec, int physicalDisplayWidth, int physicalDisplayHeight,
int displayWidth, int displayHeight, float density, Insets waterfallInsets) { int displayWidth, int displayHeight, float density, Insets waterfallInsets) {
// Always use the rect approximation spec to create the cutout if it's not null because // Always use the rect approximation spec to create the cutout if it's not null because
// transforming and sending a Region constructed from a path is very costly. // transforming and sending a Region constructed from a path is very costly.
@@ -1099,7 +1099,7 @@ public final class DisplayCutout {
} }
final float physicalPixelDisplaySizeRatio = DisplayUtils.getPhysicalPixelDisplaySizeRatio( final float physicalPixelDisplaySizeRatio = DisplayUtils.getPhysicalPixelDisplaySizeRatio(
stableDisplayWidth, stableDisplayHeight, displayWidth, displayHeight); physicalDisplayWidth, physicalDisplayHeight, displayWidth, displayHeight);
synchronized (CACHE_LOCK) { synchronized (CACHE_LOCK) {
if (spec.equals(sCachedSpec) && sCachedDisplayWidth == displayWidth if (spec.equals(sCachedSpec) && sCachedDisplayWidth == displayWidth
@@ -1114,7 +1114,8 @@ public final class DisplayCutout {
spec = spec.trim(); spec = spec.trim();
CutoutSpecification cutoutSpec = new CutoutSpecification.Parser(density, CutoutSpecification cutoutSpec = new CutoutSpecification.Parser(density,
stableDisplayWidth, stableDisplayHeight, physicalPixelDisplaySizeRatio).parse(spec); physicalDisplayWidth, physicalDisplayHeight, physicalPixelDisplaySizeRatio)
.parse(spec);
Rect safeInset = cutoutSpec.getSafeInset(); Rect safeInset = cutoutSpec.getSafeInset();
final Rect boundLeft = cutoutSpec.getLeftBound(); final Rect boundLeft = cutoutSpec.getLeftBound();
final Rect boundTop = cutoutSpec.getTopBound(); final Rect boundTop = cutoutSpec.getTopBound();
@@ -1131,7 +1132,7 @@ public final class DisplayCutout {
} }
final CutoutPathParserInfo cutoutPathParserInfo = new CutoutPathParserInfo( final CutoutPathParserInfo cutoutPathParserInfo = new CutoutPathParserInfo(
displayWidth, displayHeight, stableDisplayWidth, stableDisplayHeight, density, displayWidth, displayHeight, physicalDisplayWidth, physicalDisplayHeight, density,
pathSpec.trim(), ROTATION_0, 1f /* scale */, physicalPixelDisplaySizeRatio); pathSpec.trim(), ROTATION_0, 1f /* scale */, physicalPixelDisplaySizeRatio);
final DisplayCutout cutout = new DisplayCutout( final DisplayCutout cutout = new DisplayCutout(
@@ -1182,9 +1183,9 @@ public final class DisplayCutout {
Collections.rotate(Arrays.asList(newBounds), -rotation); Collections.rotate(Arrays.asList(newBounds), -rotation);
final CutoutPathParserInfo info = getCutoutPathParserInfo(); final CutoutPathParserInfo info = getCutoutPathParserInfo();
final CutoutPathParserInfo newInfo = new CutoutPathParserInfo( final CutoutPathParserInfo newInfo = new CutoutPathParserInfo(
info.getDisplayWidth(), info.getDisplayHeight(), info.getStableDisplayWidth(), info.getDisplayWidth(), info.getDisplayHeight(), info.getPhysicalDisplayWidth(),
info.getStableDisplayHeight(), info.getDensity(), info.getCutoutSpec(), toRotation, info.getPhysicalDisplayHeight(), info.getDensity(), info.getCutoutSpec(),
info.getScale(), info.getPhysicalPixelDisplaySizeRatio()); toRotation, info.getScale(), info.getPhysicalPixelDisplaySizeRatio());
final boolean swapAspect = (rotation % 2) != 0; final boolean swapAspect = (rotation % 2) != 0;
final int endWidth = swapAspect ? startHeight : startWidth; final int endWidth = swapAspect ? startHeight : startWidth;
final int endHeight = swapAspect ? startWidth : startHeight; final int endHeight = swapAspect ? startWidth : startHeight;
@@ -1284,8 +1285,8 @@ public final class DisplayCutout {
out.writeTypedObject(cutout.mWaterfallInsets, flags); out.writeTypedObject(cutout.mWaterfallInsets, flags);
out.writeInt(cutout.mCutoutPathParserInfo.getDisplayWidth()); out.writeInt(cutout.mCutoutPathParserInfo.getDisplayWidth());
out.writeInt(cutout.mCutoutPathParserInfo.getDisplayHeight()); out.writeInt(cutout.mCutoutPathParserInfo.getDisplayHeight());
out.writeInt(cutout.mCutoutPathParserInfo.getStableDisplayWidth()); out.writeInt(cutout.mCutoutPathParserInfo.getPhysicalDisplayWidth());
out.writeInt(cutout.mCutoutPathParserInfo.getStableDisplayHeight()); out.writeInt(cutout.mCutoutPathParserInfo.getPhysicalDisplayHeight());
out.writeFloat(cutout.mCutoutPathParserInfo.getDensity()); out.writeFloat(cutout.mCutoutPathParserInfo.getDensity());
out.writeString(cutout.mCutoutPathParserInfo.getCutoutSpec()); out.writeString(cutout.mCutoutPathParserInfo.getCutoutSpec());
out.writeInt(cutout.mCutoutPathParserInfo.getRotation()); out.writeInt(cutout.mCutoutPathParserInfo.getRotation());
@@ -1336,16 +1337,16 @@ public final class DisplayCutout {
Insets waterfallInsets = in.readTypedObject(Insets.CREATOR); Insets waterfallInsets = in.readTypedObject(Insets.CREATOR);
int displayWidth = in.readInt(); int displayWidth = in.readInt();
int displayHeight = in.readInt(); int displayHeight = in.readInt();
int stableDisplayWidth = in.readInt(); int physicalDisplayWidth = in.readInt();
int stableDisplayHeight = in.readInt(); int physicalDisplayHeight = in.readInt();
float density = in.readFloat(); float density = in.readFloat();
String cutoutSpec = in.readString(); String cutoutSpec = in.readString();
int rotation = in.readInt(); int rotation = in.readInt();
float scale = in.readFloat(); float scale = in.readFloat();
float physicalPixelDisplaySizeRatio = in.readFloat(); float physicalPixelDisplaySizeRatio = in.readFloat();
final CutoutPathParserInfo info = new CutoutPathParserInfo( final CutoutPathParserInfo info = new CutoutPathParserInfo(
displayWidth, displayHeight, stableDisplayWidth, stableDisplayHeight, density, displayWidth, displayHeight, physicalDisplayWidth, physicalDisplayHeight,
cutoutSpec, rotation, scale, physicalPixelDisplaySizeRatio); density, cutoutSpec, rotation, scale, physicalPixelDisplaySizeRatio);
return new DisplayCutout( return new DisplayCutout(
safeInsets, waterfallInsets, bounds, info, false /* copyArguments */); safeInsets, waterfallInsets, bounds, info, false /* copyArguments */);
@@ -1373,8 +1374,8 @@ public final class DisplayCutout {
final CutoutPathParserInfo info = new CutoutPathParserInfo( final CutoutPathParserInfo info = new CutoutPathParserInfo(
mInner.mCutoutPathParserInfo.getDisplayWidth(), mInner.mCutoutPathParserInfo.getDisplayWidth(),
mInner.mCutoutPathParserInfo.getDisplayHeight(), mInner.mCutoutPathParserInfo.getDisplayHeight(),
mInner.mCutoutPathParserInfo.getStableDisplayWidth(), mInner.mCutoutPathParserInfo.getPhysicalDisplayWidth(),
mInner.mCutoutPathParserInfo.getStableDisplayHeight(), mInner.mCutoutPathParserInfo.getPhysicalDisplayHeight(),
mInner.mCutoutPathParserInfo.getDensity(), mInner.mCutoutPathParserInfo.getDensity(),
mInner.mCutoutPathParserInfo.getCutoutSpec(), mInner.mCutoutPathParserInfo.getCutoutSpec(),
mInner.mCutoutPathParserInfo.getRotation(), mInner.mCutoutPathParserInfo.getRotation(),

View File

@@ -98,10 +98,10 @@ public class RoundedCorners implements Parcelable {
* @android:dimen/rounded_corner_radius_top and @android:dimen/rounded_corner_radius_bottom * @android:dimen/rounded_corner_radius_top and @android:dimen/rounded_corner_radius_bottom
*/ */
public static RoundedCorners fromResources( public static RoundedCorners fromResources(
Resources res, String displayUniqueId, int stableDisplayWidth, int stableDisplayHeight, Resources res, String displayUniqueId, int physicalDisplayWidth,
int displayWidth, int displayHeight) { int physicalDisplayHeight, int displayWidth, int displayHeight) {
return fromRadii(loadRoundedCornerRadii(res, displayUniqueId), stableDisplayWidth, return fromRadii(loadRoundedCornerRadii(res, displayUniqueId), physicalDisplayWidth,
stableDisplayHeight, displayWidth, displayHeight); physicalDisplayHeight, displayWidth, displayHeight);
} }
/** /**
@@ -113,14 +113,14 @@ public class RoundedCorners implements Parcelable {
return fromRadii(radii, displayWidth, displayHeight, displayWidth, displayHeight); return fromRadii(radii, displayWidth, displayHeight, displayWidth, displayHeight);
} }
private static RoundedCorners fromRadii(Pair<Integer, Integer> radii, int stableDisplayWidth, private static RoundedCorners fromRadii(Pair<Integer, Integer> radii, int physicalDisplayWidth,
int stableDisplayHeight, int displayWidth, int displayHeight) { int physicalDisplayHeight, int displayWidth, int displayHeight) {
if (radii == null) { if (radii == null) {
return null; return null;
} }
final float physicalPixelDisplaySizeRatio = DisplayUtils.getPhysicalPixelDisplaySizeRatio( final float physicalPixelDisplaySizeRatio = DisplayUtils.getPhysicalPixelDisplaySizeRatio(
stableDisplayWidth, stableDisplayHeight, displayWidth, displayHeight); physicalDisplayWidth, physicalDisplayHeight, displayWidth, displayHeight);
synchronized (CACHE_LOCK) { synchronized (CACHE_LOCK) {
if (radii.equals(sCachedRadii) && sCachedDisplayWidth == displayWidth if (radii.equals(sCachedRadii) && sCachedDisplayWidth == displayWidth

View File

@@ -3527,6 +3527,9 @@
appended after the path string to interpret coordinates in dp instead of px units. appended after the path string to interpret coordinates in dp instead of px units.
Note that a physical cutout should be configured in pixels for the best results. Note that a physical cutout should be configured in pixels for the best results.
If the display supports multiple resolutions, please define the path config based on the
highest resolution so that it can be scaled correctly in each resolution.
Example for a 10px x 10px square top-center cutout: Example for a 10px x 10px square top-center cutout:
<string ...>M -5,0 L -5,10 L 5,10 L 5,0 Z</string> <string ...>M -5,0 L -5,10 L 5,10 L 5,0 Z</string>
Example for a 10dp x 10dp square top-center cutout: Example for a 10dp x 10dp square top-center cutout:

View File

@@ -423,8 +423,8 @@ public class DisplayLayout {
} }
final DisplayCutout.CutoutPathParserInfo info = cutout.getCutoutPathParserInfo(); final DisplayCutout.CutoutPathParserInfo info = cutout.getCutoutPathParserInfo();
final DisplayCutout.CutoutPathParserInfo newInfo = new DisplayCutout.CutoutPathParserInfo( final DisplayCutout.CutoutPathParserInfo newInfo = new DisplayCutout.CutoutPathParserInfo(
info.getDisplayWidth(), info.getDisplayHeight(), info.getStableDisplayWidth(), info.getDisplayWidth(), info.getDisplayHeight(), info.getPhysicalDisplayWidth(),
info.getStableDisplayHeight(), info.getDensity(), info.getCutoutSpec(), rotation, info.getPhysicalDisplayHeight(), info.getDensity(), info.getCutoutSpec(), rotation,
info.getScale(), info.getPhysicalPixelDisplaySizeRatio()); info.getScale(), info.getPhysicalPixelDisplaySizeRatio());
return computeSafeInsets( return computeSafeInsets(
DisplayCutout.constructDisplayCutout(newBounds, waterfallInsets, newInfo), DisplayCutout.constructDisplayCutout(newBounds, waterfallInsets, newInfo),

View File

@@ -46,8 +46,9 @@ import com.android.systemui.animation.Interpolators
*/ */
open class DisplayCutoutBaseView : View, RegionInterceptableView { open class DisplayCutoutBaseView : View, RegionInterceptableView {
private val shouldDrawCutout: Boolean = DisplayCutout.getFillBuiltInDisplayCutout( private var shouldDrawCutout: Boolean = DisplayCutout.getFillBuiltInDisplayCutout(
context.resources, context.display?.uniqueId) context.resources, context.display?.uniqueId)
private var displayUniqueId: String? = null
private var displayMode: Display.Mode? = null private var displayMode: Display.Mode? = null
protected val location = IntArray(2) protected val location = IntArray(2)
protected var displayRotation = 0 protected var displayRotation = 0
@@ -78,6 +79,7 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView {
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
displayUniqueId = context.display?.uniqueId
updateCutout() updateCutout()
updateProtectionBoundingPath() updateProtectionBoundingPath()
onUpdate() onUpdate()
@@ -87,6 +89,12 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView {
val oldMode: Display.Mode? = displayMode val oldMode: Display.Mode? = displayMode
displayMode = display.mode displayMode = display.mode
if (displayUniqueId != context.display?.uniqueId) {
displayUniqueId = context.display?.uniqueId
shouldDrawCutout = DisplayCutout.getFillBuiltInDisplayCutout(
context.resources, displayUniqueId)
}
// Skip if display mode or cutout hasn't changed. // Skip if display mode or cutout hasn't changed.
if (!displayModeChanged(oldMode, displayMode) && if (!displayModeChanged(oldMode, displayMode) &&
display.cutout == displayInfo.displayCutout) { display.cutout == displayInfo.displayCutout) {

View File

@@ -39,7 +39,6 @@ import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
@@ -926,11 +925,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
@VisibleForTesting @VisibleForTesting
float getPhysicalPixelDisplaySizeRatio() { float getPhysicalPixelDisplaySizeRatio() {
final Point stableDisplaySize = mDisplayManager.getStableDisplaySize();
mContext.getDisplay().getDisplayInfo(mDisplayInfo); mContext.getDisplay().getDisplayInfo(mDisplayInfo);
final Display.Mode maxDisplayMode =
DisplayUtils.getMaximumResolutionDisplayMode(mDisplayInfo.supportedModes);
if (maxDisplayMode == null) {
return 1f;
}
return DisplayUtils.getPhysicalPixelDisplaySizeRatio( return DisplayUtils.getPhysicalPixelDisplaySizeRatio(
stableDisplaySize.x, stableDisplaySize.y, mDisplayInfo.getNaturalWidth(), maxDisplayMode.getPhysicalWidth(), maxDisplayMode.getPhysicalHeight(),
mDisplayInfo.getNaturalHeight()); mDisplayInfo.getNaturalWidth(), mDisplayInfo.getNaturalHeight());
} }
@Override @Override

View File

@@ -169,6 +169,7 @@ class DisplayCutoutBaseViewTest : SysuiTestCase() {
cutoutBaseView = spy(DisplayCutoutBaseView(mContext)) cutoutBaseView = spy(DisplayCutoutBaseView(mContext))
whenever(cutoutBaseView.display).thenReturn(mockDisplay) whenever(cutoutBaseView.display).thenReturn(mockDisplay)
whenever(mockDisplay.uniqueId).thenReturn("mockDisplayUniqueId")
whenever(cutoutBaseView.rootView).thenReturn(mockRootView) whenever(cutoutBaseView.rootView).thenReturn(mockRootView)
whenever(cutoutBaseView.getPhysicalPixelDisplaySizeRatio()).thenReturn(1f) whenever(cutoutBaseView.getPhysicalPixelDisplaySizeRatio()).thenReturn(1f)
whenever(mockDisplay.getDisplayInfo(eq(cutoutBaseView.displayInfo)) whenever(mockDisplay.getDisplayInfo(eq(cutoutBaseView.displayInfo))

View File

@@ -22,8 +22,6 @@ import static android.view.Display.Mode.INVALID_MODE_ID;
import android.app.ActivityThread; import android.app.ActivityThread;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.sidekick.SidekickInternal; import android.hardware.sidekick.SidekickInternal;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
@@ -32,6 +30,7 @@ import android.os.Looper;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.Trace; import android.os.Trace;
import android.util.DisplayUtils;
import android.util.LongSparseArray; import android.util.LongSparseArray;
import android.util.Slog; import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
@@ -680,15 +679,17 @@ final class LocalDisplayAdapter extends DisplayAdapter {
mInfo.flags |= DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT; mInfo.flags |= DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT;
} }
final Point stableDisplaySize = getOverlayContext() final Display.Mode maxDisplayMode =
.getSystemService(DisplayManager.class).getStableDisplaySize(); DisplayUtils.getMaximumResolutionDisplayMode(mInfo.supportedModes);
final int maxWidth =
maxDisplayMode == null ? mInfo.width : maxDisplayMode.getPhysicalWidth();
final int maxHeight =
maxDisplayMode == null ? mInfo.height : maxDisplayMode.getPhysicalHeight();
mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res, mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res,
mInfo.uniqueId, stableDisplaySize.x, stableDisplaySize.y, mInfo.width, mInfo.uniqueId, maxWidth, maxHeight, mInfo.width, mInfo.height);
mInfo.height);
mInfo.roundedCorners = RoundedCorners.fromResources( mInfo.roundedCorners = RoundedCorners.fromResources(
res, mInfo.uniqueId, stableDisplaySize.x, stableDisplaySize.y, mInfo.width, res, mInfo.uniqueId, maxWidth, maxHeight, mInfo.width, mInfo.height);
mInfo.height);
mInfo.installOrientation = mStaticDisplayInfo.installOrientation; mInfo.installOrientation = mStaticDisplayInfo.installOrientation;
if (mStaticDisplayInfo.isInternal) { if (mStaticDisplayInfo.isInternal) {

View File

@@ -190,6 +190,7 @@ import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.DisplayUtils;
import android.util.IntArray; import android.util.IntArray;
import android.util.RotationUtils; import android.util.RotationUtils;
import android.util.Size; import android.util.Size;
@@ -359,7 +360,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
float mInitialPhysicalXDpi = 0.0f; float mInitialPhysicalXDpi = 0.0f;
float mInitialPhysicalYDpi = 0.0f; float mInitialPhysicalYDpi = 0.0f;
private Point mStableDisplaySize; private Point mPhysicalDisplaySize;
DisplayCutout mInitialDisplayCutout; DisplayCutout mInitialDisplayCutout;
private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
@@ -2751,7 +2752,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mInitialRoundedCorners = mDisplayInfo.roundedCorners; mInitialRoundedCorners = mDisplayInfo.roundedCorners;
mCurrentPrivacyIndicatorBounds = new PrivacyIndicatorBounds(new Rect[4], mCurrentPrivacyIndicatorBounds = new PrivacyIndicatorBounds(new Rect[4],
mDisplayInfo.rotation); mDisplayInfo.rotation);
mStableDisplaySize = mWmService.mDisplayManager.getStableDisplaySize(); final Display.Mode maxDisplayMode =
DisplayUtils.getMaximumResolutionDisplayMode(mDisplayInfo.supportedModes);
mPhysicalDisplaySize = new Point(
maxDisplayMode == null ? mInitialDisplayWidth : maxDisplayMode.getPhysicalWidth(),
maxDisplayMode == null ? mInitialDisplayHeight : maxDisplayMode.getPhysicalHeight()
);
} }
/** /**
@@ -2949,7 +2955,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
} }
return DisplayCutout.fromResourcesRectApproximation( return DisplayCutout.fromResourcesRectApproximation(
mDisplayPolicy.getSystemUiContext().getResources(), mDisplayInfo.uniqueId, mDisplayPolicy.getSystemUiContext().getResources(), mDisplayInfo.uniqueId,
mStableDisplaySize.x, mStableDisplaySize.y, displayWidth, displayHeight); mPhysicalDisplaySize.x, mPhysicalDisplaySize.y, displayWidth, displayHeight);
} }
RoundedCorners loadRoundedCorners(int displayWidth, int displayHeight) { RoundedCorners loadRoundedCorners(int displayWidth, int displayHeight) {
@@ -2958,7 +2964,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
} }
return RoundedCorners.fromResources( return RoundedCorners.fromResources(
mDisplayPolicy.getSystemUiContext().getResources(), mDisplayInfo.uniqueId, mDisplayPolicy.getSystemUiContext().getResources(), mDisplayInfo.uniqueId,
mStableDisplaySize.x, mStableDisplaySize.y, displayWidth, displayHeight); mPhysicalDisplaySize.x, mPhysicalDisplaySize.y, displayWidth, displayHeight);
} }
@Override @Override

View File

@@ -35,8 +35,6 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerInternal.RefreshRateRange; import android.hardware.display.DisplayManagerInternal.RefreshRateRange;
import android.os.Binder; import android.os.Binder;
import android.os.Handler; import android.os.Handler;
@@ -95,11 +93,6 @@ public class LocalDisplayAdapterTest {
@Mock @Mock
private LogicalLight mMockedBacklight; private LogicalLight mMockedBacklight;
@Mock
private DisplayManager mMockDisplayManager;
@Mock
private Point mMockDisplayStableSize;
private Handler mHandler; private Handler mHandler;
private TestListener mListener = new TestListener(); private TestListener mListener = new TestListener();
@@ -130,8 +123,6 @@ public class LocalDisplayAdapterTest {
mListener, mInjector); mListener, mInjector);
spyOn(mAdapter); spyOn(mAdapter);
doReturn(mMockedContext).when(mAdapter).getOverlayContext(); doReturn(mMockedContext).when(mAdapter).getOverlayContext();
doReturn(mMockDisplayManager).when(mMockedContext).getSystemService(DisplayManager.class);
doReturn(mMockDisplayStableSize).when(mMockDisplayManager).getStableDisplaySize();
TypedArray mockNitsRange = createFloatTypedArray(DISPLAY_RANGE_NITS); TypedArray mockNitsRange = createFloatTypedArray(DISPLAY_RANGE_NITS);
when(mMockedResources.obtainTypedArray(R.array.config_screenBrightnessNits)) when(mMockedResources.obtainTypedArray(R.array.config_screenBrightnessNits))