summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/RenderScript.java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java/android/renderscript/RenderScript.java')
-rw-r--r--graphics/java/android/renderscript/RenderScript.java34
1 files changed, 24 insertions, 10 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 1264adc37768..4de4766577c4 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -29,8 +29,8 @@ import android.graphics.SurfaceTexture;
import android.os.Process;
import android.util.Log;
import android.view.Surface;
-
-
+import android.os.SystemProperties;
+import android.os.Trace;
/**
* This class provides access to a RenderScript context, which controls RenderScript
@@ -44,6 +44,8 @@ import android.view.Surface;
* </div>
**/
public class RenderScript {
+ static final long TRACE_TAG = Trace.TRACE_TAG_RS;
+
static final String LOG_TAG = "RenderScript_jni";
static final boolean DEBUG = false;
@SuppressWarnings({"UnusedDeclaration", "deprecation"})
@@ -55,20 +57,22 @@ public class RenderScript {
* We use a class initializer to allow the native code to cache some
* field offsets.
*/
- @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
+ @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
static boolean sInitialized;
native static void _nInit();
static {
sInitialized = false;
- try {
- System.loadLibrary("rs_jni");
- _nInit();
- sInitialized = true;
- } catch (UnsatisfiedLinkError e) {
- Log.e(LOG_TAG, "Error loading RS jni library: " + e);
- throw new RSRuntimeException("Error loading RS jni library: " + e);
+ if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
+ try {
+ System.loadLibrary("rs_jni");
+ _nInit();
+ sInitialized = true;
+ } catch (UnsatisfiedLinkError e) {
+ Log.e(LOG_TAG, "Error loading RS jni library: " + e);
+ throw new RSRuntimeException("Error loading RS jni library: " + e);
+ }
}
}
@@ -92,6 +96,11 @@ public class RenderScript {
* @param cacheDir A directory the current process can write to
*/
public static void setupDiskCache(File cacheDir) {
+ if (!sInitialized) {
+ Log.e(LOG_TAG, "RenderScript.setupDiskCache() called when disabled");
+ return;
+ }
+
// Defer creation of cache path to nScriptCCreate().
mCacheDir = cacheDir;
}
@@ -1137,6 +1146,11 @@ public class RenderScript {
* @return RenderScript
*/
public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
+ if (!sInitialized) {
+ Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
+ return null;
+ }
+
RenderScript rs = new RenderScript(ctx);
rs.mDev = rs.nDeviceCreate();