From 092f3a9b75b1fd465373730ca8d6038c89ed9220 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 25 Nov 2021 10:53:27 -0800 Subject: Add getSurfaceRotation API to MotionEvent Add an API to get the current rotation value of the transform of the MotionEvent. Bug: 207771136 Test: atest MotionEventTest Change-Id: I05fb4455d0dcfc0de8c8564473ee8d43ac86c0bd --- libs/input/Input.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libs/input/Input.cpp') diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index cb93c92310..44487c3a85 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -506,6 +507,24 @@ void MotionEvent::addSample( mSamplePointerCoords.appendArray(pointerCoords, getPointerCount()); } +int MotionEvent::getSurfaceRotation() const { + // The surface rotation is the rotation from the window's coordinate space to that of the + // display. Since the event's transform takes display space coordinates to window space, the + // returned surface rotation is the inverse of the rotation for the surface. + switch (mTransform.getOrientation()) { + case ui::Transform::ROT_0: + return DISPLAY_ORIENTATION_0; + case ui::Transform::ROT_90: + return DISPLAY_ORIENTATION_270; + case ui::Transform::ROT_180: + return DISPLAY_ORIENTATION_180; + case ui::Transform::ROT_270: + return DISPLAY_ORIENTATION_90; + default: + return -1; + } +} + float MotionEvent::getXCursorPosition() const { vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition()); return vals.x; -- cgit v1.2.3-59-g8ed1b