Skip to content

Commit 1a4e1f3

Browse files
author
Jason Sams
committed
Make compute work without an app context.
Change-Id: I644b4711135d6f5d9866b6c2e5e6f6a5ceb1f3d4
1 parent a6f338c commit 1a4e1f3

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

graphics/java/android/renderscript/RenderScript.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public class RenderScript {
8787
* Name of the file that holds the object cache.
8888
*/
8989
private static final String CACHE_PATH = "com.android.renderscript.cache";
90+
static String mCachePath;
9091

9192
/**
9293
* Sets the directory to use as a persistent storage for the
@@ -95,8 +96,6 @@ public class RenderScript {
9596
* @hide
9697
* @param cacheDir A directory the current process can write to
9798
*/
98-
99-
static String mCachePath;
10099
public static void setupDiskCache(File cacheDir) {
101100
File f = new File(cacheDir, CACHE_PATH);
102101
mCachePath = f.getAbsolutePath();
@@ -905,7 +904,9 @@ public void run() {
905904
}
906905

907906
RenderScript(Context ctx) {
908-
mApplicationContext = ctx.getApplicationContext();
907+
if (ctx != null) {
908+
mApplicationContext = ctx.getApplicationContext();
909+
}
909910
}
910911

911912
/**
@@ -917,21 +918,16 @@ public final Context getApplicationContext() {
917918
return mApplicationContext;
918919
}
919920

920-
static int getTargetSdkVersion(Context ctx) {
921-
return ctx.getApplicationInfo().targetSdkVersion;
922-
}
923-
924921
/**
925922
* Create a basic RenderScript context.
926923
*
924+
* @hide
927925
* @param ctx The context.
928926
* @return RenderScript
929927
*/
930-
public static RenderScript create(Context ctx) {
928+
public static RenderScript create(Context ctx, int sdkVersion) {
931929
RenderScript rs = new RenderScript(ctx);
932930

933-
int sdkVersion = getTargetSdkVersion(ctx);
934-
935931
rs.mDev = rs.nDeviceCreate();
936932
rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion);
937933
if (rs.mContext == 0) {
@@ -942,6 +938,17 @@ public static RenderScript create(Context ctx) {
942938
return rs;
943939
}
944940

941+
/**
942+
* Create a basic RenderScript context.
943+
*
944+
* @param ctx The context.
945+
* @return RenderScript
946+
*/
947+
public static RenderScript create(Context ctx) {
948+
int v = ctx.getApplicationInfo().targetSdkVersion;
949+
return create(ctx, v);
950+
}
951+
945952
/**
946953
* Print the currently available debugging information about the state of
947954
* the RS context to the log.

graphics/java/android/renderscript/RenderScriptGL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public RenderScriptGL(Context ctx, SurfaceConfig sc) {
166166
super(ctx);
167167
mSurfaceConfig = new SurfaceConfig(sc);
168168

169-
int sdkVersion = getTargetSdkVersion(ctx);
169+
int sdkVersion = ctx.getApplicationInfo().targetSdkVersion;
170170

171171
mWidth = 0;
172172
mHeight = 0;

0 commit comments

Comments
 (0)