summaryrefslogtreecommitdiffstats
path: root/graphics/java/android/renderscript/Allocation.java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java/android/renderscript/Allocation.java')
-rw-r--r--graphics/java/android/renderscript/Allocation.java66
1 files changed, 53 insertions, 13 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 5751331..5d1990a 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;
/**
@@ -274,20 +278,12 @@ 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() {
@@ -370,11 +366,20 @@ public class Allocation extends BaseObj {
*/
public void syncAll(int srcLocation) {
switch (srcLocation) {
+ case USAGE_GRAPHICS_TEXTURE:
case USAGE_SCRIPT:
+ if ((mUsage & USAGE_SHARED) != 0) {
+ copyFrom(mBitmap);
+ }
+ break;
case USAGE_GRAPHICS_CONSTANTS:
- case USAGE_GRAPHICS_TEXTURE:
case USAGE_GRAPHICS_VERTEX:
break;
+ case USAGE_SHARED:
+ if ((mUsage & USAGE_SHARED) != 0) {
+ copyTo(mBitmap);
+ }
+ break;
default:
throw new RSIllegalArgumentException("Source must be exactly one usage type.");
}
@@ -1245,7 +1250,6 @@ 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.");
@@ -1383,7 +1387,7 @@ public class Allocation extends BaseObj {
// enable optimized bitmap path only with no mipmap and script-only usage
if (mips == MipmapControl.MIPMAP_NONE &&
t.getElement().isCompatible(Element.RGBA_8888(rs)) &&
- usage == (USAGE_SHARED | USAGE_SCRIPT)) {
+ usage == (USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE)) {
int id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage);
if (id == 0) {
throw new RSRuntimeException("Load failed.");
@@ -1395,6 +1399,7 @@ 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.");
@@ -1454,7 +1459,7 @@ public class Allocation extends BaseObj {
static public Allocation createFromBitmap(RenderScript rs, Bitmap b) {
if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) {
return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
- USAGE_SHARED | USAGE_SCRIPT);
+ USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE);
}
return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
USAGE_GRAPHICS_TEXTURE);
@@ -1672,7 +1677,7 @@ public class Allocation extends BaseObj {
if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) {
return createFromBitmapResource(rs, res, id,
MipmapControl.MIPMAP_NONE,
- USAGE_SHARED | USAGE_SCRIPT);
+ USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE);
}
return createFromBitmapResource(rs, res, id,
MipmapControl.MIPMAP_NONE,
@@ -1704,6 +1709,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 callback 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);
+ }
+ }
+ }
+
}