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" |
| 13 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 14 | /** |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 15 | * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars, |
| 16 | * but should be applicable to other shader languages.) |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 17 | */ |
| 18 | enum GrSLType { |
| 19 | kVoid_GrSLType, |
| 20 | kFloat_GrSLType, |
| 21 | kVec2f_GrSLType, |
| 22 | kVec3f_GrSLType, |
| 23 | kVec4f_GrSLType, |
| 24 | kMat33f_GrSLType, |
| 25 | kMat44f_GrSLType, |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 26 | kSampler2D_GrSLType, |
| 27 | |
| 28 | kLast_GrSLType = kSampler2D_GrSLType |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 29 | }; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 30 | static const int kGrSLTypeCount = kLast_GrSLType + 1; |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 31 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 32 | enum GrShaderType { |
| 33 | kVertex_GrShaderType, |
| 34 | kGeometry_GrShaderType, |
| 35 | kFragment_GrShaderType, |
| 36 | |
| 37 | kLastkFragment_GrShaderType = kFragment_GrShaderType |
| 38 | }; |
| 39 | static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1; |
| 40 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 41 | /** |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 42 | * Precisions of shader language variables. Not all shading languages support precisions or actually |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame^] | 43 | * vary the internal precision based on the qualifiers. These currently only apply to float types ( |
| 44 | * including float vectors and matrices). |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 45 | */ |
| 46 | enum GrSLPrecision { |
| 47 | kLow_GrSLPrecision, |
| 48 | kMedium_GrSLPrecision, |
| 49 | kHigh_GrSLPrecision, |
| 50 | |
| 51 | // Default precision is medium. This is because on OpenGL ES 2 highp support is not |
| 52 | // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision. |
| 53 | kDefault_GrSLPrecision = kMedium_GrSLPrecision, |
| 54 | |
| 55 | kLast_GrSLPrecision = kHigh_GrSLPrecision |
| 56 | }; |
| 57 | |
| 58 | static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; |
| 59 | |
| 60 | /** |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 61 | * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers. |
| 62 | */ |
| 63 | static inline int GrSLTypeVectorCount(GrSLType type) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 64 | SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 65 | static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1 }; |
| 66 | return kCounts[type]; |
| 67 | |
| 68 | GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 69 | GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 70 | GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 71 | GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 72 | GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 73 | GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 74 | GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 75 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 76 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 77 | } |
| 78 | |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 79 | /** Return the type enum for a vector of floats of length n (1..4), |
| 80 | e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 81 | static inline GrSLType GrSLFloatVectorType(int count) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 82 | SkASSERT(count > 0 && count <= 4); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 83 | return (GrSLType)(count); |
| 84 | |
| 85 | GR_STATIC_ASSERT(kFloat_GrSLType == 1); |
| 86 | GR_STATIC_ASSERT(kVec2f_GrSLType == 2); |
| 87 | GR_STATIC_ASSERT(kVec3f_GrSLType == 3); |
| 88 | GR_STATIC_ASSERT(kVec4f_GrSLType == 4); |
| 89 | } |
| 90 | |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame^] | 91 | /** Is the shading language type floating point (or vector/matrix of fp)? */ |
| 92 | static inline bool GrSLTypeIsFloatType(GrSLType type) { |
| 93 | SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 94 | return type >= 1 && type <= 6; |
| 95 | |
| 96 | GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 97 | GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 98 | GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 99 | GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 100 | GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 101 | GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 102 | GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 103 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 104 | GR_STATIC_ASSERT(8 == kGrSLTypeCount); |
| 105 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 106 | ////////////////////////////////////////////////////////////////////////////// |
| 107 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 108 | /** |
| 109 | * Types used to describe format of vertices in arrays. |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 110 | */ |
| 111 | enum GrVertexAttribType { |
| 112 | kFloat_GrVertexAttribType = 0, |
| 113 | kVec2f_GrVertexAttribType, |
| 114 | kVec3f_GrVertexAttribType, |
| 115 | kVec4f_GrVertexAttribType, |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 116 | |
| 117 | kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 118 | kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
| 119 | |
| 120 | kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType |
| 121 | }; |
| 122 | static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 123 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 124 | /** |
| 125 | * Returns the vector size of the type. |
| 126 | */ |
| 127 | static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 128 | SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 129 | static const int kCounts[] = { 1, 2, 3, 4, 1, 4 }; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 130 | return kCounts[type]; |
| 131 | |
| 132 | GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 133 | GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 134 | GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 135 | GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 136 | GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 137 | GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 138 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Returns the size of the attrib type in bytes. |
| 143 | */ |
| 144 | static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 145 | SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 146 | static const size_t kSizes[] = { |
| 147 | sizeof(float), // kFloat_GrVertexAttribType |
| 148 | 2*sizeof(float), // kVec2f_GrVertexAttribType |
| 149 | 3*sizeof(float), // kVec3f_GrVertexAttribType |
| 150 | 4*sizeof(float), // kVec4f_GrVertexAttribType |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 151 | 1*sizeof(char), // kUByte_GrVertexAttribType |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 152 | 4*sizeof(char) // kVec4ub_GrVertexAttribType |
| 153 | }; |
| 154 | return kSizes[type]; |
| 155 | |
| 156 | GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 157 | GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 158 | GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 159 | GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 160 | GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 161 | GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 162 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 166 | * converts a GrVertexAttribType to a GrSLType |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 167 | */ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 168 | static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { |
| 169 | switch (type) { |
| 170 | default: |
| 171 | SkFAIL("Unsupported type conversion"); |
| 172 | case kUByte_GrVertexAttribType: |
| 173 | case kFloat_GrVertexAttribType: |
| 174 | return kFloat_GrSLType; |
| 175 | case kVec2f_GrVertexAttribType: |
| 176 | return kVec2f_GrSLType; |
| 177 | case kVec3f_GrVertexAttribType: |
| 178 | return kVec3f_GrSLType; |
| 179 | case kVec4ub_GrVertexAttribType: |
| 180 | case kVec4f_GrVertexAttribType: |
| 181 | return kVec4f_GrSLType; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 182 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 183 | } |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 184 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 185 | ////////////////////////////////////////////////////////////////////////////// |
| 186 | |
| 187 | /** |
| 188 | * 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] | 189 | * 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] | 190 | * 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] | 191 | * a NULL return. |
| 192 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 193 | enum GrPrimitiveEdgeType { |
| 194 | kFillBW_GrProcessorEdgeType, |
| 195 | kFillAA_GrProcessorEdgeType, |
| 196 | kInverseFillBW_GrProcessorEdgeType, |
| 197 | kInverseFillAA_GrProcessorEdgeType, |
| 198 | kHairlineAA_GrProcessorEdgeType, |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 199 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 200 | kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 201 | }; |
| 202 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 203 | static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 204 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 205 | static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) { |
| 206 | return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 207 | } |
| 208 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 209 | static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) { |
| 210 | return (kInverseFillAA_GrProcessorEdgeType == edgeType || |
| 211 | kInverseFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 212 | } |
| 213 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 214 | static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) { |
| 215 | return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 216 | } |
| 217 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 218 | static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 219 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 220 | case kFillBW_GrProcessorEdgeType: |
| 221 | return kInverseFillBW_GrProcessorEdgeType; |
| 222 | case kFillAA_GrProcessorEdgeType: |
| 223 | return kInverseFillAA_GrProcessorEdgeType; |
| 224 | case kInverseFillBW_GrProcessorEdgeType: |
| 225 | return kFillBW_GrProcessorEdgeType; |
| 226 | case kInverseFillAA_GrProcessorEdgeType: |
| 227 | return kFillAA_GrProcessorEdgeType; |
| 228 | case kHairlineAA_GrProcessorEdgeType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 229 | SkFAIL("Hairline fill isn't invertible."); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 230 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 231 | return kFillAA_GrProcessorEdgeType; // suppress warning. |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 232 | } |
| 233 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 234 | /** |
| 235 | * Indicates the type of pending IO operations that can be recorded for gpu resources. |
| 236 | */ |
| 237 | enum GrIOType { |
| 238 | kRead_GrIOType, |
| 239 | kWrite_GrIOType, |
| 240 | kRW_GrIOType |
| 241 | }; |
| 242 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 243 | #endif |