Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -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 | b8c5a84 | 2009-07-31 20:40:47 -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 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 19 | |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 20 | import java.lang.reflect.Field; |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 21 | |
| 22 | import android.graphics.ImageFormat; |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 23 | import android.util.Log; |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 24 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 25 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 26 | * <p>A Type describes the {@link android.renderscript.Element} and dimensions used for an {@link |
| 27 | * android.renderscript.Allocation} or a parallel operation. Types are created through {@link |
| 28 | * android.renderscript.Type.Builder}.</p> |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 29 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 30 | * <p>A Type always includes an {@link android.renderscript.Element} and an X |
| 31 | * dimension. A Type may be multidimensional, up to three dimensions. A nonzero |
| 32 | * value in the Y or Z dimensions indicates that the dimension is present. Note |
| 33 | * that a Type with only a given X dimension and a Type with the same X |
| 34 | * dimension but Y = 1 are not equivalent.</p> |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 35 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 36 | * <p>A Type also supports inclusion of level of detail (LOD) or cube map |
| 37 | * faces. LOD and cube map faces are booleans to indicate present or not |
| 38 | * present. </p> |
| 39 | * |
| 40 | * <p>A Type also supports YUV format information to support an {@link |
| 41 | * android.renderscript.Allocation} in a YUV format. The YUV formats supported |
| 42 | * are {@link android.graphics.ImageFormat#YV12} and {@link |
| 43 | * android.graphics.ImageFormat#NV21}.</p> |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 44 | * |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 45 | * <div class="special reference"> |
| 46 | * <h3>Developer Guides</h3> |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 47 | * <p>For more information about creating an application that uses RenderScript, read the |
| 48 | * <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] | 49 | * </div> |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 50 | **/ |
| 51 | public class Type extends BaseObj { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 52 | int mDimX; |
| 53 | int mDimY; |
| 54 | int mDimZ; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 55 | boolean mDimMipmaps; |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 56 | boolean mDimFaces; |
Jason Sams | 8140d7b | 2012-12-13 17:01:09 -0800 | [diff] [blame] | 57 | int mDimYuv; |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 58 | int mElementCount; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 59 | Element mElement; |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 60 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 61 | public enum CubemapFace { |
Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 62 | POSITIVE_X (0), |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 63 | NEGATIVE_X (1), |
Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 64 | POSITIVE_Y (2), |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 65 | NEGATIVE_Y (3), |
Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 66 | POSITIVE_Z (4), |
| 67 | NEGATIVE_Z (5), |
| 68 | @Deprecated |
| 69 | POSITVE_X (0), |
| 70 | @Deprecated |
| 71 | POSITVE_Y (2), |
| 72 | @Deprecated |
| 73 | POSITVE_Z (4); |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 74 | |
| 75 | int mID; |
| 76 | CubemapFace(int id) { |
| 77 | mID = id; |
| 78 | } |
| 79 | } |
| 80 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 81 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 82 | * Return the element associated with this Type. |
| 83 | * |
| 84 | * @return Element |
| 85 | */ |
Jason Sams | e17964e | 2010-01-04 16:52:27 -0800 | [diff] [blame] | 86 | public Element getElement() { |
| 87 | return mElement; |
| 88 | } |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 89 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 90 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 91 | * Return the value of the X dimension. |
| 92 | * |
| 93 | * @return int |
| 94 | */ |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 95 | public int getX() { |
| 96 | return mDimX; |
| 97 | } |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 98 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 99 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 100 | * Return the value of the Y dimension or 0 for a 1D allocation. |
| 101 | * |
| 102 | * @return int |
| 103 | */ |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 104 | public int getY() { |
| 105 | return mDimY; |
| 106 | } |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 107 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 108 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 109 | * Return the value of the Z dimension or 0 for a 1D or 2D allocation. |
| 110 | * |
| 111 | * @return int |
| 112 | */ |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 113 | public int getZ() { |
| 114 | return mDimZ; |
| 115 | } |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 116 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 117 | /** |
Jason Sams | 5a722cf | 2013-03-26 13:27:37 -0700 | [diff] [blame] | 118 | * Get the YUV format |
| 119 | * |
Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 120 | * |
Jason Sams | 5a722cf | 2013-03-26 13:27:37 -0700 | [diff] [blame] | 121 | * @return int |
| 122 | */ |
| 123 | public int getYuv() { |
| 124 | return mDimYuv; |
| 125 | } |
| 126 | |
| 127 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 128 | * Return if the Type has a mipmap chain. |
| 129 | * |
| 130 | * @return boolean |
| 131 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 132 | public boolean hasMipmaps() { |
| 133 | return mDimMipmaps; |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 134 | } |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 135 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 136 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 137 | * Return if the Type is a cube map. |
| 138 | * |
| 139 | * @return boolean |
| 140 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 141 | public boolean hasFaces() { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 142 | return mDimFaces; |
| 143 | } |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 144 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 145 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 146 | * Return the total number of accessable cells in the Type. |
| 147 | * |
| 148 | * @return int |
| 149 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 150 | public int getCount() { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 151 | return mElementCount; |
| 152 | } |
| 153 | |
| 154 | void calcElementCount() { |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 155 | boolean hasLod = hasMipmaps(); |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 156 | int x = getX(); |
| 157 | int y = getY(); |
| 158 | int z = getZ(); |
| 159 | int faces = 1; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 160 | if (hasFaces()) { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 161 | faces = 6; |
| 162 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 163 | if (x == 0) { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 164 | x = 1; |
| 165 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 166 | if (y == 0) { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 167 | y = 1; |
| 168 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 169 | if (z == 0) { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 170 | z = 1; |
| 171 | } |
| 172 | |
| 173 | int count = x * y * z * faces; |
Alex Sakhartchouk | 9ea30a6 | 2011-03-02 12:33:50 -0800 | [diff] [blame] | 174 | |
| 175 | while (hasLod && ((x > 1) || (y > 1) || (z > 1))) { |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 176 | if(x > 1) { |
| 177 | x >>= 1; |
| 178 | } |
| 179 | if(y > 1) { |
| 180 | y >>= 1; |
| 181 | } |
| 182 | if(z > 1) { |
| 183 | z >>= 1; |
| 184 | } |
| 185 | |
| 186 | count += x * y * z * faces; |
| 187 | } |
| 188 | mElementCount = count; |
| 189 | } |
| 190 | |
| 191 | |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 192 | Type(int id, RenderScript rs) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 193 | super(id, rs); |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 196 | @Override |
| 197 | void updateFromNative() { |
| 198 | // We have 6 integer to obtain mDimX; mDimY; mDimZ; |
| 199 | // mDimLOD; mDimFaces; mElement; |
| 200 | int[] dataBuffer = new int[6]; |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 201 | mRS.nTypeGetNativeData(getID(mRS), dataBuffer); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 202 | |
| 203 | mDimX = dataBuffer[0]; |
| 204 | mDimY = dataBuffer[1]; |
| 205 | mDimZ = dataBuffer[2]; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 206 | mDimMipmaps = dataBuffer[3] == 1 ? true : false; |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 207 | mDimFaces = dataBuffer[4] == 1 ? true : false; |
| 208 | |
| 209 | int elementID = dataBuffer[5]; |
| 210 | if(elementID != 0) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 211 | mElement = new Element(elementID, mRS); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 212 | mElement.updateFromNative(); |
| 213 | } |
| 214 | calcElementCount(); |
| 215 | } |
| 216 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 217 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 218 | * Builder class for Type. |
| 219 | * |
| 220 | */ |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 221 | public static class Builder { |
| 222 | RenderScript mRS; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 223 | int mDimX = 1; |
| 224 | int mDimY; |
| 225 | int mDimZ; |
| 226 | boolean mDimMipmaps; |
| 227 | boolean mDimFaces; |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 228 | int mYuv; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 229 | |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 230 | Element mElement; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 231 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 232 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 233 | * Create a new builder object. |
| 234 | * |
| 235 | * @param rs |
| 236 | * @param e The element for the type to be created. |
| 237 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 238 | public Builder(RenderScript rs, Element e) { |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 239 | e.checkValid(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 240 | mRS = rs; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 241 | mElement = e; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 244 | /** |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 245 | * Add a dimension to the Type. |
| 246 | * |
| 247 | * |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 248 | * @param value |
| 249 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 250 | public Builder setX(int value) { |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 251 | if(value < 1) { |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 252 | throw new RSIllegalArgumentException("Values of less than 1 for Dimension X are not valid."); |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 253 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 254 | mDimX = value; |
| 255 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 258 | public Builder setY(int value) { |
| 259 | if(value < 1) { |
| 260 | throw new RSIllegalArgumentException("Values of less than 1 for Dimension Y are not valid."); |
| 261 | } |
| 262 | mDimY = value; |
| 263 | return this; |
| 264 | } |
| 265 | |
Jason Sams | d1c306a | 2012-12-27 20:26:41 -0800 | [diff] [blame] | 266 | public Builder setZ(int value) { |
| 267 | if(value < 1) { |
| 268 | throw new RSIllegalArgumentException("Values of less than 1 for Dimension Z are not valid."); |
| 269 | } |
| 270 | mDimZ = value; |
| 271 | return this; |
| 272 | } |
| 273 | |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 274 | public Builder setMipmaps(boolean value) { |
| 275 | mDimMipmaps = value; |
| 276 | return this; |
| 277 | } |
| 278 | |
| 279 | public Builder setFaces(boolean value) { |
| 280 | mDimFaces = value; |
| 281 | return this; |
| 282 | } |
| 283 | |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 284 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 285 | * Set the YUV layout for a Type. |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 286 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 287 | * @param yuvFormat {@link android.graphics.ImageFormat#YV12} or {@link android.graphics.ImageFormat#NV21} |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 288 | */ |
| 289 | public Builder setYuvFormat(int yuvFormat) { |
| 290 | switch (yuvFormat) { |
| 291 | case android.graphics.ImageFormat.NV21: |
| 292 | case android.graphics.ImageFormat.YV12: |
| 293 | break; |
| 294 | |
| 295 | default: |
| 296 | throw new RSIllegalArgumentException("Only NV21 and YV12 are supported.."); |
| 297 | } |
| 298 | |
| 299 | mYuv = yuvFormat; |
| 300 | return this; |
| 301 | } |
| 302 | |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 303 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 304 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 305 | * Validate structure and create a new Type. |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 306 | * |
| 307 | * @return Type |
| 308 | */ |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 309 | public Type create() { |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 310 | if (mDimZ > 0) { |
| 311 | if ((mDimX < 1) || (mDimY < 1)) { |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 312 | throw new RSInvalidStateException("Both X and Y dimension required when Z is present."); |
| 313 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 314 | if (mDimFaces) { |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 315 | throw new RSInvalidStateException("Cube maps not supported with 3D types."); |
| 316 | } |
| 317 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 318 | if (mDimY > 0) { |
| 319 | if (mDimX < 1) { |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 320 | throw new RSInvalidStateException("X dimension required when Y is present."); |
| 321 | } |
| 322 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 323 | if (mDimFaces) { |
| 324 | if (mDimY < 1) { |
Jason Sams | a1b13ed | 2010-11-12 14:58:37 -0800 | [diff] [blame] | 325 | throw new RSInvalidStateException("Cube maps require 2D Types."); |
| 326 | } |
| 327 | } |
| 328 | |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 329 | if (mYuv != 0) { |
| 330 | if ((mDimZ != 0) || mDimFaces || mDimMipmaps) { |
| 331 | throw new RSInvalidStateException("YUV only supports basic 2D."); |
| 332 | } |
| 333 | } |
| 334 | |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 335 | int id = mRS.nTypeCreate(mElement.getID(mRS), |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 336 | mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces, mYuv); |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 337 | Type t = new Type(id, mRS); |
| 338 | t.mElement = mElement; |
| 339 | t.mDimX = mDimX; |
| 340 | t.mDimY = mDimY; |
| 341 | t.mDimZ = mDimZ; |
| 342 | t.mDimMipmaps = mDimMipmaps; |
| 343 | t.mDimFaces = mDimFaces; |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 344 | t.mDimYuv = mYuv; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 345 | |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 346 | t.calcElementCount(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 347 | return t; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | } |