summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/Element.java
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2011-12-27 09:03:38 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-12-27 09:03:38 -0800
commit60deb2d9ba186a89d5d74e45f0e928ebaac6a074 (patch)
treefb39b750b96f48b23efda535fb4de4bc7fa4c7c2 /graphics/java/android/renderscript/Element.java
parentfc8d7a960ac11eaa9dda07b8166ec935513fcceb (diff)
parent3aac0abe7965ce9e2078c7d5796805d83e39df7c (diff)
Merge "Adding tests for element/mesh getters. Fixing bugs found by tests." into graphics-dev
Diffstat (limited to 'graphics/java/android/renderscript/Element.java')
-rw-r--r--graphics/java/android/renderscript/Element.java63
1 files changed, 48 insertions, 15 deletions
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index 97ff30706ee5..11566c7438da 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -54,11 +54,36 @@ public class Element extends BaseObj {
int[] mArraySizes;
int[] mOffsetInBytes;
+ int[] mVisibleElementMap;
+
DataType mType;
DataKind mKind;
boolean mNormalized;
int mVectorSize;
+ private void updateVisibleSubElements() {
+ if (mElements == null) {
+ return;
+ }
+
+ int noPaddingFieldCount = 0;
+ int fieldCount = mElementNames.length;
+ // Find out how many elements are not padding
+ for (int ct = 0; ct < fieldCount; ct ++) {
+ if (mElementNames[ct].charAt(0) != '#') {
+ noPaddingFieldCount ++;
+ }
+ }
+ mVisibleElementMap = new int[noPaddingFieldCount];
+
+ // Make a map that points us at non-padding elements
+ for (int ct = 0, ctNoPadding = 0; ct < fieldCount; ct ++) {
+ if (mElementNames[ct].charAt(0) != '#') {
+ mVisibleElementMap[ctNoPadding ++] = ct;
+ }
+ }
+ }
+
/**
* @hide
* @return element size in bytes
@@ -83,6 +108,11 @@ public class Element extends BaseObj {
* RS_* objects. 32 bit opaque handles.
*/
public enum DataType {
+ /**
+ * @hide
+ * new enum
+ */
+ NONE (0, 0),
//FLOAT_16 (1, 2),
FLOAT_32 (2, 4),
FLOAT_64 (3, 8),
@@ -169,10 +199,10 @@ public class Element extends BaseObj {
* @return number of sub-elements in this element
*/
public int getSubElementCount() {
- if (mElements == null) {
+ if (mVisibleElementMap == null) {
return 0;
}
- return mElements.length;
+ return mVisibleElementMap.length;
}
/**
@@ -181,13 +211,13 @@ public class Element extends BaseObj {
* @return sub-element in this element at given index
*/
public Element getSubElement(int index) {
- if (mElements == null) {
+ if (mVisibleElementMap == null) {
throw new RSIllegalArgumentException("Element contains no sub-elements");
}
- if (index < 0 || index >= mElements.length) {
+ if (index < 0 || index >= mVisibleElementMap.length) {
throw new RSIllegalArgumentException("Illegal sub-element index");
}
- return mElements[index];
+ return mElements[mVisibleElementMap[index]];
}
/**
@@ -196,13 +226,13 @@ public class Element extends BaseObj {
* @return sub-element in this element at given index
*/
public String getSubElementName(int index) {
- if (mElements == null) {
+ if (mVisibleElementMap == null) {
throw new RSIllegalArgumentException("Element contains no sub-elements");
}
- if (index < 0 || index >= mElements.length) {
+ if (index < 0 || index >= mVisibleElementMap.length) {
throw new RSIllegalArgumentException("Illegal sub-element index");
}
- return mElementNames[index];
+ return mElementNames[mVisibleElementMap[index]];
}
/**
@@ -211,13 +241,13 @@ public class Element extends BaseObj {
* @return array size of sub-element in this element at given index
*/
public int getSubElementArraySize(int index) {
- if (mElements == null) {
+ if (mVisibleElementMap == null) {
throw new RSIllegalArgumentException("Element contains no sub-elements");
}
- if (index < 0 || index >= mElements.length) {
+ if (index < 0 || index >= mVisibleElementMap.length) {
throw new RSIllegalArgumentException("Illegal sub-element index");
}
- return mArraySizes[index];
+ return mArraySizes[mVisibleElementMap[index]];
}
/**
@@ -226,13 +256,13 @@ public class Element extends BaseObj {
* @return offset in bytes of sub-element in this element at given index
*/
public int getSubElementOffsetBytes(int index) {
- if (mElements == null) {
+ if (mVisibleElementMap == null) {
throw new RSIllegalArgumentException("Element contains no sub-elements");
}
- if (index < 0 || index >= mElements.length) {
+ if (index < 0 || index >= mVisibleElementMap.length) {
throw new RSIllegalArgumentException("Illegal sub-element index");
}
- return mOffsetInBytes[index];
+ return mOffsetInBytes[mVisibleElementMap[index]];
}
/**
@@ -702,11 +732,14 @@ public class Element extends BaseObj {
mElements = e;
mElementNames = n;
mArraySizes = as;
+ mType = DataType.NONE;
+ mKind = DataKind.USER;
mOffsetInBytes = new int[mElements.length];
for (int ct = 0; ct < mElements.length; ct++ ) {
mOffsetInBytes[ct] = mSize;
mSize += mElements[ct].mSize * mArraySizes[ct];
}
+ updateVisibleSubElements();
}
Element(int id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
@@ -771,7 +804,7 @@ public class Element extends BaseObj {
mSize += mElements[i].mSize * mArraySizes[i];
}
}
-
+ updateVisibleSubElements();
}
/**