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

Commit 1d45c479 authored by Jason Sams's avatar Jason Sams
Browse files

Add matrix component types.

Fix potental overflow in script -> java messages.

Change-Id: Ie6fd9dc376be4043fc938a1517106936937689c8
parent 7462fc73
Loading
Loading
Loading
Loading
+37 −10
Original line number Diff line number Diff line
@@ -54,16 +54,20 @@ public class Element extends BaseObj {
        UNSIGNED_5_5_5_1 (14, 2),
        UNSIGNED_4_4_4_4 (15, 2),

        RS_ELEMENT (16, 4),
        RS_TYPE (17, 4),
        RS_ALLOCATION (18, 4),
        RS_SAMPLER (19, 4),
        RS_SCRIPT (20, 4),
        RS_MESH (21, 4),
        RS_PROGRAM_FRAGMENT (22, 4),
        RS_PROGRAM_VERTEX (23, 4),
        RS_PROGRAM_RASTER (24, 4),
        RS_PROGRAM_STORE (25, 4);
        MATRIX_4X4 (16, 64),
        MATRIX_3X3 (17, 36),
        MATRIX_2X2 (18, 16),

        RS_ELEMENT (1000, 4),
        RS_TYPE (1001, 4),
        RS_ALLOCATION (1002, 4),
        RS_SAMPLER (1003, 4),
        RS_SCRIPT (1004, 4),
        RS_MESH (1005, 4),
        RS_PROGRAM_FRAGMENT (1006, 4),
        RS_PROGRAM_VERTEX (1007, 4),
        RS_PROGRAM_RASTER (1008, 4),
        RS_PROGRAM_STORE (1009, 4);

        int mID;
        int mSize;
@@ -285,6 +289,29 @@ public class Element extends BaseObj {
        return rs.mElement_UCHAR_4;
    }

    public static Element MATRIX_4X4(RenderScript rs) {
        if(rs.mElement_MATRIX_4X4 == null) {
            rs.mElement_MATRIX_4X4 = createUser(rs, DataType.MATRIX_4X4);
        }
        return rs.mElement_MATRIX_4X4;
    }
    public static Element MATRIX4X4(RenderScript rs) {
        return MATRIX_4X4(rs);
    }

    public static Element MATRIX_3X3(RenderScript rs) {
        if(rs.mElement_MATRIX_3X3 == null) {
            rs.mElement_MATRIX_3X3 = createUser(rs, DataType.MATRIX_3X3);
        }
        return rs.mElement_MATRIX_4X4;
    }

    public static Element MATRIX_2X2(RenderScript rs) {
        if(rs.mElement_MATRIX_2X2 == null) {
            rs.mElement_MATRIX_2X2 = createUser(rs, DataType.MATRIX_2X2);
        }
        return rs.mElement_MATRIX_2X2;
    }

    Element(int id, RenderScript rs, Element[] e, String[] n) {
        super(id, rs);
+18 −0
Original line number Diff line number Diff line
@@ -248,6 +248,24 @@ public class FieldPacker {
        addU32(v.w);
    }

    public void addObj(Matrix4f v) {
        for (int i=0; i < v.mMat.length; i++) {
            addF32(v.mMat[i]);
        }
    }

    public void addObj(Matrix3f v) {
        for (int i=0; i < v.mMat.length; i++) {
            addF32(v.mMat[i]);
        }
    }

    public void addObj(Matrix2f v) {
        for (int i=0; i < v.mMat.length; i++) {
            addF32(v.mMat[i]);
        }
    }

    public void addBoolean(boolean v) {
        addI8((byte)(v ? 1 : 0));
    }
+18 −7
Original line number Diff line number Diff line
@@ -542,6 +542,10 @@ public class RenderScript {
    Element mElement_FLOAT_4;
    Element mElement_UCHAR_4;

    Element mElement_MATRIX_4X4;
    Element mElement_MATRIX_3X3;
    Element mElement_MATRIX_2X2;

    Sampler mSampler_CLAMP_NEAREST;
    Sampler mSampler_CLAMP_LINEAR;
    Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
@@ -614,9 +618,15 @@ public class RenderScript {
            int[] rbuf = new int[16];
            mRS.nContextInitToClient(mRS.mContext);
            while(mRun) {
                rbuf[0] = 0;
                int msg = mRS.nContextGetMessage(mRS.mContext, rbuf, true);
                if (msg == 0) {
                    // Should only happen during teardown.
                    // Can happen for two reasons
                    if (rbuf[0] > 0) {
                        // 1: Buffer needs to be enlarged.
                        rbuf = new int[rbuf[0] + 2];
                    } else {
                        // 2: teardown.
                        // But we want to avoid starving other threads during
                        // teardown by yielding until the next line in the destructor
                        // can execute to set mRun = false
@@ -625,6 +635,7 @@ public class RenderScript {
                        } catch(InterruptedException e) {
                        }
                    }
                }
                if(mRS.mMessageCallback != null) {
                    mRS.mMessageCallback.mData = rbuf;
                    mRS.mMessageCallback.mID = msg;
+2 −1
Original line number Diff line number Diff line
@@ -228,7 +228,8 @@ nContextGetMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data, j
    size_t receiveLen;
    int id = rsContextGetMessage(con, ptr, &receiveLen, len * 4, wait);
    if (!id && receiveLen) {
        LOGE("message receive buffer too small.  %i", receiveLen);
        LOGV("message receive buffer too small.  %i", receiveLen);
        *ptr = (jint)receiveLen;
    }
    _env->ReleaseIntArrayElements(data, ptr, 0);
    return id;
+6 −2
Original line number Diff line number Diff line
@@ -91,7 +91,11 @@ enum RsDataType {
    RS_TYPE_UNSIGNED_5_5_5_1,
    RS_TYPE_UNSIGNED_4_4_4_4,

    RS_TYPE_ELEMENT,
    RS_TYPE_MATRIX_4X4,
    RS_TYPE_MATRIX_3X3,
    RS_TYPE_MATRIX_2X2,

    RS_TYPE_ELEMENT = 1000,
    RS_TYPE_TYPE,
    RS_TYPE_ALLOCATION,
    RS_TYPE_SAMPLER,
@@ -100,7 +104,7 @@ enum RsDataType {
    RS_TYPE_PROGRAM_FRAGMENT,
    RS_TYPE_PROGRAM_VERTEX,
    RS_TYPE_PROGRAM_RASTER,
    RS_TYPE_PROGRAM_STORE
    RS_TYPE_PROGRAM_STORE,
};

enum RsDataKind {
Loading