Do RS caching the same way HardwareRenderer does.

Eliminates the need for an application context for caching.

Change-Id: I4374738083b5eb4ce983d2cb5409428e3668c423
This commit is contained in:
Jason Sams
2012-02-24 16:22:16 -08:00
parent 9733f26093
commit a6f338ca5f
3 changed files with 24 additions and 5 deletions

View File

@@ -78,6 +78,7 @@ import android.view.ViewRootImpl;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
import android.renderscript.RenderScript;
import com.android.internal.os.BinderInternal;
import com.android.internal.os.RuntimeInit;
@@ -3779,6 +3780,7 @@ public final class ActivityThread {
appContext.init(info, null, this);
HardwareRenderer.setupDiskCache(appContext.getCacheDir());
RenderScript.setupDiskCache(appContext.getCacheDir());
}
} catch (RemoteException e) {
// Ignore

View File

@@ -17,6 +17,7 @@
package android.renderscript;
import java.lang.reflect.Field;
import java.io.File;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -82,6 +83,26 @@ public class RenderScript {
native void nContextInitToClient(int con);
native void nContextDeinitToClient(int con);
/**
* Name of the file that holds the object cache.
*/
private static final String CACHE_PATH = "com.android.renderscript.cache";
/**
* Sets the directory to use as a persistent storage for the
* renderscript object file cache.
*
* @hide
* @param cacheDir A directory the current process can write to
*/
static String mCachePath;
public static void setupDiskCache(File cacheDir) {
File f = new File(cacheDir, CACHE_PATH);
mCachePath = f.getAbsolutePath();
f.mkdirs();
}
// Methods below are wrapped to protect the non-threadsafe
// lockless fifo.

View File

@@ -92,13 +92,9 @@ public class ScriptC extends Script {
throw new Resources.NotFoundException();
}
// E.g, /system/apps/Fountain.apk
//String packageName = rs.getApplicationContext().getPackageResourcePath();
// For res/raw/fountain.bc, it wil be /com.android.fountain:raw/fountain
String resName = resources.getResourceEntryName(resourceID);
String cacheDir = rs.getApplicationContext().getCacheDir().toString();
Log.v(TAG, "Create script for resource = " + resName);
return rs.nScriptCCreate(resName, cacheDir, pgm, pgmLength);
return rs.nScriptCCreate(resName, rs.mCachePath, pgm, pgmLength);
}
}