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