Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6f338ca authored by Jason Sams's avatar Jason Sams
Browse files

Do RS caching the same way HardwareRenderer does.

Eliminates the need for an application context for caching.

Change-Id: I4374738083b5eb4ce983d2cb5409428e3668c423
parent 9733f260
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+21 −0
Original line number Diff line number Diff line
@@ -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.
+1 −5
Original line number Diff line number Diff line
@@ -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);
    }
}