summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-08-18 17:07:09 -0700
committerJason Sams <rjsams@android.com>2009-08-18 17:07:09 -0700
commit730ee65d4ddb307898053b623120bad1655fadad (patch)
treeea3d8f41940ef06af43a5fe5436c9c9c3943227d /graphics
parent7ce033d797e5df5e2131e2ed459fba181eaf4658 (diff)
downloadframeworks_base-730ee65d4ddb307898053b623120bad1655fadad.zip
frameworks_base-730ee65d4ddb307898053b623120bad1655fadad.tar.gz
frameworks_base-730ee65d4ddb307898053b623120bad1655fadad.tar.bz2
Implement OOB destroy method that can be called from the java finalizer removing the need to explicitly destroy objects.
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/BaseObj.java7
-rw-r--r--graphics/java/android/renderscript/RenderScript.java1
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp10
3 files changed, 17 insertions, 1 deletions
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index eaeb401..c25f16a 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -60,8 +60,13 @@ class BaseObj {
protected void finalize() throws Throwable
{
if (!mDestroyed) {
+ if(mID != 0) {
+ mRS.nObjDestroyOOB(mID);
+ }
+ mID = 0;
+ mDestroyed = true;
Log.v(RenderScript.LOG_TAG,
- getClass() + " finalized without having released the RS reference.");
+ getClass() + " auto finalizing object without having released the RS reference.");
}
super.finalize();
}
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 08418c6..fca1c7a 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -75,6 +75,7 @@ public class RenderScript {
native void nAssignName(int obj, byte[] name);
native void nObjDestroy(int id);
+ native void nObjDestroyOOB(int id);
native int nFileOpen(byte[] name);
native void nElementBegin();
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 2d48165..001ecd0 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -86,6 +86,15 @@ nObjDestroy(JNIEnv *_env, jobject _this, jint obj)
rsObjDestroy(con, (void *)obj);
}
+static void
+nObjDestroyOOB(JNIEnv *_env, jobject _this, jint obj)
+{
+ // This function only differs from nObjDestroy in that it calls the
+ // special Out Of Band version of ObjDestroy which is thread safe.
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nObjDestroyOOB, con(%p) obj(%p)", con, (void *)obj);
+ rsObjDestroyOOB(con, (void *)obj);
+}
static jint
nFileOpen(JNIEnv *_env, jobject _this, jbyteArray str)
@@ -1217,6 +1226,7 @@ static JNINativeMethod methods[] = {
{"nContextDestroy", "(I)V", (void*)nContextDestroy },
{"nAssignName", "(I[B)V", (void*)nAssignName },
{"nObjDestroy", "(I)V", (void*)nObjDestroy },
+{"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB },
{"nFileOpen", "([B)I", (void*)nFileOpen },