Loading graphics/java/android/renderscript/Allocation.java +9 −1 Original line number Diff line number Diff line Loading @@ -274,12 +274,20 @@ public class Allocation extends BaseObj { } } // don't need to account for USAGE_SHARED Allocations if ((usage & USAGE_SHARED) == 0) { int numBytes = t.getCount() * t.getElement().getBytesSize(); rs.addAllocSizeForGC(numBytes); mGCSize = numBytes; } mType = t; mUsage = usage; if (t != null) { updateCacheInfo(t); } } private void validateIsInt32() { Loading Loading @@ -1235,6 +1243,7 @@ public class Allocation extends BaseObj { if (type.getID(rs) == 0) { throw new RSInvalidStateException("Bad Type"); } int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); Loading Loading @@ -1384,7 +1393,6 @@ public class Allocation extends BaseObj { return alloc; } int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); Loading graphics/java/android/renderscript/BaseObj.java +6 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,9 @@ public class BaseObj { private int mID; private boolean mDestroyed; private String mName; int mGCSize; RenderScript mRS; /** Loading Loading @@ -135,6 +138,9 @@ public class BaseObj { throw new RSInvalidStateException("Object already destroyed."); } mDestroyed = true; if (mGCSize != 0) { mRS.removeAllocSizeForGC(mGCSize); } mRS.nObjDestroy(mID); } Loading graphics/java/android/renderscript/RenderScript.java +58 −0 Original line number Diff line number Diff line Loading @@ -759,6 +759,8 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; GCThread mGCThread; Element mElement_U8; Element mElement_I8; Loading Loading @@ -1041,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(); Loading @@ -1063,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. * Loading @@ -1079,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; } Loading Loading @@ -1134,8 +1190,10 @@ public class RenderScript { validate(); nContextDeinitToClient(mContext); mMessageThread.mRun = false; mGCThread.mRun = false; try { mMessageThread.join(); mGCThread.join(); } catch(InterruptedException e) { } Loading graphics/java/android/renderscript/ScriptC.java +2 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,8 @@ public class ScriptC extends Script { throw new RSRuntimeException("Loading of ScriptC script failed."); } setID(id); mGCSize = 2 * 1024 * 1024; rs.addAllocSizeForGC(mGCSize); } Loading Loading
graphics/java/android/renderscript/Allocation.java +9 −1 Original line number Diff line number Diff line Loading @@ -274,12 +274,20 @@ public class Allocation extends BaseObj { } } // don't need to account for USAGE_SHARED Allocations if ((usage & USAGE_SHARED) == 0) { int numBytes = t.getCount() * t.getElement().getBytesSize(); rs.addAllocSizeForGC(numBytes); mGCSize = numBytes; } mType = t; mUsage = usage; if (t != null) { updateCacheInfo(t); } } private void validateIsInt32() { Loading Loading @@ -1235,6 +1243,7 @@ public class Allocation extends BaseObj { if (type.getID(rs) == 0) { throw new RSInvalidStateException("Bad Type"); } int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); Loading Loading @@ -1384,7 +1393,6 @@ public class Allocation extends BaseObj { return alloc; } int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); Loading
graphics/java/android/renderscript/BaseObj.java +6 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,9 @@ public class BaseObj { private int mID; private boolean mDestroyed; private String mName; int mGCSize; RenderScript mRS; /** Loading Loading @@ -135,6 +138,9 @@ public class BaseObj { throw new RSInvalidStateException("Object already destroyed."); } mDestroyed = true; if (mGCSize != 0) { mRS.removeAllocSizeForGC(mGCSize); } mRS.nObjDestroy(mID); } Loading
graphics/java/android/renderscript/RenderScript.java +58 −0 Original line number Diff line number Diff line Loading @@ -759,6 +759,8 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; GCThread mGCThread; Element mElement_U8; Element mElement_I8; Loading Loading @@ -1041,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(); Loading @@ -1063,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. * Loading @@ -1079,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; } Loading Loading @@ -1134,8 +1190,10 @@ public class RenderScript { validate(); nContextDeinitToClient(mContext); mMessageThread.mRun = false; mGCThread.mRun = false; try { mMessageThread.join(); mGCThread.join(); } catch(InterruptedException e) { } Loading
graphics/java/android/renderscript/ScriptC.java +2 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,8 @@ public class ScriptC extends Script { throw new RSRuntimeException("Loading of ScriptC script failed."); } setID(id); mGCSize = 2 * 1024 * 1024; rs.addAllocSizeForGC(mGCSize); } Loading