Merge "USAGE_IO_INPUT buffer notifications" into jb-mr2-dev
This commit is contained in:
@ -19727,6 +19727,7 @@ package android.renderscript {
|
||||
method public deprecated synchronized void resize(int);
|
||||
method public void setFromFieldPacker(int, android.renderscript.FieldPacker);
|
||||
method public void setFromFieldPacker(int, int, android.renderscript.FieldPacker);
|
||||
method public void setIoInputNotificationHandler(android.renderscript.Allocation.IoInputNotifier);
|
||||
method public void setSurface(android.view.Surface);
|
||||
method public void syncAll(int);
|
||||
field public static final int USAGE_GRAPHICS_CONSTANTS = 8; // 0x8
|
||||
@ -19739,6 +19740,10 @@ package android.renderscript {
|
||||
field public static final int USAGE_SHARED = 128; // 0x80
|
||||
}
|
||||
|
||||
public static abstract interface Allocation.IoInputNotifier {
|
||||
method public abstract void onBufferAvailable(android.renderscript.Allocation);
|
||||
}
|
||||
|
||||
public static final class Allocation.MipmapControl extends java.lang.Enum {
|
||||
method public static android.renderscript.Allocation.MipmapControl valueOf(java.lang.String);
|
||||
method public static final android.renderscript.Allocation.MipmapControl[] values();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -966,6 +966,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;
|
||||
|
||||
@ -1025,6 +1026,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
|
||||
|
Reference in New Issue
Block a user