Apply display ratio to cutout protection
Bug: 230281608 Test: atest DisplayCutoutBaseViewTest Change-Id: Ief4319bc1edfe81d74925aa43e8c869551306592
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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<String>())
|
||||
@@ -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<DisplayInfo>(0)
|
||||
|
||||
Reference in New Issue
Block a user