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