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

Commit 1e16e401 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 21152

* changes:
  Implement named slots and convert script.addType to script.setType to remove ordering restrictions.
parents f71db959 fbf0b9ec
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -142,10 +142,10 @@ public class RenderScript {
    native void nScriptSetClearDepth(int script, float depth);
    native void nScriptSetClearStencil(int script, int stencil);
    native void nScriptSetTimeZone(int script, byte[] timeZone);
    native void nScriptSetType(int type, String name, int slot);
    native void nScriptSetRoot(boolean isRoot);

    native void nScriptCBegin();
    native void nScriptCAddType(int type);
    native void nScriptCSetRoot(boolean isRoot);
    native void nScriptCSetScript(byte[] script, int offset, int length);
    native int  nScriptCCreate();
    native void nScriptCAddDefineI32(String name, int value);
+19 −20
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ package android.renderscript;
 * @hide
 **/
public class Script extends BaseObj {
    public static final int MAX_SLOT = 16;

    boolean mIsRoot;
    Type[] mTypes;

@@ -64,39 +66,36 @@ public class Script extends BaseObj {
        RenderScript mRS;
        boolean mIsRoot = false;
        Type[] mTypes;
        int mTypeCount;
        String[] mNames;

        Builder(RenderScript rs) {
            mRS = rs;
            mTypes = new Type[4];
            mTypeCount = 0;
            mTypes = new Type[MAX_SLOT];
            mNames = new String[MAX_SLOT];
        }

        public void addType(Type t) {
            if(mTypeCount >= mTypes.length) {
                Type[] nt = new Type[mTypeCount * 2];
                for(int ct=0; ct < mTypeCount; ct++) {
                    nt[ct] = mTypes[ct];
                }
                mTypes = nt;
        public void setType(Type t, int slot) {
            mTypes[slot] = t;
            mNames[slot] = null;
        }
            mTypes[mTypeCount] = t;
            mTypeCount++;

        public void setType(Type t, String name, int slot) {
            mTypes[slot] = t;
            mNames[slot] = name;
        }

        void transferCreate() {
            mRS.nScriptCSetRoot(mIsRoot);
            for(int ct=0; ct < mTypeCount; ct++) {
                mRS.nScriptCAddType(mTypes[ct].mID);
            mRS.nScriptSetRoot(mIsRoot);
            for(int ct=0; ct < mTypes.length; ct++) {
                if(mTypes[ct] != null) {
                    mRS.nScriptSetType(mTypes[ct].mID, mNames[ct], ct);
                }
            }
        }

        void transferObject(Script s) {
            s.mIsRoot = mIsRoot;
            s.mTypes = new Type[mTypeCount];
            for(int ct=0; ct < mTypeCount; ct++) {
                s.mTypes[ct] = mTypes[ct];
            }
            s.mTypes = mTypes;
        }

        public void setRoot(boolean r) {
+7 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class Type extends BaseObj {
        mRS.nTypeDestroy(mID);
    }

    public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) {
    public static Type createFromClass(RenderScript rs, Class c, int size) {
        Element e = Element.createFromClass(rs, c);
        Builder b = new Builder(rs, e);
        b.add(Dimension.X, size);
@@ -91,10 +91,16 @@ public class Type extends BaseObj {
            rs.nTypeSetupFields(t, arTypes, arBits, fields);
        }
        t.mJavaClass = c;
        return t;
    }

    public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) {
        Type t = createFromClass(rs, c, size);
        t.setName(scriptName);
        return t;
    }


    public static class Builder {
        RenderScript mRS;
        Entry[] mEntries;
+20 −13
Original line number Diff line number Diff line
@@ -824,30 +824,37 @@ nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone
    }
}

// -----------------------------------

static void
nScriptCBegin(JNIEnv *_env, jobject _this)
nScriptSetType(JNIEnv *_env, jobject _this, jint type, jstring _str, jint slot)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nScriptCBegin, con(%p)", con);
    rsScriptCBegin();
    LOG_API("nScriptCAddType, con(%p), type(%p), slot(%i)", con, (RsType)type, slot);
    const char* n = NULL;
    if (_str) {
        n = _env->GetStringUTFChars(_str, NULL);
    }
    rsScriptSetType((RsType)type, slot, n);
    if (n) {
        _env->ReleaseStringUTFChars(_str, n);
    }
}

static void
nScriptCAddType(JNIEnv *_env, jobject _this, jint type)
nScriptSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nScriptCAddType, con(%p), type(%p)", con, (RsType)type);
    rsScriptCAddType((RsType)type);
    LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot);
    rsScriptSetRoot(isRoot);
}

// -----------------------------------

static void
nScriptCSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot)
nScriptCBegin(JNIEnv *_env, jobject _this)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot);
    rsScriptCSetRoot(isRoot);
    LOG_API("nScriptCBegin, con(%p)", con);
    rsScriptCBegin();
}

static void
@@ -1374,10 +1381,10 @@ static JNINativeMethod methods[] = {
{"nScriptSetClearDepth",           "(IF)V",                                (void*)nScriptSetClearDepth },
{"nScriptSetClearStencil",         "(II)V",                                (void*)nScriptSetClearStencil },
{"nScriptSetTimeZone",             "(I[B)V",                               (void*)nScriptSetTimeZone },
{"nScriptSetType",                 "(ILjava/lang/String;I)V",              (void*)nScriptSetType },
{"nScriptSetRoot",                 "(Z)V",                                 (void*)nScriptSetRoot },

{"nScriptCBegin",                  "()V",                                  (void*)nScriptCBegin },
{"nScriptCAddType",                "(I)V",                                 (void*)nScriptCAddType },
{"nScriptCSetRoot",                "(Z)V",                                 (void*)nScriptCSetRoot },
{"nScriptCSetScript",              "([BII)V",                              (void*)nScriptCSetScript },
{"nScriptCCreate",                 "()I",                                  (void*)nScriptCCreate },
{"nScriptCAddDefineI32",           "(Ljava/lang/String;I)V",               (void*)nScriptCAddDefineI32 },
+4 −4
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ int main(int index)
{
    float mat1[16];

    float trans = loadF(1, POS_TRANSLATE);
    float rot = loadF(1, POS_ROTATE);
    float trans = Pos_translate;
    float rot = Pos_rotate;
    matrixLoadScale(mat1, 2.f, 2.f, 2.f);
    matrixTranslate(mat1, 0.f, 0.f, trans);
    matrixRotate(mat1, 90.f, 0.f, 0.f, 1.f);
@@ -39,7 +39,7 @@ int main(int index)
    bindProgramFragment(NAMED_PFImages);
    bindProgramVertex(NAMED_PVImages);

    float focusPos = loadF(1, POS_FOCUS);
    float focusPos = Pos_focus;
    int focusID = 0;
    int lastFocusID = loadI32(2, STATE_LAST_FOCUS);
    int imgCount = 13;
@@ -65,7 +65,7 @@ int main(int index)
    */
    storeI32(2, STATE_LAST_FOCUS, focusID);

    int triangleOffsetsCount = loadI32(2, STATE_TRIANGLE_OFFSET_COUNT);
    int triangleOffsetsCount = Pos_triangleOffsetCount;

    int imgId = 0;
    for (imgId=1; imgId <= imgCount; imgId++) {
Loading