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