From fd2311407622cee40d27573c118c5311192daebc Mon Sep 17 00:00:00 2001 From: shawnlin Date: Wed, 27 Apr 2022 13:28:12 +0800 Subject: [PATCH] Apply display ratio to cutout protection Bug: 230281608 Test: atest DisplayCutoutBaseViewTest Change-Id: Ief4319bc1edfe81d74925aa43e8c869551306592 --- .../android/systemui/DisplayCutoutBaseView.kt | 24 +++++++++++++++---- .../systemui/DisplayCutoutBaseViewTest.kt | 20 ++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt b/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt index ccb5b1146a1cd..e51a63fbcd10f 100644 --- a/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt +++ b/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt @@ -228,14 +228,20 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView { if (pendingRotationChange) { return } + val m = Matrix() + // Apply display ratio. + val physicalPixelDisplaySizeRatio = getPhysicalPixelDisplaySizeRatio() + m.postScale(physicalPixelDisplaySizeRatio, physicalPixelDisplaySizeRatio) + + // Apply rotation. val lw: Int = displayInfo.logicalWidth val lh: Int = displayInfo.logicalHeight val flipped = (displayInfo.rotation == Surface.ROTATION_90 || displayInfo.rotation == Surface.ROTATION_270) val dw = if (flipped) lh else lw val dh = if (flipped) lw else lh - val m = Matrix() transformPhysicalToLogicalCoordinates(displayInfo.rotation, dw, dh, m) + if (!protectionPathOrig.isEmpty) { // Reset the protection path so we don't aggregate rotations protectionPath.set(protectionPathOrig) @@ -244,6 +250,14 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView { } } + @VisibleForTesting + open fun getPhysicalPixelDisplaySizeRatio(): Float { + displayInfo.displayCutout?.let { + return it.cutoutPathParserInfo.physicalPixelDisplaySizeRatio + } + return 1f + } + private fun displayModeChanged(oldMode: Display.Mode?, newMode: Display.Mode?): Boolean { if (oldMode == null) { return true @@ -265,17 +279,17 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView { out: Matrix ) { when (rotation) { - Surface.ROTATION_0 -> out.reset() + Surface.ROTATION_0 -> return Surface.ROTATION_90 -> { - out.setRotate(270f) + out.postRotate(270f) out.postTranslate(0f, physicalWidth.toFloat()) } Surface.ROTATION_180 -> { - out.setRotate(180f) + out.postRotate(180f) out.postTranslate(physicalWidth.toFloat(), physicalHeight.toFloat()) } Surface.ROTATION_270 -> { - out.setRotate(90f) + out.postRotate(90f) out.postTranslate(physicalHeight.toFloat(), 0f) } else -> throw IllegalArgumentException("Unknown rotation: $rotation") diff --git a/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt index e62b4e63e3d5d..55f0591b6ce01 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt @@ -142,6 +142,25 @@ class DisplayCutoutBaseViewTest : SysuiTestCase() { assertThat(cutoutBaseView.protectionRect).isEqualTo(pathBounds) } + @Test + fun testCutoutProtection_withDisplayRatio() { + setupDisplayCutoutBaseView(true /* fillCutout */, false /* hasCutout */) + whenever(cutoutBaseView.getPhysicalPixelDisplaySizeRatio()).thenReturn(0.5f) + val bounds = Rect(0, 0, 10, 10) + val path = Path() + val pathBounds = RectF(bounds) + path.addRect(pathBounds, Path.Direction.CCW) + + context.mainExecutor.execute { + cutoutBaseView.setProtection(path, bounds) + cutoutBaseView.enableShowProtection(true) + } + waitForIdleSync() + + assertThat(cutoutBaseView.protectionPath.isRect(pathBounds)).isTrue() + assertThat(cutoutBaseView.protectionRect).isEqualTo(RectF(0f, 0f, 5f, 5f)) + } + private fun setupDisplayCutoutBaseView(fillCutout: Boolean, hasCutout: Boolean) { mContext.orCreateTestableResources.addOverride( R.array.config_displayUniqueIdArray, arrayOf()) @@ -151,6 +170,7 @@ class DisplayCutoutBaseViewTest : SysuiTestCase() { cutoutBaseView = spy(DisplayCutoutBaseView(mContext)) whenever(cutoutBaseView.display).thenReturn(mockDisplay) whenever(cutoutBaseView.rootView).thenReturn(mockRootView) + whenever(cutoutBaseView.getPhysicalPixelDisplaySizeRatio()).thenReturn(1f) whenever(mockDisplay.getDisplayInfo(eq(cutoutBaseView.displayInfo)) ).then { val info = it.getArgument(0)