Merge "Rotate touch orientation to ROTATION_0" into tm-qpr-dev am: c75d47d452

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20752388

Change-Id: I78a5c6d571d61e22aa315aa51736cf46863b56e0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Austin Delgado
2023-01-11 01:53:40 +00:00
committed by Automerger Merge Worker
2 changed files with 26 additions and 11 deletions

View File

@@ -27,6 +27,8 @@ import com.android.systemui.biometrics.udfps.TouchProcessorResult.ProcessedTouch
import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject import javax.inject.Inject
private val SUPPORTED_ROTATIONS = setOf(Surface.ROTATION_90, Surface.ROTATION_270)
/** /**
* TODO(b/259140693): Consider using an object pool of TouchProcessorResult to avoid allocations. * TODO(b/259140693): Consider using an object pool of TouchProcessorResult to avoid allocations.
*/ */
@@ -129,19 +131,27 @@ private fun MotionEvent.normalize(
val nativeY = naturalTouch.y / overlayParams.scaleFactor val nativeY = naturalTouch.y / overlayParams.scaleFactor
val nativeMinor: Float = getTouchMinor(pointerIndex) / overlayParams.scaleFactor val nativeMinor: Float = getTouchMinor(pointerIndex) / overlayParams.scaleFactor
val nativeMajor: Float = getTouchMajor(pointerIndex) / overlayParams.scaleFactor val nativeMajor: Float = getTouchMajor(pointerIndex) / overlayParams.scaleFactor
var nativeOrientation: Float = getOrientation(pointerIndex)
if (SUPPORTED_ROTATIONS.contains(overlayParams.rotation)) {
nativeOrientation = toRadVerticalFromRotated(nativeOrientation.toDouble()).toFloat()
}
return NormalizedTouchData( return NormalizedTouchData(
pointerId = getPointerId(pointerIndex), pointerId = getPointerId(pointerIndex),
x = nativeX, x = nativeX,
y = nativeY, y = nativeY,
minor = nativeMinor, minor = nativeMinor,
major = nativeMajor, major = nativeMajor,
// TODO(b/259311354): touch orientation should be reported relative to Surface.ROTATION_O. orientation = nativeOrientation,
orientation = getOrientation(pointerIndex),
time = eventTime, time = eventTime,
gestureStart = downTime, gestureStart = downTime,
) )
} }
private fun toRadVerticalFromRotated(rad: Double): Double {
val piBound = ((rad % Math.PI) + Math.PI / 2) % Math.PI
return if (piBound < Math.PI / 2.0) piBound else piBound - Math.PI
}
/** /**
* Returns the [MotionEvent.getRawX] and [MotionEvent.getRawY] of the given pointer as if the device * Returns the [MotionEvent.getRawX] and [MotionEvent.getRawY] of the given pointer as if the device
* is in the [Surface.ROTATION_0] orientation. * is in the [Surface.ROTATION_0] orientation.
@@ -152,7 +162,7 @@ private fun MotionEvent.rotateToNaturalOrientation(
): PointF { ): PointF {
val touchPoint = PointF(getRawX(pointerIndex), getRawY(pointerIndex)) val touchPoint = PointF(getRawX(pointerIndex), getRawY(pointerIndex))
val rot = overlayParams.rotation val rot = overlayParams.rotation
if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { if (SUPPORTED_ROTATIONS.contains(rot)) {
RotationUtils.rotatePointF( RotationUtils.rotatePointF(
touchPoint, touchPoint,
RotationUtils.deltaRotation(rot, Surface.ROTATION_0), RotationUtils.deltaRotation(rot, Surface.ROTATION_0),

View File

@@ -221,6 +221,14 @@ class SinglePointerTouchProcessorTest(val testCase: TestCase) : SysuiTestCase()
private const val ROTATION_0_NATIVE_DISPLAY_WIDTH = 400 private const val ROTATION_0_NATIVE_DISPLAY_WIDTH = 400
private const val ROTATION_0_NATIVE_DISPLAY_HEIGHT = 600 private const val ROTATION_0_NATIVE_DISPLAY_HEIGHT = 600
/* Placeholder touch parameters. */
private const val POINTER_ID = 42
private const val NATIVE_MINOR = 2.71828f
private const val NATIVE_MAJOR = 3.14f
private const val ORIENTATION = 1.2345f
private const val TIME = 12345699L
private const val GESTURE_START = 12345600L
/* /*
* ROTATION_0 map: * ROTATION_0 map:
* _ _ _ _ * _ _ _ _
@@ -244,6 +252,7 @@ private val ROTATION_0_NATIVE_SENSOR_BOUNDS =
private val ROTATION_0_INPUTS = private val ROTATION_0_INPUTS =
OrientationBasedInputs( OrientationBasedInputs(
rotation = Surface.ROTATION_0, rotation = Surface.ROTATION_0,
nativeOrientation = ORIENTATION,
nativeXWithinSensor = ROTATION_0_NATIVE_SENSOR_BOUNDS.exactCenterX(), nativeXWithinSensor = ROTATION_0_NATIVE_SENSOR_BOUNDS.exactCenterX(),
nativeYWithinSensor = ROTATION_0_NATIVE_SENSOR_BOUNDS.exactCenterY(), nativeYWithinSensor = ROTATION_0_NATIVE_SENSOR_BOUNDS.exactCenterY(),
nativeXOutsideSensor = 250f, nativeXOutsideSensor = 250f,
@@ -271,6 +280,7 @@ private val ROTATION_90_NATIVE_SENSOR_BOUNDS =
private val ROTATION_90_INPUTS = private val ROTATION_90_INPUTS =
OrientationBasedInputs( OrientationBasedInputs(
rotation = Surface.ROTATION_90, rotation = Surface.ROTATION_90,
nativeOrientation = (ORIENTATION - Math.PI.toFloat() / 2),
nativeXWithinSensor = ROTATION_90_NATIVE_SENSOR_BOUNDS.exactCenterX(), nativeXWithinSensor = ROTATION_90_NATIVE_SENSOR_BOUNDS.exactCenterX(),
nativeYWithinSensor = ROTATION_90_NATIVE_SENSOR_BOUNDS.exactCenterY(), nativeYWithinSensor = ROTATION_90_NATIVE_SENSOR_BOUNDS.exactCenterY(),
nativeXOutsideSensor = 150f, nativeXOutsideSensor = 150f,
@@ -304,20 +314,13 @@ private val ROTATION_270_NATIVE_SENSOR_BOUNDS =
private val ROTATION_270_INPUTS = private val ROTATION_270_INPUTS =
OrientationBasedInputs( OrientationBasedInputs(
rotation = Surface.ROTATION_270, rotation = Surface.ROTATION_270,
nativeOrientation = (ORIENTATION + Math.PI.toFloat() / 2),
nativeXWithinSensor = ROTATION_270_NATIVE_SENSOR_BOUNDS.exactCenterX(), nativeXWithinSensor = ROTATION_270_NATIVE_SENSOR_BOUNDS.exactCenterX(),
nativeYWithinSensor = ROTATION_270_NATIVE_SENSOR_BOUNDS.exactCenterY(), nativeYWithinSensor = ROTATION_270_NATIVE_SENSOR_BOUNDS.exactCenterY(),
nativeXOutsideSensor = 450f, nativeXOutsideSensor = 450f,
nativeYOutsideSensor = 250f, nativeYOutsideSensor = 250f,
) )
/* Placeholder touch parameters. */
private const val POINTER_ID = 42
private const val NATIVE_MINOR = 2.71828f
private const val NATIVE_MAJOR = 3.14f
private const val ORIENTATION = 1.23f
private const val TIME = 12345699L
private const val GESTURE_START = 12345600L
/* Template [MotionEvent]. */ /* Template [MotionEvent]. */
private val MOTION_EVENT = private val MOTION_EVENT =
obtainMotionEvent( obtainMotionEvent(
@@ -352,6 +355,7 @@ private val NORMALIZED_TOUCH_DATA =
*/ */
private data class OrientationBasedInputs( private data class OrientationBasedInputs(
@Rotation val rotation: Int, @Rotation val rotation: Int,
val nativeOrientation: Float,
val nativeXWithinSensor: Float, val nativeXWithinSensor: Float,
val nativeYWithinSensor: Float, val nativeYWithinSensor: Float,
val nativeXOutsideSensor: Float, val nativeXOutsideSensor: Float,
@@ -404,6 +408,7 @@ private fun genPositiveTestCases(
y = nativeY * scaleFactor, y = nativeY * scaleFactor,
minor = NATIVE_MINOR * scaleFactor, minor = NATIVE_MINOR * scaleFactor,
major = NATIVE_MAJOR * scaleFactor, major = NATIVE_MAJOR * scaleFactor,
orientation = orientation.nativeOrientation
) )
val expectedTouchData = val expectedTouchData =
NORMALIZED_TOUCH_DATA.copy( NORMALIZED_TOUCH_DATA.copy(