From 689f63770048589e1001ce99faf1d2eaf9780a80 Mon Sep 17 00:00:00 2001 From: Yang Ni Date: Thu, 10 Mar 2016 16:12:31 -0800 Subject: 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 --- rs/java/android/renderscript/RenderScript.java | 27 +++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'rs/java/android/renderscript/RenderScript.java') diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java index 425569cd8fa1..9beaba301072 100644 --- a/rs/java/android/renderscript/RenderScript.java +++ b/rs/java/android/renderscript/RenderScript.java @@ -1386,6 +1386,27 @@ public class RenderScript { return mApplicationContext; } + /** + * Name of the file that holds the object cache. + */ + private static String mCachePath; + + /** + * Gets the path to the code cache. + */ + static synchronized String getCachePath() { + if (mCachePath == null) { + final String CACHE_PATH = "com.android.renderscript.cache"; + if (RenderScriptCacheDir.mCacheDir == null) { + throw new RSRuntimeException("RenderScript code cache directory uninitialized."); + } + File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH); + mCachePath = f.getAbsolutePath(); + f.mkdirs(); + } + return mCachePath; + } + /** * Create a RenderScript context. * @@ -1415,11 +1436,7 @@ public class RenderScript { } // set up cache directory for entire context - final String CACHE_PATH = "com.android.renderscript.cache"; - File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH); - String mCachePath = f.getAbsolutePath(); - f.mkdirs(); - rs.nContextSetCacheDir(mCachePath); + rs.nContextSetCacheDir(RenderScript.getCachePath()); rs.mMessageThread = new MessageThread(rs); rs.mMessageThread.start(); -- cgit v1.2.3