| 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
only GrGLShaderVars, | 16 * Types of shader-language-specific boxed variables we can create. (Currently
only 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 kSampler2DRect_GrSLType, |
| 29 | 30 |
| 30 kLast_GrSLType = kSamplerExternal_GrSLType | 31 kLast_GrSLType = kSampler2DRect_GrSLType |
| 31 }; | 32 }; |
| 32 static const int kGrSLTypeCount = kLast_GrSLType + 1; | 33 static const int kGrSLTypeCount = kLast_GrSLType + 1; |
| 33 | 34 |
| 34 enum GrShaderType { | 35 enum GrShaderType { |
| 35 kVertex_GrShaderType, | 36 kVertex_GrShaderType, |
| 36 kGeometry_GrShaderType, | 37 kGeometry_GrShaderType, |
| 37 kFragment_GrShaderType, | 38 kFragment_GrShaderType, |
| 38 | 39 |
| 39 kLastkFragment_GrShaderType = kFragment_GrShaderType | 40 kLastkFragment_GrShaderType = kFragment_GrShaderType |
| 40 }; | 41 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 kLast_GrSLPrecision = kHigh_GrSLPrecision | 58 kLast_GrSLPrecision = kHigh_GrSLPrecision |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; | 61 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; |
| 61 | 62 |
| 62 /** | 63 /** |
| 63 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. | 64 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. |
| 64 */ | 65 */ |
| 65 static inline int GrSLTypeVectorCount(GrSLType type) { | 66 static inline int GrSLTypeVectorCount(GrSLType type) { |
| 66 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 67 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 67 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1 }; | 68 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1 }; |
| 68 return kCounts[type]; | 69 return kCounts[type]; |
| 69 | 70 |
| 70 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 71 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 71 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 72 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 72 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 73 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 73 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 74 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 74 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 75 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 75 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); | 76 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 76 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); | 77 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 77 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); | 78 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 78 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); | 79 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 80 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
| 79 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); | 81 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); |
| 80 } | 82 } |
| 81 | 83 |
| 82 /** Return the type enum for a vector of floats of length n (1..4), | 84 /** Return the type enum for a vector of floats of length n (1..4), |
| 83 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ | 85 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
| 84 static inline GrSLType GrSLFloatVectorType(int count) { | 86 static inline GrSLType GrSLFloatVectorType(int count) { |
| 85 SkASSERT(count > 0 && count <= 4); | 87 SkASSERT(count > 0 && count <= 4); |
| 86 return (GrSLType)(count); | 88 return (GrSLType)(count); |
| 87 | 89 |
| 88 GR_STATIC_ASSERT(kFloat_GrSLType == 1); | 90 GR_STATIC_ASSERT(kFloat_GrSLType == 1); |
| 89 GR_STATIC_ASSERT(kVec2f_GrSLType == 2); | 91 GR_STATIC_ASSERT(kVec2f_GrSLType == 2); |
| 90 GR_STATIC_ASSERT(kVec3f_GrSLType == 3); | 92 GR_STATIC_ASSERT(kVec3f_GrSLType == 3); |
| 91 GR_STATIC_ASSERT(kVec4f_GrSLType == 4); | 93 GR_STATIC_ASSERT(kVec4f_GrSLType == 4); |
| 92 } | 94 } |
| 93 | 95 |
| 94 /** Is the shading language type floating point (or vector/matrix of fp)? */ | 96 /** Is the shading language type floating point (or vector/matrix of fp)? */ |
| 95 static inline bool GrSLTypeIsFloatType(GrSLType type) { | 97 static inline bool GrSLTypeIsFloatType(GrSLType type) { |
| 96 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 98 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 97 return type >= 1 && type <= 6; | 99 return type >= 1 && type <= 6; |
| 98 | 100 |
| 99 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 101 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 100 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 102 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 101 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 103 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 102 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 104 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 103 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 105 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 104 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); | 106 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 105 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); | 107 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 106 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); | 108 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 107 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); | 109 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 108 GR_STATIC_ASSERT(9 == kGrSLTypeCount); | 110 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
| 111 GR_STATIC_ASSERT(10 == kGrSLTypeCount); |
| 109 } | 112 } |
| 110 | 113 |
| 111 /** Returns the size in bytes for floating point GrSLTypes. For non floating poi
nt type returns 0 */ | 114 /** Returns the size in bytes for floating point GrSLTypes. For non floating poi
nt type returns 0 */ |
| 112 static inline size_t GrSLTypeSize(GrSLType type) { | 115 static inline size_t GrSLTypeSize(GrSLType type) { |
| 113 SkASSERT(GrSLTypeIsFloatType(type)); | 116 SkASSERT(GrSLTypeIsFloatType(type)); |
| 114 static const size_t kSizes[] = { | 117 static const size_t kSizes[] = { |
| 115 0, // kVoid_GrSLType | 118 0, // kVoid_GrSLType |
| 116 sizeof(float), // kFloat_GrSLType | 119 sizeof(float), // kFloat_GrSLType |
| 117 2 * sizeof(float), // kVec2f_GrSLType | 120 2 * sizeof(float), // kVec2f_GrSLType |
| 118 3 * sizeof(float), // kVec3f_GrSLType | 121 3 * sizeof(float), // kVec3f_GrSLType |
| 119 4 * sizeof(float), // kVec4f_GrSLType | 122 4 * sizeof(float), // kVec4f_GrSLType |
| 120 9 * sizeof(float), // kMat33f_GrSLType | 123 9 * sizeof(float), // kMat33f_GrSLType |
| 121 16 * sizeof(float), // kMat44f_GrSLType | 124 16 * sizeof(float), // kMat44f_GrSLType |
| 122 0, // kSampler2D_GrSLType | 125 0, // kSampler2D_GrSLType |
| 123 0 // kSamplerExternal_GrSLType | 126 0, // kSamplerExternal_GrSLType |
| 127 0 // kSampler2DRect_GrSLType |
| 124 }; | 128 }; |
| 125 return kSizes[type]; | 129 return kSizes[type]; |
| 126 | 130 |
| 127 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 131 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 128 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 132 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 129 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 133 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 130 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 134 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 131 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 135 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 132 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); | 136 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 133 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); | 137 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 134 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); | 138 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 135 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); | 139 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 136 GR_STATIC_ASSERT(9 == kGrSLTypeCount); | 140 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
| 141 GR_STATIC_ASSERT(10 == kGrSLTypeCount); |
| 142 } |
| 143 |
| 144 static inline bool GrSLTypeIsSamplerType(GrSLType type) { |
| 145 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 146 return type >= 7 && type <= 9; |
| 147 |
| 148 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 149 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 150 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
| 137 } | 151 } |
| 138 | 152 |
| 139 ////////////////////////////////////////////////////////////////////////////// | 153 ////////////////////////////////////////////////////////////////////////////// |
| 140 | 154 |
| 141 /** | 155 /** |
| 142 * Types used to describe format of vertices in arrays. | 156 * Types used to describe format of vertices in arrays. |
| 143 */ | 157 */ |
| 144 enum GrVertexAttribType { | 158 enum GrVertexAttribType { |
| 145 kFloat_GrVertexAttribType = 0, | 159 kFloat_GrVertexAttribType = 0, |
| 146 kVec2f_GrVertexAttribType, | 160 kVec2f_GrVertexAttribType, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // Takes a pointer to a GrCaps, and will suppress prints if required | 326 // Takes a pointer to a GrCaps, and will suppress prints if required |
| 313 #define GrCapsDebugf(caps, ...) \ | 327 #define GrCapsDebugf(caps, ...) \ |
| 314 if (!caps->suppressPrints()) { \ | 328 if (!caps->suppressPrints()) { \ |
| 315 SkDebugf(__VA_ARGS__); \ | 329 SkDebugf(__VA_ARGS__); \ |
| 316 } | 330 } |
| 317 #else | 331 #else |
| 318 #define GrCapsDebugf(caps, ...) | 332 #define GrCapsDebugf(caps, ...) |
| 319 #endif | 333 #endif |
| 320 | 334 |
| 321 #endif | 335 #endif |
| OLD | NEW |