diff options
author | Stephen Hines <srhines@google.com> | 2012-02-14 20:38:20 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2012-02-15 19:07:43 -0800 |
commit | 3beb60e67a23b8a7381a7ae16338f793a9ee256a (patch) | |
tree | b8de34b8508c23163c864e1581cb9249b097f679 /graphics/java/android/renderscript/Element.java | |
parent | 687bdf0ae12addc095ba9f195e4ef3aa1133aa38 (diff) |
Vectors of non-primitive types are not allowed.
BUG=6016669
Change-Id: Ibab2dfc5ce3d9ceb5513e6b5ffc53d5df8b7c6e7
Diffstat (limited to 'graphics/java/android/renderscript/Element.java')
-rw-r--r-- | graphics/java/android/renderscript/Element.java | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index 2c0925bc82fa..3d4951f534ce 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2008-2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -832,10 +832,12 @@ public class Element extends BaseObj { /** * Create a custom vector element of the specified DataType and vector size. - * DataKind will be set to USER. + * DataKind will be set to USER. Only primitive types (FLOAT_32, FLOAT_64, + * SIGNED_8, SIGNED_16, SIGNED_32, SIGNED_64, UNSIGNED_8, UNSIGNED_16, + * UNSIGNED_32, UNSIGNED_64, BOOLEAN) are supported. * * @param rs The context associated with the new Element. - * @param dt The DataType for the new element. + * @param dt The DataType for the new Element. * @param size Vector size for the new Element. Range 2-4 inclusive * supported. * @@ -845,10 +847,31 @@ public class Element extends BaseObj { if (size < 2 || size > 4) { throw new RSIllegalArgumentException("Vector size out of range 2-4."); } - DataKind dk = DataKind.USER; - boolean norm = false; - int id = rs.nElementCreate(dt.mID, dk.mID, norm, size); - return new Element(id, rs, dt, dk, norm, size); + + switch (dt) { + // Support only primitive integer/float/boolean types as vectors. + case FLOAT_32: + case FLOAT_64: + case SIGNED_8: + case SIGNED_16: + case SIGNED_32: + case SIGNED_64: + case UNSIGNED_8: + case UNSIGNED_16: + case UNSIGNED_32: + case UNSIGNED_64: + case BOOLEAN: { + DataKind dk = DataKind.USER; + boolean norm = false; + int id = rs.nElementCreate(dt.mID, dk.mID, norm, size); + return new Element(id, rs, dt, dk, norm, size); + } + + default: { + throw new RSIllegalArgumentException("Cannot create vector of " + + "non-primitive type."); + } + } } /** |