Remove static asserts for GrSLType and GrVertexAttribType enum values.
Replaces with switch statements that will produce a compiler warning if a type is added and helper functions are not updated.
This also removes several unused helper functions for these enum types.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4486
Change-Id: Iee6d8e5095dc4ba2488a8928bf60f8e903cd3320
Reviewed-on: https://skia-review.googlesource.com/4486
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h
index 44d5599..2fa4c3a 100644
--- a/include/gpu/GrTypesPriv.h
+++ b/include/gpu/GrTypesPriv.h
@@ -17,6 +17,9 @@
*/
enum GrSLType {
kVoid_GrSLType,
+ kBool_GrSLType,
+ kInt_GrSLType,
+ kUint_GrSLType,
kFloat_GrSLType,
kVec2f_GrSLType,
kVec3f_GrSLType,
@@ -29,9 +32,6 @@
kTextureExternalSampler_GrSLType,
kTexture2DRectSampler_GrSLType,
kTextureBufferSampler_GrSLType,
- kBool_GrSLType,
- kInt_GrSLType,
- kUint_GrSLType,
kTexture2D_GrSLType,
kSampler_GrSLType,
@@ -83,173 +83,117 @@
static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
-/**
- * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
- */
-static inline int GrSLTypeVectorCount(GrSLType type) {
- SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
- static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, -1 };
- return kCounts[type];
-
- GR_STATIC_ASSERT(0 == kVoid_GrSLType);
- GR_STATIC_ASSERT(1 == kFloat_GrSLType);
- GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
- GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
- GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
- GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
- GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
- GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
- GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
- GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
- GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
- GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
- GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
- GR_STATIC_ASSERT(13 == kBool_GrSLType);
- GR_STATIC_ASSERT(14 == kInt_GrSLType);
- GR_STATIC_ASSERT(15 == kUint_GrSLType);
- GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
- GR_STATIC_ASSERT(17 == kSampler_GrSLType);
- GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
-}
-
-/** Return the type enum for a vector of floats of length n (1..4),
- e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
-static inline GrSLType GrSLFloatVectorType(int count) {
- SkASSERT(count > 0 && count <= 4);
- return (GrSLType)(count);
-
- GR_STATIC_ASSERT(kFloat_GrSLType == 1);
- GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
- GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
- GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
-}
-
/** Is the shading language type float (including vectors/matrices)? */
static inline bool GrSLTypeIsFloatType(GrSLType type) {
- SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
- return type >= kFloat_GrSLType && type <= kMat44f_GrSLType;
+ switch (type) {
+ case kFloat_GrSLType:
+ case kVec2f_GrSLType:
+ case kVec3f_GrSLType:
+ case kVec4f_GrSLType:
+ case kMat22f_GrSLType:
+ case kMat33f_GrSLType:
+ case kMat44f_GrSLType:
+ return true;
- GR_STATIC_ASSERT(0 == kVoid_GrSLType);
- GR_STATIC_ASSERT(1 == kFloat_GrSLType);
- GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
- GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
- GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
- GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
- GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
- GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
- GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
- GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
- GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
- GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
- GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
- GR_STATIC_ASSERT(13 == kBool_GrSLType);
- GR_STATIC_ASSERT(14 == kInt_GrSLType);
- GR_STATIC_ASSERT(15 == kUint_GrSLType);
- GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
- GR_STATIC_ASSERT(17 == kSampler_GrSLType);
- GR_STATIC_ASSERT(18 == kGrSLTypeCount);
-}
-
-/** Is the shading language type integral (including vectors/matrices)? */
-static inline bool GrSLTypeIsIntType(GrSLType type) {
- SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
- return type >= kInt_GrSLType && type <= kUint_GrSLType;
-
- GR_STATIC_ASSERT(0 == kVoid_GrSLType);
- GR_STATIC_ASSERT(1 == kFloat_GrSLType);
- GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
- GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
- GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
- GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
- GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
- GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
- GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
- GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
- GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
- GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
- GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
- GR_STATIC_ASSERT(13 == kBool_GrSLType);
- GR_STATIC_ASSERT(14 == kInt_GrSLType);
- GR_STATIC_ASSERT(15 == kUint_GrSLType);
- GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
- GR_STATIC_ASSERT(17 == kSampler_GrSLType);
- GR_STATIC_ASSERT(18 == kGrSLTypeCount);
-}
-
-/** Is the shading language type numeric (including vectors/matrices)? */
-static inline bool GrSLTypeIsNumeric(GrSLType type) {
- return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
-}
-
-/** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */
-static inline size_t GrSLTypeSize(GrSLType type) {
- SkASSERT(GrSLTypeIsFloatType(type));
- static const size_t kSizes[] = {
- 0, // kVoid_GrSLType
- sizeof(float), // kFloat_GrSLType
- 2 * sizeof(float), // kVec2f_GrSLType
- 3 * sizeof(float), // kVec3f_GrSLType
- 4 * sizeof(float), // kVec4f_GrSLType
- 2 * 2 * sizeof(float), // kMat22f_GrSLType
- 3 * 3 * sizeof(float), // kMat33f_GrSLType
- 4 * 4 * sizeof(float), // kMat44f_GrSLType
- 0, // kTexture2DSampler_GrSLType
- 0, // kTexture2DISampler_GrSLType
- 0, // kTextureExternalSampler_GrSLType
- 0, // kTexture2DRectSampler_GrSLType
- 0, // kTextureBufferSampler_GrSLType
- 0, // kBool_GrSLType
- 0, // kInt_GrSLType
- 0, // kUint_GrSLType
- 0, // kTexture2D_GrSLType
- 0, // kSampler_GrSLType
- };
- return kSizes[type];
-
- GR_STATIC_ASSERT(0 == kVoid_GrSLType);
- GR_STATIC_ASSERT(1 == kFloat_GrSLType);
- GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
- GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
- GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
- GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
- GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
- GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
- GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
- GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
- GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
- GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
- GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
- GR_STATIC_ASSERT(13 == kBool_GrSLType);
- GR_STATIC_ASSERT(14 == kInt_GrSLType);
- GR_STATIC_ASSERT(15 == kUint_GrSLType);
- GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
- GR_STATIC_ASSERT(17 == kSampler_GrSLType);
- GR_STATIC_ASSERT(18 == kGrSLTypeCount);
+ case kVoid_GrSLType:
+ case kTexture2DSampler_GrSLType:
+ case kTexture2DISampler_GrSLType:
+ case kTextureExternalSampler_GrSLType:
+ case kTexture2DRectSampler_GrSLType:
+ case kTextureBufferSampler_GrSLType:
+ case kBool_GrSLType:
+ case kInt_GrSLType:
+ case kUint_GrSLType:
+ case kTexture2D_GrSLType:
+ case kSampler_GrSLType:
+ return false;
+ }
+ SkFAIL("Unexpected type");
+ return false;
}
static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
- SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
- return type >= kTexture2DSampler_GrSLType && type <= kTexture2DRectSampler_GrSLType;
+ switch (type) {
+ case kTexture2DSampler_GrSLType:
+ case kTexture2DISampler_GrSLType:
+ case kTextureExternalSampler_GrSLType:
+ case kTexture2DRectSampler_GrSLType:
+ return true;
- GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
- GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
- GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
- GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
+ case kVoid_GrSLType:
+ case kFloat_GrSLType:
+ case kVec2f_GrSLType:
+ case kVec3f_GrSLType:
+ case kVec4f_GrSLType:
+ case kMat22f_GrSLType:
+ case kMat33f_GrSLType:
+ case kMat44f_GrSLType:
+ case kTextureBufferSampler_GrSLType:
+ case kInt_GrSLType:
+ case kUint_GrSLType:
+ case kBool_GrSLType:
+ case kTexture2D_GrSLType:
+ case kSampler_GrSLType:
+ return false;
+ }
+ SkFAIL("Unexpected type");
+ return false;
}
static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
- SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
- return type >= kTexture2DSampler_GrSLType && type <= kTextureBufferSampler_GrSLType;
+ switch (type) {
+ case kTexture2DSampler_GrSLType:
+ case kTexture2DISampler_GrSLType:
+ case kTextureExternalSampler_GrSLType:
+ case kTexture2DRectSampler_GrSLType:
+ case kTextureBufferSampler_GrSLType:
+ return true;
- GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
- GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
- GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
- GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
- GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
+ case kVoid_GrSLType:
+ case kFloat_GrSLType:
+ case kVec2f_GrSLType:
+ case kVec3f_GrSLType:
+ case kVec4f_GrSLType:
+ case kMat22f_GrSLType:
+ case kMat33f_GrSLType:
+ case kMat44f_GrSLType:
+ case kInt_GrSLType:
+ case kUint_GrSLType:
+ case kBool_GrSLType:
+ case kTexture2D_GrSLType:
+ case kSampler_GrSLType:
+ return false;
+ }
+ SkFAIL("Unexpected type");
+ return false;
}
static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
- return type != kVoid_GrSLType && type != kBool_GrSLType;
+ switch (type) {
+ case kInt_GrSLType:
+ case kUint_GrSLType:
+ case kFloat_GrSLType:
+ case kVec2f_GrSLType:
+ case kVec3f_GrSLType:
+ case kVec4f_GrSLType:
+ case kMat22f_GrSLType:
+ case kMat33f_GrSLType:
+ case kMat44f_GrSLType:
+ case kTexture2DSampler_GrSLType:
+ case kTexture2DISampler_GrSLType:
+ case kTextureExternalSampler_GrSLType:
+ case kTexture2DRectSampler_GrSLType:
+ case kTextureBufferSampler_GrSLType:
+ case kTexture2D_GrSLType:
+ case kSampler_GrSLType:
+ return true;
+
+ case kVoid_GrSLType:
+ case kBool_GrSLType:
+ return false;
+ }
+ SkFAIL("Unexpected type");
+ return false;
}
//////////////////////////////////////////////////////////////////////////////
@@ -275,72 +219,61 @@
};
static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
-/**
- * Returns the vector size of the type.
- */
-static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
- SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
- static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
- return kCounts[type];
-
- GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
- GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
- GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
- GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
- GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
- GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
- GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
- GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
- GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
- GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
-}
/**
* Returns the size of the attrib type in bytes.
*/
static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
- static const size_t kSizes[] = {
- sizeof(float), // kFloat_GrVertexAttribType
- 2*sizeof(float), // kVec2f_GrVertexAttribType
- 3*sizeof(float), // kVec3f_GrVertexAttribType
- 4*sizeof(float), // kVec4f_GrVertexAttribType
- 1*sizeof(char), // kUByte_GrVertexAttribType
- 4*sizeof(char), // kVec4ub_GrVertexAttribType
- 2*sizeof(int16_t), // kVec2us_GrVertexAttribType
- sizeof(int32_t), // kInt_GrVertexAttribType
- sizeof(uint32_t) // kUint_GrVertexAttribType
- };
- return kSizes[type];
-
- GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
- GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
- GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
- GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
- GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
- GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
- GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
- GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
- GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
- GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
+ switch (type) {
+ case kFloat_GrVertexAttribType:
+ return sizeof(float);
+ case kVec2f_GrVertexAttribType:
+ return 2*sizeof(float);
+ case kVec3f_GrVertexAttribType:
+ return 3*sizeof(float);
+ case kVec4f_GrVertexAttribType:
+ return 4*sizeof(float);
+ case kUByte_GrVertexAttribType:
+ return 1*sizeof(char);
+ case kVec4ub_GrVertexAttribType:
+ return 4*sizeof(char);
+ case kVec2us_GrVertexAttribType:
+ return 2*sizeof(int16_t);
+ case kInt_GrVertexAttribType:
+ return sizeof(int32_t);
+ case kUint_GrVertexAttribType:
+ return sizeof(uint32_t);
+ }
+ SkFAIL("Unexpected attribute type");
+ return 0;
}
/**
* Is the attrib type integral?
*/
static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
- SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
- return type >= kInt_GrVertexAttribType;
-
- GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
- GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
- GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
- GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
- GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
- GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
- GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
- GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
- GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
- GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
+ switch (type) {
+ case kFloat_GrVertexAttribType:
+ return false;
+ case kVec2f_GrVertexAttribType:
+ return false;
+ case kVec3f_GrVertexAttribType:
+ return false;
+ case kVec4f_GrVertexAttribType:
+ return false;
+ case kUByte_GrVertexAttribType:
+ return false;
+ case kVec4ub_GrVertexAttribType:
+ return false;
+ case kVec2us_GrVertexAttribType:
+ return false;
+ case kInt_GrVertexAttribType:
+ return true;
+ case kUint_GrVertexAttribType:
+ return true;
+ }
+ SkFAIL("Unexpected attribute type");
+ return false;
}
/**
@@ -348,9 +281,6 @@
*/
static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
switch (type) {
- default:
- SkFAIL("Unsupported type conversion");
- return kVoid_GrSLType;
case kUByte_GrVertexAttribType:
case kFloat_GrVertexAttribType:
return kFloat_GrSLType;
@@ -367,6 +297,8 @@
case kUint_GrVertexAttribType:
return kUint_GrSLType;
}
+ SkFAIL("Unsupported type conversion");
+ return kVoid_GrSLType;
}
//////////////////////////////////////////////////////////////////////////////