diff options
Diffstat (limited to 'graphics/java/android/renderscript/RenderScript.java')
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 120 |
1 files changed, 107 insertions, 13 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index bef28aa89709..d87ca32fdc52 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,9 +93,8 @@ 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; } public enum ContextType { @@ -420,6 +415,46 @@ public class RenderScript { rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b); } + native void rsnAllocationData3D(int con, + int dstAlloc, int dstXoff, int dstYoff, int dstZoff, + int dstMip, + int width, int height, int depth, + int srcAlloc, int srcXoff, int srcYoff, int srcZoff, + int srcMip); + synchronized void nAllocationData3D(int dstAlloc, int dstXoff, int dstYoff, int dstZoff, + int dstMip, + int width, int height, int depth, + int srcAlloc, int srcXoff, int srcYoff, int srcZoff, + int srcMip) { + validate(); + rsnAllocationData3D(mContext, + dstAlloc, dstXoff, dstYoff, dstZoff, + dstMip, width, height, depth, + srcAlloc, srcXoff, srcYoff, srcZoff, srcMip); + } + + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + + native void rsnAllocationRead(int con, int id, byte[] d); synchronized void nAllocationRead(int id, byte[] d) { validate(); @@ -451,11 +486,6 @@ public class RenderScript { validate(); rsnAllocationResize1D(mContext, id, dimX); } - native void rsnAllocationResize2D(int con, int id, int dimX, int dimY); - synchronized void nAllocationResize2D(int id, int dimX, int dimY) { - validate(); - rsnAllocationResize2D(mContext, id, dimX, dimY); - } native int rsnFileA3DCreateFromAssetStream(int con, int assetStream); synchronized int nFileA3DCreateFromAssetStream(int assetStream) { @@ -724,6 +754,8 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; + GCThread mGCThread; + Element mElement_U8; Element mElement_I8; @@ -934,6 +966,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; @@ -993,6 +1026,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 @@ -1006,6 +1044,49 @@ 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(); @@ -1028,6 +1109,15 @@ 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. * @@ -1044,7 +1134,9 @@ 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; } @@ -1099,8 +1191,10 @@ public class RenderScript { validate(); nContextDeinitToClient(mContext); mMessageThread.mRun = false; + mGCThread.mRun = false; try { mMessageThread.join(); + mGCThread.join(); } catch(InterruptedException e) { } |