Loading core/java/android/view/DisplayCutout.java +26 −24 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.graphics.Path; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.graphics.Region.Op; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; Loading Loading @@ -325,14 +326,9 @@ public final class DisplayCutout { * @hide */ public static DisplayCutout fromBoundingRect(int left, int top, int right, int bottom) { Path path = new Path(); path.reset(); path.moveTo(left, top); path.lineTo(left, bottom); path.lineTo(right, bottom); path.lineTo(right, top); path.close(); return fromBounds(path); Region r = Region.obtain(); r.set(left, top, right, bottom); return fromBounds(r); } /** Loading @@ -340,26 +336,19 @@ public final class DisplayCutout { * * @hide */ public static DisplayCutout fromBounds(Path path) { RectF clipRect = new RectF(); path.computeBounds(clipRect, false /* unused */); Region clipRegion = Region.obtain(); clipRegion.set((int) clipRect.left, (int) clipRect.top, (int) clipRect.right, (int) clipRect.bottom); Region bounds = new Region(); bounds.setPath(path, clipRegion); clipRegion.recycle(); return new DisplayCutout(ZERO_RECT, bounds, false /* copyArguments */); public static DisplayCutout fromBounds(Region region) { return new DisplayCutout(ZERO_RECT, region, false /* copyArguments */); } /** * Creates the bounding path according to @android:string/config_mainBuiltInDisplayCutout. * Creates the display cutout according to * @android:string/config_mainBuiltInDisplayCutoutRectApproximation, which is the closest * rectangle-base approximation of the cutout. * * @hide */ public static DisplayCutout fromResources(Resources res, int displayWidth, int displayHeight) { return fromSpec(res.getString(R.string.config_mainBuiltInDisplayCutout), public static DisplayCutout fromResourcesRectApproximation(Resources res, int displayWidth, int displayHeight) { return fromSpec(res.getString(R.string.config_mainBuiltInDisplayCutoutRectApproximation), displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT); } Loading @@ -369,7 +358,8 @@ public final class DisplayCutout { * @hide */ public static Path pathFromResources(Resources res, int displayWidth, int displayHeight) { return pathAndDisplayCutoutFromSpec(res.getString(R.string.config_mainBuiltInDisplayCutout), return pathAndDisplayCutoutFromSpec( res.getString(R.string.config_mainBuiltInDisplayCutout), displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT).first; } Loading Loading @@ -417,6 +407,7 @@ public final class DisplayCutout { } final Path p; final Region r = Region.obtain(); try { p = PathParser.createPathFromPathData(spec); } catch (Throwable e) { Loading @@ -431,6 +422,8 @@ public final class DisplayCutout { m.postTranslate(offsetX, 0); p.transform(m); addToRegion(p, r); if (bottomSpec != null) { final Path bottomPath; try { Loading @@ -443,9 +436,10 @@ public final class DisplayCutout { m.postTranslate(0, displayHeight); bottomPath.transform(m); p.addPath(bottomPath); addToRegion(bottomPath, r); } final Pair<Path, DisplayCutout> result = new Pair<>(p, fromBounds(p)); final Pair<Path, DisplayCutout> result = new Pair<>(p, fromBounds(r)); synchronized (CACHE_LOCK) { sCachedSpec = spec; sCachedDisplayWidth = displayWidth; Loading @@ -456,6 +450,14 @@ public final class DisplayCutout { return result; } private static void addToRegion(Path p, Region r) { final RectF rectF = new RectF(); final Rect rect = new Rect(); p.computeBounds(rectF, false /* unused */); rectF.round(rect); r.op(rect, Op.UNION); } private static Region boundingRectsToRegion(List<Rect> rects) { Region result = Region.obtain(); if (rects != null) { Loading core/res/res/values/config.xml +8 −0 Original line number Diff line number Diff line Loading @@ -2966,6 +2966,14 @@ --> <string translatable="false" name="config_mainBuiltInDisplayCutout"></string> <!-- Like config_mainBuiltInDisplayCutout, but this path is used to report the one single bounding rect per device edge to the app via {@link DisplayCutout#getBoundingRect}. Note that this path should try to match the visual appearance of the cutout as much as possible, and may be smaller than config_mainBuiltInDisplayCutout --> <string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@string/config_mainBuiltInDisplayCutout</string> <!-- Whether the display cutout region of the main built-in display should be forced to black in software (to avoid aliasing or emulate a cutout that is not physically existent). --> Loading core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -3364,6 +3364,7 @@ <java-symbol type="string" name="global_action_logout" /> <java-symbol type="string" name="config_mainBuiltInDisplayCutout" /> <java-symbol type="string" name="config_mainBuiltInDisplayCutoutRectApproximation" /> <java-symbol type="drawable" name="messaging_user" /> <java-symbol type="bool" name="config_fillMainBuiltInDisplayCutout" /> <java-symbol type="drawable" name="ic_logout" /> Loading packages/overlays/DisplayCutoutEmulationCornerOverlay/res/values/config.xml +2 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ @right </string> <string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string> <!-- Whether the display cutout region of the main built-in display should be forced to black in software (to avoid aliasing or emulate a cutout that is not physically existent). --> Loading packages/overlays/DisplayCutoutEmulationDoubleOverlay/res/values/config.xml +2 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,8 @@ @dp </string> <string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string> <!-- Whether the display cutout region of the main built-in display should be forced to black in software (to avoid aliasing or emulate a cutout that is not physically existent). --> Loading Loading
core/java/android/view/DisplayCutout.java +26 −24 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.graphics.Path; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.graphics.Region.Op; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; Loading Loading @@ -325,14 +326,9 @@ public final class DisplayCutout { * @hide */ public static DisplayCutout fromBoundingRect(int left, int top, int right, int bottom) { Path path = new Path(); path.reset(); path.moveTo(left, top); path.lineTo(left, bottom); path.lineTo(right, bottom); path.lineTo(right, top); path.close(); return fromBounds(path); Region r = Region.obtain(); r.set(left, top, right, bottom); return fromBounds(r); } /** Loading @@ -340,26 +336,19 @@ public final class DisplayCutout { * * @hide */ public static DisplayCutout fromBounds(Path path) { RectF clipRect = new RectF(); path.computeBounds(clipRect, false /* unused */); Region clipRegion = Region.obtain(); clipRegion.set((int) clipRect.left, (int) clipRect.top, (int) clipRect.right, (int) clipRect.bottom); Region bounds = new Region(); bounds.setPath(path, clipRegion); clipRegion.recycle(); return new DisplayCutout(ZERO_RECT, bounds, false /* copyArguments */); public static DisplayCutout fromBounds(Region region) { return new DisplayCutout(ZERO_RECT, region, false /* copyArguments */); } /** * Creates the bounding path according to @android:string/config_mainBuiltInDisplayCutout. * Creates the display cutout according to * @android:string/config_mainBuiltInDisplayCutoutRectApproximation, which is the closest * rectangle-base approximation of the cutout. * * @hide */ public static DisplayCutout fromResources(Resources res, int displayWidth, int displayHeight) { return fromSpec(res.getString(R.string.config_mainBuiltInDisplayCutout), public static DisplayCutout fromResourcesRectApproximation(Resources res, int displayWidth, int displayHeight) { return fromSpec(res.getString(R.string.config_mainBuiltInDisplayCutoutRectApproximation), displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT); } Loading @@ -369,7 +358,8 @@ public final class DisplayCutout { * @hide */ public static Path pathFromResources(Resources res, int displayWidth, int displayHeight) { return pathAndDisplayCutoutFromSpec(res.getString(R.string.config_mainBuiltInDisplayCutout), return pathAndDisplayCutoutFromSpec( res.getString(R.string.config_mainBuiltInDisplayCutout), displayWidth, displayHeight, DENSITY_DEVICE_STABLE / (float) DENSITY_DEFAULT).first; } Loading Loading @@ -417,6 +407,7 @@ public final class DisplayCutout { } final Path p; final Region r = Region.obtain(); try { p = PathParser.createPathFromPathData(spec); } catch (Throwable e) { Loading @@ -431,6 +422,8 @@ public final class DisplayCutout { m.postTranslate(offsetX, 0); p.transform(m); addToRegion(p, r); if (bottomSpec != null) { final Path bottomPath; try { Loading @@ -443,9 +436,10 @@ public final class DisplayCutout { m.postTranslate(0, displayHeight); bottomPath.transform(m); p.addPath(bottomPath); addToRegion(bottomPath, r); } final Pair<Path, DisplayCutout> result = new Pair<>(p, fromBounds(p)); final Pair<Path, DisplayCutout> result = new Pair<>(p, fromBounds(r)); synchronized (CACHE_LOCK) { sCachedSpec = spec; sCachedDisplayWidth = displayWidth; Loading @@ -456,6 +450,14 @@ public final class DisplayCutout { return result; } private static void addToRegion(Path p, Region r) { final RectF rectF = new RectF(); final Rect rect = new Rect(); p.computeBounds(rectF, false /* unused */); rectF.round(rect); r.op(rect, Op.UNION); } private static Region boundingRectsToRegion(List<Rect> rects) { Region result = Region.obtain(); if (rects != null) { Loading
core/res/res/values/config.xml +8 −0 Original line number Diff line number Diff line Loading @@ -2966,6 +2966,14 @@ --> <string translatable="false" name="config_mainBuiltInDisplayCutout"></string> <!-- Like config_mainBuiltInDisplayCutout, but this path is used to report the one single bounding rect per device edge to the app via {@link DisplayCutout#getBoundingRect}. Note that this path should try to match the visual appearance of the cutout as much as possible, and may be smaller than config_mainBuiltInDisplayCutout --> <string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@string/config_mainBuiltInDisplayCutout</string> <!-- Whether the display cutout region of the main built-in display should be forced to black in software (to avoid aliasing or emulate a cutout that is not physically existent). --> Loading
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -3364,6 +3364,7 @@ <java-symbol type="string" name="global_action_logout" /> <java-symbol type="string" name="config_mainBuiltInDisplayCutout" /> <java-symbol type="string" name="config_mainBuiltInDisplayCutoutRectApproximation" /> <java-symbol type="drawable" name="messaging_user" /> <java-symbol type="bool" name="config_fillMainBuiltInDisplayCutout" /> <java-symbol type="drawable" name="ic_logout" /> Loading
packages/overlays/DisplayCutoutEmulationCornerOverlay/res/values/config.xml +2 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ @right </string> <string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string> <!-- Whether the display cutout region of the main built-in display should be forced to black in software (to avoid aliasing or emulate a cutout that is not physically existent). --> Loading
packages/overlays/DisplayCutoutEmulationDoubleOverlay/res/values/config.xml +2 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,8 @@ @dp </string> <string translatable="false" name="config_mainBuiltInDisplayCutoutRectApproximation">@*android:string/config_mainBuiltInDisplayCutout</string> <!-- Whether the display cutout region of the main built-in display should be forced to black in software (to avoid aliasing or emulate a cutout that is not physically existent). --> Loading