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