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