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