Merge "Add support for mixed 32/64 APKs using RenderScript."

This commit is contained in:
Tim Murray
2014-06-03 21:36:19 +00:00
committed by Gerrit Code Review
4 changed files with 58 additions and 3 deletions

View File

@ -232,10 +232,18 @@ public class FieldPacker {
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);
}
}
}

View File

@ -67,6 +67,12 @@ public class RenderScript {
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 @@ public class RenderScript {
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);

View File

@ -73,6 +73,26 @@ public class ScriptC extends Script {
setID(id);
}
/**
* 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.
*/
@ -120,4 +140,17 @@ public class ScriptC extends Script {
// 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);
}
}

View File

@ -1576,6 +1576,12 @@ nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _
free(prims);
}
static jint
nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
return (jint)sizeof(void*);
}
// ---------------------------------------------------------------------------
@ -1711,6 +1717,7 @@ static JNINativeMethod methods[] = {
{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
};
static int registerFuncs(JNIEnv *_env)