Correctly init code cache path for RS

Bug: 27439261

Script Group needs to know the code cache path before it can call bcc to
merge kernels. However, before this change, the code cache path has been
initialized by the ScriptC class.

In the case where a script group (or even the entire app) does not contain any
regular script but only intrinsics, the code cache would remain uninitialized.

Fixed this by initializing the code cache path in the RenderScript class
the first time when the accessor method is called.

Change-Id: I87f9e62e0f3b479f94e43daa3e9695a5b38710db
This commit is contained in:
Yang Ni
2016-03-10 16:12:31 -08:00
parent 1b4afc275f
commit 689f637700
3 changed files with 25 additions and 29 deletions

View File

@@ -84,13 +84,6 @@ public class ScriptC extends Script {
setID(id);
}
/**
* Name of the file that holds the object cache.
*/
private static final String CACHE_PATH = "com.android.renderscript.cache";
static String mCachePath;
private static synchronized long internalCreate(RenderScript rs, Resources resources, int resourceID) {
byte[] pgm;
int pgmLength;
@@ -122,26 +115,12 @@ public class ScriptC extends Script {
String resName = resources.getResourceEntryName(resourceID);
// Create the RS cache path if we haven't done so already.
if (mCachePath == null) {
File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
mCachePath = f.getAbsolutePath();
f.mkdirs();
}
// Log.v(TAG, "Create script for resource = " + resName);
return rs.nScriptCCreate(resName, mCachePath, pgm, pgmLength);
return rs.nScriptCCreate(resName, RenderScript.getCachePath(), pgm, pgmLength);
}
private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) {
// Create the RS cache path if we haven't done so already.
if (mCachePath == null) {
File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
mCachePath = f.getAbsolutePath();
f.mkdirs();
}
// Log.v(TAG, "Create script for resource = " + resName);
return rs.nScriptCCreate(resName, mCachePath, bitcode, bitcode.length);
return rs.nScriptCCreate(resName, RenderScript.getCachePath(), bitcode, bitcode.length);
}
}