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