summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/Allocation.java
diff options
context:
space:
mode:
authorJason Sams <jsams@google.com>2013-04-12 02:20:10 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-04-12 02:20:11 +0000
commita2f289a40db821c1961e16c2f4acc5785dbb3394 (patch)
tree78f96aa3d8b4a513d9a2df7757389324022420f5 /graphics/java/android/renderscript/Allocation.java
parent5adae45addad702de4393a68b6236b1d528c58d6 (diff)
parent739c8263a10d34f5acba7fce2052012d1545d10b (diff)
Merge "USAGE_IO_INPUT buffer notifications" into jb-mr2-dev
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 eb0c164af112..acf3ebb872b7 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;
/**
@@ -1713,6 +1717,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);
+ }
+ }
+ }
+
}