summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-10-06 13:58:47 -0700
committerJason Sams <rjsams@android.com>2009-10-06 13:58:47 -0700
commit516c31911578db8ce53529483c3ded918ac7dc6b (patch)
treeeee49f301e720ddfa249375abf611d550a0fba5d /graphics
parentf7ae77cd67f1a3993b8e56c1af4720a7adf4e69d (diff)
downloadframeworks_base-516c31911578db8ce53529483c3ded918ac7dc6b.zip
frameworks_base-516c31911578db8ce53529483c3ded918ac7dc6b.tar.gz
frameworks_base-516c31911578db8ce53529483c3ded918ac7dc6b.tar.bz2
Implement data push from scripts. Fixes the problem where apps would have to poll to monitor a scripts state.
Fix bug in StoreState where state could be overridden by the default unless the script used more than one state. Change only impacts renderscript and renderscript apps.
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/RenderScript.java55
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp34
2 files changed, 89 insertions, 0 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 6b0b696..1f2ea38 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -75,6 +75,9 @@ public class RenderScript {
native void nContextAddDefineF(String name, float value);
native void nContextPause();
native void nContextResume();
+ native int nContextGetMessage(int[] data, boolean wait);
+ native void nContextInitToClient();
+ native void nContextDeinitToClient();
native void nAssignName(int obj, byte[] name);
native void nObjDestroy(int id);
@@ -190,6 +193,7 @@ public class RenderScript {
private int mContext;
@SuppressWarnings({"FieldCanBeLocal"})
private Surface mSurface;
+ private MessageThread mMessageThread;
Element mElement_USER_U8;
@@ -214,6 +218,52 @@ public class RenderScript {
///////////////////////////////////////////////////////////////////////////////////
//
+ public static class RSMessage implements Runnable {
+ protected int[] mData;
+ protected int mID;
+ public void run() {
+ }
+ }
+ public RSMessage mMessageCallback = null;
+
+ private static class MessageThread extends Thread {
+ RenderScript mRS;
+ boolean mRun = true;
+
+ MessageThread(RenderScript rs) {
+ super("RSMessageThread");
+ mRS = rs;
+
+ }
+
+ public void run() {
+ // This function is a temporary solution. The final solution will
+ // used typed allocations where the message id is the type indicator.
+ int[] rbuf = new int[16];
+ mRS.nContextInitToClient();
+ while(mRun) {
+ int msg = mRS.nContextGetMessage(rbuf, true);
+ if (msg == 0) {
+ // Should only happen during teardown.
+ // But we want to avoid starving other threads during
+ // teardown by yielding until the next line in the destructor
+ // can execute to set mRun = false
+ try {
+ sleep(1, 0);
+ } catch(InterruptedException e) {
+ }
+ }
+ if(mRS.mMessageCallback != null) {
+ mRS.mMessageCallback.mData = rbuf;
+ mRS.mMessageCallback.mID = msg;
+ mRS.mMessageCallback.run();
+ }
+ //Log.d("rs", "MessageThread msg " + msg + " v1 " + rbuf[0] + " v2 " + rbuf[1] + " v3 " +rbuf[2]);
+ }
+ Log.d("rs", "MessageThread exiting.");
+ }
+ }
+
public RenderScript(Surface sur, boolean useDepth, boolean forceSW) {
mSurface = sur;
mDev = nDeviceCreate();
@@ -222,9 +272,14 @@ public class RenderScript {
}
mContext = nContextCreate(mDev, mSurface, 0, useDepth);
Element.initPredefined(this);
+ mMessageThread = new MessageThread(this);
+ mMessageThread.start();
}
public void destroy() {
+ nContextDeinitToClient();
+ mMessageThread.mRun = false;
+
nContextDestroy(mContext);
mContext = 0;
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 9054b65..fa3baa2 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -194,6 +194,37 @@ nContextResume(JNIEnv *_env, jobject _this)
rsContextResume(con);
}
+static jint
+nContextGetMessage(JNIEnv *_env, jobject _this, jintArray data, jboolean wait)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ jint len = _env->GetArrayLength(data);
+ LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
+ jint *ptr = _env->GetIntArrayElements(data, NULL);
+ size_t receiveLen;
+ int id = rsContextGetMessage(con, ptr, &receiveLen, len * 4, wait);
+ if (!id && receiveLen) {
+ LOGE("message receive buffer too small. %i", receiveLen);
+ }
+ _env->ReleaseIntArrayElements(data, ptr, 0);
+ return id;
+}
+
+static void nContextInitToClient(JNIEnv *_env, jobject _this)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nContextInitToClient, con(%p)", con);
+ rsContextInitToClient(con);
+}
+
+static void nContextDeinitToClient(JNIEnv *_env, jobject _this)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nContextDeinitToClient, con(%p)", con);
+ rsContextDeinitToClient(con);
+}
+
+
static void
nElementBegin(JNIEnv *_env, jobject _this)
{
@@ -1303,6 +1334,9 @@ static JNINativeMethod methods[] = {
{"nAssignName", "(I[B)V", (void*)nAssignName },
{"nObjDestroy", "(I)V", (void*)nObjDestroy },
{"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB },
+{"nContextGetMessage", "([IZ)I", (void*)nContextGetMessage },
+{"nContextInitToClient", "()V", (void*)nContextInitToClient },
+{"nContextDeinitToClient", "()V", (void*)nContextDeinitToClient },
{"nFileOpen", "([B)I", (void*)nFileOpen },