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