summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/Allocation.java
diff options
context:
space:
mode:
authorJason Sams <jsams@google.com>2013-04-11 18:07:52 -0700
committerJason Sams <jsams@google.com>2013-04-11 18:14:26 -0700
commit739c8263a10d34f5acba7fce2052012d1545d10b (patch)
tree454a3ae0a166bf36ed1a48ef8e2be4d4dcec9e78 /graphics/java/android/renderscript/Allocation.java
parent0cb19909211cefc5874c0bcb02335d7b0e988328 (diff)
USAGE_IO_INPUT buffer notifications
Change-Id: I6ec0508089029da9ed118127f0c13b7b189ef5e9
Diffstat (limited to 'graphics/java/android/renderscript/Allocation.java')
-rw-r--r--graphics/java/android/renderscript/Allocation.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 575133146008..2f027a421ff2 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -18,6 +18,7 @@ package android.renderscript;
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
import android.content.res.Resources;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
@@ -92,6 +93,9 @@ public class Allocation extends BaseObj {
int mCurrentDimY;
int mCurrentDimZ;
int mCurrentCount;
+ static HashMap<Integer, Allocation> mAllocationMap =
+ new HashMap<Integer, Allocation>();
+ IoInputNotifier mBufferNotifier;
/**
@@ -1704,6 +1708,41 @@ public class Allocation extends BaseObj {
throw new RSRuntimeException("Could not convert string to utf-8.");
}
}
+
+ /**
+ * Interface to handle notification when new buffers are
+ * available via USAGE_IO_INPUT. An application will receive
+ * one notification when a buffer is available. Additional
+ * buffers will not trigger new notifications until a buffer is
+ * processed.
+ */
+ public interface IoInputNotifier {
+ public void onBufferAvailable(Allocation a);
+ }
+
+ /**
+ * Set a notification handler for USAGE_IO_INPUT
+ *
+ * @param instance of the IoInputNotifier class to be called
+ * when buffer arrive.
+ */
+ public void setIoInputNotificationHandler(IoInputNotifier callback) {
+ synchronized(mAllocationMap) {
+ mAllocationMap.put(new Integer(getID(mRS)), this);
+ mBufferNotifier = callback;
+ }
+ }
+
+ static void sendBufferNotification(int id) {
+ synchronized(mAllocationMap) {
+ Allocation a = mAllocationMap.get(new Integer(id));
+
+ if ((a != null) && (a.mBufferNotifier != null)) {
+ a.mBufferNotifier.onBufferAvailable(a);
+ }
+ }
+ }
+
}