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

Commit 4e7b772b authored by Romain Guy's avatar Romain Guy
Browse files

Fix crashes in setMatrix() and concat()

setMatrix() was crashing in native code, only with hw acceleration on.
concat() would throw a NullPointerException. It now ignores null matrices.

Change-Id: Iebd8b410a957d2ba501570c6fbb3f680ff4a1a23
parent d91f8af4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ class GLES20Canvas extends HardwareCanvas {

    @Override
    public void concat(Matrix matrix) {
        nConcatMatrix(mRenderer, matrix.native_instance);
        if (matrix != null) nConcatMatrix(mRenderer, matrix.native_instance);
    }
    
    private static native void nConcatMatrix(int renderer, int matrix);
+3 −2
Original line number Diff line number Diff line
@@ -513,12 +513,13 @@ public class Canvas {
    public native void skew(float sx, float sy);

    /**
     * Preconcat the current matrix with the specified matrix.
     * Preconcat the current matrix with the specified matrix. If the specified
     * matrix is null, this method does nothing.
     *
     * @param matrix The matrix to preconcatenate with the current matrix
     */
    public void concat(Matrix matrix) {
        native_concat(mNativeCanvas, matrix.native_instance);
        if (matrix != null) native_concat(mNativeCanvas, matrix.native_instance);
    }
    
    /**
+5 −1
Original line number Diff line number Diff line
@@ -468,7 +468,11 @@ public:
    }

    virtual void output(int level, uint32_t logFlags) const {
        if (mMatrix) {
            OP_LOG("SetMatrix " MATRIX_STRING, MATRIX_ARGS(mMatrix));
        } else {
            OP_LOGS("SetMatrix (reset)");
        }
    }

    virtual const char* name() { return "SetMatrix"; }
+8 −5
Original line number Diff line number Diff line
@@ -269,12 +269,15 @@ private:
    }

    inline SkMatrix* refMatrix(SkMatrix* matrix) {
        // Copying the matrix is cheap and prevents against the user changing the original
        // matrix before the operation that uses it
        if (matrix) {
            // Copying the matrix is cheap and prevents against the user changing
            // the original matrix before the operation that uses it
            SkMatrix* copy = new SkMatrix(*matrix);
            mMatrices.add(copy);
            return copy;
        }
        return matrix;
    }

    inline Layer* refLayer(Layer* layer) {
        mLayers.add(layer);