diff options
author | Evan Rosky <erosky@google.com> | 2021-04-16 10:42:42 -0700 |
---|---|---|
committer | Evan Rosky <erosky@google.com> | 2021-04-29 13:24:06 -0700 |
commit | 84f07f0cbec87736f3d04846a7558869d69a2005 (patch) | |
tree | 3c53336d3f203a99953f64a1827f6325a78426c6 /include | |
parent | 9e8dd09f886e14585d2018f713b7d384e768856a (diff) |
Add enough information to compatibility-transform getRaw()
Many apps are mis-using getRaw (assuming it means screen-coordinates).
This means, for now, we have to do a compatibility transform on the
API to prevent breaking said apps.
Fortunately, since the input window transform includes rotation,
the only extra information we need to calculate this compat-raw
is the display size.
This CL topic pipes the display size around so that it makes into the
MotionEvent and can be used to calculate getRaw()
Bug: 179274888
Test: atest inputflinger_tests:InputDispatcherTest
Change-Id: Iff893643312e8ec9f38eeb96d76a41fdb3a28350
Diffstat (limited to 'include')
-rw-r--r-- | include/input/Input.h | 36 | ||||
-rw-r--r-- | include/input/InputTransport.h | 7 | ||||
-rw-r--r-- | include/input/InputWindow.h | 4 |
3 files changed, 42 insertions, 5 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index bb5ca0ef04..7b522bbc1e 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -318,6 +318,12 @@ private: */ constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits<float>::quiet_NaN(); +/** + * Invalid value for display size. Used when display size isn't available for an event or doesn't + * matter. This is just a constant 0 so that it has no effect if unused. + */ +constexpr int32_t AMOTION_EVENT_INVALID_DISPLAY_SIZE = 0; + /* * Pointer coordinate data. */ @@ -360,6 +366,8 @@ struct PointerCoords { return getAxisValue(AMOTION_EVENT_AXIS_Y); } + vec2 getXYValue() const { return vec2(getX(), getY()); } + #ifdef __linux__ status_t readFromParcel(Parcel* parcel); status_t writeToParcel(Parcel* parcel) const; @@ -548,6 +556,8 @@ public: void setCursorPosition(float x, float y); + int2 getDisplaySize() const { return {mDisplayWidth, mDisplayHeight}; } + static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); } inline nsecs_t getDownTime() const { return mDownTime; } @@ -570,8 +580,17 @@ public: inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } + /** + * The actual raw pointer coords: whatever comes from the input device without any external + * transforms applied. + */ const PointerCoords* getRawPointerCoords(size_t pointerIndex) const; + /** + * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw" + * transform because many apps (incorrectly) assumed that raw == oriented-screen-space. + * "compat raw" is raw coordinates with screen rotation applied. + */ float getRawAxisValue(int32_t axis, size_t pointerIndex) const; inline float getRawX(size_t pointerIndex) const { @@ -634,9 +653,18 @@ public: return mSampleEventTimes[historicalIndex]; } + /** + * The actual raw pointer coords: whatever comes from the input device without any external + * transforms applied. + */ const PointerCoords* getHistoricalRawPointerCoords( size_t pointerIndex, size_t historicalIndex) const; + /** + * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw" + * transform because many apps (incorrectly) assumed that raw == oriented-screen-space. + * "compat raw" is raw coordinates with screen rotation applied. + */ float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const; @@ -704,9 +732,9 @@ public: int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, const ui::Transform& transform, float xPrecision, float yPrecision, float rawXCursorPosition, - float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime, - size_t pointerCount, const PointerProperties* pointerProperties, - const PointerCoords* pointerCoords); + float rawYCursorPosition, int32_t displayWidth, int32_t displayHeight, + nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, + const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); void copyFrom(const MotionEvent* other, bool keepHistory); @@ -759,6 +787,8 @@ protected: float mYPrecision; float mRawXCursorPosition; float mRawYCursorPosition; + int32_t mDisplayWidth; + int32_t mDisplayHeight; nsecs_t mDownTime; Vector<PointerProperties> mPointerProperties; std::vector<nsecs_t> mSampleEventTimes; diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index 898d1a937c..ff3367839d 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -136,6 +136,8 @@ struct InputMessage { float yPrecision; float xCursorPosition; float yCursorPosition; + int32_t displayWidth; + int32_t displayHeight; uint32_t pointerCount; uint32_t empty3; /** @@ -353,8 +355,9 @@ public: int32_t metaState, int32_t buttonState, MotionClassification classification, const ui::Transform& transform, float xPrecision, float yPrecision, float xCursorPosition, - float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, - uint32_t pointerCount, const PointerProperties* pointerProperties, + float yCursorPosition, int32_t displayWidth, int32_t displayHeight, + nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount, + const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); /* Publishes a focus event to the input channel. diff --git a/include/input/InputWindow.h b/include/input/InputWindow.h index 36097d6d65..121be6d963 100644 --- a/include/input/InputWindow.h +++ b/include/input/InputWindow.h @@ -168,6 +168,10 @@ struct InputWindowInfo : public Parcelable { // Transform applied to individual windows. ui::Transform transform; + // Display size in its natural rotation. Used to rotate raw coordinates for compatibility. + int32_t displayWidth = AMOTION_EVENT_INVALID_DISPLAY_SIZE; + int32_t displayHeight = AMOTION_EVENT_INVALID_DISPLAY_SIZE; + /* * This is filled in by the WM relative to the frame and then translated * to absolute coordinates by SurfaceFlinger once the frame is computed. |