commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrTypesPriv_DEFINED |
| 9 | #define GrTypesPriv_DEFINED |
| 10 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 11 | #include "GrTypes.h" |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 12 | #include "SkTArray.h" |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 13 | #include "SkRect.h" |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 14 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 15 | /** |
| 16 | * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars, |
| 17 | * but should be applicable to other shader languages.) |
| 18 | */ |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 19 | enum GrSLType { |
| 20 | kVoid_GrSLType, |
| 21 | kFloat_GrSLType, |
| 22 | kVec2f_GrSLType, |
| 23 | kVec3f_GrSLType, |
| 24 | kVec4f_GrSLType, |
| 25 | kMat33f_GrSLType, |
| 26 | kMat44f_GrSLType, |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 27 | kSampler2D_GrSLType, |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 28 | kSamplerExternal_GrSLType, |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 29 | kSampler2DRect_GrSLType, |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 30 | kBool_GrSLType, |
| 31 | kInt_GrSLType, |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 32 | kUint_GrSLType, |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 33 | |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 34 | kLast_GrSLType = kUint_GrSLType |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 35 | }; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 36 | static const int kGrSLTypeCount = kLast_GrSLType + 1; |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 37 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 38 | enum GrShaderType { |
| 39 | kVertex_GrShaderType, |
| 40 | kGeometry_GrShaderType, |
| 41 | kFragment_GrShaderType, |
| 42 | |
| 43 | kLastkFragment_GrShaderType = kFragment_GrShaderType |
| 44 | }; |
| 45 | static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1; |
| 46 | |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame^] | 47 | enum GrShaderFlags { |
| 48 | kNone_GrShaderFlags = 0, |
| 49 | kVertex_GrShaderFlag = 1 << kVertex_GrShaderType, |
| 50 | kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType, |
| 51 | kFragment_GrShaderFlag = 1 << kFragment_GrShaderType |
| 52 | }; |
| 53 | GR_MAKE_BITFIELD_OPS(GrShaderFlags); |
| 54 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 55 | /** |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 56 | * Precisions of shader language variables. Not all shading languages support precisions or actually |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 57 | * vary the internal precision based on the qualifiers. These currently only apply to float types ( |
| 58 | * including float vectors and matrices). |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 59 | */ |
| 60 | enum GrSLPrecision { |
| 61 | kLow_GrSLPrecision, |
| 62 | kMedium_GrSLPrecision, |
| 63 | kHigh_GrSLPrecision, |
| 64 | |
| 65 | // Default precision is medium. This is because on OpenGL ES 2 highp support is not |
| 66 | // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision. |
| 67 | kDefault_GrSLPrecision = kMedium_GrSLPrecision, |
| 68 | |
| 69 | kLast_GrSLPrecision = kHigh_GrSLPrecision |
| 70 | }; |
| 71 | |
| 72 | static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; |
| 73 | |
| 74 | /** |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 75 | * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers. |
| 76 | */ |
| 77 | static inline int GrSLTypeVectorCount(GrSLType type) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 78 | SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 79 | static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, 1, 1, 1 }; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 80 | return kCounts[type]; |
| 81 | |
| 82 | GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 83 | GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 84 | GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 85 | GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 86 | GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 87 | GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 88 | GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 89 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 90 | GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 91 | GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 92 | GR_STATIC_ASSERT(10 == kBool_GrSLType); |
| 93 | GR_STATIC_ASSERT(11 == kInt_GrSLType); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 94 | GR_STATIC_ASSERT(12 == kUint_GrSLType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 95 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 96 | } |
| 97 | |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 98 | /** Return the type enum for a vector of floats of length n (1..4), |
| 99 | e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 100 | static inline GrSLType GrSLFloatVectorType(int count) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 101 | SkASSERT(count > 0 && count <= 4); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 102 | return (GrSLType)(count); |
| 103 | |
| 104 | GR_STATIC_ASSERT(kFloat_GrSLType == 1); |
| 105 | GR_STATIC_ASSERT(kVec2f_GrSLType == 2); |
| 106 | GR_STATIC_ASSERT(kVec3f_GrSLType == 3); |
| 107 | GR_STATIC_ASSERT(kVec4f_GrSLType == 4); |
| 108 | } |
| 109 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 110 | /** Is the shading language type float (including vectors/matrices)? */ |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 111 | static inline bool GrSLTypeIsFloatType(GrSLType type) { |
| 112 | SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 113 | return (type >= 1 && type <= 6); |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 114 | |
| 115 | GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 116 | GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 117 | GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 118 | GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 119 | GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 120 | GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 121 | GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 122 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 123 | GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 124 | GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 125 | GR_STATIC_ASSERT(10 == kBool_GrSLType); |
| 126 | GR_STATIC_ASSERT(11 == kInt_GrSLType); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 127 | GR_STATIC_ASSERT(12 == kUint_GrSLType); |
| 128 | GR_STATIC_ASSERT(13 == kGrSLTypeCount); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /** Is the shading language type integral (including vectors/matrices)? */ |
| 132 | static inline bool GrSLTypeIsIntType(GrSLType type) { |
| 133 | SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 134 | return type >= kInt_GrSLType; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 135 | |
| 136 | GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 137 | GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 138 | GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 139 | GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 140 | GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 141 | GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 142 | GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 143 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 144 | GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 145 | GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
| 146 | GR_STATIC_ASSERT(10 == kBool_GrSLType); |
| 147 | GR_STATIC_ASSERT(11 == kInt_GrSLType); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 148 | GR_STATIC_ASSERT(12 == kUint_GrSLType); |
| 149 | GR_STATIC_ASSERT(13 == kGrSLTypeCount); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** Is the shading language type numeric (including vectors/matrices)? */ |
| 153 | static inline bool GrSLTypeIsNumeric(GrSLType type) { |
| 154 | return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type); |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 155 | } |
egdaniel | fa89632 | 2016-01-13 12:19:30 -0800 | [diff] [blame] | 156 | |
| 157 | /** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */ |
| 158 | static inline size_t GrSLTypeSize(GrSLType type) { |
| 159 | SkASSERT(GrSLTypeIsFloatType(type)); |
| 160 | static const size_t kSizes[] = { |
| 161 | 0, // kVoid_GrSLType |
| 162 | sizeof(float), // kFloat_GrSLType |
| 163 | 2 * sizeof(float), // kVec2f_GrSLType |
| 164 | 3 * sizeof(float), // kVec3f_GrSLType |
| 165 | 4 * sizeof(float), // kVec4f_GrSLType |
| 166 | 9 * sizeof(float), // kMat33f_GrSLType |
| 167 | 16 * sizeof(float), // kMat44f_GrSLType |
| 168 | 0, // kSampler2D_GrSLType |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 169 | 0, // kSamplerExternal_GrSLType |
| 170 | 0, // kSampler2DRect_GrSLType |
| 171 | 0, // kBool_GrSLType |
| 172 | 0, // kInt_GrSLType |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 173 | 0, // kUint_GrSLType |
egdaniel | fa89632 | 2016-01-13 12:19:30 -0800 | [diff] [blame] | 174 | }; |
| 175 | return kSizes[type]; |
| 176 | |
| 177 | GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 178 | GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 179 | GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 180 | GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 181 | GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 182 | GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 183 | GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 184 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 185 | GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 186 | GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 187 | GR_STATIC_ASSERT(10 == kBool_GrSLType); |
| 188 | GR_STATIC_ASSERT(11 == kInt_GrSLType); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 189 | GR_STATIC_ASSERT(12 == kUint_GrSLType); |
| 190 | GR_STATIC_ASSERT(13 == kGrSLTypeCount); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static inline bool GrSLTypeIsSamplerType(GrSLType type) { |
| 194 | SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 195 | return type >= 7 && type <= 9; |
| 196 | |
| 197 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 198 | GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); |
| 199 | GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); |
egdaniel | fa89632 | 2016-01-13 12:19:30 -0800 | [diff] [blame] | 200 | } |
| 201 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 202 | ////////////////////////////////////////////////////////////////////////////// |
| 203 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 204 | /** |
| 205 | * Types used to describe format of vertices in arrays. |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 206 | */ |
| 207 | enum GrVertexAttribType { |
| 208 | kFloat_GrVertexAttribType = 0, |
| 209 | kVec2f_GrVertexAttribType, |
| 210 | kVec3f_GrVertexAttribType, |
| 211 | kVec4f_GrVertexAttribType, |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 212 | |
| 213 | kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 214 | kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 215 | |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 216 | kVec2s_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 217 | |
| 218 | kInt_GrVertexAttribType, |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 219 | kUint_GrVertexAttribType, |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 220 | |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 221 | kLast_GrVertexAttribType = kUint_GrVertexAttribType |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 222 | }; |
| 223 | static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 224 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 225 | /** |
| 226 | * Returns the vector size of the type. |
| 227 | */ |
| 228 | static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 229 | SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
| 230 | static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 }; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 231 | return kCounts[type]; |
| 232 | |
| 233 | GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 234 | GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 235 | GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 236 | GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 237 | GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 238 | GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 239 | GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 240 | GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 241 | GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 242 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Returns the size of the attrib type in bytes. |
| 247 | */ |
| 248 | static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 249 | static const size_t kSizes[] = { |
| 250 | sizeof(float), // kFloat_GrVertexAttribType |
| 251 | 2*sizeof(float), // kVec2f_GrVertexAttribType |
| 252 | 3*sizeof(float), // kVec3f_GrVertexAttribType |
| 253 | 4*sizeof(float), // kVec4f_GrVertexAttribType |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 254 | 1*sizeof(char), // kUByte_GrVertexAttribType |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 255 | 4*sizeof(char), // kVec4ub_GrVertexAttribType |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 256 | 2*sizeof(int16_t), // kVec2s_GrVertexAttribType |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 257 | sizeof(int32_t), // kInt_GrVertexAttribType |
| 258 | sizeof(uint32_t) // kUint_GrVertexAttribType |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 259 | }; |
| 260 | return kSizes[type]; |
| 261 | |
| 262 | GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 263 | GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 264 | GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 265 | GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 266 | GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 267 | GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 268 | GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 269 | GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 270 | GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 271 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /** |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 275 | * Is the attrib type integral? |
| 276 | */ |
| 277 | static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) { |
| 278 | SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount)); |
| 279 | return type >= kInt_GrVertexAttribType; |
| 280 | |
| 281 | GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 282 | GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 283 | GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 284 | GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 285 | GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 286 | GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
| 287 | GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); |
| 288 | GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType); |
| 289 | GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType); |
| 290 | GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount); |
| 291 | } |
| 292 | |
| 293 | /** |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 294 | * converts a GrVertexAttribType to a GrSLType |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 295 | */ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 296 | static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { |
| 297 | switch (type) { |
| 298 | default: |
| 299 | SkFAIL("Unsupported type conversion"); |
tzik | bc7d235 | 2016-01-05 00:35:50 -0800 | [diff] [blame] | 300 | return kVoid_GrSLType; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 301 | case kUByte_GrVertexAttribType: |
| 302 | case kFloat_GrVertexAttribType: |
| 303 | return kFloat_GrSLType; |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 304 | case kVec2s_GrVertexAttribType: |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 305 | case kVec2f_GrVertexAttribType: |
| 306 | return kVec2f_GrSLType; |
| 307 | case kVec3f_GrVertexAttribType: |
| 308 | return kVec3f_GrSLType; |
| 309 | case kVec4ub_GrVertexAttribType: |
| 310 | case kVec4f_GrVertexAttribType: |
| 311 | return kVec4f_GrSLType; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 312 | case kInt_GrVertexAttribType: |
| 313 | return kInt_GrSLType; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 314 | case kUint_GrVertexAttribType: |
| 315 | return kUint_GrSLType; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 316 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 317 | } |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 318 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 319 | ////////////////////////////////////////////////////////////////////////////// |
| 320 | |
| 321 | /** |
| 322 | * We have coverage effects that clip rendering to the edge of some geometric primitive. |
skia.committer@gmail.com | 06acb58 | 2014-03-06 03:02:32 +0000 | [diff] [blame] | 323 | * This enum specifies how that clipping is performed. Not all factories that take a |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 324 | * GrProcessorEdgeType will succeed with all values and it is up to the caller to check for |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 325 | * a NULL return. |
| 326 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 327 | enum GrPrimitiveEdgeType { |
| 328 | kFillBW_GrProcessorEdgeType, |
| 329 | kFillAA_GrProcessorEdgeType, |
| 330 | kInverseFillBW_GrProcessorEdgeType, |
| 331 | kInverseFillAA_GrProcessorEdgeType, |
| 332 | kHairlineAA_GrProcessorEdgeType, |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 333 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 334 | kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 337 | static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 338 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 339 | static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) { |
| 340 | return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 341 | } |
| 342 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 343 | static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) { |
| 344 | return (kInverseFillAA_GrProcessorEdgeType == edgeType || |
| 345 | kInverseFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 346 | } |
| 347 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 348 | static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) { |
| 349 | return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 350 | } |
| 351 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 352 | static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 353 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 354 | case kFillBW_GrProcessorEdgeType: |
| 355 | return kInverseFillBW_GrProcessorEdgeType; |
| 356 | case kFillAA_GrProcessorEdgeType: |
| 357 | return kInverseFillAA_GrProcessorEdgeType; |
| 358 | case kInverseFillBW_GrProcessorEdgeType: |
| 359 | return kFillBW_GrProcessorEdgeType; |
| 360 | case kInverseFillAA_GrProcessorEdgeType: |
| 361 | return kFillAA_GrProcessorEdgeType; |
| 362 | case kHairlineAA_GrProcessorEdgeType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 363 | SkFAIL("Hairline fill isn't invertible."); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 364 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 365 | return kFillAA_GrProcessorEdgeType; // suppress warning. |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 366 | } |
| 367 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 368 | /** |
| 369 | * Indicates the type of pending IO operations that can be recorded for gpu resources. |
| 370 | */ |
| 371 | enum GrIOType { |
| 372 | kRead_GrIOType, |
| 373 | kWrite_GrIOType, |
| 374 | kRW_GrIOType |
| 375 | }; |
| 376 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 377 | struct GrScissorState { |
| 378 | GrScissorState() : fEnabled(false) {} |
| 379 | void set(const SkIRect& rect) { fRect = rect; fEnabled = true; } |
| 380 | bool operator==(const GrScissorState& other) const { |
| 381 | return fEnabled == other.fEnabled && |
| 382 | (false == fEnabled || fRect == other.fRect); |
| 383 | } |
| 384 | bool operator!=(const GrScissorState& other) const { return !(*this == other); } |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 385 | |
| 386 | bool enabled() const { return fEnabled; } |
| 387 | const SkIRect& rect() const { return fRect; } |
| 388 | |
| 389 | private: |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 390 | bool fEnabled; |
| 391 | SkIRect fRect; |
| 392 | }; |
| 393 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 394 | /** |
| 395 | * Indicates the transfer direction for a transfer buffer |
| 396 | */ |
| 397 | enum TransferType { |
| 398 | /** Caller intends to use the buffer to transfer data to the GPU */ |
| 399 | kCpuToGpu_TransferType, |
| 400 | /** Caller intends to use the buffer to transfer data from the GPU */ |
| 401 | kGpuToCpu_TransferType |
| 402 | }; |
| 403 | |
| 404 | |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 405 | #ifdef SK_DEBUG |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 406 | // Takes a pointer to a GrCaps, and will suppress prints if required |
| 407 | #define GrCapsDebugf(caps, ...) \ |
| 408 | if (!caps->suppressPrints()) { \ |
| 409 | SkDebugf(__VA_ARGS__); \ |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 410 | } |
| 411 | #else |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 412 | #define GrCapsDebugf(caps, ...) |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 413 | #endif |
| 414 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 415 | #endif |