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.java63
1 files changed, 55 insertions, 8 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index b27c7f5..6775c08 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -35,11 +35,25 @@ public class Allocation extends BaseObj {
Bitmap mBitmap;
Allocation(int id, RenderScript rs, Type t) {
- super(rs);
- mID = id;
+ super(id, rs);
mType = t;
}
+ Allocation(int id, RenderScript rs) {
+ super(id, rs);
+ }
+
+ @Override
+ void updateFromNative() {
+ mRS.validate();
+ mName = mRS.nGetName(mID);
+ int typeID = mRS.nAllocationGetType(mID);
+ if(typeID != 0) {
+ mType = new Type(typeID, mRS);
+ mType.updateFromNative();
+ }
+ }
+
public Type getType() {
return mType;
}
@@ -76,10 +90,30 @@ public class Allocation extends BaseObj {
subData1D(0, mType.getElementCount(), d);
}
+ public void subData(int off, FieldPacker fp) {
+ int eSize = mType.mElement.getSizeBytes();
+ final byte[] data = fp.getData();
+
+ int count = data.length / eSize;
+ if ((eSize * count) != data.length) {
+ throw new IllegalArgumentException("Field packer length " + data.length +
+ " not divisible by element size " + eSize + ".");
+ }
+ data1DChecks(off, count, data.length, data.length);
+ mRS.nAllocationSubData1D(mID, off, count, data, data.length);
+ }
+
private void data1DChecks(int off, int count, int len, int dataSize) {
mRS.validate();
- if((off < 0) || (count < 1) || ((off + count) > mType.getElementCount())) {
- throw new IllegalArgumentException("Offset or Count out of bounds.");
+ if(off < 0) {
+ throw new IllegalArgumentException("Offset must be >= 0.");
+ }
+ if(count < 1) {
+ throw new IllegalArgumentException("Count must be >= 1.");
+ }
+ if((off + count) > mType.getElementCount()) {
+ throw new IllegalArgumentException("Overflow, Available count " + mType.getElementCount() +
+ ", got " + count + " at offset " + off + ".");
}
if((len) < dataSize) {
throw new IllegalArgumentException("Array too small for allocation type.");
@@ -146,8 +180,7 @@ public class Allocation extends BaseObj {
public class Adapter1D extends BaseObj {
Adapter1D(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
public void setConstraint(Dimension dim, int value) {
@@ -189,8 +222,7 @@ public class Allocation extends BaseObj {
public class Adapter2D extends BaseObj {
Adapter2D(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
public void setConstraint(Dimension dim, int value) {
@@ -377,6 +409,21 @@ public class Allocation extends BaseObj {
Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions);
return createFromBitmapBoxed(rs, b, dstFmt, genMips);
}
+
+ static public Allocation createFromString(RenderScript rs, String str)
+ throws IllegalArgumentException {
+ byte[] allocArray = null;
+ try {
+ allocArray = str.getBytes("UTF-8");
+ Allocation alloc = Allocation.createSized(rs, Element.U8(rs), allocArray.length);
+ alloc.data(allocArray);
+ return alloc;
+ }
+ catch (Exception e) {
+ Log.e("rs", "could not convert string to utf-8");
+ }
+ return null;
+ }
}