Skip to content

Commit 3beb60e

Browse files
committed
Vectors of non-primitive types are not allowed.
BUG=6016669 Change-Id: Ibab2dfc5ce3d9ceb5513e6b5ffc53d5df8b7c6e7
1 parent 687bdf0 commit 3beb60e

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

graphics/java/android/renderscript/Element.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 The Android Open Source Project
2+
* Copyright (C) 2008-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -832,10 +832,12 @@ static Element createUser(RenderScript rs, DataType dt) {
832832

833833
/**
834834
* Create a custom vector element of the specified DataType and vector size.
835-
* DataKind will be set to USER.
835+
* DataKind will be set to USER. Only primitive types (FLOAT_32, FLOAT_64,
836+
* SIGNED_8, SIGNED_16, SIGNED_32, SIGNED_64, UNSIGNED_8, UNSIGNED_16,
837+
* UNSIGNED_32, UNSIGNED_64, BOOLEAN) are supported.
836838
*
837839
* @param rs The context associated with the new Element.
838-
* @param dt The DataType for the new element.
840+
* @param dt The DataType for the new Element.
839841
* @param size Vector size for the new Element. Range 2-4 inclusive
840842
* supported.
841843
*
@@ -845,10 +847,31 @@ public static Element createVector(RenderScript rs, DataType dt, int size) {
845847
if (size < 2 || size > 4) {
846848
throw new RSIllegalArgumentException("Vector size out of range 2-4.");
847849
}
848-
DataKind dk = DataKind.USER;
849-
boolean norm = false;
850-
int id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
851-
return new Element(id, rs, dt, dk, norm, size);
850+
851+
switch (dt) {
852+
// Support only primitive integer/float/boolean types as vectors.
853+
case FLOAT_32:
854+
case FLOAT_64:
855+
case SIGNED_8:
856+
case SIGNED_16:
857+
case SIGNED_32:
858+
case SIGNED_64:
859+
case UNSIGNED_8:
860+
case UNSIGNED_16:
861+
case UNSIGNED_32:
862+
case UNSIGNED_64:
863+
case BOOLEAN: {
864+
DataKind dk = DataKind.USER;
865+
boolean norm = false;
866+
int id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
867+
return new Element(id, rs, dt, dk, norm, size);
868+
}
869+
870+
default: {
871+
throw new RSIllegalArgumentException("Cannot create vector of " +
872+
"non-primitive type.");
873+
}
874+
}
852875
}
853876

854877
/**

0 commit comments

Comments
 (0)