@@ -46,13 +46,18 @@ public class Element extends BaseObj {
4646 Element [] mElements ;
4747 String [] mElementNames ;
4848 int [] mArraySizes ;
49+ int [] mOffsetInBytes ;
4950
5051 DataType mType ;
5152 DataKind mKind ;
5253 boolean mNormalized ;
5354 int mVectorSize ;
5455
55- int getSizeBytes () {return mSize ;}
56+ /**
57+ * @hide
58+ * @return element size in bytes
59+ */
60+ public int getSizeBytes () {return mSize ;}
5661
5762
5863 /**
@@ -151,6 +156,77 @@ public boolean isComplex() {
151156 return false ;
152157 }
153158
159+ /**
160+ * @hide
161+ * @return number of sub-elements in this element
162+ */
163+ public int getSubElementCount () {
164+ if (mElements == null ) {
165+ return 0 ;
166+ }
167+ return mElements .length ;
168+ }
169+
170+ /**
171+ * @hide
172+ * @param index index of the sub-element to return
173+ * @return sub-element in this element at given index
174+ */
175+ public Element getSubElement (int index ) {
176+ if (mElements == null ) {
177+ throw new RSIllegalArgumentException ("Element contains no sub-elements" );
178+ }
179+ if (index < 0 || index >= mElements .length ) {
180+ throw new RSIllegalArgumentException ("Illegal sub-element index" );
181+ }
182+ return mElements [index ];
183+ }
184+
185+ /**
186+ * @hide
187+ * @param index index of the sub-element
188+ * @return sub-element in this element at given index
189+ */
190+ public String getSubElementName (int index ) {
191+ if (mElements == null ) {
192+ throw new RSIllegalArgumentException ("Element contains no sub-elements" );
193+ }
194+ if (index < 0 || index >= mElements .length ) {
195+ throw new RSIllegalArgumentException ("Illegal sub-element index" );
196+ }
197+ return mElementNames [index ];
198+ }
199+
200+ /**
201+ * @hide
202+ * @param index index of the sub-element
203+ * @return array size of sub-element in this element at given index
204+ */
205+ public int getSubElementArraySize (int index ) {
206+ if (mElements == null ) {
207+ throw new RSIllegalArgumentException ("Element contains no sub-elements" );
208+ }
209+ if (index < 0 || index >= mElements .length ) {
210+ throw new RSIllegalArgumentException ("Illegal sub-element index" );
211+ }
212+ return mArraySizes [index ];
213+ }
214+
215+ /**
216+ * @hide
217+ * @param index index of the sub-element
218+ * @return offset in bytes of sub-element in this element at given index
219+ */
220+ public int getSubElementOffsetBytes (int index ) {
221+ if (mElements == null ) {
222+ throw new RSIllegalArgumentException ("Element contains no sub-elements" );
223+ }
224+ if (index < 0 || index >= mElements .length ) {
225+ throw new RSIllegalArgumentException ("Illegal sub-element index" );
226+ }
227+ return mOffsetInBytes [index ];
228+ }
229+
154230 /**
155231 * Utility function for returning an Element containing a single Boolean.
156232 *
@@ -602,7 +678,9 @@ public static Element MATRIX_2X2(RenderScript rs) {
602678 mElements = e ;
603679 mElementNames = n ;
604680 mArraySizes = as ;
681+ mOffsetInBytes = new int [mElements .length ];
605682 for (int ct = 0 ; ct < mElements .length ; ct ++ ) {
683+ mOffsetInBytes [ct ] = mSize ;
606684 mSize += mElements [ct ].mSize * mArraySizes [ct ];
607685 }
608686 }
@@ -653,13 +731,16 @@ void updateFromNative() {
653731 if (numSubElements > 0 ) {
654732 mElements = new Element [numSubElements ];
655733 mElementNames = new String [numSubElements ];
734+ mArraySizes = new int [numSubElements ];
735+ mOffsetInBytes = new int [numSubElements ];
656736
657737 int [] subElementIds = new int [numSubElements ];
658- mRS .nElementGetSubElements (getID (), subElementIds , mElementNames );
738+ mRS .nElementGetSubElements (getID (), subElementIds , mElementNames , mArraySizes );
659739 for (int i = 0 ; i < numSubElements ; i ++) {
660740 mElements [i ] = new Element (subElementIds [i ], mRS );
661741 mElements [i ].updateFromNative ();
662- mSize += mElements [i ].mSize ;
742+ mOffsetInBytes [i ] = mSize ;
743+ mSize += mElements [i ].mSize * mArraySizes [i ];
663744 }
664745 }
665746
0 commit comments