blob: 0941907d35f8f2f03ff910caff89b07d06b1ef06 [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>
Jason Sams36e612a2009-07-31 16:26:13 -070054 **/
55public class Element extends BaseObj {
Jason Samsea84a7c2009-09-04 14:42:41 -070056 int mSize;
Jason Sams718cd1f2009-12-23 14:35:29 -080057 Element[] mElements;
58 String[] mElementNames;
Jason Sams70d4e502010-09-02 17:35:23 -070059 int[] mArraySizes;
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -070060 int[] mOffsetInBytes;
Jason Sams36e612a2009-07-31 16:26:13 -070061
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -080062 int[] mVisibleElementMap;
63
Jason Sams718cd1f2009-12-23 14:35:29 -080064 DataType mType;
65 DataKind mKind;
66 boolean mNormalized;
67 int mVectorSize;
Jason Sams768bc022009-09-21 19:41:04 -070068
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -080069 private void updateVisibleSubElements() {
70 if (mElements == null) {
71 return;
72 }
73
74 int noPaddingFieldCount = 0;
75 int fieldCount = mElementNames.length;
76 // Find out how many elements are not padding
77 for (int ct = 0; ct < fieldCount; ct ++) {
78 if (mElementNames[ct].charAt(0) != '#') {
79 noPaddingFieldCount ++;
80 }
81 }
82 mVisibleElementMap = new int[noPaddingFieldCount];
83
84 // Make a map that points us at non-padding elements
85 for (int ct = 0, ctNoPadding = 0; ct < fieldCount; ct ++) {
86 if (mElementNames[ct].charAt(0) != '#') {
87 mVisibleElementMap[ctNoPadding ++] = ct;
88 }
89 }
90 }
91
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070092 /**
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -070093 * @return element size in bytes
94 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -070095 public int getBytesSize() {return mSize;}
Jason Sams36e612a2009-07-31 16:26:13 -070096
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070097 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -070098 * Returns the number of vector components. 2 for float2, 4 for
99 * float4, etc.
Alex Sakhartchoukfd79e022011-12-22 14:30:55 -0800100 * @return element vector size
101 */
102 public int getVectorSize() {return mVectorSize;}
103
Jason Samsa1b13ed2010-11-12 14:58:37 -0800104
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700105 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800106 * DataType represents the basic type information for a basic element. The
Alex Sakhartchoukf5d8ac72011-12-16 09:44:26 -0800107 * naming convention follows. For numeric types it is FLOAT,
108 * SIGNED, or UNSIGNED followed by the _BITS where BITS is the
109 * size of the data. BOOLEAN is a true / false (1,0)
110 * represented in an 8 bit container. The UNSIGNED variants
111 * with multiple bit definitions are for packed graphical data
112 * formats and represent vectors with per vector member sizes
113 * which are treated as a single unit for packing and alignment
114 * purposes.
Jason Samsa1b13ed2010-11-12 14:58:37 -0800115 *
116 * MATRIX the three matrix types contain FLOAT_32 elements and are treated
117 * as 32 bits for alignment purposes.
118 *
Jason Samsfb4f5cf2015-03-26 17:39:34 -0700119 * RS_* objects: opaque handles with implementation dependent
120 * sizes.
Jason Samsa1b13ed2010-11-12 14:58:37 -0800121 */
Jason Sams36e612a2009-07-31 16:26:13 -0700122 public enum DataType {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800123 NONE (0, 0),
Jason Samsa5835a22014-11-05 15:16:26 -0800124 FLOAT_16 (1, 2),
Jason Sams718cd1f2009-12-23 14:35:29 -0800125 FLOAT_32 (2, 4),
Stephen Hines02f417052010-09-30 15:19:22 -0700126 FLOAT_64 (3, 8),
Jason Sams718cd1f2009-12-23 14:35:29 -0800127 SIGNED_8 (4, 1),
128 SIGNED_16 (5, 2),
129 SIGNED_32 (6, 4),
Stephen Hinesef1dac22010-10-01 15:39:33 -0700130 SIGNED_64 (7, 8),
Jason Sams718cd1f2009-12-23 14:35:29 -0800131 UNSIGNED_8 (8, 1),
132 UNSIGNED_16 (9, 2),
133 UNSIGNED_32 (10, 4),
Stephen Hines52d83632010-10-11 16:10:42 -0700134 UNSIGNED_64 (11, 8),
Jason Sams718cd1f2009-12-23 14:35:29 -0800135
Jason Samsf110d4b2010-06-21 17:42:41 -0700136 BOOLEAN(12, 1),
Jason Sams718cd1f2009-12-23 14:35:29 -0800137
Jason Samsf110d4b2010-06-21 17:42:41 -0700138 UNSIGNED_5_6_5 (13, 2),
139 UNSIGNED_5_5_5_1 (14, 2),
140 UNSIGNED_4_4_4_4 (15, 2),
141
Jason Sams1d45c472010-08-25 14:31:48 -0700142 MATRIX_4X4 (16, 64),
143 MATRIX_3X3 (17, 36),
144 MATRIX_2X2 (18, 16),
145
Jason Samsb49dfea2014-06-18 13:17:57 -0700146 RS_ELEMENT (1000),
147 RS_TYPE (1001),
148 RS_ALLOCATION (1002),
149 RS_SAMPLER (1003),
150 RS_SCRIPT (1004),
151 RS_MESH (1005),
152 RS_PROGRAM_FRAGMENT (1006),
153 RS_PROGRAM_VERTEX (1007),
154 RS_PROGRAM_RASTER (1008),
155 RS_PROGRAM_STORE (1009),
156 RS_FONT (1010);
Jason Sams36e612a2009-07-31 16:26:13 -0700157
158 int mID;
Jason Sams718cd1f2009-12-23 14:35:29 -0800159 int mSize;
160 DataType(int id, int size) {
Jason Sams36e612a2009-07-31 16:26:13 -0700161 mID = id;
Jason Sams718cd1f2009-12-23 14:35:29 -0800162 mSize = size;
Jason Sams36e612a2009-07-31 16:26:13 -0700163 }
Jason Samsb49dfea2014-06-18 13:17:57 -0700164
165 DataType(int id) {
166 mID = id;
167 mSize = 4;
168 if (RenderScript.sPointerSize == 8) {
169 mSize = 32;
170 }
171 }
Jason Sams36e612a2009-07-31 16:26:13 -0700172 }
173
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700174 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800175 * The special interpretation of the data if required. This is primarly
176 * useful for graphical data. USER indicates no special interpretation is
177 * expected. PIXEL is used in conjunction with the standard data types for
178 * representing texture formats.
179 */
Jason Sams36e612a2009-07-31 16:26:13 -0700180 public enum DataKind {
181 USER (0),
Jason Sams718cd1f2009-12-23 14:35:29 -0800182
183 PIXEL_L (7),
184 PIXEL_A (8),
185 PIXEL_LA (9),
186 PIXEL_RGB (10),
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -0700187 PIXEL_RGBA (11),
Jason Sams8140d7b2012-12-13 17:01:09 -0800188 PIXEL_DEPTH (12),
189 PIXEL_YUV(13);
Jason Sams36e612a2009-07-31 16:26:13 -0700190
191 int mID;
192 DataKind(int id) {
193 mID = id;
194 }
195 }
196
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700197 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800198 * Return if a element is too complex for use as a data source for a Mesh or
199 * a Program.
200 *
201 * @return boolean
202 */
Jason Samsc1d62102010-11-04 14:32:19 -0700203 public boolean isComplex() {
204 if (mElements == null) {
205 return false;
206 }
207 for (int ct=0; ct < mElements.length; ct++) {
208 if (mElements[ct].mElements != null) {
209 return true;
210 }
211 }
212 return false;
213 }
214
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700215 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700216 * Elements could be simple, such as an int or a float, or a
217 * structure with multiple sub elements, such as a collection of
218 * floats, float2, float4. This function returns zero for simple
219 * elements or the number of sub-elements otherwise.
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700220 * @return number of sub-elements in this element
221 */
222 public int getSubElementCount() {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800223 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700224 return 0;
225 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800226 return mVisibleElementMap.length;
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700227 }
228
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700229 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700230 * For complex elements, this function will return the
231 * sub-element at index
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700232 * @param index index of the sub-element to return
233 * @return sub-element in this element at given index
234 */
235 public Element getSubElement(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800236 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700237 throw new RSIllegalArgumentException("Element contains no sub-elements");
238 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800239 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700240 throw new RSIllegalArgumentException("Illegal sub-element index");
241 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800242 return mElements[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700243 }
244
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700245 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700246 * For complex elements, this function will return the
247 * sub-element name at index
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700248 * @param index index of the sub-element
249 * @return sub-element in this element at given index
250 */
251 public String getSubElementName(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800252 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700253 throw new RSIllegalArgumentException("Element contains no sub-elements");
254 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800255 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700256 throw new RSIllegalArgumentException("Illegal sub-element index");
257 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800258 return mElementNames[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700259 }
260
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700261 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700262 * For complex elements, some sub-elements could be statically
263 * sized arrays. This function will return the array size for
264 * sub-element at index
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700265 * @param index index of the sub-element
266 * @return array size of sub-element in this element at given index
267 */
268 public int getSubElementArraySize(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800269 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700270 throw new RSIllegalArgumentException("Element contains no sub-elements");
271 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800272 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700273 throw new RSIllegalArgumentException("Illegal sub-element index");
274 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800275 return mArraySizes[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700276 }
277
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700278 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700279 * This function specifies the location of a sub-element within
280 * the element
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700281 * @param index index of the sub-element
282 * @return offset in bytes of sub-element in this element at given index
283 */
284 public int getSubElementOffsetBytes(int index) {
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800285 if (mVisibleElementMap == null) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700286 throw new RSIllegalArgumentException("Element contains no sub-elements");
287 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800288 if (index < 0 || index >= mVisibleElementMap.length) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700289 throw new RSIllegalArgumentException("Illegal sub-element index");
290 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -0800291 return mOffsetInBytes[mVisibleElementMap[index]];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700292 }
293
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700294 /**
Alex Sakhartchoukf5d8ac72011-12-16 09:44:26 -0800295 * @return element data type
296 */
297 public DataType getDataType() {
298 return mType;
299 }
300
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700301 /**
Alex Sakhartchoukf5d8ac72011-12-16 09:44:26 -0800302 * @return element data kind
303 */
304 public DataKind getDataKind() {
305 return mKind;
306 }
307
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700308 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800309 * Utility function for returning an Element containing a single Boolean.
310 *
311 * @param rs Context to which the element will belong.
312 *
313 * @return Element
314 */
Jason Samsf110d4b2010-06-21 17:42:41 -0700315 public static Element BOOLEAN(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700316 if (rs.mElement_BOOLEAN == null) {
317 synchronized (rs) {
318 if (rs.mElement_BOOLEAN == null) {
319 rs.mElement_BOOLEAN = createUser(rs, DataType.BOOLEAN);
320 }
321 }
Jason Samsf110d4b2010-06-21 17:42:41 -0700322 }
323 return rs.mElement_BOOLEAN;
324 }
325
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700326 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800327 * Utility function for returning an Element containing a single UNSIGNED_8.
328 *
329 * @param rs Context to which the element will belong.
330 *
331 * @return Element
332 */
Jason Sams8cb39de2010-06-01 15:47:01 -0700333 public static Element U8(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700334 if (rs.mElement_U8 == null) {
335 synchronized (rs) {
336 if (rs.mElement_U8 == null) {
337 rs.mElement_U8 = createUser(rs, DataType.UNSIGNED_8);
338 }
339 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800340 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700341 return rs.mElement_U8;
Jason Sams718cd1f2009-12-23 14:35:29 -0800342 }
343
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700344 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -0800345 * Utility function for returning an Element containing a single SIGNED_8.
346 *
347 * @param rs Context to which the element will belong.
348 *
349 * @return Element
350 */
Jason Sams8cb39de2010-06-01 15:47:01 -0700351 public static Element I8(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700352 if (rs.mElement_I8 == null) {
353 synchronized (rs) {
354 if (rs.mElement_I8 == null) {
355 rs.mElement_I8 = createUser(rs, DataType.SIGNED_8);
356 }
357 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800358 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700359 return rs.mElement_I8;
Jason Sams718cd1f2009-12-23 14:35:29 -0800360 }
361
Jason Samse29f3e72010-06-08 15:40:48 -0700362 public static Element U16(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700363 if (rs.mElement_U16 == null) {
364 synchronized (rs) {
365 if (rs.mElement_U16 == null) {
366 rs.mElement_U16 = createUser(rs, DataType.UNSIGNED_16);
367 }
368 }
Jason Samse29f3e72010-06-08 15:40:48 -0700369 }
370 return rs.mElement_U16;
371 }
372
373 public static Element I16(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700374 if (rs.mElement_I16 == null) {
375 synchronized (rs) {
376 if (rs.mElement_I16 == null) {
377 rs.mElement_I16 = createUser(rs, DataType.SIGNED_16);
378 }
379 }
Jason Samse29f3e72010-06-08 15:40:48 -0700380 }
381 return rs.mElement_I16;
382 }
383
Jason Sams8cb39de2010-06-01 15:47:01 -0700384 public static Element U32(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700385 if (rs.mElement_U32 == null) {
386 synchronized (rs) {
387 if (rs.mElement_U32 == null) {
388 rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32);
389 }
390 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800391 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700392 return rs.mElement_U32;
Jason Sams718cd1f2009-12-23 14:35:29 -0800393 }
394
Jason Sams8cb39de2010-06-01 15:47:01 -0700395 public static Element I32(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700396 if (rs.mElement_I32 == null) {
397 synchronized (rs) {
398 if (rs.mElement_I32 == null) {
399 rs.mElement_I32 = createUser(rs, DataType.SIGNED_32);
400 }
401 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800402 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700403 return rs.mElement_I32;
Jason Sams718cd1f2009-12-23 14:35:29 -0800404 }
405
Stephen Hines52d83632010-10-11 16:10:42 -0700406 public static Element U64(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700407 if (rs.mElement_U64 == null) {
408 synchronized (rs) {
409 if (rs.mElement_U64 == null) {
410 rs.mElement_U64 = createUser(rs, DataType.UNSIGNED_64);
411 }
412 }
Stephen Hines52d83632010-10-11 16:10:42 -0700413 }
414 return rs.mElement_U64;
415 }
416
Stephen Hinesef1dac22010-10-01 15:39:33 -0700417 public static Element I64(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700418 if (rs.mElement_I64 == null) {
419 synchronized (rs) {
420 if (rs.mElement_I64 == null) {
421 rs.mElement_I64 = createUser(rs, DataType.SIGNED_64);
422 }
423 }
Stephen Hinesef1dac22010-10-01 15:39:33 -0700424 }
425 return rs.mElement_I64;
426 }
427
Jason Samsa5835a22014-11-05 15:16:26 -0800428 public static Element F16(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700429 if (rs.mElement_F16 == null) {
430 synchronized (rs) {
431 if (rs.mElement_F16 == null) {
432 rs.mElement_F16 = createUser(rs, DataType.FLOAT_16);
433 }
434 }
Jason Samsa5835a22014-11-05 15:16:26 -0800435 }
436 return rs.mElement_F16;
437 }
438
Jason Sams8cb39de2010-06-01 15:47:01 -0700439 public static Element F32(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700440 if (rs.mElement_F32 == null) {
441 synchronized (rs) {
442 if (rs.mElement_F32 == null) {
443 rs.mElement_F32 = createUser(rs, DataType.FLOAT_32);
444 }
445 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800446 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700447 return rs.mElement_F32;
Jason Sams718cd1f2009-12-23 14:35:29 -0800448 }
449
Stephen Hines02f417052010-09-30 15:19:22 -0700450 public static Element F64(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700451 if (rs.mElement_F64 == null) {
452 synchronized (rs) {
453 if (rs.mElement_F64 == null) {
454 rs.mElement_F64 = createUser(rs, DataType.FLOAT_64);
455 }
456 }
Stephen Hines02f417052010-09-30 15:19:22 -0700457 }
458 return rs.mElement_F64;
459 }
460
Jason Sams8cb39de2010-06-01 15:47:01 -0700461 public static Element ELEMENT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700462 if (rs.mElement_ELEMENT == null) {
463 synchronized (rs) {
464 if (rs.mElement_ELEMENT == null) {
465 rs.mElement_ELEMENT = createUser(rs, DataType.RS_ELEMENT);
466 }
467 }
Jason Samsa70f4162010-03-26 15:33:42 -0700468 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700469 return rs.mElement_ELEMENT;
Jason Samsa70f4162010-03-26 15:33:42 -0700470 }
471
Jason Sams8cb39de2010-06-01 15:47:01 -0700472 public static Element TYPE(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700473 if (rs.mElement_TYPE == null) {
474 synchronized (rs) {
475 if (rs.mElement_TYPE == null) {
476 rs.mElement_TYPE = createUser(rs, DataType.RS_TYPE);
477 }
478 }
Jason Samsa70f4162010-03-26 15:33:42 -0700479 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700480 return rs.mElement_TYPE;
Jason Samsa70f4162010-03-26 15:33:42 -0700481 }
482
Jason Sams8cb39de2010-06-01 15:47:01 -0700483 public static Element ALLOCATION(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700484 if (rs.mElement_ALLOCATION == null) {
485 synchronized (rs) {
486 if (rs.mElement_ALLOCATION == null) {
487 rs.mElement_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION);
488 }
489 }
Jason Samsa70f4162010-03-26 15:33:42 -0700490 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700491 return rs.mElement_ALLOCATION;
Jason Samsa70f4162010-03-26 15:33:42 -0700492 }
493
Jason Sams8cb39de2010-06-01 15:47:01 -0700494 public static Element SAMPLER(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700495 if (rs.mElement_SAMPLER == null) {
496 synchronized (rs) {
497 if (rs.mElement_SAMPLER == null) {
498 rs.mElement_SAMPLER = createUser(rs, DataType.RS_SAMPLER);
499 }
500 }
Jason Samsa70f4162010-03-26 15:33:42 -0700501 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700502 return rs.mElement_SAMPLER;
Jason Samsa70f4162010-03-26 15:33:42 -0700503 }
504
Jason Sams8cb39de2010-06-01 15:47:01 -0700505 public static Element SCRIPT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700506 if (rs.mElement_SCRIPT == null) {
507 synchronized (rs) {
508 if (rs.mElement_SCRIPT == null) {
509 rs.mElement_SCRIPT = createUser(rs, DataType.RS_SCRIPT);
510 }
511 }
Jason Samsa70f4162010-03-26 15:33:42 -0700512 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700513 return rs.mElement_SCRIPT;
Jason Samsa70f4162010-03-26 15:33:42 -0700514 }
515
Jason Sams8cb39de2010-06-01 15:47:01 -0700516 public static Element MESH(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700517 if (rs.mElement_MESH == null) {
518 synchronized (rs) {
519 if (rs.mElement_MESH == null) {
520 rs.mElement_MESH = createUser(rs, DataType.RS_MESH);
521 }
522 }
Jason Samsa70f4162010-03-26 15:33:42 -0700523 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700524 return rs.mElement_MESH;
Jason Samsa70f4162010-03-26 15:33:42 -0700525 }
526
Jason Sams8cb39de2010-06-01 15:47:01 -0700527 public static Element PROGRAM_FRAGMENT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700528 if (rs.mElement_PROGRAM_FRAGMENT == null) {
529 synchronized (rs) {
530 if (rs.mElement_PROGRAM_FRAGMENT == null) {
531 rs.mElement_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT);
532 }
533 }
Jason Samsa70f4162010-03-26 15:33:42 -0700534 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700535 return rs.mElement_PROGRAM_FRAGMENT;
Jason Samsa70f4162010-03-26 15:33:42 -0700536 }
537
Jason Sams8cb39de2010-06-01 15:47:01 -0700538 public static Element PROGRAM_VERTEX(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700539 if (rs.mElement_PROGRAM_VERTEX == null) {
540 synchronized (rs) {
541 if (rs.mElement_PROGRAM_VERTEX == null) {
542 rs.mElement_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX);
543 }
544 }
Jason Samsa70f4162010-03-26 15:33:42 -0700545 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700546 return rs.mElement_PROGRAM_VERTEX;
Jason Samsa70f4162010-03-26 15:33:42 -0700547 }
548
Jason Sams8cb39de2010-06-01 15:47:01 -0700549 public static Element PROGRAM_RASTER(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700550 if (rs.mElement_PROGRAM_RASTER == null) {
551 synchronized (rs) {
552 if (rs.mElement_PROGRAM_RASTER == null) {
553 rs.mElement_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER);
554 }
555 }
Jason Samsa70f4162010-03-26 15:33:42 -0700556 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700557 return rs.mElement_PROGRAM_RASTER;
Jason Samsa70f4162010-03-26 15:33:42 -0700558 }
559
Jason Sams8cb39de2010-06-01 15:47:01 -0700560 public static Element PROGRAM_STORE(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700561 if (rs.mElement_PROGRAM_STORE == null) {
562 synchronized (rs) {
563 if (rs.mElement_PROGRAM_STORE == null) {
564 rs.mElement_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE);
565 }
566 }
Jason Samsa70f4162010-03-26 15:33:42 -0700567 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700568 return rs.mElement_PROGRAM_STORE;
Jason Samsa70f4162010-03-26 15:33:42 -0700569 }
570
Stephen Hines3a291412012-04-11 17:27:29 -0700571 public static Element FONT(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700572 if (rs.mElement_FONT == null) {
573 synchronized (rs) {
574 if (rs.mElement_FONT == null) {
575 rs.mElement_FONT = createUser(rs, DataType.RS_FONT);
576 }
577 }
Stephen Hines3a291412012-04-11 17:27:29 -0700578 }
579 return rs.mElement_FONT;
580 }
581
Jason Sams718cd1f2009-12-23 14:35:29 -0800582 public static Element A_8(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700583 if (rs.mElement_A_8 == null) {
584 synchronized (rs) {
585 if (rs.mElement_A_8 == null) {
586 rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A);
587 }
588 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800589 }
590 return rs.mElement_A_8;
591 }
592
593 public static Element RGB_565(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700594 if (rs.mElement_RGB_565 == null) {
595 synchronized (rs) {
596 if (rs.mElement_RGB_565 == null) {
597 rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB);
598 }
599 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800600 }
601 return rs.mElement_RGB_565;
602 }
603
604 public static Element RGB_888(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700605 if (rs.mElement_RGB_888 == null) {
606 synchronized (rs) {
607 if (rs.mElement_RGB_888 == null) {
608 rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB);
609 }
610 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800611 }
612 return rs.mElement_RGB_888;
613 }
614
615 public static Element RGBA_5551(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700616 if (rs.mElement_RGBA_5551 == null) {
617 synchronized (rs) {
618 if (rs.mElement_RGBA_5551 == null) {
619 rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA);
620 }
621 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800622 }
623 return rs.mElement_RGBA_5551;
624 }
625
626 public static Element RGBA_4444(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700627 if (rs.mElement_RGBA_4444 == null) {
628 synchronized (rs) {
629 if (rs.mElement_RGBA_4444 == null) {
630 rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA);
631 }
632 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800633 }
634 return rs.mElement_RGBA_4444;
635 }
636
637 public static Element RGBA_8888(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700638 if (rs.mElement_RGBA_8888 == null) {
639 synchronized (rs) {
640 if (rs.mElement_RGBA_8888 == null) {
641 rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA);
642 }
643 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800644 }
645 return rs.mElement_RGBA_8888;
646 }
647
Jason Samsa5835a22014-11-05 15:16:26 -0800648 public static Element F16_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700649 if (rs.mElement_HALF_2 == null) {
650 synchronized (rs) {
651 if (rs.mElement_HALF_2 == null) {
652 rs.mElement_HALF_2 = createVector(rs, DataType.FLOAT_16, 2);
653 }
654 }
Jason Samsa5835a22014-11-05 15:16:26 -0800655 }
656 return rs.mElement_HALF_2;
657 }
658
Jason Samsa5835a22014-11-05 15:16:26 -0800659 public static Element F16_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700660 if (rs.mElement_HALF_3 == null) {
661 synchronized (rs) {
662 if (rs.mElement_HALF_3 == null) {
663 rs.mElement_HALF_3 = createVector(rs, DataType.FLOAT_16, 3);
664 }
665 }
Jason Samsa5835a22014-11-05 15:16:26 -0800666 }
667 return rs.mElement_HALF_3;
668 }
669
Jason Samsa5835a22014-11-05 15:16:26 -0800670 public static Element F16_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700671 if (rs.mElement_HALF_4 == null) {
672 synchronized (rs) {
673 if (rs.mElement_HALF_4 == null) {
674 rs.mElement_HALF_4 = createVector(rs, DataType.FLOAT_16, 4);
675 }
676 }
Jason Samsa5835a22014-11-05 15:16:26 -0800677 }
678 return rs.mElement_HALF_4;
679 }
680
Jason Sams8cb39de2010-06-01 15:47:01 -0700681 public static Element F32_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700682 if (rs.mElement_FLOAT_2 == null) {
683 synchronized (rs) {
684 if (rs.mElement_FLOAT_2 == null) {
685 rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2);
686 }
687 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800688 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700689 return rs.mElement_FLOAT_2;
Jason Sams718cd1f2009-12-23 14:35:29 -0800690 }
691
Jason Sams8cb39de2010-06-01 15:47:01 -0700692 public static Element F32_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700693 if (rs.mElement_FLOAT_3 == null) {
694 synchronized (rs) {
695 if (rs.mElement_FLOAT_3 == null) {
696 rs.mElement_FLOAT_3 = createVector(rs, DataType.FLOAT_32, 3);
697 }
698 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800699 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700700 return rs.mElement_FLOAT_3;
Jason Sams718cd1f2009-12-23 14:35:29 -0800701 }
702
Jason Sams8cb39de2010-06-01 15:47:01 -0700703 public static Element F32_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700704 if (rs.mElement_FLOAT_4 == null) {
705 synchronized (rs) {
706 if (rs.mElement_FLOAT_4 == null) {
707 rs.mElement_FLOAT_4 = createVector(rs, DataType.FLOAT_32, 4);
708 }
709 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800710 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700711 return rs.mElement_FLOAT_4;
Jason Sams718cd1f2009-12-23 14:35:29 -0800712 }
713
Stephen Hines836c4a52011-06-01 14:38:10 -0700714 public static Element F64_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700715 if (rs.mElement_DOUBLE_2 == null) {
716 synchronized (rs) {
717 if (rs.mElement_DOUBLE_2 == null) {
718 rs.mElement_DOUBLE_2 = createVector(rs, DataType.FLOAT_64, 2);
719 }
720 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700721 }
722 return rs.mElement_DOUBLE_2;
723 }
724
725 public static Element F64_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700726 if (rs.mElement_DOUBLE_3 == null) {
727 synchronized (rs) {
728 if (rs.mElement_DOUBLE_3 == null) {
729 rs.mElement_DOUBLE_3 = createVector(rs, DataType.FLOAT_64, 3);
730 }
731 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700732 }
733 return rs.mElement_DOUBLE_3;
734 }
735
736 public static Element F64_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700737 if (rs.mElement_DOUBLE_4 == null) {
738 synchronized (rs) {
739 if (rs.mElement_DOUBLE_4 == null) {
740 rs.mElement_DOUBLE_4 = createVector(rs, DataType.FLOAT_64, 4);
741 }
742 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700743 }
744 return rs.mElement_DOUBLE_4;
745 }
746
747 public static Element U8_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700748 if (rs.mElement_UCHAR_2 == null) {
749 synchronized (rs) {
750 if (rs.mElement_UCHAR_2 == null) {
751 rs.mElement_UCHAR_2 = createVector(rs, DataType.UNSIGNED_8, 2);
752 }
753 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700754 }
755 return rs.mElement_UCHAR_2;
756 }
757
758 public static Element U8_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700759 if (rs.mElement_UCHAR_3 == null) {
760 synchronized (rs) {
761 if (rs.mElement_UCHAR_3 == null) {
762 rs.mElement_UCHAR_3 = createVector(rs, DataType.UNSIGNED_8, 3);
763 }
764 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700765 }
766 return rs.mElement_UCHAR_3;
767 }
768
Jason Sams8cb39de2010-06-01 15:47:01 -0700769 public static Element U8_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700770 if (rs.mElement_UCHAR_4 == null) {
771 synchronized (rs) {
772 if (rs.mElement_UCHAR_4 == null) {
773 rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4);
774 }
775 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800776 }
Jason Sams8cb39de2010-06-01 15:47:01 -0700777 return rs.mElement_UCHAR_4;
Jason Sams718cd1f2009-12-23 14:35:29 -0800778 }
779
Stephen Hines836c4a52011-06-01 14:38:10 -0700780 public static Element I8_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700781 if (rs.mElement_CHAR_2 == null) {
782 synchronized (rs) {
783 if (rs.mElement_CHAR_2 == null) {
784 rs.mElement_CHAR_2 = createVector(rs, DataType.SIGNED_8, 2);
785 }
786 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700787 }
788 return rs.mElement_CHAR_2;
789 }
790
791 public static Element I8_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700792 if (rs.mElement_CHAR_3 == null) {
793 synchronized (rs) {
794 if (rs.mElement_CHAR_3 == null) {
795 rs.mElement_CHAR_3 = createVector(rs, DataType.SIGNED_8, 3);
796 }
797 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700798 }
799 return rs.mElement_CHAR_3;
800 }
801
802 public static Element I8_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700803 if (rs.mElement_CHAR_4 == null) {
804 synchronized (rs) {
805 if (rs.mElement_CHAR_4 == null) {
806 rs.mElement_CHAR_4 = createVector(rs, DataType.SIGNED_8, 4);
807 }
808 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700809 }
810 return rs.mElement_CHAR_4;
811 }
812
813 public static Element U16_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700814 if (rs.mElement_USHORT_2 == null) {
815 synchronized (rs) {
816 if (rs.mElement_USHORT_2 == null) {
817 rs.mElement_USHORT_2 = createVector(rs, DataType.UNSIGNED_16, 2);
818 }
819 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700820 }
821 return rs.mElement_USHORT_2;
822 }
823
824 public static Element U16_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700825 if (rs.mElement_USHORT_3 == null) {
826 synchronized (rs) {
827 if (rs.mElement_USHORT_3 == null) {
828 rs.mElement_USHORT_3 = createVector(rs, DataType.UNSIGNED_16, 3);
829 }
830 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700831 }
832 return rs.mElement_USHORT_3;
833 }
834
835 public static Element U16_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700836 if (rs.mElement_USHORT_4 == null) {
837 synchronized (rs) {
838 if (rs.mElement_USHORT_4 == null) {
839 rs.mElement_USHORT_4 = createVector(rs, DataType.UNSIGNED_16, 4);
840 }
841 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700842 }
843 return rs.mElement_USHORT_4;
844 }
845
846 public static Element I16_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700847 if (rs.mElement_SHORT_2 == null) {
848 synchronized (rs) {
849 if (rs.mElement_SHORT_2 == null) {
850 rs.mElement_SHORT_2 = createVector(rs, DataType.SIGNED_16, 2);
851 }
852 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700853 }
854 return rs.mElement_SHORT_2;
855 }
856
857 public static Element I16_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700858 if (rs.mElement_SHORT_3 == null) {
859 synchronized (rs) {
860 if (rs.mElement_SHORT_3 == null) {
861 rs.mElement_SHORT_3 = createVector(rs, DataType.SIGNED_16, 3);
862 }
863 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700864 }
865 return rs.mElement_SHORT_3;
866 }
867
868 public static Element I16_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700869 if (rs.mElement_SHORT_4 == null) {
870 synchronized (rs) {
871 if (rs.mElement_SHORT_4 == null) {
872 rs.mElement_SHORT_4 = createVector(rs, DataType.SIGNED_16, 4);
873 }
874 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700875 }
876 return rs.mElement_SHORT_4;
877 }
878
879 public static Element U32_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700880 if (rs.mElement_UINT_2 == null) {
881 synchronized (rs) {
882 if (rs.mElement_UINT_2 == null) {
883 rs.mElement_UINT_2 = createVector(rs, DataType.UNSIGNED_32, 2);
884 }
885 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700886 }
887 return rs.mElement_UINT_2;
888 }
889
890 public static Element U32_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700891 if (rs.mElement_UINT_3 == null) {
892 synchronized (rs) {
893 if (rs.mElement_UINT_3 == null) {
894 rs.mElement_UINT_3 = createVector(rs, DataType.UNSIGNED_32, 3);
895 }
896 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700897 }
898 return rs.mElement_UINT_3;
899 }
900
901 public static Element U32_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700902 if (rs.mElement_UINT_4 == null) {
903 synchronized (rs) {
904 if (rs.mElement_UINT_4 == null) {
905 rs.mElement_UINT_4 = createVector(rs, DataType.UNSIGNED_32, 4);
906 }
907 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700908 }
909 return rs.mElement_UINT_4;
910 }
911
912 public static Element I32_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700913 if (rs.mElement_INT_2 == null) {
914 synchronized (rs) {
915 if (rs.mElement_INT_2 == null) {
916 rs.mElement_INT_2 = createVector(rs, DataType.SIGNED_32, 2);
917 }
918 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700919 }
920 return rs.mElement_INT_2;
921 }
922
923 public static Element I32_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700924 if (rs.mElement_INT_3 == null) {
925 synchronized (rs) {
926 if (rs.mElement_INT_3 == null) {
927 rs.mElement_INT_3 = createVector(rs, DataType.SIGNED_32, 3);
928 }
929 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700930 }
931 return rs.mElement_INT_3;
932 }
933
934 public static Element I32_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700935 if (rs.mElement_INT_4 == null) {
936 synchronized (rs) {
937 if (rs.mElement_INT_4 == null) {
938 rs.mElement_INT_4 = createVector(rs, DataType.SIGNED_32, 4);
939 }
940 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700941 }
942 return rs.mElement_INT_4;
943 }
944
945 public static Element U64_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700946 if (rs.mElement_ULONG_2 == null) {
947 synchronized (rs) {
948 if (rs.mElement_ULONG_2 == null) {
949 rs.mElement_ULONG_2 = createVector(rs, DataType.UNSIGNED_64, 2);
950 }
951 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700952 }
953 return rs.mElement_ULONG_2;
954 }
955
956 public static Element U64_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700957 if (rs.mElement_ULONG_3 == null) {
958 synchronized (rs) {
959 if (rs.mElement_ULONG_3 == null) {
960 rs.mElement_ULONG_3 = createVector(rs, DataType.UNSIGNED_64, 3);
961 }
962 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700963 }
964 return rs.mElement_ULONG_3;
965 }
966
967 public static Element U64_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700968 if (rs.mElement_ULONG_4 == null) {
969 synchronized (rs) {
970 if (rs.mElement_ULONG_4 == null) {
971 rs.mElement_ULONG_4 = createVector(rs, DataType.UNSIGNED_64, 4);
972 }
973 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700974 }
975 return rs.mElement_ULONG_4;
976 }
977
978 public static Element I64_2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700979 if (rs.mElement_LONG_2 == null) {
980 synchronized (rs) {
981 if (rs.mElement_LONG_2 == null) {
982 rs.mElement_LONG_2 = createVector(rs, DataType.SIGNED_64, 2);
983 }
984 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700985 }
986 return rs.mElement_LONG_2;
987 }
988
989 public static Element I64_3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -0700990 if (rs.mElement_LONG_3 == null) {
991 synchronized (rs) {
992 if (rs.mElement_LONG_3 == null) {
993 rs.mElement_LONG_3 = createVector(rs, DataType.SIGNED_64, 3);
994 }
995 }
Stephen Hines836c4a52011-06-01 14:38:10 -0700996 }
997 return rs.mElement_LONG_3;
998 }
999
1000 public static Element I64_4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001001 if (rs.mElement_LONG_4 == null) {
1002 synchronized (rs) {
1003 if (rs.mElement_LONG_4 == null) {
1004 rs.mElement_LONG_4 = createVector(rs, DataType.SIGNED_64, 4);
1005 }
1006 }
Stephen Hines836c4a52011-06-01 14:38:10 -07001007 }
1008 return rs.mElement_LONG_4;
1009 }
1010
Tim Murray932e78e2013-09-03 11:42:26 -07001011 public static Element YUV(RenderScript rs) {
1012 if (rs.mElement_YUV == null) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001013 synchronized (rs) {
1014 if (rs.mElement_YUV == null) {
1015 rs.mElement_YUV = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_YUV);
1016 }
1017 }
Tim Murray932e78e2013-09-03 11:42:26 -07001018 }
1019 return rs.mElement_YUV;
1020 }
1021
Jason Sams1d45c472010-08-25 14:31:48 -07001022 public static Element MATRIX_4X4(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001023 if (rs.mElement_MATRIX_4X4 == null) {
1024 synchronized (rs) {
1025 if (rs.mElement_MATRIX_4X4 == null) {
1026 rs.mElement_MATRIX_4X4 = createUser(rs, DataType.MATRIX_4X4);
1027 }
1028 }
Jason Sams1d45c472010-08-25 14:31:48 -07001029 }
1030 return rs.mElement_MATRIX_4X4;
1031 }
Jason Sams65c80f82012-05-08 17:30:26 -07001032
1033 /** @deprecated use MATRIX_4X4
1034 */
Jason Sams1d45c472010-08-25 14:31:48 -07001035 public static Element MATRIX4X4(RenderScript rs) {
1036 return MATRIX_4X4(rs);
1037 }
1038
1039 public static Element MATRIX_3X3(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001040 if (rs.mElement_MATRIX_3X3 == null) {
1041 synchronized (rs) {
1042 if (rs.mElement_MATRIX_3X3 == null) {
1043 rs.mElement_MATRIX_3X3 = createUser(rs, DataType.MATRIX_3X3);
1044 }
1045 }
Jason Sams1d45c472010-08-25 14:31:48 -07001046 }
Alex Sakhartchouk34769772011-02-28 16:01:28 -08001047 return rs.mElement_MATRIX_3X3;
Jason Sams1d45c472010-08-25 14:31:48 -07001048 }
1049
1050 public static Element MATRIX_2X2(RenderScript rs) {
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001051 if (rs.mElement_MATRIX_2X2 == null) {
1052 synchronized (rs) {
1053 if (rs.mElement_MATRIX_2X2 == null) {
1054 rs.mElement_MATRIX_2X2 = createUser(rs, DataType.MATRIX_2X2);
1055 }
1056 }
Jason Sams1d45c472010-08-25 14:31:48 -07001057 }
1058 return rs.mElement_MATRIX_2X2;
1059 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001060
Tim Murray460a0492013-11-19 12:45:54 -08001061 Element(long id, RenderScript rs, Element[] e, String[] n, int[] as) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001062 super(id, rs);
Jason Samsea84a7c2009-09-04 14:42:41 -07001063 mSize = 0;
Alex Sakhartchoukfd79e022011-12-22 14:30:55 -08001064 mVectorSize = 1;
Jason Sams718cd1f2009-12-23 14:35:29 -08001065 mElements = e;
1066 mElementNames = n;
Jason Sams70d4e502010-09-02 17:35:23 -07001067 mArraySizes = as;
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -08001068 mType = DataType.NONE;
1069 mKind = DataKind.USER;
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001070 mOffsetInBytes = new int[mElements.length];
Jason Sams718cd1f2009-12-23 14:35:29 -08001071 for (int ct = 0; ct < mElements.length; ct++ ) {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001072 mOffsetInBytes[ct] = mSize;
Alex Sakhartchouk9e401bc2010-10-13 14:22:02 -07001073 mSize += mElements[ct].mSize * mArraySizes[ct];
Jason Sams718cd1f2009-12-23 14:35:29 -08001074 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -08001075 updateVisibleSubElements();
Jason Sams718cd1f2009-12-23 14:35:29 -08001076 }
1077
Tim Murray460a0492013-11-19 12:45:54 -08001078 Element(long id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001079 super(id, rs);
Jason Sams252c0782011-01-11 17:42:52 -08001080 if ((dt != DataType.UNSIGNED_5_6_5) &&
1081 (dt != DataType.UNSIGNED_4_4_4_4) &&
1082 (dt != DataType.UNSIGNED_5_5_5_1)) {
Alex Sakhartchouke60149d2011-11-15 15:15:21 -08001083 if (size == 3) {
1084 mSize = dt.mSize * 4;
1085 } else {
1086 mSize = dt.mSize * size;
1087 }
Jason Sams252c0782011-01-11 17:42:52 -08001088 } else {
1089 mSize = dt.mSize;
1090 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001091 mType = dt;
1092 mKind = dk;
1093 mNormalized = norm;
1094 mVectorSize = size;
Jason Sams36e612a2009-07-31 16:26:13 -07001095 }
1096
Tim Murray460a0492013-11-19 12:45:54 -08001097 Element(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001098 super(id, rs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001099 }
1100
1101 @Override
1102 void updateFromNative() {
Jason Sams06d69de2010-11-09 17:11:40 -08001103 super.updateFromNative();
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001104
1105 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
1106 int[] dataBuffer = new int[5];
Jason Samse07694b2012-04-03 15:36:36 -07001107 mRS.nElementGetNativeData(getID(mRS), dataBuffer);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001108
1109 mNormalized = dataBuffer[2] == 1 ? true : false;
1110 mVectorSize = dataBuffer[3];
1111 mSize = 0;
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001112 for (DataType dt: DataType.values()) {
1113 if(dt.mID == dataBuffer[0]){
1114 mType = dt;
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001115 mSize = mType.mSize * mVectorSize;
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001116 }
1117 }
1118 for (DataKind dk: DataKind.values()) {
1119 if(dk.mID == dataBuffer[1]){
1120 mKind = dk;
1121 }
1122 }
1123
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001124 int numSubElements = dataBuffer[4];
1125 if(numSubElements > 0) {
1126 mElements = new Element[numSubElements];
1127 mElementNames = new String[numSubElements];
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001128 mArraySizes = new int[numSubElements];
1129 mOffsetInBytes = new int[numSubElements];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001130
Ashok Bhat98071552014-02-12 09:54:43 +00001131 long[] subElementIds = new long[numSubElements];
Jason Samse07694b2012-04-03 15:36:36 -07001132 mRS.nElementGetSubElements(getID(mRS), subElementIds, mElementNames, mArraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001133 for(int i = 0; i < numSubElements; i ++) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001134 mElements[i] = new Element(subElementIds[i], mRS);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001135 mElements[i].updateFromNative();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001136 mOffsetInBytes[i] = mSize;
1137 mSize += mElements[i].mSize * mArraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001138 }
1139 }
Alex Sakhartchouk3aac0ab2011-12-22 13:11:48 -08001140 updateVisibleSubElements();
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001141 }
1142
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001143 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001144 * Create a custom Element of the specified DataType. The DataKind will be
1145 * set to USER and the vector size to 1 indicating non-vector.
1146 *
1147 * @param rs The context associated with the new Element.
1148 * @param dt The DataType for the new element.
1149 * @return Element
1150 */
Mathew Inwood15324472018-08-06 11:18:49 +01001151 @UnsupportedAppUsage
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001152 static Element createUser(RenderScript rs, DataType dt) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001153 DataKind dk = DataKind.USER;
1154 boolean norm = false;
1155 int vecSize = 1;
Tim Murray460a0492013-11-19 12:45:54 -08001156 long id = rs.nElementCreate(dt.mID, dk.mID, norm, vecSize);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001157 return new Element(id, rs, dt, dk, norm, vecSize);
Jason Sams718cd1f2009-12-23 14:35:29 -08001158 }
1159
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001160 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001161 * Create a custom vector element of the specified DataType and vector size.
Stephen Hines3beb60e2012-02-14 20:38:20 -08001162 * DataKind will be set to USER. Only primitive types (FLOAT_32, FLOAT_64,
1163 * SIGNED_8, SIGNED_16, SIGNED_32, SIGNED_64, UNSIGNED_8, UNSIGNED_16,
1164 * UNSIGNED_32, UNSIGNED_64, BOOLEAN) are supported.
Jason Samsa1b13ed2010-11-12 14:58:37 -08001165 *
1166 * @param rs The context associated with the new Element.
Stephen Hines3beb60e2012-02-14 20:38:20 -08001167 * @param dt The DataType for the new Element.
Jason Samsa1b13ed2010-11-12 14:58:37 -08001168 * @param size Vector size for the new Element. Range 2-4 inclusive
1169 * supported.
1170 *
1171 * @return Element
1172 */
Jason Sams718cd1f2009-12-23 14:35:29 -08001173 public static Element createVector(RenderScript rs, DataType dt, int size) {
Jason Sams718cd1f2009-12-23 14:35:29 -08001174 if (size < 2 || size > 4) {
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001175 throw new RSIllegalArgumentException("Vector size out of range 2-4.");
Jason Samsea84a7c2009-09-04 14:42:41 -07001176 }
Stephen Hines3beb60e2012-02-14 20:38:20 -08001177
1178 switch (dt) {
1179 // Support only primitive integer/float/boolean types as vectors.
Jason Sams54371b42015-05-13 13:21:30 -07001180 case FLOAT_16:
Stephen Hines3beb60e2012-02-14 20:38:20 -08001181 case FLOAT_32:
1182 case FLOAT_64:
1183 case SIGNED_8:
1184 case SIGNED_16:
1185 case SIGNED_32:
1186 case SIGNED_64:
1187 case UNSIGNED_8:
1188 case UNSIGNED_16:
1189 case UNSIGNED_32:
1190 case UNSIGNED_64:
1191 case BOOLEAN: {
1192 DataKind dk = DataKind.USER;
1193 boolean norm = false;
Tim Murray460a0492013-11-19 12:45:54 -08001194 long id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
Stephen Hines3beb60e2012-02-14 20:38:20 -08001195 return new Element(id, rs, dt, dk, norm, size);
1196 }
1197
1198 default: {
1199 throw new RSIllegalArgumentException("Cannot create vector of " +
1200 "non-primitive type.");
1201 }
1202 }
Jason Samsea84a7c2009-09-04 14:42:41 -07001203 }
1204
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001205 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001206 * Create a new pixel Element type. A matching DataType and DataKind must
1207 * be provided. The DataType and DataKind must contain the same number of
1208 * components. Vector size will be set to 1.
1209 *
1210 * @param rs The context associated with the new Element.
1211 * @param dt The DataType for the new element.
1212 * @param dk The DataKind to specify the mapping of each component in the
1213 * DataType.
1214 *
1215 * @return Element
1216 */
Jason Sams718cd1f2009-12-23 14:35:29 -08001217 public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
Jason Sams718cd1f2009-12-23 14:35:29 -08001218 if (!(dk == DataKind.PIXEL_L ||
1219 dk == DataKind.PIXEL_A ||
1220 dk == DataKind.PIXEL_LA ||
1221 dk == DataKind.PIXEL_RGB ||
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001222 dk == DataKind.PIXEL_RGBA ||
Jason Samsdd6c8b32013-02-15 17:27:24 -08001223 dk == DataKind.PIXEL_DEPTH ||
1224 dk == DataKind.PIXEL_YUV)) {
Jason Samsc1d62102010-11-04 14:32:19 -07001225 throw new RSIllegalArgumentException("Unsupported DataKind");
Jason Sams718cd1f2009-12-23 14:35:29 -08001226 }
1227 if (!(dt == DataType.UNSIGNED_8 ||
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001228 dt == DataType.UNSIGNED_16 ||
Jason Sams718cd1f2009-12-23 14:35:29 -08001229 dt == DataType.UNSIGNED_5_6_5 ||
1230 dt == DataType.UNSIGNED_4_4_4_4 ||
1231 dt == DataType.UNSIGNED_5_5_5_1)) {
Jason Samsc1d62102010-11-04 14:32:19 -07001232 throw new RSIllegalArgumentException("Unsupported DataType");
Jason Sams718cd1f2009-12-23 14:35:29 -08001233 }
1234 if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) {
Jason Samsc1d62102010-11-04 14:32:19 -07001235 throw new RSIllegalArgumentException("Bad kind and type combo");
Jason Sams718cd1f2009-12-23 14:35:29 -08001236 }
1237 if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) {
Jason Samsc1d62102010-11-04 14:32:19 -07001238 throw new RSIllegalArgumentException("Bad kind and type combo");
Jason Sams718cd1f2009-12-23 14:35:29 -08001239 }
1240 if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
Jason Samsc1d62102010-11-04 14:32:19 -07001241 throw new RSIllegalArgumentException("Bad kind and type combo");
Jason Sams718cd1f2009-12-23 14:35:29 -08001242 }
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001243 if (dt == DataType.UNSIGNED_16 &&
1244 dk != DataKind.PIXEL_DEPTH) {
1245 throw new RSIllegalArgumentException("Bad kind and type combo");
1246 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001247
1248 int size = 1;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001249 switch (dk) {
1250 case PIXEL_LA:
Jason Sams718cd1f2009-12-23 14:35:29 -08001251 size = 2;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001252 break;
1253 case PIXEL_RGB:
Jason Sams718cd1f2009-12-23 14:35:29 -08001254 size = 3;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001255 break;
1256 case PIXEL_RGBA:
Jason Sams718cd1f2009-12-23 14:35:29 -08001257 size = 4;
Alex Sakhartchouk8e90f2b2011-04-01 14:19:01 -07001258 break;
1259 case PIXEL_DEPTH:
1260 size = 2;
1261 break;
Jason Sams718cd1f2009-12-23 14:35:29 -08001262 }
1263
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001264 boolean norm = true;
Tim Murray460a0492013-11-19 12:45:54 -08001265 long id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001266 return new Element(id, rs, dt, dk, norm, size);
Jason Sams718cd1f2009-12-23 14:35:29 -08001267 }
Jason Sams36e612a2009-07-31 16:26:13 -07001268
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001269 /**
Stephen Hinesf257e512011-06-14 14:54:29 -07001270 * Check if the current Element is compatible with another Element.
1271 * Primitive Elements are compatible if they share the same underlying
1272 * size and type (i.e. U8 is compatible with A_8). User-defined Elements
1273 * must be equal in order to be compatible. This requires strict name
1274 * equivalence for all sub-Elements (in addition to structural equivalence).
1275 *
1276 * @param e The Element to check compatibility with.
1277 *
1278 * @return boolean true if the Elements are compatible, otherwise false.
1279 */
1280 public boolean isCompatible(Element e) {
1281 // Try strict BaseObj equality to start with.
1282 if (this.equals(e)) {
1283 return true;
1284 }
1285
1286 // Ignore mKind because it is allowed to be different (user vs. pixel).
1287 // We also ignore mNormalized because it can be different. The mType
Stephen Hines20948112012-02-14 19:42:42 -08001288 // field must not be NONE since we require name equivalence for
1289 // all user-created Elements.
Stephen Hinesf257e512011-06-14 14:54:29 -07001290 return ((mSize == e.mSize) &&
Stephen Hines20948112012-02-14 19:42:42 -08001291 (mType != DataType.NONE) &&
Stephen Hinesf257e512011-06-14 14:54:29 -07001292 (mType == e.mType) &&
1293 (mVectorSize == e.mVectorSize));
1294 }
1295
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001296 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001297 * Builder class for producing complex elements with matching field and name
1298 * pairs. The builder starts empty. The order in which elements are added
1299 * is retained for the layout in memory.
1300 *
1301 */
Jason Sams36e612a2009-07-31 16:26:13 -07001302 public static class Builder {
1303 RenderScript mRS;
Jason Sams718cd1f2009-12-23 14:35:29 -08001304 Element[] mElements;
1305 String[] mElementNames;
Jason Sams70d4e502010-09-02 17:35:23 -07001306 int[] mArraySizes;
Jason Sams718cd1f2009-12-23 14:35:29 -08001307 int mCount;
Alex Sakhartchouke60149d2011-11-15 15:15:21 -08001308 int mSkipPadding;
Jason Sams22534172009-08-04 16:58:20 -07001309
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001310 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001311 * Create a builder object.
1312 *
1313 * @param rs
1314 */
Jason Sams22534172009-08-04 16:58:20 -07001315 public Builder(RenderScript rs) {
Jason Sams36e612a2009-07-31 16:26:13 -07001316 mRS = rs;
Jason Sams718cd1f2009-12-23 14:35:29 -08001317 mCount = 0;
1318 mElements = new Element[8];
1319 mElementNames = new String[8];
Jason Sams70d4e502010-09-02 17:35:23 -07001320 mArraySizes = new int[8];
Jason Sams36e612a2009-07-31 16:26:13 -07001321 }
1322
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001323 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001324 * Add an array of elements to this element.
1325 *
1326 * @param element
1327 * @param name
1328 * @param arraySize
1329 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001330 public Builder add(Element element, String name, int arraySize) {
Jason Sams70d4e502010-09-02 17:35:23 -07001331 if (arraySize < 1) {
Jason Samsc1d62102010-11-04 14:32:19 -07001332 throw new RSIllegalArgumentException("Array size cannot be less than 1.");
Jason Sams70d4e502010-09-02 17:35:23 -07001333 }
Alex Sakhartchouke60149d2011-11-15 15:15:21 -08001334
1335 // Skip padding fields after a vector 3 type.
1336 if (mSkipPadding != 0) {
1337 if (name.startsWith("#padding_")) {
1338 mSkipPadding = 0;
1339 return this;
1340 }
1341 }
1342
1343 if (element.mVectorSize == 3) {
1344 mSkipPadding = 1;
1345 } else {
1346 mSkipPadding = 0;
1347 }
1348
Jason Sams718cd1f2009-12-23 14:35:29 -08001349 if(mCount == mElements.length) {
1350 Element[] e = new Element[mCount + 8];
1351 String[] s = new String[mCount + 8];
Jason Sams70d4e502010-09-02 17:35:23 -07001352 int[] as = new int[mCount + 8];
Jason Sams718cd1f2009-12-23 14:35:29 -08001353 System.arraycopy(mElements, 0, e, 0, mCount);
1354 System.arraycopy(mElementNames, 0, s, 0, mCount);
Jason Sams70d4e502010-09-02 17:35:23 -07001355 System.arraycopy(mArraySizes, 0, as, 0, mCount);
Jason Sams718cd1f2009-12-23 14:35:29 -08001356 mElements = e;
1357 mElementNames = s;
Jason Sams70d4e502010-09-02 17:35:23 -07001358 mArraySizes = as;
Jason Sams36e612a2009-07-31 16:26:13 -07001359 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001360 mElements[mCount] = element;
1361 mElementNames[mCount] = name;
Jason Sams70d4e502010-09-02 17:35:23 -07001362 mArraySizes[mCount] = arraySize;
Jason Sams718cd1f2009-12-23 14:35:29 -08001363 mCount++;
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001364 return this;
Jason Sams07ae4062009-08-27 20:23:34 -07001365 }
1366
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001367 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001368 * Add a single element to this Element.
1369 *
1370 * @param element
1371 * @param name
1372 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001373 public Builder add(Element element, String name) {
1374 return add(element, name, 1);
Jason Sams70d4e502010-09-02 17:35:23 -07001375 }
1376
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001377 /**
Jason Samsa1b13ed2010-11-12 14:58:37 -08001378 * Create the element from this builder.
1379 *
1380 *
1381 * @return Element
1382 */
Jason Sams22534172009-08-04 16:58:20 -07001383 public Element create() {
Jason Sams771bebb2009-12-07 12:40:12 -08001384 mRS.validate();
Jason Sams718cd1f2009-12-23 14:35:29 -08001385 Element[] ein = new Element[mCount];
1386 String[] sin = new String[mCount];
Jason Sams70d4e502010-09-02 17:35:23 -07001387 int[] asin = new int[mCount];
Jason Sams718cd1f2009-12-23 14:35:29 -08001388 java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
1389 java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
Jason Sams70d4e502010-09-02 17:35:23 -07001390 java.lang.System.arraycopy(mArraySizes, 0, asin, 0, mCount);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001391
Ashok Bhat98071552014-02-12 09:54:43 +00001392 long[] ids = new long[ein.length];
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001393 for (int ct = 0; ct < ein.length; ct++ ) {
Ashok Bhat98071552014-02-12 09:54:43 +00001394 ids[ct] = ein[ct].getID(mRS);
Alex Sakhartchouk0de94442010-08-11 14:41:28 -07001395 }
Tim Murray460a0492013-11-19 12:45:54 -08001396 long id = mRS.nElementCreate2(ids, sin, asin);
Jason Sams70d4e502010-09-02 17:35:23 -07001397 return new Element(id, mRS, ein, sin, asin);
Jason Sams36e612a2009-07-31 16:26:13 -07001398 }
1399 }
Jason Sams36e612a2009-07-31 16:26:13 -07001400}
1401