Skip to content

Commit b561f3b

Browse files
miaowang14Gerrit Code Review
authored andcommitted
Merge "[RenderScript] Add additional check for determining whether to use native RS."
2 parents 544fa4e + 0cc3605 commit b561f3b

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

v8/renderscript/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include $(CLEAR_VARS)
2424
LOCAL_CFLAGS += -std=c++11
2525

2626
LOCAL_MODULE := android-support-v8-renderscript
27-
LOCAL_SDK_VERSION := 19
27+
LOCAL_SDK_VERSION := 21
2828
LOCAL_SRC_FILES := $(call all-java-files-under, java/src)
2929

3030
include $(BUILD_STATIC_JAVA_LIBRARY)

v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class RenderScript {
6565
static Object lock = new Object();
6666

6767
// Non-threadsafe functions.
68-
native boolean nLoadSO(boolean useNative);
68+
native boolean nLoadSO(boolean useNative, int deviceApi);
6969
native boolean nLoadIOSO();
7070
native long nDeviceCreate();
7171
native void nDeviceDestroy(long dev);
@@ -95,6 +95,13 @@ boolean isUseNative() {
9595
* RenderScript layer or actually using the compatibility library.
9696
*/
9797
static private boolean setupNative(int sdkVersion, Context ctx) {
98+
// if targetSdkVersion is higher than the device api version, always use compat mode.
99+
// Workaround for KK
100+
if (android.os.Build.VERSION.SDK_INT < sdkVersion &&
101+
android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
102+
sNative = 0;
103+
}
104+
98105
if (sNative == -1) {
99106

100107
// get the value of the debug.rs.forcecompat property
@@ -1176,7 +1183,7 @@ public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
11761183
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
11771184
useIOlib = true;
11781185
}
1179-
if (!rs.nLoadSO(useNative)) {
1186+
if (!rs.nLoadSO(useNative, android.os.Build.VERSION.SDK_INT)) {
11801187
if (useNative) {
11811188
android.util.Log.v(LOG_TAG, "Unable to load libRS.so, falling back to compat mode");
11821189
useNative = false;
@@ -1187,7 +1194,7 @@ public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
11871194
Log.e(LOG_TAG, "Error loading RS Compat library: " + e);
11881195
throw new RSRuntimeException("Error loading RS Compat library: " + e);
11891196
}
1190-
if (!rs.nLoadSO(false)) {
1197+
if (!rs.nLoadSO(false, android.os.Build.VERSION.SDK_INT)) {
11911198
throw new RSRuntimeException("Error loading libRSSupport library");
11921199
}
11931200
}

v8/renderscript/jni/android_renderscript_RenderScript.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static dispatchTable dispatchTab;
269269
// Incremental Support lib
270270
static dispatchTable dispatchTabInc;
271271

272-
static jboolean nLoadSO(JNIEnv *_env, jobject _this, jboolean useNative) {
272+
static jboolean nLoadSO(JNIEnv *_env, jobject _this, jboolean useNative, jint deviceApi) {
273273
void* handle = NULL;
274274
if (useNative) {
275275
handle = dlopen("libRS.so", RTLD_LAZY | RTLD_LOCAL);
@@ -281,7 +281,7 @@ static jboolean nLoadSO(JNIEnv *_env, jobject _this, jboolean useNative) {
281281
return false;
282282
}
283283

284-
if (loadSymbols(handle, dispatchTab) == false) {
284+
if (loadSymbols(handle, dispatchTab, deviceApi) == false) {
285285
LOG_API("%s init failed!", filename);
286286
return false;
287287
}
@@ -1601,7 +1601,7 @@ nIncAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong incCon,
16011601
static const char *classPathName = "android/support/v8/renderscript/RenderScript";
16021602

16031603
static JNINativeMethod methods[] = {
1604-
{"nLoadSO", "(Z)Z", (bool*)nLoadSO },
1604+
{"nLoadSO", "(ZI)Z", (bool*)nLoadSO },
16051605
{"nLoadIOSO", "()Z", (bool*)nLoadIOSO },
16061606
{"nDeviceCreate", "()J", (void*)nDeviceCreate },
16071607
{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },

0 commit comments

Comments
 (0)