summaryrefslogtreecommitdiffstats
path: root/graphics/java/android/renderscript
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java/android/renderscript')
-rw-r--r--graphics/java/android/renderscript/Allocation.java124
-rw-r--r--graphics/java/android/renderscript/AllocationAdapter.java323
-rw-r--r--graphics/java/android/renderscript/ScriptC.java2
3 files changed, 215 insertions, 234 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index e900584..6254192 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -67,6 +67,22 @@ public class Allocation extends BaseObj {
Type mType;
Bitmap mBitmap;
int mUsage;
+ Allocation mAdaptedAllocation;
+
+ boolean mConstrainedLOD;
+ boolean mConstrainedFace;
+ boolean mConstrainedY;
+ boolean mConstrainedZ;
+ int mSelectedY;
+ int mSelectedZ;
+ int mSelectedLOD;
+ Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITIVE_X;
+
+ int mCurrentDimX;
+ int mCurrentDimY;
+ int mCurrentDimZ;
+ int mCurrentCount;
+
/**
* The usage of the allocation. These signal to renderscript
@@ -139,6 +155,19 @@ public class Allocation extends BaseObj {
}
}
+ private void updateCacheInfo(Type t) {
+ mCurrentDimX = t.getX();
+ mCurrentDimY = t.getY();
+ mCurrentDimZ = t.getZ();
+ mCurrentCount = mCurrentDimX;
+ if (mCurrentDimY > 1) {
+ mCurrentCount *= mCurrentDimY;
+ }
+ if (mCurrentDimZ > 1) {
+ mCurrentCount *= mCurrentDimZ;
+ }
+ }
+
Allocation(int id, RenderScript rs, Type t, int usage) {
super(id, rs);
if ((usage & ~(USAGE_SCRIPT |
@@ -149,6 +178,10 @@ public class Allocation extends BaseObj {
throw new RSIllegalArgumentException("Unknown usage specified.");
}
mType = t;
+
+ if (t != null) {
+ updateCacheInfo(t);
+ }
}
private void validateIsInt32() {
@@ -210,6 +243,7 @@ public class Allocation extends BaseObj {
if(typeID != 0) {
mType = new Type(typeID, mRS);
mType.updateFromNative();
+ updateCacheInfo(mType);
}
}
@@ -234,15 +268,15 @@ public class Allocation extends BaseObj {
public void copyFrom(BaseObj[] d) {
mRS.validate();
validateIsObject();
- if (d.length != mType.getCount()) {
+ if (d.length != mCurrentCount) {
throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
- mType.getCount() + ", array length = " + d.length);
+ mCurrentCount + ", array length = " + d.length);
}
int i[] = new int[d.length];
for (int ct=0; ct < d.length; ct++) {
i[ct] = d[ct].getID();
}
- copy1DRangeFromUnchecked(0, mType.getCount(), i);
+ copy1DRangeFromUnchecked(0, mCurrentCount, i);
}
private void validateBitmapFormat(Bitmap b) {
@@ -292,8 +326,7 @@ public class Allocation extends BaseObj {
}
private void validateBitmapSize(Bitmap b) {
- if(mType.getX() != b.getWidth() ||
- mType.getY() != b.getHeight()) {
+ if((mCurrentDimX != b.getWidth()) || (mCurrentDimY != b.getHeight())) {
throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch");
}
}
@@ -307,7 +340,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(int[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
* Copy an allocation from an array. This variant is not type
@@ -318,7 +351,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(short[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
* Copy an allocation from an array. This variant is not type
@@ -329,7 +362,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(byte[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
* Copy an allocation from an array. This variant is not type
@@ -340,7 +373,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(float[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
@@ -352,7 +385,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(int[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -364,7 +397,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(short[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -376,7 +409,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(byte[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -388,7 +421,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(float[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -420,8 +453,7 @@ public class Allocation extends BaseObj {
throw new RSIllegalArgumentException("Field packer length " + data.length +
" not divisible by element size " + eSize + ".");
}
- data1DChecks(xoff, count, data.length, data.length);
- mRS.nAllocationData1D(getID(), xoff, 0, count, data, data.length);
+ copy1DRangeFromUnchecked(xoff, count, data);
}
/**
@@ -448,7 +480,8 @@ public class Allocation extends BaseObj {
" does not match component size " + eSize + ".");
}
- mRS.nAllocationElementData1D(getID(), xoff, 0, component_number, data, data.length);
+ mRS.nAllocationElementData1D(getID(), xoff, mSelectedLOD,
+ component_number, data, data.length);
}
private void data1DChecks(int off, int count, int len, int dataSize) {
@@ -459,11 +492,11 @@ public class Allocation extends BaseObj {
if(count < 1) {
throw new RSIllegalArgumentException("Count must be >= 1.");
}
- if((off + count) > mType.getCount()) {
- throw new RSIllegalArgumentException("Overflow, Available count " + mType.getCount() +
+ if((off + count) > mCurrentCount) {
+ throw new RSIllegalArgumentException("Overflow, Available count " + mCurrentCount +
", got " + count + " at offset " + off + ".");
}
- if((len) < dataSize) {
+ if(len < dataSize) {
throw new RSIllegalArgumentException("Array too small for allocation type.");
}
}
@@ -494,7 +527,7 @@ public class Allocation extends BaseObj {
public 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);
+ mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
}
/**
* Copy part of an allocation from an array. This variant is
@@ -508,7 +541,7 @@ public class Allocation extends BaseObj {
public 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);
+ mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
}
/**
* Copy part of an allocation from an array. This variant is
@@ -522,7 +555,7 @@ public class Allocation extends BaseObj {
public 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);
+ mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
}
/**
* Copy part of an allocation from an array. This variant is
@@ -536,7 +569,7 @@ public class Allocation extends BaseObj {
public 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);
+ mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
}
/**
@@ -606,21 +639,25 @@ public class Allocation extends BaseObj {
*/
public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) {
mRS.nAllocationData2D(getID(), off, 0,
- 0, Type.CubemapFace.POSITIVE_X.mID,
+ mSelectedLOD, mSelectedFace.mID,
count, 1, data.getID(), dataOff, 0,
- 0, Type.CubemapFace.POSITIVE_X.mID);
+ data.mSelectedLOD, data.mSelectedFace.mID);
}
private void validate2DRange(int xoff, int yoff, int w, int h) {
- if (xoff < 0 || yoff < 0) {
- throw new RSIllegalArgumentException("Offset cannot be negative.");
- }
- if (h < 0 || w < 0) {
- throw new RSIllegalArgumentException("Height or width cannot be negative.");
- }
- if ((xoff + w) > mType.mDimX ||
- (yoff + h) > mType.mDimY) {
- throw new RSIllegalArgumentException("Updated region larger than allocation.");
+ if (mAdaptedAllocation != null) {
+
+ } else {
+
+ if (xoff < 0 || yoff < 0) {
+ throw new RSIllegalArgumentException("Offset cannot be negative.");
+ }
+ if (h < 0 || w < 0) {
+ throw new RSIllegalArgumentException("Height or width cannot be negative.");
+ }
+ if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) {
+ throw new RSIllegalArgumentException("Updated region larger than allocation.");
+ }
}
}
@@ -637,25 +674,29 @@ public class Allocation extends BaseObj {
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length);
+ mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length);
}
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 2);
+ mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length * 2);
}
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 4);
+ mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length * 4);
}
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 4);
+ mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length * 4);
}
/**
@@ -675,9 +716,9 @@ public class Allocation extends BaseObj {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
mRS.nAllocationData2D(getID(), xoff, yoff,
- 0, Type.CubemapFace.POSITIVE_X.mID,
+ mSelectedLOD, mSelectedFace.mID,
w, h, data.getID(), dataXoff, dataYoff,
- 0, Type.CubemapFace.POSITIVE_X.mID);
+ data.mSelectedLOD, data.mSelectedFace.mID);
}
/**
@@ -693,7 +734,7 @@ public class Allocation extends BaseObj {
mRS.validate();
validateBitmapFormat(data);
validate2DRange(xoff, yoff, data.getWidth(), data.getHeight());
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, data);
+ mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data);
}
@@ -750,6 +791,7 @@ public class Allocation extends BaseObj {
int typeID = mRS.nAllocationGetType(getID());
mType = new Type(typeID, mRS);
mType.updateFromNative();
+ updateCacheInfo(mType);
}
/*
diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java
index 77dd86a..ca5246a 100644
--- a/graphics/java/android/renderscript/AllocationAdapter.java
+++ b/graphics/java/android/renderscript/AllocationAdapter.java
@@ -17,228 +17,92 @@
package android.renderscript;
import android.content.res.Resources;
-import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.util.Log;
import android.util.TypedValue;
/**
*
**/
public class AllocationAdapter extends Allocation {
- private boolean mConstrainedLOD;
- private boolean mConstrainedFace;
- private boolean mConstrainedY;
- private boolean mConstrainedZ;
-
- private int mSelectedDimX;
- private int mSelectedDimY;
- private int mSelectedDimZ;
- private int mSelectedCount;
- private Allocation mAlloc;
-
- private int mSelectedLOD = 0;
- private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITIVE_X;
-
AllocationAdapter(int id, RenderScript rs, Allocation alloc) {
- super(id, rs, null, alloc.mUsage);
- mAlloc = alloc;
+ super(id, rs, alloc.mType, alloc.mUsage);
+ mAdaptedAllocation = alloc;
}
-
int getID() {
- return mAlloc.getID();
+ return mAdaptedAllocation.getID();
}
- public void copyFrom(BaseObj[] d) {
- mRS.validate();
- if (d.length != mSelectedCount) {
- throw new RSIllegalArgumentException("Array size mismatch, allocation size = " +
- mSelectedCount + ", array length = " + d.length);
- }
- int i[] = new int[d.length];
- for (int ct=0; ct < d.length; ct++) {
- i[ct] = d[ct].getID();
- }
- subData1D(0, mAlloc.mType.getCount(), i);
- }
-
- void validateBitmap(Bitmap b) {
- mRS.validate();
- if(mSelectedDimX != b.getWidth() ||
- mSelectedDimY != b.getHeight()) {
- throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch");
- }
- }
-
- public void copyFrom(int[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(short[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(byte[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(float[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(Bitmap b) {
- validateBitmap(b);
- mRS.nAllocationCopyFromBitmap(getID(), b);
- }
-
- public void copyTo(Bitmap b) {
- validateBitmap(b);
- mRS.nAllocationCopyToBitmap(getID(), b);
- }
-
-
+ /**
+ * @hide
+ */
public void subData(int xoff, FieldPacker fp) {
- int eSize = mAlloc.mType.mElement.getSizeBytes();
- final byte[] data = fp.getData();
-
- int count = data.length / eSize;
- if ((eSize * count) != data.length) {
- throw new RSIllegalArgumentException("Field packer length " + data.length +
- " not divisible by element size " + eSize + ".");
- }
- data1DChecks(xoff, count, data.length, data.length);
- mRS.nAllocationData1D(getID(), xoff, mSelectedLOD, count, data, data.length);
+ super.setFromFieldPacker(xoff, fp);
}
-
-
+ /**
+ * @hide
+ */
public void subElementData(int xoff, int component_number, FieldPacker fp) {
- if (component_number >= mAlloc.mType.mElement.mElements.length) {
- throw new RSIllegalArgumentException("Component_number " + component_number + " out of range.");
- }
- if(xoff < 0) {
- throw new RSIllegalArgumentException("Offset must be >= 0.");
- }
-
- final byte[] data = fp.getData();
- int eSize = mAlloc.mType.mElement.mElements[component_number].getSizeBytes();
-
- if (data.length != eSize) {
- throw new RSIllegalArgumentException("Field packer sizelength " + data.length +
- " does not match component size " + eSize + ".");
- }
-
- mRS.nAllocationElementData1D(getID(), xoff, mSelectedLOD, component_number, data, data.length);
+ super.setFromFieldPacker(xoff, component_number, fp);
}
-
- void data1DChecks(int off, int count, int len, int dataSize) {
- mRS.validate();
- if(off < 0) {
- throw new RSIllegalArgumentException("Offset must be >= 0.");
- }
- if(count < 1) {
- throw new RSIllegalArgumentException("Count must be >= 1.");
- }
- if((off + count) > mSelectedCount) {
- throw new RSIllegalArgumentException("Overflow, Available count " + mAlloc.mType.getCount() +
- ", got " + count + " at offset " + off + ".");
- }
- if((len) < dataSize) {
- throw new RSIllegalArgumentException("Array too small for allocation type. len = " +
- len + ", dataSize = " + dataSize);
- }
- }
-
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, int[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length * 4, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, short[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length * 2, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, byte[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, float[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length * 4, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
-
/**
- * Copy part of an allocation from another allocation.
- *
- * @param off The offset of the first element to be copied.
- * @param count The number of elements to be copied.
- * @param data the source data allocation.
- * @param dataOff off The offset of the first element in data to
- * be copied.
+ * @hide
*/
- public void subData1D(int off, int count, AllocationAdapter data, int dataOff) {
- mRS.nAllocationData2D(getID(), off, 0,
- mSelectedLOD, mSelectedFace.mID,
- count, 1, data.getID(), dataOff, 0,
- data.mSelectedLOD, data.mSelectedFace.mID);
- }
-
-
public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
- mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
- w, h, d, d.length * 4);
+ super.copy2DRangeFrom(xoff, yoff, w, h, d);
}
-
+ /**
+ * @hide
+ */
public void subData2D(int xoff, int yoff, int w, int h, float[] d) {
- mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
- w, h, d, d.length * 4);
+ super.copy2DRangeFrom(xoff, yoff, w, h, d);
}
-
/**
- * Copy a rectangular region into the allocation from another
- * allocation.
- *
- * @param xoff X offset of the region to update.
- * @param yoff Y offset of the region to update.
- * @param w Width of the incoming region to update.
- * @param h Height of the incoming region to update.
- * @param data source allocation.
- * @param dataXoff X offset in data of the region to update.
- * @param dataYoff Y offset in data of the region to update.
+ * @hide
*/
- public void subData2D(int xoff, int yoff, int w, int h,
- AllocationAdapter data, int dataXoff, int dataYoff) {
- mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff,
- mSelectedLOD, mSelectedFace.mID,
- w, h, data.getID(), dataXoff, dataYoff,
- data.mSelectedLOD, data.mSelectedFace.mID);
- }
-
public void readData(int[] d) {
- mRS.validate();
- mRS.nAllocationRead(getID(), d);
+ super.copyTo(d);
}
-
+ /**
+ * @hide
+ */
public void readData(float[] d) {
- mRS.validate();
- mRS.nAllocationRead(getID(), d);
+ super.copyTo(d);
}
- private void initLOD(int lod) {
+ void initLOD(int lod) {
if (lod < 0) {
throw new RSIllegalArgumentException("Attempting to set negative lod (" + lod + ").");
}
- int tx = mAlloc.mType.getX();
- int ty = mAlloc.mType.getY();
- int tz = mAlloc.mType.getZ();
+ int tx = mAdaptedAllocation.mType.getX();
+ int ty = mAdaptedAllocation.mType.getY();
+ int tz = mAdaptedAllocation.mType.getZ();
for (int ct=0; ct < lod; ct++) {
if ((tx==1) && (ty == 1) && (tz == 1)) {
@@ -250,25 +114,31 @@ public class AllocationAdapter extends Allocation {
if (tz > 1) tz >>= 1;
}
- mSelectedDimX = tx;
- mSelectedDimY = ty;
- mSelectedCount = tx;
- if (ty > 1) {
- mSelectedCount *= ty;
+ mCurrentDimX = tx;
+ mCurrentDimY = ty;
+ mCurrentDimZ = tz;
+ mCurrentCount = mCurrentDimX;
+ if (mCurrentDimY > 1) {
+ mCurrentCount *= mCurrentDimY;
}
- if (tz > 1) {
- mSelectedCount *= tz;
+ if (mCurrentDimZ > 1) {
+ mCurrentCount *= mCurrentDimZ;
}
+ mSelectedY = 0;
+ mSelectedZ = 0;
}
/**
* Set the active LOD. The LOD must be within the range for the
- * type being adapted.
+ * type being adapted. The base allocation must have mipmaps.
+ *
+ * Because this changes the dimensions of the adapter the
+ * current Y and Z will be reset.
*
* @param lod The LOD to make active.
*/
public void setLOD(int lod) {
- if (!mAlloc.getType().hasMipmaps()) {
+ if (!mAdaptedAllocation.getType().hasMipmaps()) {
throw new RSInvalidStateException("Cannot set LOD when the allocation type does not include mipmaps.");
}
if (!mConstrainedLOD) {
@@ -278,22 +148,81 @@ public class AllocationAdapter extends Allocation {
initLOD(lod);
}
+ /**
+ * Set the active Face. The base allocation must be of a type
+ * that includes faces.
+ *
+ * @param cf The face to make active.
+ */
public void setFace(Type.CubemapFace cf) {
+ if (!mAdaptedAllocation.getType().hasFaces()) {
+ throw new RSInvalidStateException("Cannot set Face when the allocation type does not include faces.");
+ }
+ if (!mConstrainedFace) {
+ throw new RSInvalidStateException("Cannot set LOD when the adapter includes mipmaps.");
+ }
+ if (cf == null) {
+ throw new RSIllegalArgumentException("Cannot set null face.");
+ }
+
mSelectedFace = cf;
}
+ /**
+ * Set the active Y. The y value must be within the range for
+ * the allocation being adapted. The base allocation must
+ * contain the Y dimension.
+ *
+ * @param y The y to make active.
+ */
public void setY(int y) {
- mSelectedDimY = y;
+ if (mAdaptedAllocation.getType().getY() == 0) {
+ throw new RSInvalidStateException("Cannot set Y when the allocation type does not include Y dim.");
+ }
+ if (mAdaptedAllocation.getType().getY() <= y) {
+ throw new RSInvalidStateException("Cannot set Y greater than dimension of allocation.");
+ }
+ if (!mConstrainedY) {
+ throw new RSInvalidStateException("Cannot set Y when the adapter includes Y.");
+ }
+
+ mSelectedY = y;
}
+ /**
+ * Set the active Z. The z value must be within the range for
+ * the allocation being adapted. The base allocation must
+ * contain the Z dimension.
+ *
+ * @param z The z to make active.
+ */
public void setZ(int z) {
+ if (mAdaptedAllocation.getType().getZ() == 0) {
+ throw new RSInvalidStateException("Cannot set Z when the allocation type does not include Z dim.");
+ }
+ if (mAdaptedAllocation.getType().getZ() <= z) {
+ throw new RSInvalidStateException("Cannot set Z greater than dimension of allocation.");
+ }
+ if (!mConstrainedZ) {
+ throw new RSInvalidStateException("Cannot set Z when the adapter includes Z.");
+ }
+
+ mSelectedZ = z;
}
- // creation
- //static public AllocationAdapter create1D(RenderScript rs, Allocation a) {
- //}
+ static public AllocationAdapter create1D(RenderScript rs, Allocation a) {
+ rs.validate();
+ AllocationAdapter aa = new AllocationAdapter(0, rs, a);
+ aa.mConstrainedLOD = true;
+ aa.mConstrainedFace = true;
+ aa.mConstrainedY = true;
+ aa.mConstrainedZ = true;
+ aa.initLOD(0);
+ return aa;
+ }
static public AllocationAdapter create2D(RenderScript rs, Allocation a) {
+ android.util.Log.e("rs", "create2d " + a);
rs.validate();
AllocationAdapter aa = new AllocationAdapter(0, rs, a);
aa.mConstrainedLOD = true;
@@ -305,6 +234,16 @@ public class AllocationAdapter extends Allocation {
}
+ /**
+ * Override the Allocation resize. Resizing adapters is not
+ * allowed and will throw a RSInvalidStateException.
+ *
+ * @param dimX ignored.
+ */
+ public synchronized void resize(int dimX) {
+ throw new RSInvalidStateException("Resize not allowed for Adapters.");
+ }
+
}
diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java
index f865753..90f959f 100644
--- a/graphics/java/android/renderscript/ScriptC.java
+++ b/graphics/java/android/renderscript/ScriptC.java
@@ -95,7 +95,7 @@ public class ScriptC extends Script {
// E.g, /system/apps/Fountain.apk
//String packageName = rs.getApplicationContext().getPackageResourcePath();
// For res/raw/fountain.bc, it wil be /com.android.fountain:raw/fountain
- String resName = resources.getResourceName(resourceID);
+ String resName = resources.getResourceEntryName(resourceID);
String cacheDir = rs.getApplicationContext().getCacheDir().toString();
Log.v(TAG, "Create script for resource = " + resName);