Skip to content

Commit 93d083b

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "Do RS caching the same way HardwareRenderer does. Eliminates the need for an application context for caching."
2 parents 3d408e5 + a6f338c commit 93d083b

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import android.view.Window;
7979
import android.view.WindowManager;
8080
import android.view.WindowManagerImpl;
81+
import android.renderscript.RenderScript;
8182

8283
import com.android.internal.os.BinderInternal;
8384
import com.android.internal.os.RuntimeInit;
@@ -3779,6 +3780,7 @@ private void setupGraphicsSupport(LoadedApk info) {
37793780
appContext.init(info, null, this);
37803781

37813782
HardwareRenderer.setupDiskCache(appContext.getCacheDir());
3783+
RenderScript.setupDiskCache(appContext.getCacheDir());
37823784
}
37833785
} catch (RemoteException e) {
37843786
// Ignore

graphics/java/android/renderscript/RenderScript.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.renderscript;
1818

1919
import java.lang.reflect.Field;
20+
import java.io.File;
2021

2122
import android.content.Context;
2223
import android.content.pm.ApplicationInfo;
@@ -82,6 +83,26 @@ public class RenderScript {
8283
native void nContextInitToClient(int con);
8384
native void nContextDeinitToClient(int con);
8485

86+
/**
87+
* Name of the file that holds the object cache.
88+
*/
89+
private static final String CACHE_PATH = "com.android.renderscript.cache";
90+
91+
/**
92+
* Sets the directory to use as a persistent storage for the
93+
* renderscript object file cache.
94+
*
95+
* @hide
96+
* @param cacheDir A directory the current process can write to
97+
*/
98+
99+
static String mCachePath;
100+
public static void setupDiskCache(File cacheDir) {
101+
File f = new File(cacheDir, CACHE_PATH);
102+
mCachePath = f.getAbsolutePath();
103+
f.mkdirs();
104+
}
105+
85106

86107
// Methods below are wrapped to protect the non-threadsafe
87108
// lockless fifo.

graphics/java/android/renderscript/ScriptC.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,9 @@ private static synchronized int internalCreate(RenderScript rs, Resources resour
9292
throw new Resources.NotFoundException();
9393
}
9494

95-
// E.g, /system/apps/Fountain.apk
96-
//String packageName = rs.getApplicationContext().getPackageResourcePath();
97-
// For res/raw/fountain.bc, it wil be /com.android.fountain:raw/fountain
9895
String resName = resources.getResourceEntryName(resourceID);
99-
String cacheDir = rs.getApplicationContext().getCacheDir().toString();
10096

10197
Log.v(TAG, "Create script for resource = " + resName);
102-
return rs.nScriptCCreate(resName, cacheDir, pgm, pgmLength);
98+
return rs.nScriptCCreate(resName, rs.mCachePath, pgm, pgmLength);
10399
}
104100
}

0 commit comments

Comments
 (0)