| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrTypesPriv_DEFINED | 8 #ifndef GrTypesPriv_DEFINED |
| 9 #define GrTypesPriv_DEFINED | 9 #define GrTypesPriv_DEFINED |
| 10 | 10 |
| 11 #include "GrTypes.h" | 11 #include "GrTypes.h" |
| 12 #include "SkTArray.h" | 12 #include "SkTArray.h" |
| 13 #include "SkRect.h" | 13 #include "SkRect.h" |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Types of shader-language-specific boxed variables we can create. (Currently o
nly GrGLShaderVars, | 16 * Types of shader-language-specific boxed variables we can create. (Currently o
nly GrGLShaderVars, |
| 17 * but should be applicable to other shader languages.) | 17 * but should be applicable to other shader languages.) |
| 18 */ | 18 */ |
| 19 enum GrSLType { | 19 enum GrSLType { |
| 20 kVoid_GrSLType, | 20 kVoid_GrSLType, |
| 21 kFloat_GrSLType, | 21 kFloat_GrSLType, |
| 22 kVec2f_GrSLType, | 22 kVec2f_GrSLType, |
| 23 kVec3f_GrSLType, | 23 kVec3f_GrSLType, |
| 24 kVec4f_GrSLType, | 24 kVec4f_GrSLType, |
| 25 kMat33f_GrSLType, | 25 kMat33f_GrSLType, |
| 26 kMat44f_GrSLType, | 26 kMat44f_GrSLType, |
| 27 kSampler2D_GrSLType, | 27 kSampler2D_GrSLType, |
| 28 kSamplerExternal_GrSLType, | 28 kSamplerExternal_GrSLType, |
| 29 kBool_GrSLType, |
| 30 kInt_GrSLType, |
| 29 | 31 |
| 30 kLast_GrSLType = kSamplerExternal_GrSLType | 32 kLast_GrSLType = kInt_GrSLType |
| 31 }; | 33 }; |
| 32 static const int kGrSLTypeCount = kLast_GrSLType + 1; | 34 static const int kGrSLTypeCount = kLast_GrSLType + 1; |
| 33 | 35 |
| 34 enum GrShaderType { | 36 enum GrShaderType { |
| 35 kVertex_GrShaderType, | 37 kVertex_GrShaderType, |
| 36 kGeometry_GrShaderType, | 38 kGeometry_GrShaderType, |
| 37 kFragment_GrShaderType, | 39 kFragment_GrShaderType, |
| 38 | 40 |
| 39 kLastkFragment_GrShaderType = kFragment_GrShaderType | 41 kLastkFragment_GrShaderType = kFragment_GrShaderType |
| 40 }; | 42 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 kLast_GrSLPrecision = kHigh_GrSLPrecision | 59 kLast_GrSLPrecision = kHigh_GrSLPrecision |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; | 62 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; |
| 61 | 63 |
| 62 /** | 64 /** |
| 63 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. | 65 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. |
| 64 */ | 66 */ |
| 65 static inline int GrSLTypeVectorCount(GrSLType type) { | 67 static inline int GrSLTypeVectorCount(GrSLType type) { |
| 66 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 68 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 67 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1 }; | 69 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1 }; |
| 68 return kCounts[type]; | 70 return kCounts[type]; |
| 69 | 71 |
| 70 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 72 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 71 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 73 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 72 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 74 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 73 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 75 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 74 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 76 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 75 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); | 77 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 76 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); | 78 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 77 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); | 79 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 78 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); | 80 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 81 GR_STATIC_ASSERT(9 == kBool_GrSLType); |
| 82 GR_STATIC_ASSERT(10 == kInt_GrSLType); |
| 79 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); | 83 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); |
| 80 } | 84 } |
| 81 | 85 |
| 82 /** Return the type enum for a vector of floats of length n (1..4), | 86 /** Return the type enum for a vector of floats of length n (1..4), |
| 83 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ | 87 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
| 84 static inline GrSLType GrSLFloatVectorType(int count) { | 88 static inline GrSLType GrSLFloatVectorType(int count) { |
| 85 SkASSERT(count > 0 && count <= 4); | 89 SkASSERT(count > 0 && count <= 4); |
| 86 return (GrSLType)(count); | 90 return (GrSLType)(count); |
| 87 | 91 |
| 88 GR_STATIC_ASSERT(kFloat_GrSLType == 1); | 92 GR_STATIC_ASSERT(kFloat_GrSLType == 1); |
| 89 GR_STATIC_ASSERT(kVec2f_GrSLType == 2); | 93 GR_STATIC_ASSERT(kVec2f_GrSLType == 2); |
| 90 GR_STATIC_ASSERT(kVec3f_GrSLType == 3); | 94 GR_STATIC_ASSERT(kVec3f_GrSLType == 3); |
| 91 GR_STATIC_ASSERT(kVec4f_GrSLType == 4); | 95 GR_STATIC_ASSERT(kVec4f_GrSLType == 4); |
| 92 } | 96 } |
| 93 | 97 |
| 94 /** Is the shading language type floating point (or vector/matrix of fp)? */ | 98 /** Is the shading language type numeric (including vectors/matrices)? */ |
| 95 static inline bool GrSLTypeIsFloatType(GrSLType type) { | 99 static inline bool GrSLTypeIsNumeric(GrSLType type) { |
| 96 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 100 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 97 return type >= 1 && type <= 6; | 101 return (type >= 1 && type <= 6) || type == 10; |
| 98 | 102 |
| 99 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 103 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 100 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 104 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 101 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 105 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 102 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 106 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 103 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 107 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 104 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); | 108 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 105 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); | 109 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 106 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); | 110 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 107 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); | 111 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 108 GR_STATIC_ASSERT(9 == kGrSLTypeCount); | 112 GR_STATIC_ASSERT(9 == kBool_GrSLType); |
| 113 GR_STATIC_ASSERT(10 == kInt_GrSLType); |
| 114 GR_STATIC_ASSERT(11 == kGrSLTypeCount); |
| 109 } | 115 } |
| 110 ////////////////////////////////////////////////////////////////////////////// | 116 ////////////////////////////////////////////////////////////////////////////// |
| 111 | 117 |
| 112 /** | 118 /** |
| 113 * Types used to describe format of vertices in arrays. | 119 * Types used to describe format of vertices in arrays. |
| 114 */ | 120 */ |
| 115 enum GrVertexAttribType { | 121 enum GrVertexAttribType { |
| 116 kFloat_GrVertexAttribType = 0, | 122 kFloat_GrVertexAttribType = 0, |
| 117 kVec2f_GrVertexAttribType, | 123 kVec2f_GrVertexAttribType, |
| 118 kVec3f_GrVertexAttribType, | 124 kVec3f_GrVertexAttribType, |
| 119 kVec4f_GrVertexAttribType, | 125 kVec4f_GrVertexAttribType, |
| 120 | 126 |
| 121 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage | 127 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage |
| 122 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors | 128 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
| 123 | 129 |
| 124 kVec2s_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates | 130 kVec2s_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates |
| 131 |
| 132 kInt_GrVertexAttribType, |
| 125 | 133 |
| 126 kLast_GrVertexAttribType = kVec2s_GrVertexAttribType | 134 kLast_GrVertexAttribType = kInt_GrVertexAttribType |
| 127 }; | 135 }; |
| 128 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; | 136 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 129 | 137 |
| 130 /** | 138 /** |
| 131 * Returns the vector size of the type. | 139 * Returns the vector size of the type. |
| 132 */ | 140 */ |
| 133 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { | 141 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { |
| 134 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); | 142 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1 }; |
| 135 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2 }; | |
| 136 return kCounts[type]; | 143 return kCounts[type]; |
| 137 | 144 |
| 138 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); | 145 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 139 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); | 146 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 140 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); | 147 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 141 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); | 148 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 142 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); | 149 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 143 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); | 150 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
| 144 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); | 151 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); |
| 152 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType); |
| 145 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); | 153 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); |
| 146 } | 154 } |
| 147 | 155 |
| 148 /** | 156 /** |
| 149 * Returns the size of the attrib type in bytes. | 157 * Returns the size of the attrib type in bytes. |
| 150 */ | 158 */ |
| 151 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { | 159 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
| 152 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); | |
| 153 static const size_t kSizes[] = { | 160 static const size_t kSizes[] = { |
| 154 sizeof(float), // kFloat_GrVertexAttribType | 161 sizeof(float), // kFloat_GrVertexAttribType |
| 155 2*sizeof(float), // kVec2f_GrVertexAttribType | 162 2*sizeof(float), // kVec2f_GrVertexAttribType |
| 156 3*sizeof(float), // kVec3f_GrVertexAttribType | 163 3*sizeof(float), // kVec3f_GrVertexAttribType |
| 157 4*sizeof(float), // kVec4f_GrVertexAttribType | 164 4*sizeof(float), // kVec4f_GrVertexAttribType |
| 158 1*sizeof(char), // kUByte_GrVertexAttribType | 165 1*sizeof(char), // kUByte_GrVertexAttribType |
| 159 4*sizeof(char), // kVec4ub_GrVertexAttribType | 166 4*sizeof(char), // kVec4ub_GrVertexAttribType |
| 160 2*sizeof(int16_t) // kVec2s_GrVertexAttribType | 167 2*sizeof(int16_t), // kVec2s_GrVertexAttribType |
| 168 sizeof(int32_t) // kInt_GrVertexAttribType |
| 161 }; | 169 }; |
| 162 return kSizes[type]; | 170 return kSizes[type]; |
| 163 | 171 |
| 164 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); | 172 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 165 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); | 173 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 166 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); | 174 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 167 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); | 175 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 168 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); | 176 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 169 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); | 177 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
| 170 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); | 178 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); |
| 179 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType); |
| 171 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); | 180 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); |
| 172 } | 181 } |
| 173 | 182 |
| 174 /** | 183 /** |
| 175 * converts a GrVertexAttribType to a GrSLType | 184 * converts a GrVertexAttribType to a GrSLType |
| 176 */ | 185 */ |
| 177 static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { | 186 static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { |
| 178 switch (type) { | 187 switch (type) { |
| 179 default: | 188 default: |
| 180 SkFAIL("Unsupported type conversion"); | 189 SkFAIL("Unsupported type conversion"); |
| 181 case kUByte_GrVertexAttribType: | 190 case kUByte_GrVertexAttribType: |
| 182 case kFloat_GrVertexAttribType: | 191 case kFloat_GrVertexAttribType: |
| 183 return kFloat_GrSLType; | 192 return kFloat_GrSLType; |
| 184 case kVec2s_GrVertexAttribType: | 193 case kVec2s_GrVertexAttribType: |
| 185 case kVec2f_GrVertexAttribType: | 194 case kVec2f_GrVertexAttribType: |
| 186 return kVec2f_GrSLType; | 195 return kVec2f_GrSLType; |
| 187 case kVec3f_GrVertexAttribType: | 196 case kVec3f_GrVertexAttribType: |
| 188 return kVec3f_GrSLType; | 197 return kVec3f_GrSLType; |
| 189 case kVec4ub_GrVertexAttribType: | 198 case kVec4ub_GrVertexAttribType: |
| 190 case kVec4f_GrVertexAttribType: | 199 case kVec4f_GrVertexAttribType: |
| 191 return kVec4f_GrSLType; | 200 return kVec4f_GrSLType; |
| 201 case kInt_GrVertexAttribType: |
| 202 return kInt_GrSLType; |
| 192 } | 203 } |
| 193 } | 204 } |
| 194 | 205 |
| 195 ////////////////////////////////////////////////////////////////////////////// | 206 ////////////////////////////////////////////////////////////////////////////// |
| 196 | 207 |
| 197 /** | 208 /** |
| 198 * We have coverage effects that clip rendering to the edge of some geometric pri
mitive. | 209 * We have coverage effects that clip rendering to the edge of some geometric pri
mitive. |
| 199 * This enum specifies how that clipping is performed. Not all factories that tak
e a | 210 * This enum specifies how that clipping is performed. Not all factories that tak
e a |
| 200 * GrProcessorEdgeType will succeed with all values and it is up to the caller to
check for | 211 * GrProcessorEdgeType will succeed with all values and it is up to the caller to
check for |
| 201 * a NULL return. | 212 * a NULL return. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // Takes a pointer to a GrCaps, and will suppress prints if required | 282 // Takes a pointer to a GrCaps, and will suppress prints if required |
| 272 #define GrCapsDebugf(caps, ...) \ | 283 #define GrCapsDebugf(caps, ...) \ |
| 273 if (!caps->suppressPrints()) { \ | 284 if (!caps->suppressPrints()) { \ |
| 274 SkDebugf(__VA_ARGS__); \ | 285 SkDebugf(__VA_ARGS__); \ |
| 275 } | 286 } |
| 276 #else | 287 #else |
| 277 #define GrCapsDebugf(caps, ...) | 288 #define GrCapsDebugf(caps, ...) |
| 278 #endif | 289 #endif |
| 279 | 290 |
| 280 #endif | 291 #endif |
| OLD | NEW |