| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 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 | |
| 17 | package android.renderscript; |
| 18 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 19 | import java.lang.reflect.Field; |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 20 | import android.util.Log; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 23 | * <p>The most basic data type. An element represents one cell of a memory allocation. |
| Alex Sakhartchouk | 3476977 | 2011-02-28 16:01:28 -0800 | [diff] [blame] | 24 | * Element is the basic data type of Renderscript. An element can be of two forms: Basic elements or Complex forms. |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 25 | * Examples of basic elements are:</p> |
| 26 | * <ul> |
| 27 | * <li>Single float value</li> |
| 28 | * <li>4 element float vector</li> |
| 29 | * <li>single RGB-565 color</li> |
| 30 | * <li>single unsigned int 16</li> |
| 31 | * </ul> |
| Alex Sakhartchouk | 3476977 | 2011-02-28 16:01:28 -0800 | [diff] [blame] | 32 | * <p>Complex elements contain a list of sub-elements and names that |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 33 | * represents a structure of data. The fields can be accessed by name |
| 34 | * from a script or shader. The memory layout is defined and ordered. Data |
| Stephen Hines | f257e51 | 2011-06-14 14:54:29 -0700 | [diff] [blame] | 35 | * alignment is determined by the most basic primitive type. i.e. a float4 |
| 36 | * vector will be aligned to sizeof(float) and not sizeof(float4). The |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 37 | * ordering of elements in memory will be the order in which they were added |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 38 | * with each component aligned as necessary. No re-ordering will be done.</p> |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 39 | * |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 40 | * <p>The primary source of elements are from scripts. A script that exports a |
| 41 | * bind point for a data structure generates a Renderscript element to represent the |
| 42 | * data exported by the script. The other common source of elements is from bitmap formats.</p> |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 43 | **/ |
| 44 | public class Element extends BaseObj { |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 45 | int mSize; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 46 | Element[] mElements; |
| 47 | String[] mElementNames; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 48 | int[] mArraySizes; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 49 | int[] mOffsetInBytes; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 50 | |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 51 | int[] mVisibleElementMap; |
| 52 | |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 53 | DataType mType; |
| 54 | DataKind mKind; |
| 55 | boolean mNormalized; |
| 56 | int mVectorSize; |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 57 | |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 58 | private void updateVisibleSubElements() { |
| 59 | if (mElements == null) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | int noPaddingFieldCount = 0; |
| 64 | int fieldCount = mElementNames.length; |
| 65 | // Find out how many elements are not padding |
| 66 | for (int ct = 0; ct < fieldCount; ct ++) { |
| 67 | if (mElementNames[ct].charAt(0) != '#') { |
| 68 | noPaddingFieldCount ++; |
| 69 | } |
| 70 | } |
| 71 | mVisibleElementMap = new int[noPaddingFieldCount]; |
| 72 | |
| 73 | // Make a map that points us at non-padding elements |
| 74 | for (int ct = 0, ctNoPadding = 0; ct < fieldCount; ct ++) { |
| 75 | if (mElementNames[ct].charAt(0) != '#') { |
| 76 | mVisibleElementMap[ctNoPadding ++] = ct; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 81 | /** |
| 82 | * @hide |
| 83 | * @return element size in bytes |
| 84 | */ |
| 85 | public int getSizeBytes() {return mSize;} |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 86 | |
| Alex Sakhartchouk | fd79e02 | 2011-12-22 14:30:55 -0800 | [diff] [blame^] | 87 | /** |
| 88 | * @hide |
| 89 | * @return element vector size |
| 90 | */ |
| 91 | public int getVectorSize() {return mVectorSize;} |
| 92 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * DataType represents the basic type information for a basic element. The |
| Alex Sakhartchouk | f5d8ac7 | 2011-12-16 09:44:26 -0800 | [diff] [blame] | 96 | * naming convention follows. For numeric types it is FLOAT, |
| 97 | * SIGNED, or UNSIGNED followed by the _BITS where BITS is the |
| 98 | * size of the data. BOOLEAN is a true / false (1,0) |
| 99 | * represented in an 8 bit container. The UNSIGNED variants |
| 100 | * with multiple bit definitions are for packed graphical data |
| 101 | * formats and represent vectors with per vector member sizes |
| 102 | * which are treated as a single unit for packing and alignment |
| 103 | * purposes. |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 104 | * |
| 105 | * MATRIX the three matrix types contain FLOAT_32 elements and are treated |
| 106 | * as 32 bits for alignment purposes. |
| 107 | * |
| 108 | * RS_* objects. 32 bit opaque handles. |
| 109 | */ |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 110 | public enum DataType { |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 111 | /** |
| 112 | * @hide |
| 113 | * new enum |
| 114 | */ |
| 115 | NONE (0, 0), |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 116 | //FLOAT_16 (1, 2), |
| 117 | FLOAT_32 (2, 4), |
| Stephen Hines | 02f41705 | 2010-09-30 15:19:22 -0700 | [diff] [blame] | 118 | FLOAT_64 (3, 8), |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 119 | SIGNED_8 (4, 1), |
| 120 | SIGNED_16 (5, 2), |
| 121 | SIGNED_32 (6, 4), |
| Stephen Hines | ef1dac2 | 2010-10-01 15:39:33 -0700 | [diff] [blame] | 122 | SIGNED_64 (7, 8), |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 123 | UNSIGNED_8 (8, 1), |
| 124 | UNSIGNED_16 (9, 2), |
| 125 | UNSIGNED_32 (10, 4), |
| Stephen Hines | 52d8363 | 2010-10-11 16:10:42 -0700 | [diff] [blame] | 126 | UNSIGNED_64 (11, 8), |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 127 | |
| Jason Sams | f110d4b | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 128 | BOOLEAN(12, 1), |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 129 | |
| Jason Sams | f110d4b | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 130 | UNSIGNED_5_6_5 (13, 2), |
| 131 | UNSIGNED_5_5_5_1 (14, 2), |
| 132 | UNSIGNED_4_4_4_4 (15, 2), |
| 133 | |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 134 | MATRIX_4X4 (16, 64), |
| 135 | MATRIX_3X3 (17, 36), |
| 136 | MATRIX_2X2 (18, 16), |
| 137 | |
| 138 | RS_ELEMENT (1000, 4), |
| 139 | RS_TYPE (1001, 4), |
| 140 | RS_ALLOCATION (1002, 4), |
| 141 | RS_SAMPLER (1003, 4), |
| 142 | RS_SCRIPT (1004, 4), |
| 143 | RS_MESH (1005, 4), |
| 144 | RS_PROGRAM_FRAGMENT (1006, 4), |
| 145 | RS_PROGRAM_VERTEX (1007, 4), |
| 146 | RS_PROGRAM_RASTER (1008, 4), |
| 147 | RS_PROGRAM_STORE (1009, 4); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 148 | |
| 149 | int mID; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 150 | int mSize; |
| 151 | DataType(int id, int size) { |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 152 | mID = id; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 153 | mSize = size; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 157 | /** |
| 158 | * The special interpretation of the data if required. This is primarly |
| 159 | * useful for graphical data. USER indicates no special interpretation is |
| 160 | * expected. PIXEL is used in conjunction with the standard data types for |
| 161 | * representing texture formats. |
| 162 | */ |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 163 | public enum DataKind { |
| 164 | USER (0), |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 165 | |
| 166 | PIXEL_L (7), |
| 167 | PIXEL_A (8), |
| 168 | PIXEL_LA (9), |
| 169 | PIXEL_RGB (10), |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 170 | PIXEL_RGBA (11), |
| 171 | PIXEL_DEPTH (12); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 172 | |
| 173 | int mID; |
| 174 | DataKind(int id) { |
| 175 | mID = id; |
| 176 | } |
| 177 | } |
| 178 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 179 | /** |
| 180 | * Return if a element is too complex for use as a data source for a Mesh or |
| 181 | * a Program. |
| 182 | * |
| 183 | * @return boolean |
| 184 | */ |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 185 | public boolean isComplex() { |
| 186 | if (mElements == null) { |
| 187 | return false; |
| 188 | } |
| 189 | for (int ct=0; ct < mElements.length; ct++) { |
| 190 | if (mElements[ct].mElements != null) { |
| 191 | return true; |
| 192 | } |
| 193 | } |
| 194 | return false; |
| 195 | } |
| 196 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 197 | /** |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 198 | * @hide |
| 199 | * @return number of sub-elements in this element |
| 200 | */ |
| 201 | public int getSubElementCount() { |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 202 | if (mVisibleElementMap == null) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 205 | return mVisibleElementMap.length; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /** |
| 209 | * @hide |
| 210 | * @param index index of the sub-element to return |
| 211 | * @return sub-element in this element at given index |
| 212 | */ |
| 213 | public Element getSubElement(int index) { |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 214 | if (mVisibleElementMap == null) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 215 | throw new RSIllegalArgumentException("Element contains no sub-elements"); |
| 216 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 217 | if (index < 0 || index >= mVisibleElementMap.length) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 218 | throw new RSIllegalArgumentException("Illegal sub-element index"); |
| 219 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 220 | return mElements[mVisibleElementMap[index]]; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @hide |
| 225 | * @param index index of the sub-element |
| 226 | * @return sub-element in this element at given index |
| 227 | */ |
| 228 | public String getSubElementName(int index) { |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 229 | if (mVisibleElementMap == null) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 230 | throw new RSIllegalArgumentException("Element contains no sub-elements"); |
| 231 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 232 | if (index < 0 || index >= mVisibleElementMap.length) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 233 | throw new RSIllegalArgumentException("Illegal sub-element index"); |
| 234 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 235 | return mElementNames[mVisibleElementMap[index]]; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /** |
| 239 | * @hide |
| 240 | * @param index index of the sub-element |
| 241 | * @return array size of sub-element in this element at given index |
| 242 | */ |
| 243 | public int getSubElementArraySize(int index) { |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 244 | if (mVisibleElementMap == null) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 245 | throw new RSIllegalArgumentException("Element contains no sub-elements"); |
| 246 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 247 | if (index < 0 || index >= mVisibleElementMap.length) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 248 | throw new RSIllegalArgumentException("Illegal sub-element index"); |
| 249 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 250 | return mArraySizes[mVisibleElementMap[index]]; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /** |
| 254 | * @hide |
| 255 | * @param index index of the sub-element |
| 256 | * @return offset in bytes of sub-element in this element at given index |
| 257 | */ |
| 258 | public int getSubElementOffsetBytes(int index) { |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 259 | if (mVisibleElementMap == null) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 260 | throw new RSIllegalArgumentException("Element contains no sub-elements"); |
| 261 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 262 | if (index < 0 || index >= mVisibleElementMap.length) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 263 | throw new RSIllegalArgumentException("Illegal sub-element index"); |
| 264 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 265 | return mOffsetInBytes[mVisibleElementMap[index]]; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| Alex Sakhartchouk | f5d8ac7 | 2011-12-16 09:44:26 -0800 | [diff] [blame] | 269 | * @hide |
| 270 | * @return element data type |
| 271 | */ |
| 272 | public DataType getDataType() { |
| 273 | return mType; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * @hide |
| 278 | * @return element data kind |
| 279 | */ |
| 280 | public DataKind getDataKind() { |
| 281 | return mKind; |
| 282 | } |
| 283 | |
| 284 | /** |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 285 | * Utility function for returning an Element containing a single Boolean. |
| 286 | * |
| 287 | * @param rs Context to which the element will belong. |
| 288 | * |
| 289 | * @return Element |
| 290 | */ |
| Jason Sams | f110d4b | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 291 | public static Element BOOLEAN(RenderScript rs) { |
| 292 | if(rs.mElement_BOOLEAN == null) { |
| 293 | rs.mElement_BOOLEAN = createUser(rs, DataType.BOOLEAN); |
| 294 | } |
| 295 | return rs.mElement_BOOLEAN; |
| 296 | } |
| 297 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 298 | /** |
| 299 | * Utility function for returning an Element containing a single UNSIGNED_8. |
| 300 | * |
| 301 | * @param rs Context to which the element will belong. |
| 302 | * |
| 303 | * @return Element |
| 304 | */ |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 305 | public static Element U8(RenderScript rs) { |
| 306 | if(rs.mElement_U8 == null) { |
| 307 | rs.mElement_U8 = createUser(rs, DataType.UNSIGNED_8); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 308 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 309 | return rs.mElement_U8; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 312 | /** |
| 313 | * Utility function for returning an Element containing a single SIGNED_8. |
| 314 | * |
| 315 | * @param rs Context to which the element will belong. |
| 316 | * |
| 317 | * @return Element |
| 318 | */ |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 319 | public static Element I8(RenderScript rs) { |
| 320 | if(rs.mElement_I8 == null) { |
| 321 | rs.mElement_I8 = createUser(rs, DataType.SIGNED_8); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 322 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 323 | return rs.mElement_I8; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| Jason Sams | e29f3e7 | 2010-06-08 15:40:48 -0700 | [diff] [blame] | 326 | public static Element U16(RenderScript rs) { |
| 327 | if(rs.mElement_U16 == null) { |
| 328 | rs.mElement_U16 = createUser(rs, DataType.UNSIGNED_16); |
| 329 | } |
| 330 | return rs.mElement_U16; |
| 331 | } |
| 332 | |
| 333 | public static Element I16(RenderScript rs) { |
| 334 | if(rs.mElement_I16 == null) { |
| 335 | rs.mElement_I16 = createUser(rs, DataType.SIGNED_16); |
| 336 | } |
| 337 | return rs.mElement_I16; |
| 338 | } |
| 339 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 340 | public static Element U32(RenderScript rs) { |
| 341 | if(rs.mElement_U32 == null) { |
| 342 | rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 343 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 344 | return rs.mElement_U32; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 345 | } |
| 346 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 347 | public static Element I32(RenderScript rs) { |
| 348 | if(rs.mElement_I32 == null) { |
| 349 | rs.mElement_I32 = createUser(rs, DataType.SIGNED_32); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 350 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 351 | return rs.mElement_I32; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| Stephen Hines | 52d8363 | 2010-10-11 16:10:42 -0700 | [diff] [blame] | 354 | public static Element U64(RenderScript rs) { |
| 355 | if(rs.mElement_U64 == null) { |
| 356 | rs.mElement_U64 = createUser(rs, DataType.UNSIGNED_64); |
| 357 | } |
| 358 | return rs.mElement_U64; |
| 359 | } |
| 360 | |
| Stephen Hines | ef1dac2 | 2010-10-01 15:39:33 -0700 | [diff] [blame] | 361 | public static Element I64(RenderScript rs) { |
| 362 | if(rs.mElement_I64 == null) { |
| 363 | rs.mElement_I64 = createUser(rs, DataType.SIGNED_64); |
| 364 | } |
| 365 | return rs.mElement_I64; |
| 366 | } |
| 367 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 368 | public static Element F32(RenderScript rs) { |
| 369 | if(rs.mElement_F32 == null) { |
| 370 | rs.mElement_F32 = createUser(rs, DataType.FLOAT_32); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 371 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 372 | return rs.mElement_F32; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| Stephen Hines | 02f41705 | 2010-09-30 15:19:22 -0700 | [diff] [blame] | 375 | public static Element F64(RenderScript rs) { |
| 376 | if(rs.mElement_F64 == null) { |
| 377 | rs.mElement_F64 = createUser(rs, DataType.FLOAT_64); |
| 378 | } |
| 379 | return rs.mElement_F64; |
| 380 | } |
| 381 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 382 | public static Element ELEMENT(RenderScript rs) { |
| 383 | if(rs.mElement_ELEMENT == null) { |
| 384 | rs.mElement_ELEMENT = createUser(rs, DataType.RS_ELEMENT); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 385 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 386 | return rs.mElement_ELEMENT; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 389 | public static Element TYPE(RenderScript rs) { |
| 390 | if(rs.mElement_TYPE == null) { |
| 391 | rs.mElement_TYPE = createUser(rs, DataType.RS_TYPE); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 392 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 393 | return rs.mElement_TYPE; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 396 | public static Element ALLOCATION(RenderScript rs) { |
| 397 | if(rs.mElement_ALLOCATION == null) { |
| 398 | rs.mElement_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 399 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 400 | return rs.mElement_ALLOCATION; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 403 | public static Element SAMPLER(RenderScript rs) { |
| 404 | if(rs.mElement_SAMPLER == null) { |
| 405 | rs.mElement_SAMPLER = createUser(rs, DataType.RS_SAMPLER); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 406 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 407 | return rs.mElement_SAMPLER; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 410 | public static Element SCRIPT(RenderScript rs) { |
| 411 | if(rs.mElement_SCRIPT == null) { |
| 412 | rs.mElement_SCRIPT = createUser(rs, DataType.RS_SCRIPT); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 413 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 414 | return rs.mElement_SCRIPT; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 417 | public static Element MESH(RenderScript rs) { |
| 418 | if(rs.mElement_MESH == null) { |
| 419 | rs.mElement_MESH = createUser(rs, DataType.RS_MESH); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 420 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 421 | return rs.mElement_MESH; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 424 | public static Element PROGRAM_FRAGMENT(RenderScript rs) { |
| 425 | if(rs.mElement_PROGRAM_FRAGMENT == null) { |
| 426 | rs.mElement_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 427 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 428 | return rs.mElement_PROGRAM_FRAGMENT; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 431 | public static Element PROGRAM_VERTEX(RenderScript rs) { |
| 432 | if(rs.mElement_PROGRAM_VERTEX == null) { |
| 433 | rs.mElement_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 434 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 435 | return rs.mElement_PROGRAM_VERTEX; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 438 | public static Element PROGRAM_RASTER(RenderScript rs) { |
| 439 | if(rs.mElement_PROGRAM_RASTER == null) { |
| 440 | rs.mElement_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 441 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 442 | return rs.mElement_PROGRAM_RASTER; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 445 | public static Element PROGRAM_STORE(RenderScript rs) { |
| 446 | if(rs.mElement_PROGRAM_STORE == null) { |
| 447 | rs.mElement_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 448 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 449 | return rs.mElement_PROGRAM_STORE; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 453 | public static Element A_8(RenderScript rs) { |
| 454 | if(rs.mElement_A_8 == null) { |
| 455 | rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A); |
| 456 | } |
| 457 | return rs.mElement_A_8; |
| 458 | } |
| 459 | |
| 460 | public static Element RGB_565(RenderScript rs) { |
| 461 | if(rs.mElement_RGB_565 == null) { |
| 462 | rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB); |
| 463 | } |
| 464 | return rs.mElement_RGB_565; |
| 465 | } |
| 466 | |
| 467 | public static Element RGB_888(RenderScript rs) { |
| 468 | if(rs.mElement_RGB_888 == null) { |
| 469 | rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB); |
| 470 | } |
| 471 | return rs.mElement_RGB_888; |
| 472 | } |
| 473 | |
| 474 | public static Element RGBA_5551(RenderScript rs) { |
| 475 | if(rs.mElement_RGBA_5551 == null) { |
| 476 | rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA); |
| 477 | } |
| 478 | return rs.mElement_RGBA_5551; |
| 479 | } |
| 480 | |
| 481 | public static Element RGBA_4444(RenderScript rs) { |
| 482 | if(rs.mElement_RGBA_4444 == null) { |
| 483 | rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA); |
| 484 | } |
| 485 | return rs.mElement_RGBA_4444; |
| 486 | } |
| 487 | |
| 488 | public static Element RGBA_8888(RenderScript rs) { |
| 489 | if(rs.mElement_RGBA_8888 == null) { |
| 490 | rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA); |
| 491 | } |
| 492 | return rs.mElement_RGBA_8888; |
| 493 | } |
| 494 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 495 | public static Element F32_2(RenderScript rs) { |
| 496 | if(rs.mElement_FLOAT_2 == null) { |
| 497 | rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 498 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 499 | return rs.mElement_FLOAT_2; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 502 | public static Element F32_3(RenderScript rs) { |
| 503 | if(rs.mElement_FLOAT_3 == null) { |
| 504 | rs.mElement_FLOAT_3 = createVector(rs, DataType.FLOAT_32, 3); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 505 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 506 | return rs.mElement_FLOAT_3; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 509 | public static Element F32_4(RenderScript rs) { |
| 510 | if(rs.mElement_FLOAT_4 == null) { |
| 511 | rs.mElement_FLOAT_4 = createVector(rs, DataType.FLOAT_32, 4); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 512 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 513 | return rs.mElement_FLOAT_4; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 514 | } |
| 515 | |
| Stephen Hines | 836c4a5 | 2011-06-01 14:38:10 -0700 | [diff] [blame] | 516 | public static Element F64_2(RenderScript rs) { |
| 517 | if(rs.mElement_DOUBLE_2 == null) { |
| 518 | rs.mElement_DOUBLE_2 = createVector(rs, DataType.FLOAT_64, 2); |
| 519 | } |
| 520 | return rs.mElement_DOUBLE_2; |
| 521 | } |
| 522 | |
| 523 | public static Element F64_3(RenderScript rs) { |
| 524 | if(rs.mElement_DOUBLE_3 == null) { |
| 525 | rs.mElement_DOUBLE_3 = createVector(rs, DataType.FLOAT_64, 3); |
| 526 | } |
| 527 | return rs.mElement_DOUBLE_3; |
| 528 | } |
| 529 | |
| 530 | public static Element F64_4(RenderScript rs) { |
| 531 | if(rs.mElement_DOUBLE_4 == null) { |
| 532 | rs.mElement_DOUBLE_4 = createVector(rs, DataType.FLOAT_64, 4); |
| 533 | } |
| 534 | return rs.mElement_DOUBLE_4; |
| 535 | } |
| 536 | |
| 537 | public static Element U8_2(RenderScript rs) { |
| 538 | if(rs.mElement_UCHAR_2 == null) { |
| 539 | rs.mElement_UCHAR_2 = createVector(rs, DataType.UNSIGNED_8, 2); |
| 540 | } |
| 541 | return rs.mElement_UCHAR_2; |
| 542 | } |
| 543 | |
| 544 | public static Element U8_3(RenderScript rs) { |
| 545 | if(rs.mElement_UCHAR_3 == null) { |
| 546 | rs.mElement_UCHAR_3 = createVector(rs, DataType.UNSIGNED_8, 3); |
| 547 | } |
| 548 | return rs.mElement_UCHAR_3; |
| 549 | } |
| 550 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 551 | public static Element U8_4(RenderScript rs) { |
| 552 | if(rs.mElement_UCHAR_4 == null) { |
| 553 | rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 554 | } |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 555 | return rs.mElement_UCHAR_4; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 556 | } |
| 557 | |
| Stephen Hines | 836c4a5 | 2011-06-01 14:38:10 -0700 | [diff] [blame] | 558 | public static Element I8_2(RenderScript rs) { |
| 559 | if(rs.mElement_CHAR_2 == null) { |
| 560 | rs.mElement_CHAR_2 = createVector(rs, DataType.SIGNED_8, 2); |
| 561 | } |
| 562 | return rs.mElement_CHAR_2; |
| 563 | } |
| 564 | |
| 565 | public static Element I8_3(RenderScript rs) { |
| 566 | if(rs.mElement_CHAR_3 == null) { |
| 567 | rs.mElement_CHAR_3 = createVector(rs, DataType.SIGNED_8, 3); |
| 568 | } |
| 569 | return rs.mElement_CHAR_3; |
| 570 | } |
| 571 | |
| 572 | public static Element I8_4(RenderScript rs) { |
| 573 | if(rs.mElement_CHAR_4 == null) { |
| 574 | rs.mElement_CHAR_4 = createVector(rs, DataType.SIGNED_8, 4); |
| 575 | } |
| 576 | return rs.mElement_CHAR_4; |
| 577 | } |
| 578 | |
| 579 | public static Element U16_2(RenderScript rs) { |
| 580 | if(rs.mElement_USHORT_2 == null) { |
| 581 | rs.mElement_USHORT_2 = createVector(rs, DataType.UNSIGNED_16, 2); |
| 582 | } |
| 583 | return rs.mElement_USHORT_2; |
| 584 | } |
| 585 | |
| 586 | public static Element U16_3(RenderScript rs) { |
| 587 | if(rs.mElement_USHORT_3 == null) { |
| 588 | rs.mElement_USHORT_3 = createVector(rs, DataType.UNSIGNED_16, 3); |
| 589 | } |
| 590 | return rs.mElement_USHORT_3; |
| 591 | } |
| 592 | |
| 593 | public static Element U16_4(RenderScript rs) { |
| 594 | if(rs.mElement_USHORT_4 == null) { |
| 595 | rs.mElement_USHORT_4 = createVector(rs, DataType.UNSIGNED_16, 4); |
| 596 | } |
| 597 | return rs.mElement_USHORT_4; |
| 598 | } |
| 599 | |
| 600 | public static Element I16_2(RenderScript rs) { |
| 601 | if(rs.mElement_SHORT_2 == null) { |
| 602 | rs.mElement_SHORT_2 = createVector(rs, DataType.SIGNED_16, 2); |
| 603 | } |
| 604 | return rs.mElement_SHORT_2; |
| 605 | } |
| 606 | |
| 607 | public static Element I16_3(RenderScript rs) { |
| 608 | if(rs.mElement_SHORT_3 == null) { |
| 609 | rs.mElement_SHORT_3 = createVector(rs, DataType.SIGNED_16, 3); |
| 610 | } |
| 611 | return rs.mElement_SHORT_3; |
| 612 | } |
| 613 | |
| 614 | public static Element I16_4(RenderScript rs) { |
| 615 | if(rs.mElement_SHORT_4 == null) { |
| 616 | rs.mElement_SHORT_4 = createVector(rs, DataType.SIGNED_16, 4); |
| 617 | } |
| 618 | return rs.mElement_SHORT_4; |
| 619 | } |
| 620 | |
| 621 | public static Element U32_2(RenderScript rs) { |
| 622 | if(rs.mElement_UINT_2 == null) { |
| 623 | rs.mElement_UINT_2 = createVector(rs, DataType.UNSIGNED_32, 2); |
| 624 | } |
| 625 | return rs.mElement_UINT_2; |
| 626 | } |
| 627 | |
| 628 | public static Element U32_3(RenderScript rs) { |
| 629 | if(rs.mElement_UINT_3 == null) { |
| 630 | rs.mElement_UINT_3 = createVector(rs, DataType.UNSIGNED_32, 3); |
| 631 | } |
| 632 | return rs.mElement_UINT_3; |
| 633 | } |
| 634 | |
| 635 | public static Element U32_4(RenderScript rs) { |
| 636 | if(rs.mElement_UINT_4 == null) { |
| 637 | rs.mElement_UINT_4 = createVector(rs, DataType.UNSIGNED_32, 4); |
| 638 | } |
| 639 | return rs.mElement_UINT_4; |
| 640 | } |
| 641 | |
| 642 | public static Element I32_2(RenderScript rs) { |
| 643 | if(rs.mElement_INT_2 == null) { |
| 644 | rs.mElement_INT_2 = createVector(rs, DataType.SIGNED_32, 2); |
| 645 | } |
| 646 | return rs.mElement_INT_2; |
| 647 | } |
| 648 | |
| 649 | public static Element I32_3(RenderScript rs) { |
| 650 | if(rs.mElement_INT_3 == null) { |
| 651 | rs.mElement_INT_3 = createVector(rs, DataType.SIGNED_32, 3); |
| 652 | } |
| 653 | return rs.mElement_INT_3; |
| 654 | } |
| 655 | |
| 656 | public static Element I32_4(RenderScript rs) { |
| 657 | if(rs.mElement_INT_4 == null) { |
| 658 | rs.mElement_INT_4 = createVector(rs, DataType.SIGNED_32, 4); |
| 659 | } |
| 660 | return rs.mElement_INT_4; |
| 661 | } |
| 662 | |
| 663 | public static Element U64_2(RenderScript rs) { |
| 664 | if(rs.mElement_ULONG_2 == null) { |
| 665 | rs.mElement_ULONG_2 = createVector(rs, DataType.UNSIGNED_64, 2); |
| 666 | } |
| 667 | return rs.mElement_ULONG_2; |
| 668 | } |
| 669 | |
| 670 | public static Element U64_3(RenderScript rs) { |
| 671 | if(rs.mElement_ULONG_3 == null) { |
| 672 | rs.mElement_ULONG_3 = createVector(rs, DataType.UNSIGNED_64, 3); |
| 673 | } |
| 674 | return rs.mElement_ULONG_3; |
| 675 | } |
| 676 | |
| 677 | public static Element U64_4(RenderScript rs) { |
| 678 | if(rs.mElement_ULONG_4 == null) { |
| 679 | rs.mElement_ULONG_4 = createVector(rs, DataType.UNSIGNED_64, 4); |
| 680 | } |
| 681 | return rs.mElement_ULONG_4; |
| 682 | } |
| 683 | |
| 684 | public static Element I64_2(RenderScript rs) { |
| 685 | if(rs.mElement_LONG_2 == null) { |
| 686 | rs.mElement_LONG_2 = createVector(rs, DataType.SIGNED_64, 2); |
| 687 | } |
| 688 | return rs.mElement_LONG_2; |
| 689 | } |
| 690 | |
| 691 | public static Element I64_3(RenderScript rs) { |
| 692 | if(rs.mElement_LONG_3 == null) { |
| 693 | rs.mElement_LONG_3 = createVector(rs, DataType.SIGNED_64, 3); |
| 694 | } |
| 695 | return rs.mElement_LONG_3; |
| 696 | } |
| 697 | |
| 698 | public static Element I64_4(RenderScript rs) { |
| 699 | if(rs.mElement_LONG_4 == null) { |
| 700 | rs.mElement_LONG_4 = createVector(rs, DataType.SIGNED_64, 4); |
| 701 | } |
| 702 | return rs.mElement_LONG_4; |
| 703 | } |
| 704 | |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 705 | public static Element MATRIX_4X4(RenderScript rs) { |
| 706 | if(rs.mElement_MATRIX_4X4 == null) { |
| 707 | rs.mElement_MATRIX_4X4 = createUser(rs, DataType.MATRIX_4X4); |
| 708 | } |
| 709 | return rs.mElement_MATRIX_4X4; |
| 710 | } |
| 711 | public static Element MATRIX4X4(RenderScript rs) { |
| 712 | return MATRIX_4X4(rs); |
| 713 | } |
| 714 | |
| 715 | public static Element MATRIX_3X3(RenderScript rs) { |
| 716 | if(rs.mElement_MATRIX_3X3 == null) { |
| 717 | rs.mElement_MATRIX_3X3 = createUser(rs, DataType.MATRIX_3X3); |
| 718 | } |
| Alex Sakhartchouk | 3476977 | 2011-02-28 16:01:28 -0800 | [diff] [blame] | 719 | return rs.mElement_MATRIX_3X3; |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | public static Element MATRIX_2X2(RenderScript rs) { |
| 723 | if(rs.mElement_MATRIX_2X2 == null) { |
| 724 | rs.mElement_MATRIX_2X2 = createUser(rs, DataType.MATRIX_2X2); |
| 725 | } |
| 726 | return rs.mElement_MATRIX_2X2; |
| 727 | } |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 728 | |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 729 | Element(int id, RenderScript rs, Element[] e, String[] n, int[] as) { |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 730 | super(id, rs); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 731 | mSize = 0; |
| Alex Sakhartchouk | fd79e02 | 2011-12-22 14:30:55 -0800 | [diff] [blame^] | 732 | mVectorSize = 1; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 733 | mElements = e; |
| 734 | mElementNames = n; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 735 | mArraySizes = as; |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 736 | mType = DataType.NONE; |
| 737 | mKind = DataKind.USER; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 738 | mOffsetInBytes = new int[mElements.length]; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 739 | for (int ct = 0; ct < mElements.length; ct++ ) { |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 740 | mOffsetInBytes[ct] = mSize; |
| Alex Sakhartchouk | 9e401bc | 2010-10-13 14:22:02 -0700 | [diff] [blame] | 741 | mSize += mElements[ct].mSize * mArraySizes[ct]; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 742 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 743 | updateVisibleSubElements(); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 746 | Element(int id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) { |
| 747 | super(id, rs); |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 748 | if ((dt != DataType.UNSIGNED_5_6_5) && |
| 749 | (dt != DataType.UNSIGNED_4_4_4_4) && |
| 750 | (dt != DataType.UNSIGNED_5_5_5_1)) { |
| Alex Sakhartchouk | e60149d | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 751 | if (size == 3) { |
| 752 | mSize = dt.mSize * 4; |
| 753 | } else { |
| 754 | mSize = dt.mSize * size; |
| 755 | } |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 756 | } else { |
| 757 | mSize = dt.mSize; |
| 758 | } |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 759 | mType = dt; |
| 760 | mKind = dk; |
| 761 | mNormalized = norm; |
| 762 | mVectorSize = size; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 765 | Element(int id, RenderScript rs) { |
| 766 | super(id, rs); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | @Override |
| 770 | void updateFromNative() { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 771 | super.updateFromNative(); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 772 | |
| 773 | // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements |
| 774 | int[] dataBuffer = new int[5]; |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 775 | mRS.nElementGetNativeData(getID(), dataBuffer); |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 776 | |
| 777 | mNormalized = dataBuffer[2] == 1 ? true : false; |
| 778 | mVectorSize = dataBuffer[3]; |
| 779 | mSize = 0; |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 780 | for (DataType dt: DataType.values()) { |
| 781 | if(dt.mID == dataBuffer[0]){ |
| 782 | mType = dt; |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 783 | mSize = mType.mSize * mVectorSize; |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | for (DataKind dk: DataKind.values()) { |
| 787 | if(dk.mID == dataBuffer[1]){ |
| 788 | mKind = dk; |
| 789 | } |
| 790 | } |
| 791 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 792 | int numSubElements = dataBuffer[4]; |
| 793 | if(numSubElements > 0) { |
| 794 | mElements = new Element[numSubElements]; |
| 795 | mElementNames = new String[numSubElements]; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 796 | mArraySizes = new int[numSubElements]; |
| 797 | mOffsetInBytes = new int[numSubElements]; |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 798 | |
| 799 | int[] subElementIds = new int[numSubElements]; |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 800 | mRS.nElementGetSubElements(getID(), subElementIds, mElementNames, mArraySizes); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 801 | for(int i = 0; i < numSubElements; i ++) { |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 802 | mElements[i] = new Element(subElementIds[i], mRS); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 803 | mElements[i].updateFromNative(); |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 804 | mOffsetInBytes[i] = mSize; |
| 805 | mSize += mElements[i].mSize * mArraySizes[i]; |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 806 | } |
| 807 | } |
| Alex Sakhartchouk | 3aac0ab | 2011-12-22 13:11:48 -0800 | [diff] [blame] | 808 | updateVisibleSubElements(); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 811 | /** |
| 812 | * Create a custom Element of the specified DataType. The DataKind will be |
| 813 | * set to USER and the vector size to 1 indicating non-vector. |
| 814 | * |
| 815 | * @param rs The context associated with the new Element. |
| 816 | * @param dt The DataType for the new element. |
| 817 | * @return Element |
| 818 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 819 | static Element createUser(RenderScript rs, DataType dt) { |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 820 | DataKind dk = DataKind.USER; |
| 821 | boolean norm = false; |
| 822 | int vecSize = 1; |
| 823 | int id = rs.nElementCreate(dt.mID, dk.mID, norm, vecSize); |
| 824 | return new Element(id, rs, dt, dk, norm, vecSize); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 825 | } |
| 826 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 827 | /** |
| 828 | * Create a custom vector element of the specified DataType and vector size. |
| 829 | * DataKind will be set to USER. |
| 830 | * |
| 831 | * @param rs The context associated with the new Element. |
| 832 | * @param dt The DataType for the new element. |
| 833 | * @param size Vector size for the new Element. Range 2-4 inclusive |
| 834 | * supported. |
| 835 | * |
| 836 | * @return Element |
| 837 | */ |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 838 | public static Element createVector(RenderScript rs, DataType dt, int size) { |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 839 | if (size < 2 || size > 4) { |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 840 | throw new RSIllegalArgumentException("Vector size out of range 2-4."); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 841 | } |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 842 | DataKind dk = DataKind.USER; |
| 843 | boolean norm = false; |
| 844 | int id = rs.nElementCreate(dt.mID, dk.mID, norm, size); |
| 845 | return new Element(id, rs, dt, dk, norm, size); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 848 | /** |
| 849 | * Create a new pixel Element type. A matching DataType and DataKind must |
| 850 | * be provided. The DataType and DataKind must contain the same number of |
| 851 | * components. Vector size will be set to 1. |
| 852 | * |
| 853 | * @param rs The context associated with the new Element. |
| 854 | * @param dt The DataType for the new element. |
| 855 | * @param dk The DataKind to specify the mapping of each component in the |
| 856 | * DataType. |
| 857 | * |
| 858 | * @return Element |
| 859 | */ |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 860 | public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) { |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 861 | if (!(dk == DataKind.PIXEL_L || |
| 862 | dk == DataKind.PIXEL_A || |
| 863 | dk == DataKind.PIXEL_LA || |
| 864 | dk == DataKind.PIXEL_RGB || |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 865 | dk == DataKind.PIXEL_RGBA || |
| 866 | dk == DataKind.PIXEL_DEPTH)) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 867 | throw new RSIllegalArgumentException("Unsupported DataKind"); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 868 | } |
| 869 | if (!(dt == DataType.UNSIGNED_8 || |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 870 | dt == DataType.UNSIGNED_16 || |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 871 | dt == DataType.UNSIGNED_5_6_5 || |
| 872 | dt == DataType.UNSIGNED_4_4_4_4 || |
| 873 | dt == DataType.UNSIGNED_5_5_5_1)) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 874 | throw new RSIllegalArgumentException("Unsupported DataType"); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 875 | } |
| 876 | if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 877 | throw new RSIllegalArgumentException("Bad kind and type combo"); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 878 | } |
| 879 | if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 880 | throw new RSIllegalArgumentException("Bad kind and type combo"); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 881 | } |
| 882 | if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 883 | throw new RSIllegalArgumentException("Bad kind and type combo"); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 884 | } |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 885 | if (dt == DataType.UNSIGNED_16 && |
| 886 | dk != DataKind.PIXEL_DEPTH) { |
| 887 | throw new RSIllegalArgumentException("Bad kind and type combo"); |
| 888 | } |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 889 | |
| 890 | int size = 1; |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 891 | switch (dk) { |
| 892 | case PIXEL_LA: |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 893 | size = 2; |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 894 | break; |
| 895 | case PIXEL_RGB: |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 896 | size = 3; |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 897 | break; |
| 898 | case PIXEL_RGBA: |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 899 | size = 4; |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 900 | break; |
| 901 | case PIXEL_DEPTH: |
| 902 | size = 2; |
| 903 | break; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 904 | } |
| 905 | |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 906 | boolean norm = true; |
| 907 | int id = rs.nElementCreate(dt.mID, dk.mID, norm, size); |
| 908 | return new Element(id, rs, dt, dk, norm, size); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 909 | } |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 910 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 911 | /** |
| Stephen Hines | f257e51 | 2011-06-14 14:54:29 -0700 | [diff] [blame] | 912 | * Check if the current Element is compatible with another Element. |
| 913 | * Primitive Elements are compatible if they share the same underlying |
| 914 | * size and type (i.e. U8 is compatible with A_8). User-defined Elements |
| 915 | * must be equal in order to be compatible. This requires strict name |
| 916 | * equivalence for all sub-Elements (in addition to structural equivalence). |
| 917 | * |
| 918 | * @param e The Element to check compatibility with. |
| 919 | * |
| 920 | * @return boolean true if the Elements are compatible, otherwise false. |
| 921 | */ |
| 922 | public boolean isCompatible(Element e) { |
| 923 | // Try strict BaseObj equality to start with. |
| 924 | if (this.equals(e)) { |
| 925 | return true; |
| 926 | } |
| 927 | |
| 928 | // Ignore mKind because it is allowed to be different (user vs. pixel). |
| 929 | // We also ignore mNormalized because it can be different. The mType |
| 930 | // field must be non-null since we require name equivalence for |
| 931 | // user-created Elements. |
| 932 | return ((mSize == e.mSize) && |
| 933 | (mType != null) && |
| 934 | (mType == e.mType) && |
| 935 | (mVectorSize == e.mVectorSize)); |
| 936 | } |
| 937 | |
| 938 | /** |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 939 | * Builder class for producing complex elements with matching field and name |
| 940 | * pairs. The builder starts empty. The order in which elements are added |
| 941 | * is retained for the layout in memory. |
| 942 | * |
| 943 | */ |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 944 | public static class Builder { |
| 945 | RenderScript mRS; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 946 | Element[] mElements; |
| 947 | String[] mElementNames; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 948 | int[] mArraySizes; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 949 | int mCount; |
| Alex Sakhartchouk | e60149d | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 950 | int mSkipPadding; |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 951 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 952 | /** |
| 953 | * Create a builder object. |
| 954 | * |
| 955 | * @param rs |
| 956 | */ |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 957 | public Builder(RenderScript rs) { |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 958 | mRS = rs; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 959 | mCount = 0; |
| 960 | mElements = new Element[8]; |
| 961 | mElementNames = new String[8]; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 962 | mArraySizes = new int[8]; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 963 | } |
| 964 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 965 | /** |
| 966 | * Add an array of elements to this element. |
| 967 | * |
| 968 | * @param element |
| 969 | * @param name |
| 970 | * @param arraySize |
| 971 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 972 | public Builder add(Element element, String name, int arraySize) { |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 973 | if (arraySize < 1) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 974 | throw new RSIllegalArgumentException("Array size cannot be less than 1."); |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 975 | } |
| Alex Sakhartchouk | e60149d | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 976 | |
| 977 | // Skip padding fields after a vector 3 type. |
| 978 | if (mSkipPadding != 0) { |
| 979 | if (name.startsWith("#padding_")) { |
| 980 | mSkipPadding = 0; |
| 981 | return this; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | if (element.mVectorSize == 3) { |
| 986 | mSkipPadding = 1; |
| 987 | } else { |
| 988 | mSkipPadding = 0; |
| 989 | } |
| 990 | |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 991 | if(mCount == mElements.length) { |
| 992 | Element[] e = new Element[mCount + 8]; |
| 993 | String[] s = new String[mCount + 8]; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 994 | int[] as = new int[mCount + 8]; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 995 | System.arraycopy(mElements, 0, e, 0, mCount); |
| 996 | System.arraycopy(mElementNames, 0, s, 0, mCount); |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 997 | System.arraycopy(mArraySizes, 0, as, 0, mCount); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 998 | mElements = e; |
| 999 | mElementNames = s; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 1000 | mArraySizes = as; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 1001 | } |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1002 | mElements[mCount] = element; |
| 1003 | mElementNames[mCount] = name; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 1004 | mArraySizes[mCount] = arraySize; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1005 | mCount++; |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1006 | return this; |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 1009 | /** |
| 1010 | * Add a single element to this Element. |
| 1011 | * |
| 1012 | * @param element |
| 1013 | * @param name |
| 1014 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1015 | public Builder add(Element element, String name) { |
| 1016 | return add(element, name, 1); |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
| Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 1019 | /** |
| 1020 | * Create the element from this builder. |
| 1021 | * |
| 1022 | * |
| 1023 | * @return Element |
| 1024 | */ |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1025 | public Element create() { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1026 | mRS.validate(); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1027 | Element[] ein = new Element[mCount]; |
| 1028 | String[] sin = new String[mCount]; |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 1029 | int[] asin = new int[mCount]; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1030 | java.lang.System.arraycopy(mElements, 0, ein, 0, mCount); |
| 1031 | java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount); |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 1032 | java.lang.System.arraycopy(mArraySizes, 0, asin, 0, mCount); |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 1033 | |
| 1034 | int[] ids = new int[ein.length]; |
| 1035 | for (int ct = 0; ct < ein.length; ct++ ) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1036 | ids[ct] = ein[ct].getID(); |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 1037 | } |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 1038 | int id = mRS.nElementCreate2(ids, sin, asin); |
| 1039 | return new Element(id, mRS, ein, sin, asin); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |