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

Commit 68f0a32d authored by Jason Sams's avatar Jason Sams Committed by Android (Google) Code Review
Browse files

Merge "Fix ref counting for globals when set from java code."

parents 4a0d0b34 6f4cf0b8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -389,6 +389,10 @@ public class RenderScript {
    synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
        rsnScriptSetVarV(mContext, id, slot, val);
    }
    native void rsnScriptSetVarObj(int con, int id, int slot, int val);
    synchronized void nScriptSetVarObj(int id, int slot, int val) {
        rsnScriptSetVarObj(mContext, id, slot, val);
    }

    native void rsnScriptCBegin(int con);
    synchronized void nScriptCBegin() {
+4 −0
Original line number Diff line number Diff line
@@ -88,6 +88,10 @@ public class Script extends BaseObj {
        mRS.nScriptSetVarI(getID(), index, v ? 1 : 0);
    }

    public void setVar(int index, BaseObj o) {
        mRS.nScriptSetVarObj(getID(), index, (o == null) ? 0 : o.getID());
    }

    public void setVar(int index, FieldPacker v) {
        mRS.nScriptSetVarV(getID(), index, v.getData());
    }
+8 −0
Original line number Diff line number Diff line
@@ -828,6 +828,13 @@ nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo
    rsScriptSetVarI(con, (RsScript)script, slot, val);
}

static void
nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
{
    LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
    rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
}

static void
nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
{
@@ -1335,6 +1342,7 @@ static JNINativeMethod methods[] = {
{"rsnScriptSetVarF",                 "(IIIF)V",                               (void*)nScriptSetVarF },
{"rsnScriptSetVarD",                 "(IIID)V",                               (void*)nScriptSetVarD },
{"rsnScriptSetVarV",                 "(III[B)V",                              (void*)nScriptSetVarV },
{"rsnScriptSetVarObj",               "(IIII)V",                               (void*)nScriptSetVarObj },

{"rsnScriptCBegin",                  "(I)V",                                  (void*)nScriptCBegin },
{"rsnScriptCSetScript",              "(I[BII)V",                              (void*)nScriptCSetScript },
+6 −0
Original line number Diff line number Diff line
@@ -280,6 +280,12 @@ ScriptSetVarI {
	param int value
	}

ScriptSetVarObj {
	param RsScript s
	param uint32_t slot
	param RsObjectBase value
	}

ScriptSetVarJ {
	param RsScript s
	param uint32_t slot
+22 −0
Original line number Diff line number Diff line
@@ -67,6 +67,22 @@ void Script::setVar(uint32_t slot, const void *val, uint32_t len) {
    }
}

void Script::setVarObj(uint32_t slot, ObjectBase *val) {
    ObjectBase **destPtr = ((ObjectBase ***)mEnviroment.mFieldAddress)[slot];

    if (destPtr) {
        if (val != NULL) {
            val->incSysRef();
        }
        if (*destPtr) {
            (*destPtr)->decSysRef();
        }
        *destPtr = val;
    } else {
        LOGV("Calling setVarObj on slot = %i which is null.  This is dangerous because the script will not hold a ref count on the object.", slot);
    }
}

namespace android {
namespace renderscript {

@@ -103,6 +119,12 @@ void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) {
    s->setVar(slot, &value, sizeof(value));
}

void rsi_ScriptSetVarObj(Context *rsc, RsScript vs, uint32_t slot, RsObjectBase value) {
    Script *s = static_cast<Script *>(vs);
    ObjectBase *o = static_cast<ObjectBase *>(value);
    s->setVarObj(slot, o);
}

void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) {
    Script *s = static_cast<Script *>(vs);
    s->setVar(slot, &value, sizeof(value));
Loading