diff options
Diffstat (limited to 'graphics/java/android/renderscript/RenderScript.java')
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 128 |
1 files changed, 60 insertions, 68 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 2438532..6f614c3 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -83,11 +83,7 @@ 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"; - static String mCachePath; + static File mCacheDir; /** * Sets the directory to use as a persistent storage for the @@ -97,14 +93,33 @@ public class RenderScript { * @param cacheDir A directory the current process can write to */ public static void setupDiskCache(File cacheDir) { - File f = new File(cacheDir, CACHE_PATH); - mCachePath = f.getAbsolutePath(); - f.mkdirs(); + // Defer creation of cache path to nScriptCCreate(). + mCacheDir = cacheDir; } + /** + * ContextType specifies the specific type of context to be created. + * + */ public enum ContextType { + /** + * NORMAL context, this is the default and what shipping apps should + * use. + */ NORMAL (0), + + /** + * DEBUG context, perform extra runtime checks to validate the + * kernels and APIs are being used as intended. Get and SetElementAt + * will be bounds checked in this mode. + */ DEBUG (1), + + /** + * PROFILE context, Intended to be used once the first time an + * application is run on a new device. This mode allows the runtime to + * do additional testing and performance tuning. + */ PROFILE (2); int mID; @@ -585,31 +600,59 @@ public class RenderScript { validate(); rsnScriptInvokeV(mContext, id, slot, params); } + native void rsnScriptSetVarI(int con, int id, int slot, int val); synchronized void nScriptSetVarI(int id, int slot, int val) { validate(); rsnScriptSetVarI(mContext, id, slot, val); } + native int rsnScriptGetVarI(int con, int id, int slot); + synchronized int nScriptGetVarI(int id, int slot) { + validate(); + return rsnScriptGetVarI(mContext, id, slot); + } + native void rsnScriptSetVarJ(int con, int id, int slot, long val); synchronized void nScriptSetVarJ(int id, int slot, long val) { validate(); rsnScriptSetVarJ(mContext, id, slot, val); } + native long rsnScriptGetVarJ(int con, int id, int slot); + synchronized long nScriptGetVarJ(int id, int slot) { + validate(); + return rsnScriptGetVarJ(mContext, id, slot); + } + native void rsnScriptSetVarF(int con, int id, int slot, float val); synchronized void nScriptSetVarF(int id, int slot, float val) { validate(); rsnScriptSetVarF(mContext, id, slot, val); } + native float rsnScriptGetVarF(int con, int id, int slot); + synchronized float nScriptGetVarF(int id, int slot) { + validate(); + return rsnScriptGetVarF(mContext, id, slot); + } native void rsnScriptSetVarD(int con, int id, int slot, double val); synchronized void nScriptSetVarD(int id, int slot, double val) { validate(); rsnScriptSetVarD(mContext, id, slot, val); } + native double rsnScriptGetVarD(int con, int id, int slot); + synchronized double nScriptGetVarD(int id, int slot) { + validate(); + return rsnScriptGetVarD(mContext, id, slot); + } native void rsnScriptSetVarV(int con, int id, int slot, byte[] val); synchronized void nScriptSetVarV(int id, int slot, byte[] val) { validate(); rsnScriptSetVarV(mContext, id, slot, val); } + native void rsnScriptGetVarV(int con, int id, int slot, byte[] val); + synchronized void nScriptGetVarV(int id, int slot, byte[] val) { + validate(); + rsnScriptGetVarV(mContext, id, slot, val); + } native void rsnScriptSetVarVE(int con, int id, int slot, byte[] val, int e, int[] dims); synchronized void nScriptSetVarVE(int id, int slot, byte[] val, @@ -759,8 +802,6 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; - GCThread mGCThread; - Element mElement_U8; Element mElement_I8; @@ -890,7 +931,8 @@ public class RenderScript { } /** - * @hide + * Place a message into the message queue to be sent back to the message + * handler once all previous commands have been executed. * * @param id * @param data @@ -971,6 +1013,7 @@ public class RenderScript { static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; static final int RS_MESSAGE_TO_CLIENT_USER = 4; + static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5; static final int RS_ERROR_FATAL_UNKNOWN = 0x1000; @@ -1030,6 +1073,11 @@ public class RenderScript { continue; } + if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) { + Allocation.sendBufferNotification(subID); + continue; + } + // 2: teardown. // But we want to avoid starving other threads during // teardown by yielding until the next line in the destructor @@ -1043,49 +1091,6 @@ public class RenderScript { } } - static class GCThread extends Thread { - RenderScript mRS; - boolean mRun = true; - - int currentSize = 0; - final static int targetSize = 256*1024*1024; // call System.gc after 256MB of allocs - - GCThread(RenderScript rs) { - super("RSGCThread"); - mRS = rs; - - } - - public void run() { - while(mRun) { - boolean doGC = false; - synchronized(this) { - if (currentSize >= targetSize) { - doGC = true; - } - } - if (doGC == true) { - System.gc(); - } - try { - sleep(1, 0); - } catch(InterruptedException e) { - } - } - Log.d(LOG_TAG, "GCThread exiting."); - } - - public synchronized void addAllocSize(int bytes) { - currentSize += bytes; - } - - public synchronized void removeAllocSize(int bytes) { - currentSize -= bytes; - } - - } - - RenderScript(Context ctx) { if (ctx != null) { mApplicationContext = ctx.getApplicationContext(); @@ -1108,15 +1113,6 @@ public class RenderScript { return create(ctx, sdkVersion, ContextType.NORMAL); } - void addAllocSizeForGC(int bytes) { - mGCThread.addAllocSize(bytes); - } - - void removeAllocSizeForGC(int bytes) { - mGCThread.removeAllocSize(bytes); - } - - /** * Create a basic RenderScript context. * @@ -1133,9 +1129,7 @@ public class RenderScript { throw new RSDriverException("Failed to create RS context."); } rs.mMessageThread = new MessageThread(rs); - rs.mGCThread = new GCThread(rs); rs.mMessageThread.start(); - rs.mGCThread.start(); return rs; } @@ -1152,9 +1146,9 @@ public class RenderScript { /** * Create a basic RenderScript context. * - * @hide * * @param ctx The context. + * @param ct The type of context to be created. * @return RenderScript */ public static RenderScript create(Context ctx, ContextType ct) { @@ -1190,10 +1184,8 @@ public class RenderScript { validate(); nContextDeinitToClient(mContext); mMessageThread.mRun = false; - mGCThread.mRun = false; try { mMessageThread.join(); - mGCThread.join(); } catch(InterruptedException e) { } |