Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "[Renderscript] Set native lib path from java RS context for rs…
Browse files Browse the repository at this point in the history
… compat lib."
  • Loading branch information
miaowang14 authored and Gerrit Code Review committed Feb 13, 2015
2 parents 4771d7c + 825350e commit a9e77d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class RenderScript {
static final boolean LOG_ENABLED = false;

private Context mApplicationContext;
private String mNativeLibDir;

/*
* We use a class initializer to allow the native code to cache some
Expand Down Expand Up @@ -212,9 +213,9 @@ public enum ContextType {
// Methods below are wrapped to protect the non-threadsafe
// lockless fifo.

native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
return rsnContextCreate(dev, ver, sdkVer, contextType);
native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType, String nativeLibDir);
synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType, String nativeLibDir) {
return rsnContextCreate(dev, ver, sdkVer, contextType, nativeLibDir);
}
native void rsnContextDestroy(long con);
synchronized void nContextDestroy() {
Expand Down Expand Up @@ -981,6 +982,7 @@ public void run() {
RenderScript(Context ctx) {
if (ctx != null) {
mApplicationContext = ctx.getApplicationContext();
mNativeLibDir = mApplicationContext.getApplicationInfo().nativeLibraryDir;
}
mRWLock = new ReentrantReadWriteLock();
}
Expand Down Expand Up @@ -1040,6 +1042,7 @@ public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
}
}
}

if (useNative) {
android.util.Log.v(LOG_TAG, "RS native mode");
} else {
Expand Down Expand Up @@ -1075,8 +1078,9 @@ public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
useIOlib = false;
}
}

rs.mDev = rs.nDeviceCreate();
rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID);
rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID, rs.mNativeLibDir);
if (rs.mContext == 0) {
throw new RSDriverException("Failed to create RS context.");
}
Expand Down
23 changes: 17 additions & 6 deletions v8/renderscript/jni/android_renderscript_RenderScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ static jboolean nLoadIOSO(JNIEnv *_env, jobject _this) {
}
return true;
}

// ---------------------------------------------------------------------------

static void
Expand Down Expand Up @@ -223,7 +224,6 @@ nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
}

// ---------------------------------------------------------------------------

static jlong
nDeviceCreate(JNIEnv *_env, jobject _this)
{
Expand All @@ -246,12 +246,23 @@ nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
}

static jlong
nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct)
nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
jint ct, jstring nativeLibDirJava)
{
LOG_API("nContextCreate");
return (jlong)(uintptr_t)dispatchTab.ContextCreate((RsDevice)dev, ver,
sdkVer,
(RsContextType)ct, 0);
// Access the NativeLibDir in the Java Context.
const char * nativeLibDir = _env->GetStringUTFChars(nativeLibDirJava, JNI_FALSE);
size_t length = (size_t)_env->GetStringUTFLength(nativeLibDirJava);

jlong id = (jlong)(uintptr_t)dispatchTab.ContextCreate((RsDevice)dev, ver,
sdkVer,
(RsContextType)ct, 0);
if (dispatchTab.SetNativeLibDir) {
dispatchTab.SetNativeLibDir((RsContext)id, nativeLibDir, length);
}

_env->ReleaseStringUTFChars(nativeLibDirJava, nativeLibDir);
return id;
}


Expand Down Expand Up @@ -1325,7 +1336,7 @@ static JNINativeMethod methods[] = {


// All methods below are thread protected in java.
{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
{"rsnContextCreate", "(JIIILjava/lang/String;)J", (void*)nContextCreate },
{"rsnContextFinish", "(J)V", (void*)nContextFinish },
{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
Expand Down

0 comments on commit a9e77d7

Please sign in to comment.