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

Commit f7ff5521 authored by shawnlin's avatar shawnlin
Browse files

Create an API to get a cutout path

- Added a new API to get the cutout paths.
- Create a @hide class CutoutPathParserInfo
  - Used to store the needed info to create the cutout paths.
  - Will be used when DisplayCutout.getCutoutPath() is called to
    create the cutout paths.

Bug: 172646505
Test: atest DisplayCutoutTest DisplayContentTests WmDisplayCutoutTest
Change-Id: Ief92ce4466f6bffb2a9375388b71de43049b4eef
parent 8241f19a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46174,6 +46174,7 @@ package android.view {
    method @NonNull public android.graphics.Rect getBoundingRectRight();
    method @NonNull public android.graphics.Rect getBoundingRectTop();
    method @NonNull public java.util.List<android.graphics.Rect> getBoundingRects();
    method @Nullable public android.graphics.Path getCutoutPath();
    method public int getSafeInsetBottom();
    method public int getSafeInsetLeft();
    method public int getSafeInsetRight();
+32 −0
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ import static android.view.Surface.ROTATION_180;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;

import android.annotation.Dimension;
import android.graphics.Insets;
import android.graphics.Matrix;
import android.view.Surface.Rotation;

/**
@@ -69,4 +71,34 @@ public class RotationUtils {
        }
        return rotated;
    }

    /**
     * Sets a matrix such that given a rotation, it transforms physical display
     * coordinates to that rotation's logical coordinates.
     *
     * @param rotation the rotation to which the matrix should transform
     * @param out the matrix to be set
     */
    public static void transformPhysicalToLogicalCoordinates(@Rotation int rotation,
            @Dimension int physicalWidth, @Dimension int physicalHeight, Matrix out) {
        switch (rotation) {
            case ROTATION_0:
                out.reset();
                break;
            case ROTATION_90:
                out.setRotate(270);
                out.postTranslate(0, physicalWidth);
                break;
            case ROTATION_180:
                out.setRotate(180);
                out.postTranslate(physicalWidth, physicalHeight);
                break;
            case ROTATION_270:
                out.setRotate(90);
                out.postTranslate(physicalHeight, 0);
                break;
            default:
                throw new IllegalArgumentException("Unknown rotation: " + rotation);
        }
    }
}
+269 −33

File changed.

Preview size limit exceeded, changes collapsed.

+58 −0

File changed.

Preview size limit exceeded, changes collapsed.

+7 −3
Original line number Diff line number Diff line
@@ -356,11 +356,11 @@ public class DisplayLayout {
        if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
            return null;
        }
        final Insets waterfallInsets =
                RotationUtils.rotateInsets(cutout.getWaterfallInsets(), rotation);
        if (rotation == ROTATION_0) {
            return computeSafeInsets(cutout, displayWidth, displayHeight);
        }
        final Insets waterfallInsets =
                RotationUtils.rotateInsets(cutout.getWaterfallInsets(), rotation);
        final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
        Rect[] cutoutRects = cutout.getBoundingRectsAll();
        final Rect[] newBounds = new Rect[cutoutRects.length];
@@ -372,8 +372,12 @@ public class DisplayLayout {
            }
            newBounds[getBoundIndexFromRotation(i, rotation)] = rect;
        }
        final DisplayCutout.CutoutPathParserInfo info = cutout.getCutoutPathParserInfo();
        final DisplayCutout.CutoutPathParserInfo newInfo = new DisplayCutout.CutoutPathParserInfo(
                info.getDisplayWidth(), info.getDisplayHeight(), info.getDensity(),
                info.getCutoutSpec(), rotation, info.getScale());
        return computeSafeInsets(
                DisplayCutout.fromBoundsAndWaterfall(newBounds, waterfallInsets),
                DisplayCutout.constructDisplayCutout(newBounds, waterfallInsets, newInfo),
                rotated ? displayHeight : displayWidth,
                rotated ? displayWidth : displayHeight);
    }
Loading