summaryrefslogtreecommitdiff
path: root/libs/input/Input.cpp
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-12-01 23:46:40 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-12-01 23:46:40 +0000
commit9aa979b5799213810b71f939cc25b460fcc25959 (patch)
tree7bfa5ba17b9c65ac1ef2abd58d10cf51d1c393fc /libs/input/Input.cpp
parent387b08fe8eb093e7bb0007f4ac722eb3f9e3c6f4 (diff)
parent092f3a9b75b1fd465373730ca8d6038c89ed9220 (diff)
Merge "Add getSurfaceRotation API to MotionEvent"
Diffstat (limited to 'libs/input/Input.cpp')
-rw-r--r--libs/input/Input.cpp19
1 files changed, 19 insertions, 0 deletions
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 <android-base/stringprintf.h>
#include <gui/constants.h>
+#include <input/DisplayViewport.h>
#include <input/Input.h>
#include <input/InputDevice.h>
#include <input/InputEventLabels.h>
@@ -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;