Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9aa979b5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add getSurfaceRotation API to MotionEvent"

parents 387b08fe 092f3a9b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -574,6 +574,8 @@ public:

    inline ui::Transform getTransform() const { return mTransform; }

    int getSurfaceRotation() const;

    inline float getXPrecision() const { return mXPrecision; }

    inline float getYPrecision() const { return mYPrecision; }
+19 −0
Original line number Diff line number Diff line
@@ -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;