Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cf58505 authored by Adrian Roos's avatar Adrian Roos
Browse files

Dispatch DisplayCutout from DisplayAdapter

Adds a config resource to configure the main display's cutout and
dispatches it from the LocalDisplayAdapter.

WindowManager's DisplayContent then transforms it to match the current
rotation.

Also fixes an issue in EmulatedDisplayCutout where the Path was never
reset and changes the color to black. Also fixes the RoundedCorners
overlay such that it can layout within the cutout area.

Test: atest CoordinateTransformsTest DisplayContentTests
Bug: 65689439
Change-Id: If39c8ea3cb55c761517f270dcca292682c0918ad
parent 72232a95
Loading
Loading
Loading
Loading
+38 −10
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public final class DisplayCutout {
    @Override
    public String toString() {
        return "DisplayCutout{insets=" + mSafeInsets
                + " bounds=" + mBounds
                + " boundingRect=" + getBoundingRect()
                + "}";
    }

@@ -279,9 +279,7 @@ public final class DisplayCutout {
     * @hide
     */
    public static DisplayCutout fromBoundingPolygon(List<Point> points) {
        Region bounds = Region.obtain();
        Path path = new Path();

        path.reset();
        for (int i = 0; i < points.size(); i++) {
            Point point = points.get(i);
@@ -292,14 +290,24 @@ public final class DisplayCutout {
            }
        }
        path.close();
        return fromBounds(path);
    }

    /**
     * Creates an instance from a bounding {@link Path}.
     *
     * @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);
    }

@@ -329,12 +337,23 @@ public final class DisplayCutout {

        @Override
        public void writeToParcel(Parcel out, int flags) {
            if (mInner == NO_CUTOUT) {
            writeCutoutToParcel(mInner, out, flags);
        }

        /**
         * Writes a DisplayCutout to a {@link Parcel}.
         *
         * @see #readCutoutFromParcel(Parcel)
         */
        public static void writeCutoutToParcel(DisplayCutout cutout, Parcel out, int flags) {
            if (cutout == null) {
                out.writeInt(-1);
            } else if (cutout == NO_CUTOUT) {
                out.writeInt(0);
            } else {
                out.writeInt(1);
                out.writeTypedObject(mInner.mSafeInsets, flags);
                out.writeTypedObject(mInner.mBounds, flags);
                out.writeTypedObject(cutout.mSafeInsets, flags);
                out.writeTypedObject(cutout.mBounds, flags);
            }
        }

@@ -345,13 +364,13 @@ public final class DisplayCutout {
         * Needed for AIDL out parameters.
         */
        public void readFromParcel(Parcel in) {
            mInner = readCutout(in);
            mInner = readCutoutFromParcel(in);
        }

        public static final Creator<ParcelableWrapper> CREATOR = new Creator<ParcelableWrapper>() {
            @Override
            public ParcelableWrapper createFromParcel(Parcel in) {
                return new ParcelableWrapper(readCutout(in));
                return new ParcelableWrapper(readCutoutFromParcel(in));
            }

            @Override
@@ -360,8 +379,17 @@ public final class DisplayCutout {
            }
        };

        private static DisplayCutout readCutout(Parcel in) {
            if (in.readInt() == 0) {
        /**
         * Reads a DisplayCutout from a {@link Parcel}.
         *
         * @see #writeCutoutToParcel(DisplayCutout, Parcel, int)
         */
        public static DisplayCutout readCutoutFromParcel(Parcel in) {
            int variant = in.readInt();
            if (variant == -1) {
                return null;
            }
            if (variant == 0) {
                return NO_CUTOUT;
            }

+11 −0
Original line number Diff line number Diff line
@@ -148,6 +148,13 @@ public final class DisplayInfo implements Parcelable {
     */
    public int overscanBottom;

    /**
     * The {@link DisplayCutout} if present, otherwise {@code null}.
     *
     * @hide
     */
    public DisplayCutout displayCutout;

    /**
     * The rotation of the display relative to its natural orientation.
     * May be one of {@link android.view.Surface#ROTATION_0},
@@ -301,6 +308,7 @@ public final class DisplayInfo implements Parcelable {
                && overscanTop == other.overscanTop
                && overscanRight == other.overscanRight
                && overscanBottom == other.overscanBottom
                && Objects.equal(displayCutout, other.displayCutout)
                && rotation == other.rotation
                && modeId == other.modeId
                && defaultModeId == other.defaultModeId
@@ -342,6 +350,7 @@ public final class DisplayInfo implements Parcelable {
        overscanTop = other.overscanTop;
        overscanRight = other.overscanRight;
        overscanBottom = other.overscanBottom;
        displayCutout = other.displayCutout;
        rotation = other.rotation;
        modeId = other.modeId;
        defaultModeId = other.defaultModeId;
@@ -379,6 +388,7 @@ public final class DisplayInfo implements Parcelable {
        overscanTop = source.readInt();
        overscanRight = source.readInt();
        overscanBottom = source.readInt();
        displayCutout = DisplayCutout.ParcelableWrapper.readCutoutFromParcel(source);
        rotation = source.readInt();
        modeId = source.readInt();
        defaultModeId = source.readInt();
@@ -425,6 +435,7 @@ public final class DisplayInfo implements Parcelable {
        dest.writeInt(overscanTop);
        dest.writeInt(overscanRight);
        dest.writeInt(overscanBottom);
        DisplayCutout.ParcelableWrapper.writeCutoutToParcel(displayCutout, dest, flags);
        dest.writeInt(rotation);
        dest.writeInt(modeId);
        dest.writeInt(defaultModeId);
+7 −0
Original line number Diff line number Diff line
@@ -2769,6 +2769,13 @@
         some existing device-specific resource overlays. -->
    <bool name="config_mainBuiltInDisplayIsRound">@bool/config_windowIsRound</bool>

    <!-- The bounding path of the cutout region of the main built-in display.
         Must either be empty if there is no cutout region, or a string that is parsable by
         {@link android.util.PathParser}.
         The path is assumed to be specified in display coordinates with pixel units and in
         the display's native orientation. -->
    <string translatable="false" name="config_mainBuiltInDisplayCutout"></string>

    <!-- Ultrasound support for Mic/speaker path -->
    <!-- Whether the default microphone audio source supports near-ultrasound frequencies
         (range of 18 - 21 kHz). -->
+1 −0
Original line number Diff line number Diff line
@@ -3198,6 +3198,7 @@
  <java-symbol type="string" name="battery_saver_warning_title" />

  <java-symbol type="string" name="global_action_logout" />
  <java-symbol type="string" name="config_mainBuiltInDisplayCutout" />
  <java-symbol type="drawable" name="ic_logout" />

  <java-symbol type="array" name="config_autoBrightnessDisplayValuesNits" />
+3 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.Region;
import android.os.Handler;
import android.os.Looper;
@@ -114,10 +115,9 @@ public class EmulatedDisplayCutout extends SystemUI {

        @Override
        public WindowInsets onApplyWindowInsets(WindowInsets insets) {
            mBounds.reset();
            if (insets.getDisplayCutout() != null) {
                insets.getDisplayCutout().getBounds().getBoundaryPath(mBounds);
            } else {
                mBounds.reset();
            }
            invalidate();
            return insets.consumeDisplayCutout();
@@ -126,7 +126,7 @@ public class EmulatedDisplayCutout extends SystemUI {
        @Override
        protected void onDraw(Canvas canvas) {
            if (!mBounds.isEmpty()) {
                mPaint.setColor(Color.DKGRAY);
                mPaint.setColor(Color.BLACK);
                mPaint.setStyle(Paint.Style.FILL);

                canvas.drawPath(mBounds, mPaint);
Loading