summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2011-01-17 15:48:00 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-17 15:48:00 -0800
commit3240339cfe25b95c04871bb78b09d666ad0e7010 (patch)
tree7e96d6e2c48ed83e4cb5f3791d20e9e1b0cfd8cc /graphics/java
parent2fd90e92ee0731fd77c2b113706c07083b9673ec (diff)
parentb97b251c26b801b26f2630e3a2e3f93e4088f2c5 (diff)
downloadframeworks_base-3240339cfe25b95c04871bb78b09d666ad0e7010.zip
frameworks_base-3240339cfe25b95c04871bb78b09d666ad0e7010.tar.gz
frameworks_base-3240339cfe25b95c04871bb78b09d666ad0e7010.tar.bz2
Merge "Add error checks to the copyFrom functions." into honeycomb
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/renderscript/Allocation.java83
-rw-r--r--graphics/java/android/renderscript/Mesh.java4
-rw-r--r--graphics/java/android/renderscript/ProgramFragmentFixedFunction.java7
-rw-r--r--graphics/java/android/renderscript/ProgramVertexFixedFunction.java2
4 files changed, 85 insertions, 11 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 852aabf..1789891 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -121,6 +121,58 @@ public class Allocation extends BaseObj {
mType = t;
}
+ private void validateIsInt32() {
+ if ((mType.mElement.mType == Element.DataType.SIGNED_32) ||
+ (mType.mElement.mType == Element.DataType.UNSIGNED_32)) {
+ return;
+ }
+ throw new RSIllegalArgumentException(
+ "32 bit integer source does not match allocation type " + mType.mElement.mType);
+ }
+
+ private void validateIsInt16() {
+ if ((mType.mElement.mType == Element.DataType.SIGNED_16) ||
+ (mType.mElement.mType == Element.DataType.UNSIGNED_16)) {
+ return;
+ }
+ throw new RSIllegalArgumentException(
+ "16 bit integer source does not match allocation type " + mType.mElement.mType);
+ }
+
+ private void validateIsInt8() {
+ if ((mType.mElement.mType == Element.DataType.SIGNED_8) ||
+ (mType.mElement.mType == Element.DataType.UNSIGNED_8)) {
+ return;
+ }
+ throw new RSIllegalArgumentException(
+ "8 bit integer source does not match allocation type " + mType.mElement.mType);
+ }
+
+ private void validateIsFloat32() {
+ if (mType.mElement.mType == Element.DataType.FLOAT_32) {
+ return;
+ }
+ throw new RSIllegalArgumentException(
+ "32 bit float source does not match allocation type " + mType.mElement.mType);
+ }
+
+ private void validateIsObject() {
+ if ((mType.mElement.mType == Element.DataType.RS_ELEMENT) ||
+ (mType.mElement.mType == Element.DataType.RS_TYPE) ||
+ (mType.mElement.mType == Element.DataType.RS_ALLOCATION) ||
+ (mType.mElement.mType == Element.DataType.RS_SAMPLER) ||
+ (mType.mElement.mType == Element.DataType.RS_SCRIPT) ||
+ (mType.mElement.mType == Element.DataType.RS_MESH) ||
+ (mType.mElement.mType == Element.DataType.RS_PROGRAM_FRAGMENT) ||
+ (mType.mElement.mType == Element.DataType.RS_PROGRAM_VERTEX) ||
+ (mType.mElement.mType == Element.DataType.RS_PROGRAM_RASTER) ||
+ (mType.mElement.mType == Element.DataType.RS_PROGRAM_STORE)) {
+ return;
+ }
+ throw new RSIllegalArgumentException(
+ "Object source does not match allocation type " + mType.mElement.mType);
+ }
+
@Override
void updateFromNative() {
super.updateFromNative();
@@ -151,6 +203,7 @@ public class Allocation extends BaseObj {
public void copyFrom(BaseObj[] d) {
mRS.validate();
+ validateIsObject();
if (d.length != mType.getCount()) {
throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
mType.getCount() + ", array length = " + d.length);
@@ -258,7 +311,6 @@ public class Allocation extends BaseObj {
mRS.nAllocationData1D(getID(), xoff, 0, count, data, data.length);
}
-
/**
* This is only intended to be used by auto-generate code reflected from the
* renderscript script files.
@@ -317,27 +369,44 @@ public class Allocation extends BaseObj {
mRS.nAllocationGenerateMipmaps(getID());
}
- public void copy1DRangeFrom(int off, int count, int[] d) {
+ void copy1DRangeFromUnchecked(int off, int count, int[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length * 4, dataSize);
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
}
- public void copy1DRangeFrom(int off, int count, short[] d) {
+ void copy1DRangeFromUnchecked(int off, int count, short[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length * 2, dataSize);
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
}
- public void copy1DRangeFrom(int off, int count, byte[] d) {
+ void copy1DRangeFromUnchecked(int off, int count, byte[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length, dataSize);
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
}
- public void copy1DRangeFrom(int off, int count, float[] d) {
+ void copy1DRangeFromUnchecked(int off, int count, float[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length * 4, dataSize);
mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
}
+ public void copy1DRangeFrom(int off, int count, int[] d) {
+ validateIsInt32();
+ copy1DRangeFromUnchecked(off, count, d);
+ }
+ public void copy1DRangeFrom(int off, int count, short[] d) {
+ validateIsInt16();
+ copy1DRangeFromUnchecked(off, count, d);
+ }
+ public void copy1DRangeFrom(int off, int count, byte[] d) {
+ validateIsInt8();
+ copy1DRangeFromUnchecked(off, count, d);
+ }
+ public void copy1DRangeFrom(int off, int count, float[] d) {
+ validateIsFloat32();
+ copy1DRangeFromUnchecked(off, count, d);
+ }
+
private void validate2DRange(int xoff, int yoff, int w, int h) {
if (xoff < 0 || yoff < 0) {
throw new RSIllegalArgumentException("Offset cannot be negative.");
@@ -411,21 +480,25 @@ public class Allocation extends BaseObj {
}
public void copyTo(byte[] d) {
+ validateIsInt8();
mRS.validate();
mRS.nAllocationRead(getID(), d);
}
public void copyTo(short[] d) {
+ validateIsInt16();
mRS.validate();
mRS.nAllocationRead(getID(), d);
}
public void copyTo(int[] d) {
+ validateIsInt32();
mRS.validate();
mRS.nAllocationRead(getID(), d);
}
public void copyTo(float[] d) {
+ validateIsFloat32();
mRS.validate();
mRS.nAllocationRead(getID(), d);
}
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
index fcf8178..c20151e 100644
--- a/graphics/java/android/renderscript/Mesh.java
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -733,14 +733,14 @@ public class Mesh extends BaseObj {
Mesh sm = smb.create();
- sm.getVertexAllocation(0).copyFrom(mVtxData);
+ sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mVtxCount / floatCount, mVtxData);
if(uploadToBufferObject) {
if (uploadToBufferObject) {
sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
}
}
- sm.getIndexSetAllocation(0).copyFrom(mIndexData);
+ sm.getIndexSetAllocation(0).copy1DRangeFromUnchecked(0, mIndexCount, mIndexData);
if (uploadToBufferObject) {
sm.getIndexSetAllocation(0).syncAll(Allocation.USAGE_SCRIPT);
}
diff --git a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
index 1af31f8..666a3e6 100644
--- a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
+++ b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
@@ -280,9 +280,10 @@ public class ProgramFragmentFixedFunction extends ProgramFragment {
pf.mTextureCount = MAX_TEXTURE;
if (!mVaryingColorEnable) {
Allocation constantData = Allocation.createTyped(mRS,constType);
- float[] data = new float[4];
- data[0] = data[1] = data[2] = data[3] = 1.0f;
- constantData.copyFrom(data);
+ FieldPacker fp = new FieldPacker(16);
+ Float4 f4 = new Float4(1.f, 1.f, 1.f, 1.f);
+ fp.addF32(f4);
+ constantData.setFromFieldPacker(0, fp);
pf.bindConstants(constantData, 0);
}
return pf;
diff --git a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
index 666c7ec..556964a 100644
--- a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
+++ b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
@@ -229,7 +229,7 @@ public class ProgramVertexFixedFunction extends ProgramVertex {
for(int i = 0; i < 16; i ++) {
mIOBuffer.addF32(m.mMat[i]);
}
- mAlloc.copyFrom(mIOBuffer.getData());
+ mAlloc.setFromFieldPacker(0, mIOBuffer);
}
/**