blob: f671953f470417a2ae1c2b943bd9f96590f50cc0 [file] [log] [blame]
Jason Sams36e612a2009-07-31 16:26:13 -07001/*
Jason Samsdd6c8b32013-02-15 17:27:24 -08002 * Copyright (C) 2013 The Android Open Source Project
Jason Sams36e612a2009-07-31 16:26:13 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.renderscript;
18
Artur Satayev2ebb31c2020-01-08 12:24:36 +000019import android.compat.annotation.UnsupportedAppUsage;
Mathew Inwood15324472018-08-06 11:18:49 +010020
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070021/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070022 * <p>An Element represents one item within an {@link
23 * android.renderscript.Allocation}. An Element is roughly equivalent to a C
24 * type in a RenderScript kernel. Elements may be basic or complex. Some basic
25 * elements are</p> <ul> <li>A single float value (equivalent to a float in a
26 * kernel)</li> <li>A four-element float vector (equivalent to a float4 in a
27 * kernel)</li> <li>An unsigned 32-bit integer (equivalent to an unsigned int in
28 * a kernel)</li> <li>A single signed 8-bit integer (equivalent to a char in a
29 * kernel)</li> </ul> <p>A complex element is roughly equivalent to a C struct
30 * and contains a number of basic or complex Elements. From Java code, a complex
31 * element contains a list of sub-elements and names that represents a
32 * particular data structure. Structs used in RS scripts are available to Java
33 * code by using the {@code ScriptField_structname} class that is reflected from
34 * a particular script.</p>
Jason Samsa1b13ed2010-11-12 14:58:37 -080035 *
Tim Murrayc11e25c2013-04-09 11:01:01 -070036 * <p>Basic Elements are comprised of a {@link
37 * android.renderscript.Element.DataType} and a {@link
38 * android.renderscript.Element.DataKind}. The DataType encodes C type
39 * information of an Element, while the DataKind encodes how that Element should
40 * be interpreted by a {@link android.renderscript.Sampler}. Note that {@link
41 * android.renderscript.Allocation} objects with DataKind {@link
42 * android.renderscript.Element.DataKind#USER} cannot be used as input for a
43 * {@link android.renderscript.Sampler}. In general, {@link
44 * android.renderscript.Allocation} objects that are intended for use with a
45 * {@link android.renderscript.Sampler} should use bitmap-derived Elements such
46 * as {@link android.renderscript.Element#RGBA_8888} or {@link
47 * android.renderscript#Element.A_8}.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080048 *
49 * <div class="special reference">
50 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070051 * <p>For more information about creating an application that uses RenderScript, read the
52 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080053 * </div>
Xusong Wang8b4548c2021-01-05 10:09:52 -080054 *
55 * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a
56 * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration
57 * guide</a> for the proposed alternatives.
Jason Sams36e612a2009-07-31 16:26:13 -070058 **/
Xusong Wang8b4548c2021-01-05 10:09:52 -080059@Deprecated
Jason Sams36e612a2009-07-31 16:26:13 -070060public class Element extends BaseObj {
Jason Samsea84a7c2009-09-04 14:42:41 -070061 int mSize;
Jason Sams718cd1f2009-12-23 14:35:29 -080062 Element[] mElements;
63 String[] mElementNames;
Jason Sams70d4e502010-09-02 17:35:23 -070064 int[] mArraySizes;
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -070065 int[] mOffsetInBytes;
Jason Sams36e612a2009-07-31 16:26:13 -070066
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -080067 int[] mVisibleElementMap;
68
Jason Sams718cd1f2009-12-23 14:35:29 -080069 DataType mType;
70 DataKind mKind;
71 boolean mNormalized;
72 int mVectorSize;
Jason Sams768bc022009-09-21 19:41:04 -070073
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -080074 private void updateVisibleSubElements() {
75 if (mElements == null) {
76 return;
77 }
78
79 int noPaddingFieldCount = 0;
80 int fieldCount = mElementNames.length;
81 // Find out how many elements are not padding
82 for (int ct = 0; ct < fieldCount; ct ++) {
83 if (mElementNames[ct].charAt(0) != '#') {
84 noPaddingFieldCount ++;
85 }
86 }
87 mVisibleElementMap = new int[noPaddingFieldCount];
88
89 // Make a map that points us at non-padding elements
90 for (int ct = 0, ctNoPadding = 0; ct < fieldCount; ct ++) {
91 if (mElementNames[ct].charAt(0) != '#') {
92 mVisibleElementMap[ctNoPadding ++] = ct;
93 }
94 }
95 }
96
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070097 /**
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -070098 * @return element size in bytes
99 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700100 public int getBytesSize() {return mSize;}
Jason Sams36e612a2009-07-31 16:26:13 -0700101
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700102 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700103 * Returns the number of vector components. 2 for float2, 4 for
104 * float4, etc.
Alex Sakhartchoukfd79e022011-12-22 14:30:55 -0800105 * @return element vector size
106 */
107 public int getVectorSize() {return mVectorSize;}
108
Jason Samsa1b13ed2010-11-12 14:58:37 -0800109
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700110 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800111 * DataType represents the basic type information for a basic element. The
Alex Sakhartchoukf5d8ac72011-12-16 09:44:26 -0800112 * naming convention follows. For numeric types it is FLOAT,
113 * SIGNED, or UNSIGNED followed by the _BITS where BITS is the
114 * size of the data. BOOLEAN is a true / false (1,0)
115 * represented in an 8 bit container. The UNSIGNED variants
116 * with multiple bit definitions are for packed graphical data
117 * formats and represent vectors with per vector member sizes
118 * which are treated as a single unit for packing and alignment
119 * purposes.
Jason Samsa1b13ed2010-11-12 14:58:37 -0800120 *
121 * MATRIX the three matrix types contain FLOAT_32 elements and are treated
122 * as 32 bits for alignment purposes.
123 *
Jason Samsfb4f5cf2015-03-26 17:39:34 -0700124 * RS_* objects: opaque handles with implementation dependent
125 * sizes.
Jason Samsa1b13ed2010-11-12 14:58:37 -0800126 */
Jason Sams36e612a2009-07-31 16:26:13 -0700127 public enum DataType {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800128 NONE (0, 0),
Jason Samsa5835a22014-11-05 15:16:26 -0800129 FLOAT_16 (1, 2),
Jason Sams718cd1f2009-12-23 14:35:29 -0800130 FLOAT_32 (2, 4),
Stephen Hines02f417052010-09-30 15:19:22 -0700131 FLOAT_64 (3, 8),
Jason Sams718cd1f2009-12-23 14:35:29 -0800132 SIGNED_8 (4, 1),
133 SIGNED_16 (5, 2),
134 SIGNED_32 (6, 4),
Stephen Hinesef1dac22010-10-01 15:39:33 -0700135 SIGNED_64 (7, 8),
Jason Sams718cd1f2009-12-23 14:35:29 -0800136 UNSIGNED_8 (8, 1),
137 UNSIGNED_16 (9, 2),
138 UNSIGNED_32 (10, 4),
Stephen Hines52d83632010-10-11 16:10:42 -0700139 UNSIGNED_64 (11, 8),
Jason Sams718cd1f2009-12-23 14:35:29 -0800140
Jason Samsf110d4b2010-06-21 17:42:41 -0700141 BOOLEAN(12, 1),
Jason Sams718cd1f2009-12-23 14:35:29 -0800142
Jason Samsf110d4b2010-06-21 17:42:41 -0700143 UNSIGNED_5_6_5 (13, 2),
144 UNSIGNED_5_5_5_1 (14, 2),
145 UNSIGNED_4_4_4_4 (15, 2),
146
Jason Sams1d45c472010-08-25 14:31:48 -0700147 MATRIX_4X4 (16, 64),
148 MATRIX_3X3 (17, 36),
149 MATRIX_2X2 (18, 16),
150
Jason Samsb49dfea2014-06-18 13:17:57 -0700151 RS_ELEMENT (1000),
152 RS_TYPE (1001),
153 RS_ALLOCATION (1002),
154 RS_SAMPLER (1003),
155 RS_SCRIPT (1004),
156 RS_MESH (1005),
157 RS_PROGRAM_FRAGMENT (1006),
158 RS_PROGRAM_VERTEX (1007),
159 RS_PROGRAM_RASTER (1008),
160 RS_PROGRAM_STORE (1009),
161 RS_FONT (1010);
Jason Sams36e612a2009-07-31 16:26:13 -0700162
163 int mID;
Jason Sams718cd1f2009-12-23 14:35:29 -0800164 int mSize;
165 DataType(int id, int size) {
Jason Sams36e612a2009-07-31 16:26:13 -0700166 mID = id;
Jason Sams718cd1f2009-12-23 14:35:29 -0800167 mSize = size;
Jason Sams36e612a2009-07-31 16:26:13 -0700168 }
Jason Samsb49dfea2014-06-18 13:17:57 -0700169
170 DataType(int id) {
171 mID = id;
172 mSize = 4;
173 if (RenderScript.sPointerSize == 8) {
174 mSize = 32;
175 }
176 }
Jason Sams36e612a2009-07-31 16:26:13 -0700177 }
178
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700179 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800180 * The special interpretation of the data if required. This is primarly
181 * useful for graphical data. USER indicates no special interpretation is
182 * expected. PIXEL is used in conjunction with the standard data types for
183 * representing texture formats.
184 */
Jason Sams36e612a2009-07-31 16:26:13 -0700185 public enum DataKind {
186 USER (0),
Jason Sams718cd1f2009-12-23 14:35:29 -0800187
188 PIXEL_L (7),
189 PIXEL_A (8),
190 PIXEL_LA (9),
191 PIXEL_RGB (10),
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -0700192 PIXEL_RGBA (11),
Jason Sams8140d7b2012-12-13 17:01:09 -0800193 PIXEL_DEPTH (12),
194 PIXEL_YUV(13);
Jason Sams36e612a2009-07-31 16:26:13 -0700195
196 int mID;
197 DataKind(int id) {
198 mID = id;
199 }
200 }
201
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700202 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800203 * Return if a element is too complex for use as a data source for a Mesh or
204 * a Program.
205 *
206 * @return boolean
207 */
Jason Samsc1d62102010-11-04 14:32:19 -0700208 public boolean isComplex() {
209 if (mElements == null) {
210 return false;
211 }
212 for (int ct=0; ct < mElements.length; ct++) {
213 if (mElements[ct].mElements != null) {
214 return true;
215 }
216 }
217 return false;
218 }
219
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700220 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700221 * Elements could be simple, such as an int or a float, or a
222 * structure with multiple sub elements, such as a collection of
223 * floats, float2, float4. This function returns zero for simple
224 * elements or the number of sub-elements otherwise.
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700225 * @return number of sub-elements in this element
226 */
227 public int getSubElementCount() {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800228 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700229 return 0;
230 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800231 return mVisibleElementMap.length;
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700232 }
233
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700234 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700235 * For complex elements, this function will return the
236 * sub-element at index
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700237 * @param index index of the sub-element to return
238 * @return sub-element in this element at given index
239 */
240 public Element getSubElement(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800241 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700242 throw new RSIllegalArgumentException("Element contains no sub-elements");
243 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800244 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700245 throw new RSIllegalArgumentException("Illegal sub-element index");
246 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800247 return mElements[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700248 }
249
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700250 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700251 * For complex elements, this function will return the
252 * sub-element name at index
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700253 * @param index index of the sub-element
254 * @return sub-element in this element at given index
255 */
256 public String getSubElementName(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800257 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700258 throw new RSIllegalArgumentException("Element contains no sub-elements");
259 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800260 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700261 throw new RSIllegalArgumentException("Illegal sub-element index");
262 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800263 return mElementNames[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700264 }
265
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700266 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700267 * For complex elements, some sub-elements could be statically
268 * sized arrays. This function will return the array size for
269 * sub-element at index
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700270 * @param index index of the sub-element
271 * @return array size of sub-element in this element at given index
272 */
273 public int getSubElementArraySize(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800274 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700275 throw new RSIllegalArgumentException("Element contains no sub-elements");
276 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800277 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700278 throw new RSIllegalArgumentException("Illegal sub-element index");
279 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800280 return mArraySizes[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700281 }
282
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700283 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700284 * This function specifies the location of a sub-element within
285 * the element
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700286 * @param index index of the sub-element
287 * @return offset in bytes of sub-element in this element at given index
288 */
289 public int getSubElementOffsetBytes(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800290 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700291 throw new RSIllegalArgumentException("Element contains no sub-elements");
292 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800293 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700294 throw new RSIllegalArgumentException("Illegal sub-element index");
295 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800296 return mOffsetInBytes[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700297 }
298
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700299 /**
Alex Sakhartchoukf5d8ac72011-12-16 09:44:26 -0800300 * @return element data type
301 */
302 public DataType getDataType() {
303 return mType;
304 }
305
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700306 /**
Alex Sakhartchoukf5d8ac72011-12-16 09:44:26 -0800307 * @return element data kind
308 */
309 public DataKind getDataKind() {
310 return mKind;
311 }
312
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700313 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800314 * Utility function for returning an Element containing a single Boolean.
315 *
316 * @param rs Context to which the element will belong.
317 *
318 * @return Element
319 */
Jason Samsf110d4b2010-06-21 17:42:41 -0700320 public static Element BOOLEAN(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700321 if (rs.mElement_BOOLEAN == null) {
322 synchronized (rs) {
323 if (rs.mElement_BOOLEAN == null) {
324 rs.mElement_BOOLEAN = createUser(rs, DataType.BOOLEAN);
325 }
326 }
Jason Samsf110d4b2010-06-21 17:42:41 -0700327 }
328 return rs.mElement_BOOLEAN;
329 }
330
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700331 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800332 * Utility function for returning an Element containing a single UNSIGNED_8.
333 *
334 * @param rs Context to which the element will belong.
335 *
336 * @return Element
337 */
Jason Sams8cb39de2010-06-01 15:47:01 -0700338 public static Element U8(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700339 if (rs.mElement_U8 == null) {
340 synchronized (rs) {
341 if (rs.mElement_U8 == null) {
342 rs.mElement_U8 = createUser(rs, DataType.UNSIGNED_8);
343 }
344 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800345 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700346 return rs.mElement_U8;
Jason Sams718cd1f2009-12-23 14:35:29 -0800347 }
348
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700349 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800350 * Utility function for returning an Element containing a single SIGNED_8.
351 *
352 * @param rs Context to which the element will belong.
353 *
354 * @return Element
355 */
Jason Sams8cb39de2010-06-01 15:47:01 -0700356 public static Element I8(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700357 if (rs.mElement_I8 == null) {
358 synchronized (rs) {
359 if (rs.mElement_I8 == null) {
360 rs.mElement_I8 = createUser(rs, DataType.SIGNED_8);
361 }
362 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800363 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700364 return rs.mElement_I8;
Jason Sams718cd1f2009-12-23 14:35:29 -0800365 }
366
Jason Samse29f3e72010-06-08 15:40:48 -0700367 public static Element U16(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700368 if (rs.mElement_U16 == null) {
369 synchronized (rs) {
370 if (rs.mElement_U16 == null) {
371 rs.mElement_U16 = createUser(rs, DataType.UNSIGNED_16);
372 }
373 }
Jason Samse29f3e72010-06-08 15:40:48 -0700374 }
375 return rs.mElement_U16;
376 }
377
378 public static Element I16(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700379 if (rs.mElement_I16 == null) {
380 synchronized (rs) {
381 if (rs.mElement_I16 == null) {
382 rs.mElement_I16 = createUser(rs, DataType.SIGNED_16);
383 }
384 }
Jason Samse29f3e72010-06-08 15:40:48 -0700385 }
386 return rs.mElement_I16;
387 }
388
Jason Sams8cb39de2010-06-01 15:47:01 -0700389 public static Element U32(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700390 if (rs.mElement_U32 == null) {
391 synchronized (rs) {
392 if (rs.mElement_U32 == null) {
393 rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32);
394 }
395 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800396 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700397 return rs.mElement_U32;
Jason Sams718cd1f2009-12-23 14:35:29 -0800398 }
399
Jason Sams8cb39de2010-06-01 15:47:01 -0700400 public static Element I32(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700401 if (rs.mElement_I32 == null) {
402 synchronized (rs) {
403 if (rs.mElement_I32 == null) {
404 rs.mElement_I32 = createUser(rs, DataType.SIGNED_32);
405 }
406 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800407 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700408 return rs.mElement_I32;
Jason Sams718cd1f2009-12-23 14:35:29 -0800409 }
410
Stephen Hines52d83632010-10-11 16:10:42 -0700411 public static Element U64(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700412 if (rs.mElement_U64 == null) {
413 synchronized (rs) {
414 if (rs.mElement_U64 == null) {
415 rs.mElement_U64 = createUser(rs, DataType.UNSIGNED_64);
416 }
417 }
Stephen Hines52d83632010-10-11 16:10:42 -0700418 }
419 return rs.mElement_U64;
420 }
421
Stephen Hinesef1dac22010-10-01 15:39:33 -0700422 public static Element I64(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700423 if (rs.mElement_I64 == null) {
424 synchronized (rs) {
425 if (rs.mElement_I64 == null) {
426 rs.mElement_I64 = createUser(rs, DataType.SIGNED_64);
427 }
428 }
Stephen Hinesef1dac22010-10-01 15:39:33 -0700429 }
430 return rs.mElement_I64;
431 }
432
Jason Samsa5835a22014-11-05 15:16:26 -0800433 public static Element F16(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700434 if (rs.mElement_F16 == null) {
435 synchronized (rs) {
436 if (rs.mElement_F16 == null) {
437 rs.mElement_F16 = createUser(rs, DataType.FLOAT_16);
438 }
439 }
Jason Samsa5835a22014-11-05 15:16:26 -0800440 }
441 return rs.mElement_F16;
442 }
443
Jason Sams8cb39de2010-06-01 15:47:01 -0700444 public static Element F32(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700445 if (rs.mElement_F32 == null) {
446 synchronized (rs) {
447 if (rs.mElement_F32 == null) {
448 rs.mElement_F32 = createUser(rs, DataType.FLOAT_32);
449 }
450 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800451 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700452 return rs.mElement_F32;
Jason Sams718cd1f2009-12-23 14:35:29 -0800453 }
454
Stephen Hines02f417052010-09-30 15:19:22 -0700455 public static Element F64(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700456 if (rs.mElement_F64 == null) {
457 synchronized (rs) {
458 if (rs.mElement_F64 == null) {
459 rs.mElement_F64 = createUser(rs, DataType.FLOAT_64);
460 }
461 }
Stephen Hines02f417052010-09-30 15:19:22 -0700462 }
463 return rs.mElement_F64;
464 }
465
Jason Sams8cb39de2010-06-01 15:47:01 -0700466 public static Element ELEMENT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700467 if (rs.mElement_ELEMENT == null) {
468 synchronized (rs) {
469 if (rs.mElement_ELEMENT == null) {
470 rs.mElement_ELEMENT = createUser(rs, DataType.RS_ELEMENT);
471 }
472 }
Jason Samsa70f4162010-03-26 15:33:42 -0700473 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700474 return rs.mElement_ELEMENT;
Jason Samsa70f4162010-03-26 15:33:42 -0700475 }
476
Jason Sams8cb39de2010-06-01 15:47:01 -0700477 public static Element TYPE(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700478 if (rs.mElement_TYPE == null) {
479 synchronized (rs) {
480 if (rs.mElement_TYPE == null) {
481 rs.mElement_TYPE = createUser(rs, DataType.RS_TYPE);
482 }
483 }
Jason Samsa70f4162010-03-26 15:33:42 -0700484 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700485 return rs.mElement_TYPE;
Jason Samsa70f4162010-03-26 15:33:42 -0700486 }
487
Jason Sams8cb39de2010-06-01 15:47:01 -0700488 public static Element ALLOCATION(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700489 if (rs.mElement_ALLOCATION == null) {
490 synchronized (rs) {
491 if (rs.mElement_ALLOCATION == null) {
492 rs.mElement_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION);
493 }
494 }
Jason Samsa70f4162010-03-26 15:33:42 -0700495 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700496 return rs.mElement_ALLOCATION;
Jason Samsa70f4162010-03-26 15:33:42 -0700497 }
498
Jason Sams8cb39de2010-06-01 15:47:01 -0700499 public static Element SAMPLER(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700500 if (rs.mElement_SAMPLER == null) {
501 synchronized (rs) {
502 if (rs.mElement_SAMPLER == null) {
503 rs.mElement_SAMPLER = createUser(rs, DataType.RS_SAMPLER);
504 }
505 }
Jason Samsa70f4162010-03-26 15:33:42 -0700506 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700507 return rs.mElement_SAMPLER;
Jason Samsa70f4162010-03-26 15:33:42 -0700508 }
509
Jason Sams8cb39de2010-06-01 15:47:01 -0700510 public static Element SCRIPT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700511 if (rs.mElement_SCRIPT == null) {
512 synchronized (rs) {
513 if (rs.mElement_SCRIPT == null) {
514 rs.mElement_SCRIPT = createUser(rs, DataType.RS_SCRIPT);
515 }
516 }
Jason Samsa70f4162010-03-26 15:33:42 -0700517 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700518 return rs.mElement_SCRIPT;
Jason Samsa70f4162010-03-26 15:33:42 -0700519 }
520
Jason Sams8cb39de2010-06-01 15:47:01 -0700521 public static Element MESH(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700522 if (rs.mElement_MESH == null) {
523 synchronized (rs) {
524 if (rs.mElement_MESH == null) {
525 rs.mElement_MESH = createUser(rs, DataType.RS_MESH);
526 }
527 }
Jason Samsa70f4162010-03-26 15:33:42 -0700528 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700529 return rs.mElement_MESH;
Jason Samsa70f4162010-03-26 15:33:42 -0700530 }
531
Jason Sams8cb39de2010-06-01 15:47:01 -0700532 public static Element PROGRAM_FRAGMENT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700533 if (rs.mElement_PROGRAM_FRAGMENT == null) {
534 synchronized (rs) {
535 if (rs.mElement_PROGRAM_FRAGMENT == null) {
536 rs.mElement_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT);
537 }
538 }
Jason Samsa70f4162010-03-26 15:33:42 -0700539 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700540 return rs.mElement_PROGRAM_FRAGMENT;
Jason Samsa70f4162010-03-26 15:33:42 -0700541 }
542
Jason Sams8cb39de2010-06-01 15:47:01 -0700543 public static Element PROGRAM_VERTEX(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700544 if (rs.mElement_PROGRAM_VERTEX == null) {
545 synchronized (rs) {
546 if (rs.mElement_PROGRAM_VERTEX == null) {
547 rs.mElement_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX);
548 }
549 }
Jason Samsa70f4162010-03-26 15:33:42 -0700550 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700551 return rs.mElement_PROGRAM_VERTEX;
Jason Samsa70f4162010-03-26 15:33:42 -0700552 }
553
Jason Sams8cb39de2010-06-01 15:47:01 -0700554 public static Element PROGRAM_RASTER(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700555 if (rs.mElement_PROGRAM_RASTER == null) {
556 synchronized (rs) {
557 if (rs.mElement_PROGRAM_RASTER == null) {
558 rs.mElement_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER);
559 }
560 }
Jason Samsa70f4162010-03-26 15:33:42 -0700561 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700562 return rs.mElement_PROGRAM_RASTER;
Jason Samsa70f4162010-03-26 15:33:42 -0700563 }
564
Jason Sams8cb39de2010-06-01 15:47:01 -0700565 public static Element PROGRAM_STORE(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700566 if (rs.mElement_PROGRAM_STORE == null) {
567 synchronized (rs) {
568 if (rs.mElement_PROGRAM_STORE == null) {
569 rs.mElement_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE);
570 }
571 }
Jason Samsa70f4162010-03-26 15:33:42 -0700572 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700573 return rs.mElement_PROGRAM_STORE;
Jason Samsa70f4162010-03-26 15:33:42 -0700574 }
575
Stephen Hines3a291412012-04-11 17:27:29 -0700576 public static Element FONT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700577 if (rs.mElement_FONT == null) {
578 synchronized (rs) {
579 if (rs.mElement_FONT == null) {
580 rs.mElement_FONT = createUser(rs, DataType.RS_FONT);
581 }
582 }
Stephen Hines3a291412012-04-11 17:27:29 -0700583 }
584 return rs.mElement_FONT;
585 }
586
Jason Sams718cd1f2009-12-23 14:35:29 -0800587 public static Element A_8(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700588 if (rs.mElement_A_8 == null) {
589 synchronized (rs) {
590 if (rs.mElement_A_8 == null) {
591 rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A);
592 }
593 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800594 }
595 return rs.mElement_A_8;
596 }
597
598 public static Element RGB_565(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700599 if (rs.mElement_RGB_565 == null) {
600 synchronized (rs) {
601 if (rs.mElement_RGB_565 == null) {
602 rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB);
603 }
604 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800605 }
606 return rs.mElement_RGB_565;
607 }
608
609 public static Element RGB_888(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700610 if (rs.mElement_RGB_888 == null) {
611 synchronized (rs) {
612 if (rs.mElement_RGB_888 == null) {
613 rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB);
614 }
615 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800616 }
617 return rs.mElement_RGB_888;
618 }
619
620 public static Element RGBA_5551(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700621 if (rs.mElement_RGBA_5551 == null) {
622 synchronized (rs) {
623 if (rs.mElement_RGBA_5551 == null) {
624 rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA);
625 }
626 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800627 }
628 return rs.mElement_RGBA_5551;
629 }
630
631 public static Element RGBA_4444(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700632 if (rs.mElement_RGBA_4444 == null) {
633 synchronized (rs) {
634 if (rs.mElement_RGBA_4444 == null) {
635 rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA);
636 }
637 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800638 }
639 return rs.mElement_RGBA_4444;
640 }
641
642 public static Element RGBA_8888(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700643 if (rs.mElement_RGBA_8888 == null) {
644 synchronized (rs) {
645 if (rs.mElement_RGBA_8888 == null) {
646 rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA);
647 }
648 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800649 }
650 return rs.mElement_RGBA_8888;
651 }
652
Jason Samsa5835a22014-11-05 15:16:26 -0800653 public static Element F16_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700654 if (rs.mElement_HALF_2 == null) {
655 synchronized (rs) {
656 if (rs.mElement_HALF_2 == null) {
657 rs.mElement_HALF_2 = createVector(rs, DataType.FLOAT_16, 2);
658 }
659 }
Jason Samsa5835a22014-11-05 15:16:26 -0800660 }
661 return rs.mElement_HALF_2;
662 }
663
Jason Samsa5835a22014-11-05 15:16:26 -0800664 public static Element F16_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700665 if (rs.mElement_HALF_3 == null) {
666 synchronized (rs) {
667 if (rs.mElement_HALF_3 == null) {
668 rs.mElement_HALF_3 = createVector(rs, DataType.FLOAT_16, 3);
669 }
670 }
Jason Samsa5835a22014-11-05 15:16:26 -0800671 }
672 return rs.mElement_HALF_3;
673 }
674
Jason Samsa5835a22014-11-05 15:16:26 -0800675 public static Element F16_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700676 if (rs.mElement_HALF_4 == null) {
677 synchronized (rs) {
678 if (rs.mElement_HALF_4 == null) {
679 rs.mElement_HALF_4 = createVector(rs, DataType.FLOAT_16, 4);
680 }
681 }
Jason Samsa5835a22014-11-05 15:16:26 -0800682 }
683 return rs.mElement_HALF_4;
684 }
685
Jason Sams8cb39de2010-06-01 15:47:01 -0700686 public static Element F32_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700687 if (rs.mElement_FLOAT_2 == null) {
688 synchronized (rs) {
689 if (rs.mElement_FLOAT_2 == null) {
690 rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2);
691 }
692 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800693 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700694 return rs.mElement_FLOAT_2;
Jason Sams718cd1f2009-12-23 14:35:29 -0800695 }
696
Jason Sams8cb39de2010-06-01 15:47:01 -0700697 public static Element F32_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700698 if (rs.mElement_FLOAT_3 == null) {
699 synchronized (rs) {
700 if (rs.mElement_FLOAT_3 == null) {
701 rs.mElement_FLOAT_3 = createVector(rs, DataType.FLOAT_32, 3);
702 }
703 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800704 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700705 return rs.mElement_FLOAT_3;
Jason Sams718cd1f2009-12-23 14:35:29 -0800706 }
707
Jason Sams8cb39de2010-06-01 15:47:01 -0700708 public static Element F32_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700709 if (rs.mElement_FLOAT_4 == null) {
710 synchronized (rs) {
711 if (rs.mElement_FLOAT_4 == null) {
712 rs.mElement_FLOAT_4 = createVector(rs, DataType.FLOAT_32, 4);
713 }
714 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800715 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700716 return rs.mElement_FLOAT_4;
Jason Sams718cd1f2009-12-23 14:35:29 -0800717 }
718
Stephen Hines836c4a52011-06-01 14:38:10 -0700719 public static Element F64_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700720 if (rs.mElement_DOUBLE_2 == null) {
721 synchronized (rs) {
722 if (rs.mElement_DOUBLE_2 == null) {
723 rs.mElement_DOUBLE_2 = createVector(rs, DataType.FLOAT_64, 2);
724 }
725 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700726 }
727 return rs.mElement_DOUBLE_2;
728 }
729
730 public static Element F64_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700731 if (rs.mElement_DOUBLE_3 == null) {
732 synchronized (rs) {
733 if (rs.mElement_DOUBLE_3 == null) {
734 rs.mElement_DOUBLE_3 = createVector(rs, DataType.FLOAT_64, 3);
735 }
736 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700737 }
738 return rs.mElement_DOUBLE_3;
739 }
740
741 public static Element F64_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700742 if (rs.mElement_DOUBLE_4 == null) {
743 synchronized (rs) {
744 if (rs.mElement_DOUBLE_4 == null) {
745 rs.mElement_DOUBLE_4 = createVector(rs, DataType.FLOAT_64, 4);
746 }
747 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700748 }
749 return rs.mElement_DOUBLE_4;
750 }
751
752 public static Element U8_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700753 if (rs.mElement_UCHAR_2 == null) {
754 synchronized (rs) {
755 if (rs.mElement_UCHAR_2 == null) {
756 rs.mElement_UCHAR_2 = createVector(rs, DataType.UNSIGNED_8, 2);
757 }
758 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700759 }
760 return rs.mElement_UCHAR_2;
761 }
762
763 public static Element U8_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700764 if (rs.mElement_UCHAR_3 == null) {
765 synchronized (rs) {
766 if (rs.mElement_UCHAR_3 == null) {
767 rs.mElement_UCHAR_3 = createVector(rs, DataType.UNSIGNED_8, 3);
768 }
769 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700770 }
771 return rs.mElement_UCHAR_3;
772 }
773
Jason Sams8cb39de2010-06-01 15:47:01 -0700774 public static Element U8_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700775 if (rs.mElement_UCHAR_4 == null) {
776 synchronized (rs) {
777 if (rs.mElement_UCHAR_4 == null) {
778 rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4);
779 }
780 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800781 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700782 return rs.mElement_UCHAR_4;
Jason Sams718cd1f2009-12-23 14:35:29 -0800783 }
784
Stephen Hines836c4a52011-06-01 14:38:10 -0700785 public static Element I8_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700786 if (rs.mElement_CHAR_2 == null) {
787 synchronized (rs) {
788 if (rs.mElement_CHAR_2 == null) {
789 rs.mElement_CHAR_2 = createVector(rs, DataType.SIGNED_8, 2);
790 }
791 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700792 }
793 return rs.mElement_CHAR_2;
794 }
795
796 public static Element I8_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700797 if (rs.mElement_CHAR_3 == null) {
798 synchronized (rs) {
799 if (rs.mElement_CHAR_3 == null) {
800 rs.mElement_CHAR_3 = createVector(rs, DataType.SIGNED_8, 3);
801 }
802 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700803 }
804 return rs.mElement_CHAR_3;
805 }
806
807 public static Element I8_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700808 if (rs.mElement_CHAR_4 == null) {
809 synchronized (rs) {
810 if (rs.mElement_CHAR_4 == null) {
811 rs.mElement_CHAR_4 = createVector(rs, DataType.SIGNED_8, 4);
812 }
813 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700814 }
815 return rs.mElement_CHAR_4;
816 }
817
818 public static Element U16_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700819 if (rs.mElement_USHORT_2 == null) {
820 synchronized (rs) {
821 if (rs.mElement_USHORT_2 == null) {
822 rs.mElement_USHORT_2 = createVector(rs, DataType.UNSIGNED_16, 2);
823 }
824 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700825 }
826 return rs.mElement_USHORT_2;
827 }
828
829 public static Element U16_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700830 if (rs.mElement_USHORT_3 == null) {
831 synchronized (rs) {
832 if (rs.mElement_USHORT_3 == null) {
833 rs.mElement_USHORT_3 = createVector(rs, DataType.UNSIGNED_16, 3);
834 }
835 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700836 }
837 return rs.mElement_USHORT_3;
838 }
839
840 public static Element U16_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700841 if (rs.mElement_USHORT_4 == null) {
842 synchronized (rs) {
843 if (rs.mElement_USHORT_4 == null) {
844 rs.mElement_USHORT_4 = createVector(rs, DataType.UNSIGNED_16, 4);
845 }
846 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700847 }
848 return rs.mElement_USHORT_4;
849 }
850
851 public static Element I16_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700852 if (rs.mElement_SHORT_2 == null) {
853 synchronized (rs) {
854 if (rs.mElement_SHORT_2 == null) {
855 rs.mElement_SHORT_2 = createVector(rs, DataType.SIGNED_16, 2);
856 }
857 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700858 }
859 return rs.mElement_SHORT_2;
860 }
861
862 public static Element I16_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700863 if (rs.mElement_SHORT_3 == null) {
864 synchronized (rs) {
865 if (rs.mElement_SHORT_3 == null) {
866 rs.mElement_SHORT_3 = createVector(rs, DataType.SIGNED_16, 3);
867 }
868 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700869 }
870 return rs.mElement_SHORT_3;
871 }
872
873 public static Element I16_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700874 if (rs.mElement_SHORT_4 == null) {
875 synchronized (rs) {
876 if (rs.mElement_SHORT_4 == null) {
877 rs.mElement_SHORT_4 = createVector(rs, DataType.SIGNED_16, 4);
878 }
879 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700880 }
881 return rs.mElement_SHORT_4;
882 }
883
884 public static Element U32_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700885 if (rs.mElement_UINT_2 == null) {
886 synchronized (rs) {
887 if (rs.mElement_UINT_2 == null) {
888 rs.mElement_UINT_2 = createVector(rs, DataType.UNSIGNED_32, 2);
889 }
890 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700891 }
892 return rs.mElement_UINT_2;
893 }
894
895 public static Element U32_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700896 if (rs.mElement_UINT_3 == null) {
897 synchronized (rs) {
898 if (rs.mElement_UINT_3 == null) {
899 rs.mElement_UINT_3 = createVector(rs, DataType.UNSIGNED_32, 3);
900 }
901 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700902 }
903 return rs.mElement_UINT_3;
904 }
905
906 public static Element U32_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700907 if (rs.mElement_UINT_4 == null) {
908 synchronized (rs) {
909 if (rs.mElement_UINT_4 == null) {
910 rs.mElement_UINT_4 = createVector(rs, DataType.UNSIGNED_32, 4);
911 }
912 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700913 }
914 return rs.mElement_UINT_4;
915 }
916
917 public static Element I32_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700918 if (rs.mElement_INT_2 == null) {
919 synchronized (rs) {
920 if (rs.mElement_INT_2 == null) {
921 rs.mElement_INT_2 = createVector(rs, DataType.SIGNED_32, 2);
922 }
923 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700924 }
925 return rs.mElement_INT_2;
926 }
927
928 public static Element I32_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700929 if (rs.mElement_INT_3 == null) {
930 synchronized (rs) {
931 if (rs.mElement_INT_3 == null) {
932 rs.mElement_INT_3 = createVector(rs, DataType.SIGNED_32, 3);
933 }
934 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700935 }
936 return rs.mElement_INT_3;
937 }
938
939 public static Element I32_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700940 if (rs.mElement_INT_4 == null) {
941 synchronized (rs) {
942 if (rs.mElement_INT_4 == null) {
943 rs.mElement_INT_4 = createVector(rs, DataType.SIGNED_32, 4);
944 }
945 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700946 }
947 return rs.mElement_INT_4;
948 }
949
950 public static Element U64_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700951 if (rs.mElement_ULONG_2 == null) {
952 synchronized (rs) {
953 if (rs.mElement_ULONG_2 == null) {
954 rs.mElement_ULONG_2 = createVector(rs, DataType.UNSIGNED_64, 2);
955 }
956 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700957 }
958 return rs.mElement_ULONG_2;
959 }
960
961 public static Element U64_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700962 if (rs.mElement_ULONG_3 == null) {
963 synchronized (rs) {
964 if (rs.mElement_ULONG_3 == null) {
965 rs.mElement_ULONG_3 = createVector(rs, DataType.UNSIGNED_64, 3);
966 }
967 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700968 }
969 return rs.mElement_ULONG_3;
970 }
971
972 public static Element U64_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700973 if (rs.mElement_ULONG_4 == null) {
974 synchronized (rs) {
975 if (rs.mElement_ULONG_4 == null) {
976 rs.mElement_ULONG_4 = createVector(rs, DataType.UNSIGNED_64, 4);
977 }
978 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700979 }
980 return rs.mElement_ULONG_4;
981 }
982
983 public static Element I64_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700984 if (rs.mElement_LONG_2 == null) {
985 synchronized (rs) {
986 if (rs.mElement_LONG_2 == null) {
987 rs.mElement_LONG_2 = createVector(rs, DataType.SIGNED_64, 2);
988 }
989 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700990 }
991 return rs.mElement_LONG_2;
992 }
993
994 public static Element I64_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700995 if (rs.mElement_LONG_3 == null) {
996 synchronized (rs) {
997 if (rs.mElement_LONG_3 == null) {
998 rs.mElement_LONG_3 = createVector(rs, DataType.SIGNED_64, 3);
999 }
1000 }
Stephen Hines836c4a52011-06-01 14:38:10 -07001001 }
1002 return rs.mElement_LONG_3;
1003 }
1004
1005 public static Element I64_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001006 if (rs.mElement_LONG_4 == null) {
1007 synchronized (rs) {
1008 if (rs.mElement_LONG_4 == null) {
1009 rs.mElement_LONG_4 = createVector(rs, DataType.SIGNED_64, 4);
1010 }
1011 }
Stephen Hines836c4a52011-06-01 14:38:10 -07001012 }
1013 return rs.mElement_LONG_4;
1014 }
1015
Tim Murray932e78e2013-09-03 11:42:26 -07001016 public static Element YUV(RenderScript rs) {
1017 if (rs.mElement_YUV == null) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001018 synchronized (rs) {
1019 if (rs.mElement_YUV == null) {
1020 rs.mElement_YUV = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_YUV);
1021 }
1022 }
Tim Murray932e78e2013-09-03 11:42:26 -07001023 }
1024 return rs.mElement_YUV;
1025 }
1026
Jason Sams1d45c472010-08-25 14:31:48 -07001027 public static Element MATRIX_4X4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001028 if (rs.mElement_MATRIX_4X4 == null) {
1029 synchronized (rs) {
1030 if (rs.mElement_MATRIX_4X4 == null) {
1031 rs.mElement_MATRIX_4X4 = createUser(rs, DataType.MATRIX_4X4);
1032 }
1033 }
Jason Sams1d45c472010-08-25 14:31:48 -07001034 }
1035 return rs.mElement_MATRIX_4X4;
1036 }
Jason Sams65c80f82012-05-08 17:30:26 -07001037
1038 /** @deprecated use MATRIX_4X4
1039 */
Jason Sams1d45c472010-08-25 14:31:48 -07001040 public static Element MATRIX4X4(RenderScript rs) {
1041 return MATRIX_4X4(rs);
1042 }
1043
1044 public static Element MATRIX_3X3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001045 if (rs.mElement_MATRIX_3X3 == null) {
1046 synchronized (rs) {
1047 if (rs.mElement_MATRIX_3X3 == null) {
1048 rs.mElement_MATRIX_3X3 = createUser(rs, DataType.MATRIX_3X3);
1049 }
1050 }
Jason Sams1d45c472010-08-25 14:31:48 -07001051 }
Alex Sakhartchouk34769772011-02-28 16:01:28 -08001052 return rs.mElement_MATRIX_3X3;
Jason Sams1d45c472010-08-25 14:31:48 -07001053 }
1054
1055 public static Element MATRIX_2X2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001056 if (rs.mElement_MATRIX_2X2 == null) {
1057 synchronized (rs) {
1058 if (rs.mElement_MATRIX_2X2 == null) {
1059 rs.mElement_MATRIX_2X2 = createUser(rs, DataType.MATRIX_2X2);
1060 }
1061 }
Jason Sams1d45c472010-08-25 14:31:48 -07001062 }
1063 return rs.mElement_MATRIX_2X2;
1064 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001065
Tim Murray460a0492013-11-19 12:45:54 -08001066 Element(long id, RenderScript rs, Element[] e, String[] n, int[] as) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001067 super(id, rs);
Jason Samsea84a7c2009-09-04 14:42:41 -07001068 mSize = 0;
Alex Sakhartchoukfd79e022011-12-22 14:30:55 -08001069 mVectorSize = 1;
Jason Sams718cd1f2009-12-23 14:35:29 -08001070 mElements = e;
1071 mElementNames = n;
Jason Sams70d4e502010-09-02 17:35:23 -07001072 mArraySizes = as;
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -08001073 mType = DataType.NONE;
1074 mKind = DataKind.USER;
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001075 mOffsetInBytes = new int[mElements.length];
Jason Sams718cd1f2009-12-23 14:35:29 -08001076 for (int ct = 0; ct < mElements.length; ct++ ) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001077 mOffsetInBytes[ct] = mSize;
Alex Sakhartchouk9e401bc2010-10-13 14:22:02 -07001078 mSize += mElements[ct].mSize * mArraySizes[ct];
Jason Sams718cd1f2009-12-23 14:35:29 -08001079 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -08001080 updateVisibleSubElements();
Jason Sams718cd1f2009-12-23 14:35:29 -08001081 }
1082
Tim Murray460a0492013-11-19 12:45:54 -08001083 Element(long id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001084 super(id, rs);
Jason Sams252c0782011-01-11 17:42:52 -08001085 if ((dt != DataType.UNSIGNED_5_6_5) &&
1086 (dt != DataType.UNSIGNED_4_4_4_4) &&
1087 (dt != DataType.UNSIGNED_5_5_5_1)) {
Alex Sakhartchouke60149d2011-11-15 15:15:21 -08001088 if (size == 3) {
1089 mSize = dt.mSize * 4;
1090 } else {
1091 mSize = dt.mSize * size;
1092 }
Jason Sams252c0782011-01-11 17:42:52 -08001093 } else {
1094 mSize = dt.mSize;
1095 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001096 mType = dt;
1097 mKind = dk;
1098 mNormalized = norm;
1099 mVectorSize = size;
Jason Sams36e612a2009-07-31 16:26:13 -07001100 }
1101
Tim Murray460a0492013-11-19 12:45:54 -08001102 Element(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001103 super(id, rs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001104 }
1105
1106 @Override
1107 void updateFromNative() {
Jason Sams06d69de2010-11-09 17:11:40 -08001108 super.updateFromNative();
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001109
1110 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
1111 int[] dataBuffer = new int[5];
Jason Samse07694b2012-04-03 15:36:36 -07001112 mRS.nElementGetNativeData(getID(mRS), dataBuffer);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001113
1114 mNormalized = dataBuffer[2] == 1 ? true : false;
1115 mVectorSize = dataBuffer[3];
1116 mSize = 0;
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001117 for (DataType dt: DataType.values()) {
1118 if(dt.mID == dataBuffer[0]){
1119 mType = dt;
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001120 mSize = mType.mSize * mVectorSize;
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001121 }
1122 }
1123 for (DataKind dk: DataKind.values()) {
1124 if(dk.mID == dataBuffer[1]){
1125 mKind = dk;
1126 }
1127 }
1128
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001129 int numSubElements = dataBuffer[4];
1130 if(numSubElements > 0) {
1131 mElements = new Element[numSubElements];
1132 mElementNames = new String[numSubElements];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001133 mArraySizes = new int[numSubElements];
1134 mOffsetInBytes = new int[numSubElements];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001135
Ashok Bhat98071552014-02-12 09:54:43 +00001136 long[] subElementIds = new long[numSubElements];
Jason Samse07694b2012-04-03 15:36:36 -07001137 mRS.nElementGetSubElements(getID(mRS), subElementIds, mElementNames, mArraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001138 for(int i = 0; i < numSubElements; i ++) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001139 mElements[i] = new Element(subElementIds[i], mRS);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001140 mElements[i].updateFromNative();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001141 mOffsetInBytes[i] = mSize;
1142 mSize += mElements[i].mSize * mArraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001143 }
1144 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -08001145 updateVisibleSubElements();
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001146 }
1147
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001148 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001149 * Create a custom Element of the specified DataType. The DataKind will be
1150 * set to USER and the vector size to 1 indicating non-vector.
1151 *
1152 * @param rs The context associated with the new Element.
1153 * @param dt The DataType for the new element.
1154 * @return Element
1155 */
Mathew Inwood15324472018-08-06 11:18:49 +01001156 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001157 static Element createUser(RenderScript rs, DataType dt) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001158 DataKind dk = DataKind.USER;
1159 boolean norm = false;
1160 int vecSize = 1;
Tim Murray460a0492013-11-19 12:45:54 -08001161 long id = rs.nElementCreate(dt.mID, dk.mID, norm, vecSize);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001162 return new Element(id, rs, dt, dk, norm, vecSize);
Jason Sams718cd1f2009-12-23 14:35:29 -08001163 }
1164
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001165 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001166 * Create a custom vector element of the specified DataType and vector size.
Stephen Hines3beb60e2012-02-14 20:38:20 -08001167 * DataKind will be set to USER. Only primitive types (FLOAT_32, FLOAT_64,
1168 * SIGNED_8, SIGNED_16, SIGNED_32, SIGNED_64, UNSIGNED_8, UNSIGNED_16,
1169 * UNSIGNED_32, UNSIGNED_64, BOOLEAN) are supported.
Jason Samsa1b13ed2010-11-12 14:58:37 -08001170 *
1171 * @param rs The context associated with the new Element.
Stephen Hines3beb60e2012-02-14 20:38:20 -08001172 * @param dt The DataType for the new Element.
Jason Samsa1b13ed2010-11-12 14:58:37 -08001173 * @param size Vector size for the new Element. Range 2-4 inclusive
1174 * supported.
1175 *
1176 * @return Element
1177 */
Jason Sams718cd1f2009-12-23 14:35:29 -08001178 public static Element createVector(RenderScript rs, DataType dt, int size) {
Jason Sams718cd1f2009-12-23 14:35:29 -08001179 if (size < 2 || size > 4) {
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001180 throw new RSIllegalArgumentException("Vector size out of range 2-4.");
Jason Samsea84a7c2009-09-04 14:42:41 -07001181 }
Stephen Hines3beb60e2012-02-14 20:38:20 -08001182
1183 switch (dt) {
1184 // Support only primitive integer/float/boolean types as vectors.
Jason Sams54371b42015-05-13 13:21:30 -07001185 case FLOAT_16:
Stephen Hines3beb60e2012-02-14 20:38:20 -08001186 case FLOAT_32:
1187 case FLOAT_64:
1188 case SIGNED_8:
1189 case SIGNED_16:
1190 case SIGNED_32:
1191 case SIGNED_64:
1192 case UNSIGNED_8:
1193 case UNSIGNED_16:
1194 case UNSIGNED_32:
1195 case UNSIGNED_64:
1196 case BOOLEAN: {
1197 DataKind dk = DataKind.USER;
1198 boolean norm = false;
Tim Murray460a0492013-11-19 12:45:54 -08001199 long id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
Stephen Hines3beb60e2012-02-14 20:38:20 -08001200 return new Element(id, rs, dt, dk, norm, size);
1201 }
1202
1203 default: {
1204 throw new RSIllegalArgumentException("Cannot create vector of " +
1205 "non-primitive type.");
1206 }
1207 }
Jason Samsea84a7c2009-09-04 14:42:41 -07001208 }
1209
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001210 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001211 * Create a new pixel Element type. A matching DataType and DataKind must
1212 * be provided. The DataType and DataKind must contain the same number of
1213 * components. Vector size will be set to 1.
1214 *
1215 * @param rs The context associated with the new Element.
1216 * @param dt The DataType for the new element.
1217 * @param dk The DataKind to specify the mapping of each component in the
1218 * DataType.
1219 *
1220 * @return Element
1221 */
Jason Sams718cd1f2009-12-23 14:35:29 -08001222 public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
Jason Sams718cd1f2009-12-23 14:35:29 -08001223 if (!(dk == DataKind.PIXEL_L ||
1224 dk == DataKind.PIXEL_A ||
1225 dk == DataKind.PIXEL_LA ||
1226 dk == DataKind.PIXEL_RGB ||
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001227 dk == DataKind.PIXEL_RGBA ||
Jason Samsdd6c8b32013-02-15 17:27:24 -08001228 dk == DataKind.PIXEL_DEPTH ||
1229 dk == DataKind.PIXEL_YUV)) {
Jason Samsc1d62102010-11-04 14:32:19 -07001230 throw new RSIllegalArgumentException("Unsupported DataKind");
Jason Sams718cd1f2009-12-23 14:35:29 -08001231 }
1232 if (!(dt == DataType.UNSIGNED_8 ||
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001233 dt == DataType.UNSIGNED_16 ||
Jason Sams718cd1f2009-12-23 14:35:29 -08001234 dt == DataType.UNSIGNED_5_6_5 ||
1235 dt == DataType.UNSIGNED_4_4_4_4 ||
1236 dt == DataType.UNSIGNED_5_5_5_1)) {
Jason Samsc1d62102010-11-04 14:32:19 -07001237 throw new RSIllegalArgumentException("Unsupported DataType");
Jason Sams718cd1f2009-12-23 14:35:29 -08001238 }
1239 if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) {
Jason Samsc1d62102010-11-04 14:32:19 -07001240 throw new RSIllegalArgumentException("Bad kind and type combo");
Jason Sams718cd1f2009-12-23 14:35:29 -08001241 }
1242 if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) {
Jason Samsc1d62102010-11-04 14:32:19 -07001243 throw new RSIllegalArgumentException("Bad kind and type combo");
Jason Sams718cd1f2009-12-23 14:35:29 -08001244 }
1245 if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
Jason Samsc1d62102010-11-04 14:32:19 -07001246 throw new RSIllegalArgumentException("Bad kind and type combo");
Jason Sams718cd1f2009-12-23 14:35:29 -08001247 }
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001248 if (dt == DataType.UNSIGNED_16 &&
1249 dk != DataKind.PIXEL_DEPTH) {
1250 throw new RSIllegalArgumentException("Bad kind and type combo");
1251 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001252
1253 int size = 1;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001254 switch (dk) {
1255 case PIXEL_LA:
Jason Sams718cd1f2009-12-23 14:35:29 -08001256 size = 2;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001257 break;
1258 case PIXEL_RGB:
Jason Sams718cd1f2009-12-23 14:35:29 -08001259 size = 3;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001260 break;
1261 case PIXEL_RGBA:
Jason Sams718cd1f2009-12-23 14:35:29 -08001262 size = 4;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001263 break;
1264 case PIXEL_DEPTH:
1265 size = 2;
1266 break;
Jason Sams718cd1f2009-12-23 14:35:29 -08001267 }
1268
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001269 boolean norm = true;
Tim Murray460a0492013-11-19 12:45:54 -08001270 long id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001271 return new Element(id, rs, dt, dk, norm, size);
Jason Sams718cd1f2009-12-23 14:35:29 -08001272 }
Jason Sams36e612a2009-07-31 16:26:13 -07001273
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001274 /**
Stephen Hinesf257e512011-06-14 14:54:29 -07001275 * Check if the current Element is compatible with another Element.
1276 * Primitive Elements are compatible if they share the same underlying
1277 * size and type (i.e. U8 is compatible with A_8). User-defined Elements
1278 * must be equal in order to be compatible. This requires strict name
1279 * equivalence for all sub-Elements (in addition to structural equivalence).
1280 *
1281 * @param e The Element to check compatibility with.
1282 *
1283 * @return boolean true if the Elements are compatible, otherwise false.
1284 */
1285 public boolean isCompatible(Element e) {
1286 // Try strict BaseObj equality to start with.
1287 if (this.equals(e)) {
1288 return true;
1289 }
1290
1291 // Ignore mKind because it is allowed to be different (user vs. pixel).
1292 // We also ignore mNormalized because it can be different. The mType
Stephen Hines20948112012-02-14 19:42:42 -08001293 // field must not be NONE since we require name equivalence for
1294 // all user-created Elements.
Stephen Hinesf257e512011-06-14 14:54:29 -07001295 return ((mSize == e.mSize) &&
Stephen Hines20948112012-02-14 19:42:42 -08001296 (mType != DataType.NONE) &&
Stephen Hinesf257e512011-06-14 14:54:29 -07001297 (mType == e.mType) &&
1298 (mVectorSize == e.mVectorSize));
1299 }
1300
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001301 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001302 * Builder class for producing complex elements with matching field and name
1303 * pairs. The builder starts empty. The order in which elements are added
1304 * is retained for the layout in memory.
1305 *
1306 */
Jason Sams36e612a2009-07-31 16:26:13 -07001307 public static class Builder {
1308 RenderScript mRS;
Jason Sams718cd1f2009-12-23 14:35:29 -08001309 Element[] mElements;
1310 String[] mElementNames;
Jason Sams70d4e502010-09-02 17:35:23 -07001311 int[] mArraySizes;
Jason Sams718cd1f2009-12-23 14:35:29 -08001312 int mCount;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -08001313 int mSkipPadding;
Jason Sams22534172009-08-04 16:58:20 -07001314
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001315 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001316 * Create a builder object.
1317 *
1318 * @param rs
1319 */
Jason Sams22534172009-08-04 16:58:20 -07001320 public Builder(RenderScript rs) {
Jason Sams36e612a2009-07-31 16:26:13 -07001321 mRS = rs;
Jason Sams718cd1f2009-12-23 14:35:29 -08001322 mCount = 0;
1323 mElements = new Element[8];
1324 mElementNames = new String[8];
Jason Sams70d4e502010-09-02 17:35:23 -07001325 mArraySizes = new int[8];
Jason Sams36e612a2009-07-31 16:26:13 -07001326 }
1327
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001328 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001329 * Add an array of elements to this element.
1330 *
1331 * @param element
1332 * @param name
1333 * @param arraySize
1334 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001335 public Builder add(Element element, String name, int arraySize) {
Jason Sams70d4e502010-09-02 17:35:23 -07001336 if (arraySize < 1) {
Jason Samsc1d62102010-11-04 14:32:19 -07001337 throw new RSIllegalArgumentException("Array size cannot be less than 1.");
Jason Sams70d4e502010-09-02 17:35:23 -07001338 }
Alex Sakhartchouke60149d2011-11-15 15:15:21 -08001339
1340 // Skip padding fields after a vector 3 type.
1341 if (mSkipPadding != 0) {
1342 if (name.startsWith("#padding_")) {
1343 mSkipPadding = 0;
1344 return this;
1345 }
1346 }
1347
1348 if (element.mVectorSize == 3) {
1349 mSkipPadding = 1;
1350 } else {
1351 mSkipPadding = 0;
1352 }
1353
Jason Sams718cd1f2009-12-23 14:35:29 -08001354 if(mCount == mElements.length) {
1355 Element[] e = new Element[mCount + 8];
1356 String[] s = new String[mCount + 8];
Jason Sams70d4e502010-09-02 17:35:23 -07001357 int[] as = new int[mCount + 8];
Jason Sams718cd1f2009-12-23 14:35:29 -08001358 System.arraycopy(mElements, 0, e, 0, mCount);
1359 System.arraycopy(mElementNames, 0, s, 0, mCount);
Jason Sams70d4e502010-09-02 17:35:23 -07001360 System.arraycopy(mArraySizes, 0, as, 0, mCount);
Jason Sams718cd1f2009-12-23 14:35:29 -08001361 mElements = e;
1362 mElementNames = s;
Jason Sams70d4e502010-09-02 17:35:23 -07001363 mArraySizes = as;
Jason Sams36e612a2009-07-31 16:26:13 -07001364 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001365 mElements[mCount] = element;
1366 mElementNames[mCount] = name;
Jason Sams70d4e502010-09-02 17:35:23 -07001367 mArraySizes[mCount] = arraySize;
Jason Sams718cd1f2009-12-23 14:35:29 -08001368 mCount++;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001369 return this;
Jason Sams07ae4062009-08-27 20:23:34 -07001370 }
1371
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001372 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001373 * Add a single element to this Element.
1374 *
1375 * @param element
1376 * @param name
1377 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001378 public Builder add(Element element, String name) {
1379 return add(element, name, 1);
Jason Sams70d4e502010-09-02 17:35:23 -07001380 }
1381
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001382 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001383 * Create the element from this builder.
1384 *
1385 *
1386 * @return Element
1387 */
Jason Sams22534172009-08-04 16:58:20 -07001388 public Element create() {
Jason Sams771bebb2009-12-07 12:40:12 -08001389 mRS.validate();
Jason Sams718cd1f2009-12-23 14:35:29 -08001390 Element[] ein = new Element[mCount];
1391 String[] sin = new String[mCount];
Jason Sams70d4e502010-09-02 17:35:23 -07001392 int[] asin = new int[mCount];
Jason Sams718cd1f2009-12-23 14:35:29 -08001393 java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
1394 java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
Jason Sams70d4e502010-09-02 17:35:23 -07001395 java.lang.System.arraycopy(mArraySizes, 0, asin, 0, mCount);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001396
Ashok Bhat98071552014-02-12 09:54:43 +00001397 long[] ids = new long[ein.length];
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001398 for (int ct = 0; ct < ein.length; ct++ ) {
Ashok Bhat98071552014-02-12 09:54:43 +00001399 ids[ct] = ein[ct].getID(mRS);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001400 }
Tim Murray460a0492013-11-19 12:45:54 -08001401 long id = mRS.nElementCreate2(ids, sin, asin);
Jason Sams70d4e502010-09-02 17:35:23 -07001402 return new Element(id, mRS, ein, sin, asin);
Jason Sams36e612a2009-07-31 16:26:13 -07001403 }
1404 }
Jason Sams36e612a2009-07-31 16:26:13 -07001405}
1406