Add support for mixed 32/64 APKs using RenderScript.
Change-Id: I8901a1547d180c9dcef320f86d07a5b82551fb5c
diff --git a/rs/java/android/renderscript/FieldPacker.java b/rs/java/android/renderscript/FieldPacker.java
index cf20e63..2ff1c28 100644
--- a/rs/java/android/renderscript/FieldPacker.java
+++ b/rs/java/android/renderscript/FieldPacker.java
@@ -232,10 +232,18 @@
public void addObj(BaseObj obj) {
if (obj != null) {
- // FIXME: this is fine for 32-bit but needs a path for 64-bit
- addI32((int)obj.getID(null));
+ if (RenderScript.sPointerSize == 8) {
+ addI64(obj.getID(null));
+ }
+ else {
+ addI32((int)obj.getID(null));
+ }
} else {
- addI32(0);
+ if (RenderScript.sPointerSize == 8) {
+ addI64(0);
+ } else {
+ addI32(0);
+ }
}
}
diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java
index ea25f58..bbe5c49 100644
--- a/rs/java/android/renderscript/RenderScript.java
+++ b/rs/java/android/renderscript/RenderScript.java
@@ -67,6 +67,12 @@
static Method registerNativeAllocation;
static Method registerNativeFree;
+ /*
+ * Detect the bitness of the VM to allow FieldPacker to do the right thing.
+ */
+ static native int rsnSystemGetPointerSize();
+ static int sPointerSize;
+
static {
sInitialized = false;
if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
@@ -84,6 +90,7 @@
System.loadLibrary("rs_jni");
_nInit();
sInitialized = true;
+ sPointerSize = rsnSystemGetPointerSize();
} catch (UnsatisfiedLinkError e) {
Log.e(LOG_TAG, "Error loading RS jni library: " + e);
throw new RSRuntimeException("Error loading RS jni library: " + e);
diff --git a/rs/java/android/renderscript/ScriptC.java b/rs/java/android/renderscript/ScriptC.java
index cdb2b08..f27cbd8 100644
--- a/rs/java/android/renderscript/ScriptC.java
+++ b/rs/java/android/renderscript/ScriptC.java
@@ -74,6 +74,26 @@
}
/**
+ * Only intended for use by the generated derived classes.
+ *
+ * @param rs
+ * @hide
+ */
+ protected ScriptC(RenderScript rs, String resName, byte[] bitcode32, byte[] bitcode64) {
+ super(0, rs);
+ long id = 0;
+ if (RenderScript.sPointerSize == 4) {
+ id = internalStringCreate(rs, resName, bitcode32);
+ } else {
+ id = internalStringCreate(rs, resName, bitcode64);
+ }
+ if (id == 0) {
+ throw new RSRuntimeException("Loading of ScriptC script failed.");
+ }
+ setID(id);
+ }
+
+ /**
* Name of the file that holds the object cache.
*/
private static final String CACHE_PATH = "com.android.renderscript.cache";
@@ -120,4 +140,17 @@
// Log.v(TAG, "Create script for resource = " + resName);
return rs.nScriptCCreate(resName, mCachePath, pgm, pgmLength);
}
+
+ private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) {
+ // Create the RS cache path if we haven't done so already.
+ if (mCachePath == null) {
+ File f = new File(rs.mCacheDir, CACHE_PATH);
+ mCachePath = f.getAbsolutePath();
+ f.mkdirs();
+ }
+ // Log.v(TAG, "Create script for resource = " + resName);
+ return rs.nScriptCCreate(resName, mCachePath, bitcode, bitcode.length);
+ }
+
+
}
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index 0d75f4c..c7f6fa8 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -1576,6 +1576,12 @@
free(prims);
}
+static jint
+nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
+ return (jint)sizeof(void*);
+}
+
+
// ---------------------------------------------------------------------------
@@ -1711,6 +1717,7 @@
{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
+{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
};
static int registerFuncs(JNIEnv *_env)