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

Commit c01e1379 authored by chaviw's avatar chaviw
Browse files

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
parent 044b4dc7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);
    }
+5 −0
Original line number Diff line number Diff line
@@ -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 ---

+34 −6
Original line number Diff line number Diff line
@@ -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,8 +233,7 @@ vec3 Transform::transform(const vec3& v) const {
    return r;
}

vec2 Transform::transform(int x, int y) const
{
vec2 Transform::transform(float x, float y) const {
    return transform(vec2(x, y));
}

+8 −3
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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) {