diff options
| author | Jason Sams <rjsams@android.com> | 2010-11-16 18:30:58 -0800 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-11-16 18:30:58 -0800 |
| commit | 68f0a32d103d3861103bce3763b222bde99c0a4c (patch) | |
| tree | 2681e49340e97dc410b9a376a84754c7c5136db0 /libs | |
| parent | 4a0d0b34b244b5b730e861d875e7ae289cbb3311 (diff) | |
| parent | 6f4cf0b8885403ead157ae00fd43cf1282331c23 (diff) | |
| download | frameworks_base-68f0a32d103d3861103bce3763b222bde99c0a4c.zip frameworks_base-68f0a32d103d3861103bce3763b222bde99c0a4c.tar.gz frameworks_base-68f0a32d103d3861103bce3763b222bde99c0a4c.tar.bz2 | |
Merge "Fix ref counting for globals when set from java code."
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/rs/rs.spec | 6 | ||||
| -rw-r--r-- | libs/rs/rsScript.cpp | 22 | ||||
| -rw-r--r-- | libs/rs/rsScript.h | 1 |
3 files changed, 29 insertions, 0 deletions
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index ac9abe0..76db14f 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -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 diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp index 4ffdbfd..efdc626 100644 --- a/libs/rs/rsScript.cpp +++ b/libs/rs/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)); diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h index 9b6d8a9..bad095b 100644 --- a/libs/rs/rsScript.h +++ b/libs/rs/rsScript.h @@ -61,6 +61,7 @@ public: void initSlots(); void setSlot(uint32_t slot, Allocation *a); void setVar(uint32_t slot, const void *val, uint32_t len); + void setVarObj(uint32_t slot, ObjectBase *val); virtual void runForEach(Context *rsc, const Allocation * ain, |
