1. Add Context to a RenderScript or RenderScriptGL instance.
This is to allow RenderScript to better interact with the Android environment.
E.g., per-app cache.
2. Plumbing, testing.
3. Added getApplicationContext in RenderScript.java.
Change-Id: I85edeebe38825e20b2e86f4f4815689dfc332ef9
diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java
index 0211a4a..507f41f 100644
--- a/graphics/java/android/renderscript/RSSurfaceView.java
+++ b/graphics/java/android/renderscript/RSSurfaceView.java
@@ -119,7 +119,7 @@
}
public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
- RenderScriptGL rs = new RenderScriptGL(sc);
+ RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
setRenderScriptGL(rs);
return rs;
}
@@ -137,4 +137,3 @@
return mRS;
}
}
-
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index c6dcff5..5f93f5b 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -18,6 +18,7 @@
import java.lang.reflect.Field;
+import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Config;
@@ -42,9 +43,9 @@
@SuppressWarnings({"UnusedDeclaration", "deprecation"})
static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
+ private Context mApplicationContext;
-
- /*
+ /*
* We use a class initializer to allow the native code to cache some
* field offsets.
*/
@@ -416,9 +417,9 @@
synchronized void nScriptCSetScript(byte[] script, int offset, int length) {
rsnScriptCSetScript(mContext, script, offset, length);
}
- native int rsnScriptCCreate(int con, String val);
- synchronized int nScriptCCreate(String val) {
- return rsnScriptCCreate(mContext, val);
+ native int rsnScriptCCreate(int con, String val, String cacheDir);
+ synchronized int nScriptCCreate(String resName, String cacheDir) {
+ return rsnScriptCCreate(mContext, resName, cacheDir);
}
native void rsnSamplerBegin(int con);
@@ -776,17 +777,27 @@
}
}
- RenderScript() {
+ RenderScript(Context ctx) {
+ mApplicationContext = ctx.getApplicationContext();
+ }
+
+ /**
+ * Gets the application context associated with the RenderScript context.
+ *
+ * @return The application context.
+ */
+ public final Context getApplicationContext() {
+ return mApplicationContext;
}
/**
* Create a basic RenderScript context.
*
- *
+ * @param ctx The context.
* @return RenderScript
*/
- public static RenderScript create() {
- RenderScript rs = new RenderScript();
+ public static RenderScript create(Context ctx) {
+ RenderScript rs = new RenderScript(ctx);
rs.mDev = rs.nDeviceCreate();
rs.mContext = rs.nContextCreate(rs.mDev, 0);
diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java
index 0886db4..5adb682 100644
--- a/graphics/java/android/renderscript/RenderScriptGL.java
+++ b/graphics/java/android/renderscript/RenderScriptGL.java
@@ -18,6 +18,7 @@
import java.lang.reflect.Field;
+import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -168,10 +169,11 @@
/**
* Construct a new RenderScriptGL context.
*
- *
+ * @param ctx The context.
* @param sc The desired format of the primart rendering surface.
*/
- public RenderScriptGL(SurfaceConfig sc) {
+ public RenderScriptGL(Context ctx, SurfaceConfig sc) {
+ super(ctx);
mSurfaceConfig = new SurfaceConfig(sc);
mSurface = null;
@@ -304,5 +306,3 @@
}
}
-
-
diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java
index 64ed75b..b10247c 100644
--- a/graphics/java/android/renderscript/ScriptC.java
+++ b/graphics/java/android/renderscript/ScriptC.java
@@ -16,9 +16,11 @@
package android.renderscript;
+import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
@@ -76,6 +78,7 @@
rs.nScriptCBegin();
rs.nScriptCSetScript(pgm, 0, pgmLength);
Log.v(TAG, "Create script for resource = " + resources.getResourceName(resourceID));
- return rs.nScriptCCreate(resources.getResourceName(resourceID));
+ String cacheDir = rs.getApplicationContext().getCacheDir().toString();
+ return rs.nScriptCCreate(resources.getResourceName(resourceID), cacheDir);
}
}