diff options
Diffstat (limited to 'graphics/java/android/renderscript/RenderScript.java')
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 103 |
1 files changed, 98 insertions, 5 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index bef28aa89709..2438532c98dd 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -420,6 +420,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 +491,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 +759,8 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; + GCThread mGCThread; + Element mElement_U8; Element mElement_I8; @@ -1006,6 +1043,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 +1108,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 +1133,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 +1190,10 @@ public class RenderScript { validate(); nContextDeinitToClient(mContext); mMessageThread.mRun = false; + mGCThread.mRun = false; try { mMessageThread.join(); + mGCThread.join(); } catch(InterruptedException e) { } |