diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-12-22 13:11:48 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2011-12-22 13:11:48 -0800 |
commit | 3aac0abe7965ce9e2078c7d5796805d83e39df7c (patch) | |
tree | d562c10f687ce53cbd3fd11d47722803225c260a /graphics/java/android/renderscript/Element.java | |
parent | a6db9389bd429e8d894209473301475159829b52 (diff) |
Adding tests for element/mesh getters.
Fixing bugs found by tests.
Change-Id: I6592a3b65f16b21255e7788fe8ee8aaafe268638
Diffstat (limited to 'graphics/java/android/renderscript/Element.java')
-rw-r--r-- | graphics/java/android/renderscript/Element.java | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index d76c20965c9f..110eceb0be13 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -48,11 +48,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 @@ -77,6 +102,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), @@ -163,10 +193,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; } /** @@ -175,13 +205,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]]; } /** @@ -190,13 +220,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]]; } /** @@ -205,13 +235,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]]; } /** @@ -220,13 +250,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]]; } /** @@ -696,11 +726,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) { @@ -765,7 +798,7 @@ public class Element extends BaseObj { mSize += mElements[i].mSize * mArraySizes[i]; } } - + updateVisibleSubElements(); } /** |