Merge "Apply display ratio to cutout protection" into tm-dev
This commit is contained in:
@@ -228,14 +228,20 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView {
|
|||||||
if (pendingRotationChange) {
|
if (pendingRotationChange) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val m = Matrix()
|
||||||
|
// Apply display ratio.
|
||||||
|
val physicalPixelDisplaySizeRatio = getPhysicalPixelDisplaySizeRatio()
|
||||||
|
m.postScale(physicalPixelDisplaySizeRatio, physicalPixelDisplaySizeRatio)
|
||||||
|
|
||||||
|
// Apply rotation.
|
||||||
val lw: Int = displayInfo.logicalWidth
|
val lw: Int = displayInfo.logicalWidth
|
||||||
val lh: Int = displayInfo.logicalHeight
|
val lh: Int = displayInfo.logicalHeight
|
||||||
val flipped = (displayInfo.rotation == Surface.ROTATION_90 ||
|
val flipped = (displayInfo.rotation == Surface.ROTATION_90 ||
|
||||||
displayInfo.rotation == Surface.ROTATION_270)
|
displayInfo.rotation == Surface.ROTATION_270)
|
||||||
val dw = if (flipped) lh else lw
|
val dw = if (flipped) lh else lw
|
||||||
val dh = if (flipped) lw else lh
|
val dh = if (flipped) lw else lh
|
||||||
val m = Matrix()
|
|
||||||
transformPhysicalToLogicalCoordinates(displayInfo.rotation, dw, dh, m)
|
transformPhysicalToLogicalCoordinates(displayInfo.rotation, dw, dh, m)
|
||||||
|
|
||||||
if (!protectionPathOrig.isEmpty) {
|
if (!protectionPathOrig.isEmpty) {
|
||||||
// Reset the protection path so we don't aggregate rotations
|
// Reset the protection path so we don't aggregate rotations
|
||||||
protectionPath.set(protectionPathOrig)
|
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 {
|
private fun displayModeChanged(oldMode: Display.Mode?, newMode: Display.Mode?): Boolean {
|
||||||
if (oldMode == null) {
|
if (oldMode == null) {
|
||||||
return true
|
return true
|
||||||
@@ -265,17 +279,17 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView {
|
|||||||
out: Matrix
|
out: Matrix
|
||||||
) {
|
) {
|
||||||
when (rotation) {
|
when (rotation) {
|
||||||
Surface.ROTATION_0 -> out.reset()
|
Surface.ROTATION_0 -> return
|
||||||
Surface.ROTATION_90 -> {
|
Surface.ROTATION_90 -> {
|
||||||
out.setRotate(270f)
|
out.postRotate(270f)
|
||||||
out.postTranslate(0f, physicalWidth.toFloat())
|
out.postTranslate(0f, physicalWidth.toFloat())
|
||||||
}
|
}
|
||||||
Surface.ROTATION_180 -> {
|
Surface.ROTATION_180 -> {
|
||||||
out.setRotate(180f)
|
out.postRotate(180f)
|
||||||
out.postTranslate(physicalWidth.toFloat(), physicalHeight.toFloat())
|
out.postTranslate(physicalWidth.toFloat(), physicalHeight.toFloat())
|
||||||
}
|
}
|
||||||
Surface.ROTATION_270 -> {
|
Surface.ROTATION_270 -> {
|
||||||
out.setRotate(90f)
|
out.postRotate(90f)
|
||||||
out.postTranslate(physicalHeight.toFloat(), 0f)
|
out.postTranslate(physicalHeight.toFloat(), 0f)
|
||||||
}
|
}
|
||||||
else -> throw IllegalArgumentException("Unknown rotation: $rotation")
|
else -> throw IllegalArgumentException("Unknown rotation: $rotation")
|
||||||
|
|||||||
@@ -142,6 +142,25 @@ class DisplayCutoutBaseViewTest : SysuiTestCase() {
|
|||||||
assertThat(cutoutBaseView.protectionRect).isEqualTo(pathBounds)
|
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) {
|
private fun setupDisplayCutoutBaseView(fillCutout: Boolean, hasCutout: Boolean) {
|
||||||
mContext.orCreateTestableResources.addOverride(
|
mContext.orCreateTestableResources.addOverride(
|
||||||
R.array.config_displayUniqueIdArray, arrayOf<String>())
|
R.array.config_displayUniqueIdArray, arrayOf<String>())
|
||||||
@@ -151,6 +170,7 @@ class DisplayCutoutBaseViewTest : SysuiTestCase() {
|
|||||||
cutoutBaseView = spy(DisplayCutoutBaseView(mContext))
|
cutoutBaseView = spy(DisplayCutoutBaseView(mContext))
|
||||||
whenever(cutoutBaseView.display).thenReturn(mockDisplay)
|
whenever(cutoutBaseView.display).thenReturn(mockDisplay)
|
||||||
whenever(cutoutBaseView.rootView).thenReturn(mockRootView)
|
whenever(cutoutBaseView.rootView).thenReturn(mockRootView)
|
||||||
|
whenever(cutoutBaseView.getPhysicalPixelDisplaySizeRatio()).thenReturn(1f)
|
||||||
whenever(mockDisplay.getDisplayInfo(eq(cutoutBaseView.displayInfo))
|
whenever(mockDisplay.getDisplayInfo(eq(cutoutBaseView.displayInfo))
|
||||||
).then {
|
).then {
|
||||||
val info = it.getArgument<DisplayInfo>(0)
|
val info = it.getArgument<DisplayInfo>(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user