diff options
| author | Evan Rosky <erosky@google.com> | 2021-02-20 01:46:25 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-02-20 01:46:25 +0000 |
| commit | aa1d38db25818e1788ce249b46ebceac4d9ac03b (patch) | |
| tree | 51d5dc46ca1187ba83f631c38c9fec0f6cc88135 /core/java/android | |
| parent | f0531b3fcb07da54e011fb08c68fd9974757671d (diff) | |
| parent | 1db6aa54ae8f875f42d153c9b62272029f2d3847 (diff) | |
Merge "Don't rotate inputflinger's display" into sc-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/MotionEvent.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index 52b7cffbc340..d67439cc9de2 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -3768,6 +3768,41 @@ public final class MotionEvent extends InputEvent implements Parcelable { return (getButtonState() & button) == button; } + /** + * Gets a rotation matrix that (when applied to a motionevent) will rotate that motion event + * such that the result coordinates end up in the same physical location on a display whose + * coordinates are rotated by `rotation`. + * + * For example, rotating 0,0 by 90 degrees will move a point from the physical top-left to + * the bottom-left of the 90-degree-rotated display. + * + * @hide + */ + public static Matrix createRotateMatrix( + @Surface.Rotation int rotation, int displayW, int displayH) { + if (rotation == Surface.ROTATION_0) { + return new Matrix(Matrix.IDENTITY_MATRIX); + } + // values is row-major + float[] values = null; + if (rotation == Surface.ROTATION_90) { + values = new float[]{0, 1, 0, + -1, 0, displayH, + 0, 0, 1}; + } else if (rotation == Surface.ROTATION_180) { + values = new float[]{-1, 0, displayW, + 0, -1, displayH, + 0, 0, 1}; + } else if (rotation == Surface.ROTATION_270) { + values = new float[]{0, -1, displayW, + 1, 0, 0, + 0, 0, 1}; + } + Matrix toOrient = new Matrix(); + toOrient.setValues(values); + return toOrient; + } + public static final @android.annotation.NonNull Parcelable.Creator<MotionEvent> CREATOR = new Parcelable.Creator<MotionEvent>() { public MotionEvent createFromParcel(Parcel in) { |
