diff options
author | 2020-07-01 12:37:31 -0700 | |
---|---|---|
committer | 2020-07-14 15:03:07 -0700 | |
commit | c01e1379d5d654234861c0881b4d5fb558524f58 (patch) | |
tree | 274a20a714ecaecd37220ea00d642c8b90178942 | |
parent | 044b4dc70dc1db15da4ee0d4352dd2a940952f14 (diff) |
Added helper functions in Transform and PointerCoords
1. Getter for each element in the Transform matrix.
2. Setter for Transform using a nine element array.
3. New multiply in Transform to multiply all elements by a single
value
4. transform function in PointerCoords to apply the transform to x and y
coordinate
Test: Builds
Bug: 158476194
Change-Id: Iafe07813c6ce8127875b06e6e6e11554d1862f6f
-rw-r--r-- | include/input/Input.h | 2 | ||||
-rw-r--r-- | libs/input/Input.cpp | 5 | ||||
-rw-r--r-- | libs/ui/Transform.cpp | 40 | ||||
-rw-r--r-- | libs/ui/include/ui/Transform.h | 11 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 4 |
5 files changed, 51 insertions, 11 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index 194db1c6b5..40d655fb43 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -342,6 +342,8 @@ struct PointerCoords { void scale(float globalScale, float windowXScale, float windowYScale); void applyOffset(float xOffset, float yOffset); + void transform(const ui::Transform& transform); + inline float getX() const { return getAxisValue(AMOTION_EVENT_AXIS_X); } diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 31aa685391..2ac079ec52 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -301,6 +301,11 @@ void PointerCoords::copyFrom(const PointerCoords& other) { } } +void PointerCoords::transform(const ui::Transform& transform) { + vec2 newCoords = transform.transform(getX(), getY()); + setAxisValue(AMOTION_EVENT_AXIS_X, newCoords.x); + setAxisValue(AMOTION_EVENT_AXIS_Y, newCoords.y); +} // --- PointerProperties --- diff --git a/libs/ui/Transform.cpp b/libs/ui/Transform.cpp index 06b6bfe797..3bf3903929 100644 --- a/libs/ui/Transform.cpp +++ b/libs/ui/Transform.cpp @@ -55,7 +55,6 @@ bool Transform::operator==(const Transform& other) const { mMatrix[1][1] == other.mMatrix[1][1] && mMatrix[1][2] == other.mMatrix[1][2] && mMatrix[2][0] == other.mMatrix[2][0] && mMatrix[2][1] == other.mMatrix[2][1] && mMatrix[2][2] == other.mMatrix[2][2]; - ; } Transform Transform::operator * (const Transform& rhs) const @@ -87,6 +86,19 @@ Transform Transform::operator * (const Transform& rhs) const return r; } +Transform Transform::operator * (float value) const { + Transform r(*this); + const mat33& M(mMatrix); + mat33& R(r.mMatrix); + for (size_t i = 0; i < 3; i++) { + for (size_t j = 0; j < 2; j++) { + R[i][j] = M[i][j] * value; + } + } + r.type(); + return r; +} + Transform& Transform::operator=(const Transform& other) { mMatrix = other.mMatrix; mType = other.mType; @@ -105,11 +117,19 @@ float Transform::ty() const { return mMatrix[2][1]; } -float Transform::sx() const { +float Transform::dsdx() const { return mMatrix[0][0]; } -float Transform::sy() const { +float Transform::dtdx() const { + return mMatrix[1][0]; +} + +float Transform::dtdy() const { + return mMatrix[0][1]; +} + +float Transform::dsdy() const { return mMatrix[1][1]; } @@ -187,6 +207,15 @@ status_t Transform::set(uint32_t flags, float w, float h) return NO_ERROR; } +void Transform::set(const std::array<float, 9>& matrix) { + mat33& M(mMatrix); + M[0][0] = matrix[0]; M[1][0] = matrix[1]; M[2][0] = matrix[2]; + M[0][1] = matrix[3]; M[1][1] = matrix[4]; M[2][1] = matrix[5]; + M[0][2] = matrix[6]; M[1][2] = matrix[7]; M[2][2] = matrix[8]; + mType = UNKNOWN_TYPE; + type(); +} + vec2 Transform::transform(const vec2& v) const { vec2 r; const mat33& M(mMatrix); @@ -204,9 +233,8 @@ vec3 Transform::transform(const vec3& v) const { return r; } -vec2 Transform::transform(int x, int y) const -{ - return transform(vec2(x,y)); +vec2 Transform::transform(float x, float y) const { + return transform(vec2(x, y)); } Rect Transform::makeBounds(int w, int h) const diff --git a/libs/ui/include/ui/Transform.h b/libs/ui/include/ui/Transform.h index 3e8caf46c5..cf59467367 100644 --- a/libs/ui/include/ui/Transform.h +++ b/libs/ui/include/ui/Transform.h @@ -18,6 +18,7 @@ #include <stdint.h> #include <sys/types.h> +#include <array> #include <ostream> #include <string> @@ -68,24 +69,28 @@ public: const vec3& operator [] (size_t i) const; // returns column i float tx() const; float ty() const; - float sx() const; - float sy() const; + float dsdx() const; + float dtdx() const; + float dtdy() const; + float dsdy() const; // modify the transform void reset(); void set(float tx, float ty); void set(float a, float b, float c, float d); status_t set(uint32_t flags, float w, float h); + void set(const std::array<float, 9>& matrix); // transform data Rect makeBounds(int w, int h) const; - vec2 transform(int x, int y) const; + vec2 transform(float x, float y) const; Region transform(const Region& reg) const; Rect transform(const Rect& bounds, bool roundOutwards = false) const; FloatRect transform(const FloatRect& bounds) const; Transform& operator = (const Transform& other); Transform operator * (const Transform& rhs) const; + Transform operator * (float value) const; // assumes the last row is < 0 , 0 , 1 > vec2 transform(const vec2& v) const; vec3 transform(const vec3& v) const; diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 8cfb908e2a..67becab0d5 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -2385,8 +2385,8 @@ InputWindowInfo Layer::fillInputInfo() { } ui::Transform t = getTransform(); - const float xScale = t.sx(); - const float yScale = t.sy(); + const float xScale = t.dsdx(); + const float yScale = t.dsdy(); int32_t xSurfaceInset = info.surfaceInset; int32_t ySurfaceInset = info.surfaceInset; if (xScale != 1.0f || yScale != 1.0f) { |