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" |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 12 | #include "SkRefCnt.h" |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 13 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 14 | /** |
| 15 | * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars, |
| 16 | * but should be applicable to other shader languages.) |
| 17 | */ |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 18 | enum GrSLType { |
| 19 | kVoid_GrSLType, |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 20 | kBool_GrSLType, |
| 21 | kInt_GrSLType, |
| 22 | kUint_GrSLType, |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 23 | kFloat_GrSLType, |
| 24 | kVec2f_GrSLType, |
| 25 | kVec3f_GrSLType, |
| 26 | kVec4f_GrSLType, |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 27 | kMat22f_GrSLType, |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 28 | kMat33f_GrSLType, |
| 29 | kMat44f_GrSLType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 30 | kTexture2DSampler_GrSLType, |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 31 | kITexture2DSampler_GrSLType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 32 | kTextureExternalSampler_GrSLType, |
| 33 | kTexture2DRectSampler_GrSLType, |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame^] | 34 | kBufferSampler_GrSLType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 35 | kTexture2D_GrSLType, |
| 36 | kSampler_GrSLType, |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 39 | enum GrShaderType { |
| 40 | kVertex_GrShaderType, |
| 41 | kGeometry_GrShaderType, |
| 42 | kFragment_GrShaderType, |
| 43 | |
| 44 | kLastkFragment_GrShaderType = kFragment_GrShaderType |
| 45 | }; |
| 46 | static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1; |
| 47 | |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 48 | enum GrShaderFlags { |
| 49 | kNone_GrShaderFlags = 0, |
| 50 | kVertex_GrShaderFlag = 1 << kVertex_GrShaderType, |
| 51 | kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType, |
| 52 | kFragment_GrShaderFlag = 1 << kFragment_GrShaderType |
| 53 | }; |
| 54 | GR_MAKE_BITFIELD_OPS(GrShaderFlags); |
| 55 | |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 56 | enum class GrDrawFace { |
| 57 | kInvalid = -1, |
| 58 | |
| 59 | kBoth, |
| 60 | kCCW, |
| 61 | kCW, |
| 62 | }; |
| 63 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 64 | /** |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 65 | * Precisions of shader language variables. Not all shading languages support precisions or actually |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 66 | * vary the internal precision based on the qualifiers. These currently only apply to float types ( |
| 67 | * including float vectors and matrices). |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 68 | */ |
| 69 | enum GrSLPrecision { |
| 70 | kLow_GrSLPrecision, |
| 71 | kMedium_GrSLPrecision, |
| 72 | kHigh_GrSLPrecision, |
| 73 | |
| 74 | // Default precision is medium. This is because on OpenGL ES 2 highp support is not |
| 75 | // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision. |
| 76 | kDefault_GrSLPrecision = kMedium_GrSLPrecision, |
| 77 | |
| 78 | kLast_GrSLPrecision = kHigh_GrSLPrecision |
| 79 | }; |
| 80 | |
| 81 | static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; |
| 82 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 83 | /** Is the shading language type float (including vectors/matrices)? */ |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 84 | static inline bool GrSLTypeIsFloatType(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 85 | switch (type) { |
| 86 | case kFloat_GrSLType: |
| 87 | case kVec2f_GrSLType: |
| 88 | case kVec3f_GrSLType: |
| 89 | case kVec4f_GrSLType: |
| 90 | case kMat22f_GrSLType: |
| 91 | case kMat33f_GrSLType: |
| 92 | case kMat44f_GrSLType: |
| 93 | return true; |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 94 | |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 95 | case kVoid_GrSLType: |
| 96 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 97 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 98 | case kTextureExternalSampler_GrSLType: |
| 99 | case kTexture2DRectSampler_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame^] | 100 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 101 | case kBool_GrSLType: |
| 102 | case kInt_GrSLType: |
| 103 | case kUint_GrSLType: |
| 104 | case kTexture2D_GrSLType: |
| 105 | case kSampler_GrSLType: |
| 106 | return false; |
| 107 | } |
| 108 | SkFAIL("Unexpected type"); |
| 109 | return false; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 110 | } |
| 111 | |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 112 | static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 113 | switch (type) { |
| 114 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 115 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 116 | case kTextureExternalSampler_GrSLType: |
| 117 | case kTexture2DRectSampler_GrSLType: |
| 118 | return true; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 119 | |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 120 | case kVoid_GrSLType: |
| 121 | case kFloat_GrSLType: |
| 122 | case kVec2f_GrSLType: |
| 123 | case kVec3f_GrSLType: |
| 124 | case kVec4f_GrSLType: |
| 125 | case kMat22f_GrSLType: |
| 126 | case kMat33f_GrSLType: |
| 127 | case kMat44f_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame^] | 128 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 129 | case kInt_GrSLType: |
| 130 | case kUint_GrSLType: |
| 131 | case kBool_GrSLType: |
| 132 | case kTexture2D_GrSLType: |
| 133 | case kSampler_GrSLType: |
| 134 | return false; |
| 135 | } |
| 136 | SkFAIL("Unexpected type"); |
| 137 | return false; |
egdaniel | fa89632 | 2016-01-13 12:19:30 -0800 | [diff] [blame] | 138 | } |
| 139 | |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 140 | static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 141 | switch (type) { |
| 142 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 143 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 144 | case kTextureExternalSampler_GrSLType: |
| 145 | case kTexture2DRectSampler_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame^] | 146 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 147 | return true; |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 148 | |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 149 | case kVoid_GrSLType: |
| 150 | case kFloat_GrSLType: |
| 151 | case kVec2f_GrSLType: |
| 152 | case kVec3f_GrSLType: |
| 153 | case kVec4f_GrSLType: |
| 154 | case kMat22f_GrSLType: |
| 155 | case kMat33f_GrSLType: |
| 156 | case kMat44f_GrSLType: |
| 157 | case kInt_GrSLType: |
| 158 | case kUint_GrSLType: |
| 159 | case kBool_GrSLType: |
| 160 | case kTexture2D_GrSLType: |
| 161 | case kSampler_GrSLType: |
| 162 | return false; |
| 163 | } |
| 164 | SkFAIL("Unexpected type"); |
| 165 | return false; |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 166 | } |
| 167 | |
cdalton | 5f2d8e2 | 2016-03-11 13:34:32 -0800 | [diff] [blame] | 168 | static inline bool GrSLTypeAcceptsPrecision(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 169 | switch (type) { |
| 170 | case kInt_GrSLType: |
| 171 | case kUint_GrSLType: |
| 172 | case kFloat_GrSLType: |
| 173 | case kVec2f_GrSLType: |
| 174 | case kVec3f_GrSLType: |
| 175 | case kVec4f_GrSLType: |
| 176 | case kMat22f_GrSLType: |
| 177 | case kMat33f_GrSLType: |
| 178 | case kMat44f_GrSLType: |
| 179 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 180 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 181 | case kTextureExternalSampler_GrSLType: |
| 182 | case kTexture2DRectSampler_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame^] | 183 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 184 | case kTexture2D_GrSLType: |
| 185 | case kSampler_GrSLType: |
| 186 | return true; |
| 187 | |
| 188 | case kVoid_GrSLType: |
| 189 | case kBool_GrSLType: |
| 190 | return false; |
| 191 | } |
| 192 | SkFAIL("Unexpected type"); |
| 193 | return false; |
cdalton | 5f2d8e2 | 2016-03-11 13:34:32 -0800 | [diff] [blame] | 194 | } |
| 195 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 196 | ////////////////////////////////////////////////////////////////////////////// |
| 197 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 198 | /** |
| 199 | * Types used to describe format of vertices in arrays. |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 200 | */ |
| 201 | enum GrVertexAttribType { |
| 202 | kFloat_GrVertexAttribType = 0, |
| 203 | kVec2f_GrVertexAttribType, |
| 204 | kVec3f_GrVertexAttribType, |
| 205 | kVec4f_GrVertexAttribType, |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 206 | |
| 207 | kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 208 | kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 209 | |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 210 | kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 211 | |
| 212 | kInt_GrVertexAttribType, |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 213 | kUint_GrVertexAttribType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 214 | |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 215 | kLast_GrVertexAttribType = kUint_GrVertexAttribType |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 216 | }; |
| 217 | static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 218 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * Returns the size of the attrib type in bytes. |
| 222 | */ |
| 223 | static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 224 | switch (type) { |
| 225 | case kFloat_GrVertexAttribType: |
| 226 | return sizeof(float); |
| 227 | case kVec2f_GrVertexAttribType: |
| 228 | return 2*sizeof(float); |
| 229 | case kVec3f_GrVertexAttribType: |
| 230 | return 3*sizeof(float); |
| 231 | case kVec4f_GrVertexAttribType: |
| 232 | return 4*sizeof(float); |
| 233 | case kUByte_GrVertexAttribType: |
| 234 | return 1*sizeof(char); |
| 235 | case kVec4ub_GrVertexAttribType: |
| 236 | return 4*sizeof(char); |
| 237 | case kVec2us_GrVertexAttribType: |
| 238 | return 2*sizeof(int16_t); |
| 239 | case kInt_GrVertexAttribType: |
| 240 | return sizeof(int32_t); |
| 241 | case kUint_GrVertexAttribType: |
| 242 | return sizeof(uint32_t); |
| 243 | } |
| 244 | SkFAIL("Unexpected attribute type"); |
| 245 | return 0; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /** |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 249 | * Is the attrib type integral? |
| 250 | */ |
| 251 | static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 252 | switch (type) { |
| 253 | case kFloat_GrVertexAttribType: |
| 254 | return false; |
| 255 | case kVec2f_GrVertexAttribType: |
| 256 | return false; |
| 257 | case kVec3f_GrVertexAttribType: |
| 258 | return false; |
| 259 | case kVec4f_GrVertexAttribType: |
| 260 | return false; |
| 261 | case kUByte_GrVertexAttribType: |
| 262 | return false; |
| 263 | case kVec4ub_GrVertexAttribType: |
| 264 | return false; |
| 265 | case kVec2us_GrVertexAttribType: |
| 266 | return false; |
| 267 | case kInt_GrVertexAttribType: |
| 268 | return true; |
| 269 | case kUint_GrVertexAttribType: |
| 270 | return true; |
| 271 | } |
| 272 | SkFAIL("Unexpected attribute type"); |
| 273 | return false; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /** |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 277 | * converts a GrVertexAttribType to a GrSLType |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 278 | */ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 279 | static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { |
| 280 | switch (type) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 281 | case kUByte_GrVertexAttribType: |
| 282 | case kFloat_GrVertexAttribType: |
| 283 | return kFloat_GrSLType; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 284 | case kVec2us_GrVertexAttribType: |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 285 | case kVec2f_GrVertexAttribType: |
| 286 | return kVec2f_GrSLType; |
| 287 | case kVec3f_GrVertexAttribType: |
| 288 | return kVec3f_GrSLType; |
| 289 | case kVec4ub_GrVertexAttribType: |
| 290 | case kVec4f_GrVertexAttribType: |
| 291 | return kVec4f_GrSLType; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 292 | case kInt_GrVertexAttribType: |
| 293 | return kInt_GrSLType; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 294 | case kUint_GrVertexAttribType: |
| 295 | return kUint_GrSLType; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 296 | } |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 297 | SkFAIL("Unsupported type conversion"); |
| 298 | return kVoid_GrSLType; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 299 | } |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 300 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 301 | ////////////////////////////////////////////////////////////////////////////// |
| 302 | |
| 303 | /** |
| 304 | * 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] | 305 | * 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] | 306 | * 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] | 307 | * a NULL return. |
| 308 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 309 | enum GrPrimitiveEdgeType { |
| 310 | kFillBW_GrProcessorEdgeType, |
| 311 | kFillAA_GrProcessorEdgeType, |
| 312 | kInverseFillBW_GrProcessorEdgeType, |
| 313 | kInverseFillAA_GrProcessorEdgeType, |
| 314 | kHairlineAA_GrProcessorEdgeType, |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 315 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 316 | kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 317 | }; |
| 318 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 319 | static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 320 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 321 | static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) { |
| 322 | return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 323 | } |
| 324 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 325 | static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) { |
| 326 | return (kInverseFillAA_GrProcessorEdgeType == edgeType || |
| 327 | kInverseFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 328 | } |
| 329 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 330 | static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) { |
| 331 | return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 332 | } |
| 333 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 334 | static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 335 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 336 | case kFillBW_GrProcessorEdgeType: |
| 337 | return kInverseFillBW_GrProcessorEdgeType; |
| 338 | case kFillAA_GrProcessorEdgeType: |
| 339 | return kInverseFillAA_GrProcessorEdgeType; |
| 340 | case kInverseFillBW_GrProcessorEdgeType: |
| 341 | return kFillBW_GrProcessorEdgeType; |
| 342 | case kInverseFillAA_GrProcessorEdgeType: |
| 343 | return kFillAA_GrProcessorEdgeType; |
| 344 | case kHairlineAA_GrProcessorEdgeType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 345 | SkFAIL("Hairline fill isn't invertible."); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 346 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 347 | return kFillAA_GrProcessorEdgeType; // suppress warning. |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 348 | } |
| 349 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 350 | /** |
| 351 | * Indicates the type of pending IO operations that can be recorded for gpu resources. |
| 352 | */ |
| 353 | enum GrIOType { |
| 354 | kRead_GrIOType, |
| 355 | kWrite_GrIOType, |
| 356 | kRW_GrIOType |
| 357 | }; |
| 358 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 359 | /** |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 360 | * Indicates the type of data that a GPU buffer will be used for. |
| 361 | */ |
| 362 | enum GrBufferType { |
| 363 | kVertex_GrBufferType, |
| 364 | kIndex_GrBufferType, |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 365 | kTexel_GrBufferType, |
| 366 | kDrawIndirect_GrBufferType, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 367 | kXferCpuToGpu_GrBufferType, |
| 368 | kXferGpuToCpu_GrBufferType, |
| 369 | |
| 370 | kLast_GrBufferType = kXferGpuToCpu_GrBufferType |
| 371 | }; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 372 | static const int kGrBufferTypeCount = kLast_GrBufferType + 1; |
| 373 | |
| 374 | static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) { |
| 375 | SkASSERT(type >= 0 && type < kGrBufferTypeCount); |
| 376 | return type <= kIndex_GrBufferType; |
| 377 | |
| 378 | GR_STATIC_ASSERT(0 == kVertex_GrBufferType); |
| 379 | GR_STATIC_ASSERT(1 == kIndex_GrBufferType); |
| 380 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * Provides a performance hint regarding the frequency at which a data store will be accessed. |
| 384 | */ |
| 385 | enum GrAccessPattern { |
| 386 | /** Data store will be respecified repeatedly and used many times. */ |
| 387 | kDynamic_GrAccessPattern, |
| 388 | /** Data store will be specified once and used many times. (Thus disqualified from caching.) */ |
| 389 | kStatic_GrAccessPattern, |
| 390 | /** Data store will be specified once and used at most a few times. (Also can't be cached.) */ |
| 391 | kStream_GrAccessPattern, |
| 392 | |
| 393 | kLast_GrAccessPattern = kStream_GrAccessPattern |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 394 | }; |
| 395 | |
| 396 | |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 397 | #ifdef SK_DEBUG |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 398 | // Takes a pointer to a GrCaps, and will suppress prints if required |
| 399 | #define GrCapsDebugf(caps, ...) \ |
| 400 | if (!caps->suppressPrints()) { \ |
| 401 | SkDebugf(__VA_ARGS__); \ |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 402 | } |
| 403 | #else |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 404 | #define GrCapsDebugf(caps, ...) |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 405 | #endif |
| 406 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 407 | /** |
| 408 | * Specifies if the holder owns the backend, OpenGL or Vulkan, object. |
| 409 | */ |
| 410 | enum class GrBackendObjectOwnership : bool { |
| 411 | /** Holder does not destroy the backend object. */ |
| 412 | kBorrowed = false, |
| 413 | /** Holder destroys the backend object. */ |
| 414 | kOwned = true |
| 415 | }; |
| 416 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 417 | template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) { |
| 418 | static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size."); |
| 419 | return reinterpret_cast<T * const *>(sp); |
| 420 | } |
| 421 | |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 422 | /* |
| 423 | * Object for CPU-GPU synchronization |
| 424 | */ |
| 425 | typedef intptr_t GrFence; |
| 426 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 427 | #endif |