diff options
Diffstat (limited to 'graphics/java/android/renderscript/RenderScript.java')
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 103 |
1 files changed, 86 insertions, 17 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 656487f585b6..49192f79ec1c 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -18,7 +18,9 @@ package android.renderscript; import java.io.File; import java.lang.reflect.Field; +import java.util.concurrent.locks.*; +import android.app.ActivityManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -105,9 +107,29 @@ public class RenderScript { 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; @@ -588,31 +610,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, @@ -893,7 +943,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 @@ -974,6 +1025,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; @@ -1033,6 +1085,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 @@ -1050,8 +1107,11 @@ public class RenderScript { RenderScript mRS; boolean mRun = true; - int currentSize = 0; - final static int targetSize = 256*1024*1024; // call System.gc after 256MB of allocs + long currentSize = 0; + long targetSize; // call System.gc after 512MB of allocs + + final Lock lock = new ReentrantLock(); + final Condition cond = lock.newCondition(); GCThread(RenderScript rs) { super("RSGCThread"); @@ -1060,29 +1120,37 @@ public class RenderScript { } public void run() { + ActivityManager am = (ActivityManager)mRS.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); + ActivityManager.MemoryInfo meminfo = new ActivityManager.MemoryInfo(); + am.getMemoryInfo(meminfo); + targetSize = (long)(meminfo.totalMem * .5f); + while(mRun) { - boolean doGC = false; - synchronized(this) { - if (currentSize >= targetSize) { - doGC = true; - } - } - if (doGC == true) { - System.gc(); - } + System.gc(); + lock.lock(); try { - sleep(1, 0); - } catch(InterruptedException e) { + cond.awaitUninterruptibly(); + } finally { + lock.unlock(); } } + Log.d(LOG_TAG, "GCThread exiting."); } - public synchronized void addAllocSize(int bytes) { + public synchronized void addAllocSize(long bytes) { currentSize += bytes; + if (currentSize >= targetSize) { + lock.lock(); + try { + cond.signal(); + } finally { + lock.unlock(); + } + } } - public synchronized void removeAllocSize(int bytes) { + public synchronized void removeAllocSize(long bytes) { currentSize -= bytes; } @@ -1160,9 +1228,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) { @@ -1199,6 +1267,7 @@ public class RenderScript { nContextDeinitToClient(mContext); mMessageThread.mRun = false; mGCThread.mRun = false; + mGCThread.addAllocSize(0); try { mMessageThread.join(); mGCThread.join(); |