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@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 32 | /** |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 33 | * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers. |
| 34 | */ |
| 35 | static inline int GrSLTypeVectorCount(GrSLType type) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 36 | SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 37 | static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1 }; |
| 38 | return kCounts[type]; |
| 39 | |
| 40 | GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 41 | GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 42 | GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 43 | GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 44 | GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 45 | GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 46 | GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 47 | GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 48 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 49 | } |
| 50 | |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 51 | /** Return the type enum for a vector of floats of length n (1..4), |
| 52 | e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 53 | static inline GrSLType GrSLFloatVectorType(int count) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 54 | SkASSERT(count > 0 && count <= 4); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 55 | return (GrSLType)(count); |
| 56 | |
| 57 | GR_STATIC_ASSERT(kFloat_GrSLType == 1); |
| 58 | GR_STATIC_ASSERT(kVec2f_GrSLType == 2); |
| 59 | GR_STATIC_ASSERT(kVec3f_GrSLType == 3); |
| 60 | GR_STATIC_ASSERT(kVec4f_GrSLType == 4); |
| 61 | } |
| 62 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 63 | ////////////////////////////////////////////////////////////////////////////// |
| 64 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 65 | /** |
| 66 | * Types used to describe format of vertices in arrays. |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 67 | */ |
| 68 | enum GrVertexAttribType { |
| 69 | kFloat_GrVertexAttribType = 0, |
| 70 | kVec2f_GrVertexAttribType, |
| 71 | kVec3f_GrVertexAttribType, |
| 72 | kVec4f_GrVertexAttribType, |
| 73 | kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
| 74 | |
| 75 | kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType |
| 76 | }; |
| 77 | static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 78 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 79 | /** |
| 80 | * Returns the vector size of the type. |
| 81 | */ |
| 82 | static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 83 | SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 84 | static const int kCounts[] = { 1, 2, 3, 4, 4 }; |
| 85 | return kCounts[type]; |
| 86 | |
| 87 | GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 88 | GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 89 | GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 90 | GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 91 | GR_STATIC_ASSERT(4 == kVec4ub_GrVertexAttribType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 92 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the size of the attrib type in bytes. |
| 97 | */ |
| 98 | static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 99 | SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 100 | static const size_t kSizes[] = { |
| 101 | sizeof(float), // kFloat_GrVertexAttribType |
| 102 | 2*sizeof(float), // kVec2f_GrVertexAttribType |
| 103 | 3*sizeof(float), // kVec3f_GrVertexAttribType |
| 104 | 4*sizeof(float), // kVec4f_GrVertexAttribType |
| 105 | 4*sizeof(char) // kVec4ub_GrVertexAttribType |
| 106 | }; |
| 107 | return kSizes[type]; |
| 108 | |
| 109 | GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 110 | GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 111 | GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 112 | GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 113 | GR_STATIC_ASSERT(4 == kVec4ub_GrVertexAttribType); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 114 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 118 | * Semantic bindings for vertex attributes. kEffect means that the attribute is input to a |
| 119 | * GrProcessor. Each binding other than kEffect may not appear more than once in the current set of |
| 120 | * attributes. kPosition must be appear for exactly one attribute. |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 121 | */ |
| 122 | enum GrVertexAttribBinding { |
| 123 | kPosition_GrVertexAttribBinding, // required, must have vector count of 2 |
| 124 | kLocalCoord_GrVertexAttribBinding, // must have vector count of 2 |
| 125 | kColor_GrVertexAttribBinding, // must have vector count of 4 |
| 126 | kCoverage_GrVertexAttribBinding, // must have vector count of 4 |
| 127 | |
| 128 | kLastFixedFunction_GrVertexAttribBinding = kCoverage_GrVertexAttribBinding, |
| 129 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 130 | kGeometryProcessor_GrVertexAttribBinding, // vector length must agree with |
| 131 | // GrProcessor::vertexAttribType() for each effect input to |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 132 | // which the attribute is mapped by GrDrawState::setEffect() |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 133 | kLast_GrVertexAttribBinding = kGeometryProcessor_GrVertexAttribBinding |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | static const int kGrVertexAttribBindingCnt = kLast_GrVertexAttribBinding + 1; |
| 137 | static const int kGrFixedFunctionVertexAttribBindingCnt = |
| 138 | kLastFixedFunction_GrVertexAttribBinding + 1; |
| 139 | |
jvanverth@google.com | 86b5e29 | 2013-04-01 20:14:02 +0000 | [diff] [blame] | 140 | static inline int GrFixedFunctionVertexAttribVectorCount(GrVertexAttribBinding binding) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 141 | SkASSERT(binding >= 0 && binding < kGrFixedFunctionVertexAttribBindingCnt); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 142 | static const int kVecCounts[] = { 2, 2, 4, 4 }; |
| 143 | |
| 144 | return kVecCounts[binding]; |
| 145 | |
| 146 | GR_STATIC_ASSERT(0 == kPosition_GrVertexAttribBinding); |
| 147 | GR_STATIC_ASSERT(1 == kLocalCoord_GrVertexAttribBinding); |
| 148 | GR_STATIC_ASSERT(2 == kColor_GrVertexAttribBinding); |
| 149 | GR_STATIC_ASSERT(3 == kCoverage_GrVertexAttribBinding); |
| 150 | GR_STATIC_ASSERT(kGrFixedFunctionVertexAttribBindingCnt == SK_ARRAY_COUNT(kVecCounts)); |
| 151 | } |
| 152 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 153 | struct GrVertexAttrib { |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 154 | inline void set(GrVertexAttribType type, size_t offset, GrVertexAttribBinding binding) { |
| 155 | fType = type; |
| 156 | fOffset = offset; |
| 157 | fBinding = binding; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 158 | } |
| 159 | bool operator==(const GrVertexAttrib& other) const { |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 160 | return fType == other.fType && fOffset == other.fOffset && fBinding == other.fBinding; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 161 | }; |
| 162 | bool operator!=(const GrVertexAttrib& other) const { return !(*this == other); } |
| 163 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 164 | GrVertexAttribType fType; |
| 165 | size_t fOffset; |
| 166 | GrVertexAttribBinding fBinding; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 169 | template <int N> class GrVertexAttribArray : public SkSTArray<N, GrVertexAttrib, true> {}; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 170 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 171 | ////////////////////////////////////////////////////////////////////////////// |
| 172 | |
| 173 | /** |
| 174 | * 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] | 175 | * 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] | 176 | * 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] | 177 | * a NULL return. |
| 178 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 179 | enum GrPrimitiveEdgeType { |
| 180 | kFillBW_GrProcessorEdgeType, |
| 181 | kFillAA_GrProcessorEdgeType, |
| 182 | kInverseFillBW_GrProcessorEdgeType, |
| 183 | kInverseFillAA_GrProcessorEdgeType, |
| 184 | kHairlineAA_GrProcessorEdgeType, |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 185 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 186 | kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 189 | static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 190 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 191 | static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) { |
| 192 | return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 193 | } |
| 194 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 195 | static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) { |
| 196 | return (kInverseFillAA_GrProcessorEdgeType == edgeType || |
| 197 | kInverseFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 198 | } |
| 199 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 200 | static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) { |
| 201 | return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 202 | } |
| 203 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 204 | static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 205 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 206 | case kFillBW_GrProcessorEdgeType: |
| 207 | return kInverseFillBW_GrProcessorEdgeType; |
| 208 | case kFillAA_GrProcessorEdgeType: |
| 209 | return kInverseFillAA_GrProcessorEdgeType; |
| 210 | case kInverseFillBW_GrProcessorEdgeType: |
| 211 | return kFillBW_GrProcessorEdgeType; |
| 212 | case kInverseFillAA_GrProcessorEdgeType: |
| 213 | return kFillAA_GrProcessorEdgeType; |
| 214 | case kHairlineAA_GrProcessorEdgeType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 215 | SkFAIL("Hairline fill isn't invertible."); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 216 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 217 | return kFillAA_GrProcessorEdgeType; // suppress warning. |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 218 | } |
| 219 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame^] | 220 | /** |
| 221 | * Indicates the type of pending IO operations that can be recorded for gpu resources. |
| 222 | */ |
| 223 | enum GrIOType { |
| 224 | kRead_GrIOType, |
| 225 | kWrite_GrIOType, |
| 226 | kRW_GrIOType |
| 227 | }; |
| 228 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 229 | #endif |