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