diff options
author | Jason Sams <rjsams@android.com> | 2010-11-16 17:37:02 -0800 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2010-11-16 17:37:02 -0800 |
commit | a5eb6e17c08426deeedf989d6be280d89662ee82 (patch) | |
tree | b84faf7a46df092850f261aea56834b6c7dc734c /rsScript.cpp | |
parent | 2fad7e47a8177235bb88fe271572bd986a7e4136 (diff) | |
download | rs-a5eb6e17c08426deeedf989d6be280d89662ee82.tar.gz |
Fix ref counting for globals when set from java code.
Change-Id: I415b6ddeaab277e60233e905a6bae357cd5193eb
Diffstat (limited to 'rsScript.cpp')
-rw-r--r-- | rsScript.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/rsScript.cpp b/rsScript.cpp index 4ffdbfdc..efdc6260 100644 --- a/rsScript.cpp +++ b/rsScript.cpp @@ -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)); |