Implement array types
Change-Id: I1b83f21ea2aeaa4b9f5934aadcb69d4a1c1fea20
diff --git a/rs/java/android/renderscript/Type.java b/rs/java/android/renderscript/Type.java
index 98aeaa9..a58e42c 100644
--- a/rs/java/android/renderscript/Type.java
+++ b/rs/java/android/renderscript/Type.java
@@ -52,6 +52,9 @@
int mDimYuv;
int mElementCount;
Element mElement;
+ int mArrays[];
+
+ static final int mMaxArrays = 4;
public enum CubemapFace {
POSITIVE_X (0),
@@ -146,6 +149,30 @@
return mElementCount;
}
+ /**
+ * @hide
+ */
+ public int getArray(int dim) {
+ if ((dim < 0) || (dim >= mMaxArrays)) {
+ throw new RSIllegalArgumentException("Array dimension out of range.");
+ }
+
+ if (mArrays == null || dim >= mArrays.length) {
+ // Dimension in range but no array for that dimension allocated
+ return 0;
+ }
+
+ return mArrays[dim];
+ }
+
+ /**
+ * @hide
+ */
+ public int getArrayCount() {
+ if (mArrays != null) return mArrays.length;
+ return 0;
+ }
+
void calcElementCount() {
boolean hasLod = hasMipmaps();
int x = getX();
@@ -180,6 +207,13 @@
count += x * y * z * faces;
}
+
+ if (mArrays != null) {
+ for (int ct = 0; ct < mArrays.length; ct++) {
+ count *= mArrays[ct];
+ }
+ }
+
mElementCount = count;
}
@@ -296,6 +330,7 @@
boolean mDimMipmaps;
boolean mDimFaces;
int mYuv;
+ int[] mArray = new int[mMaxArrays];
Element mElement;
@@ -341,6 +376,22 @@
return this;
}
+ /**
+ * @hide
+ *
+ * @param dim
+ * @param value
+ *
+ * @return Builder
+ */
+ public Builder setArray(int dim, int value) {
+ if(dim < 0 || dim >= mMaxArrays) {
+ throw new RSIllegalArgumentException("Array dimension out of range.");
+ }
+ mArray[dim] = value;
+ return this;
+ }
+
public Builder setMipmaps(boolean value) {
mDimMipmaps = value;
return this;
@@ -405,6 +456,16 @@
}
}
+ int[] arrays = null;
+ for (int ct = mMaxArrays - 1; ct >= 0; ct--) {
+ if (mArray[ct] != 0 && arrays == null) {
+ arrays = new int[ct];
+ }
+ if ((mArray[ct] == 0) && (arrays != null)) {
+ throw new RSInvalidStateException("Array dimensions must be contigous from 0.");
+ }
+ }
+
long id = mRS.nTypeCreate(mElement.getID(mRS),
mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces, mYuv);
Type t = new Type(id, mRS);
@@ -415,6 +476,7 @@
t.mDimMipmaps = mDimMipmaps;
t.mDimFaces = mDimFaces;
t.mDimYuv = mYuv;
+ t.mArrays = arrays;
t.calcElementCount();
return t;