Fix some bugs in input rotation

Set deviceWidth/Height properly when setting displayviewport

Remove unnecessary rotation from pointerlocationview (which was
double rotating PointerEventDispatcher).

Fixed PointerEventDispatcher to use "real" size.

Bug: 179308296
Test: enable input rotation, rotate, and touch things
Change-Id: I156b6b3e0bf6d71996901c6e616c5710b12e3f0c
This commit is contained in:
Evan Rosky
2021-02-24 17:53:15 -08:00
parent cc8370b542
commit ba7e1a521f
3 changed files with 13 additions and 28 deletions

View File

@@ -36,7 +36,6 @@ import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.MotionEvent.PointerCoords;
import android.view.Surface;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
@@ -60,9 +59,6 @@ public class PointerLocationView extends View implements InputDeviceListener,
*/
private static final String GESTURE_EXCLUSION_PROP = "debug.pointerlocation.showexclusion";
private static final boolean ENABLE_PER_WINDOW_INPUT_ROTATION =
SystemProperties.getBoolean("persist.debug.per_window_input_rotation", false);
public static class PointerState {
// Trace of previous points.
private float[] mTraceX = new float[32];
@@ -356,21 +352,6 @@ public class PointerLocationView extends View implements InputDeviceListener,
.toString(), 1 + itemW * 6, base, mTextPaint);
}
int saveId = canvas.save();
if (ENABLE_PER_WINDOW_INPUT_ROTATION) {
// Rotate negative (since we're rotating the drawing canvas vs the output).
canvas.rotate(-90.0f * mContext.getDisplay().getRotation());
switch (mContext.getDisplay().getRotation()) {
case Surface.ROTATION_90:
canvas.translate(-canvas.getHeight(), 0);
break;
case Surface.ROTATION_180:
canvas.translate(-canvas.getWidth(), -canvas.getHeight());
break;
case Surface.ROTATION_270:
canvas.translate(0, -canvas.getWidth());
}
}
// Pointer trace.
for (int p = 0; p < NP; p++) {
final PointerState ps = mPointers.get(p);
@@ -480,7 +461,6 @@ public class PointerLocationView extends View implements InputDeviceListener,
}
}
}
canvas.restoreToCount(saveId);
}
private void logMotionEvent(String type, MotionEvent event) {

View File

@@ -590,10 +590,13 @@ public class InputManagerService extends IInputManager.Stub
for (int i = viewports.size() - 1; i >= 0; --i) {
final DisplayViewport v = vArray[i] = viewports.get(i).makeCopy();
// deviceWidth/Height are apparently in "rotated" space, so flip them if needed.
int dw = (v.orientation % 2) == 0 ? v.deviceWidth : v.deviceHeight;
int dh = (v.orientation % 2) == 0 ? v.deviceHeight : v.deviceWidth;
v.logicalFrame.set(0, 0, dw, dh);
v.physicalFrame.set(0, 0, dw, dh);
if (v.orientation % 2 != 0) {
final int dw = v.deviceWidth;
v.deviceWidth = v.deviceHeight;
v.deviceHeight = dw;
}
v.logicalFrame.set(0, 0, v.deviceWidth, v.deviceHeight);
v.physicalFrame.set(0, 0, v.deviceWidth, v.deviceHeight);
v.orientation = 0;
}
} else {

View File

@@ -18,6 +18,7 @@ package com.android.server.wm;
import static com.android.server.input.InputManagerService.ENABLE_PER_WINDOW_INPUT_ROTATION;
import android.graphics.Point;
import android.view.InputChannel;
import android.view.InputDevice;
import android.view.InputEvent;
@@ -35,6 +36,7 @@ public class PointerEventDispatcher extends InputEventReceiver {
private PointerEventListener[] mListenersArray = new PointerEventListener[0];
private final DisplayContent mDisplayContent;
private final Point mTmpSize = new Point();
public PointerEventDispatcher(InputChannel inputChannel, DisplayContent dc) {
super(inputChannel, UiThread.getHandler().getLooper());
@@ -48,12 +50,12 @@ public class PointerEventDispatcher extends InputEventReceiver {
&& (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
MotionEvent motionEvent = (MotionEvent) event;
if (ENABLE_PER_WINDOW_INPUT_ROTATION) {
int rotation = mDisplayContent.getRotation();
final int rotation = mDisplayContent.getRotation();
if (rotation != Surface.ROTATION_0) {
mDisplayContent.getDisplay().getRealSize(mTmpSize);
motionEvent = MotionEvent.obtain(motionEvent);
motionEvent.transform(MotionEvent.createRotateMatrix(rotation,
mDisplayContent.getDisplayMetrics().widthPixels,
mDisplayContent.getDisplayMetrics().heightPixels));
motionEvent.transform(MotionEvent.createRotateMatrix(
rotation, mTmpSize.x, mTmpSize.y));
}
}
PointerEventListener[] listeners;