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