OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrDrawState_DEFINED | 8 #ifndef GrDrawState_DEFINED |
9 #define GrDrawState_DEFINED | 9 #define GrDrawState_DEFINED |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 * the interpolated vertex positions or explicit per-vertex coords, dependin
g upon the | 69 * the interpolated vertex positions or explicit per-vertex coords, dependin
g upon the |
70 * GrAttribBindings used to draw. | 70 * GrAttribBindings used to draw. |
71 * | 71 * |
72 * The stages are divided into two sets, color-computing and coverage-comput
ing. The final color | 72 * The stages are divided into two sets, color-computing and coverage-comput
ing. The final color |
73 * stage produces the final pixel color. The coverage-computing stages funct
ion exactly as the | 73 * stage produces the final pixel color. The coverage-computing stages funct
ion exactly as the |
74 * color-computing but the output of the final coverage stage is treated as
a fractional pixel | 74 * color-computing but the output of the final coverage stage is treated as
a fractional pixel |
75 * coverage rather than as input to the src/dst color blend step. | 75 * coverage rather than as input to the src/dst color blend step. |
76 * | 76 * |
77 * The input color to the first enabled color-stage is either the constant c
olor or interpolated | 77 * The input color to the first enabled color-stage is either the constant c
olor or interpolated |
78 * per-vertex colors, depending upon GrAttribBindings. The input to the firs
t coverage stage is | 78 * per-vertex colors, depending upon GrAttribBindings. The input to the firs
t coverage stage is |
79 * either a constant coverage (usually full-coverage), interpolated per-vert
ex coverage, or | 79 * either a constant coverage (usually full-coverage) or interpolated per-ve
rtex coverage. |
80 * edge-AA computed coverage. (This latter is going away as soon as it can b
e rewritten as a | |
81 * GrEffect). | |
82 * | 80 * |
83 * See the documentation of kCoverageDrawing_StateBit for information about
disabling the | 81 * See the documentation of kCoverageDrawing_StateBit for information about
disabling the |
84 * the color / coverage distinction. | 82 * the color / coverage distinction. |
85 * | 83 * |
86 * Stages 0 through GrPaint::kTotalStages-1 are reserved for stages copied f
rom the client's | 84 * Stages 0 through GrPaint::kTotalStages-1 are reserved for stages copied f
rom the client's |
87 * GrPaint. Stages GrPaint::kTotalStages through kNumStages-2 are earmarked
for use by | 85 * GrPaint. Stages GrPaint::kTotalStages through kNumStages-2 are earmarked
for use by |
88 * GrTextContext and GrPathRenderer-derived classes. kNumStages-1 is earmark
ed for clipping | 86 * GrTextContext and GrPathRenderer-derived classes. kNumStages-1 is earmark
ed for clipping |
89 * by GrClipMaskManager. | 87 * by GrClipMaskManager. |
90 */ | 88 */ |
91 enum { | 89 enum { |
(...skipping 26 matching lines...) Expand all Loading... |
118 fRenderTarget.reset(NULL); | 116 fRenderTarget.reset(NULL); |
119 | 117 |
120 this->setDefaultVertexAttribs(); | 118 this->setDefaultVertexAttribs(); |
121 | 119 |
122 fCommon.fColor = 0xffffffff; | 120 fCommon.fColor = 0xffffffff; |
123 fCommon.fViewMatrix.reset(); | 121 fCommon.fViewMatrix.reset(); |
124 fCommon.fSrcBlend = kOne_GrBlendCoeff; | 122 fCommon.fSrcBlend = kOne_GrBlendCoeff; |
125 fCommon.fDstBlend = kZero_GrBlendCoeff; | 123 fCommon.fDstBlend = kZero_GrBlendCoeff; |
126 fCommon.fBlendConstant = 0x0; | 124 fCommon.fBlendConstant = 0x0; |
127 fCommon.fFlagBits = 0x0; | 125 fCommon.fFlagBits = 0x0; |
128 fCommon.fVertexEdgeType = kHairLine_EdgeType; | |
129 fCommon.fStencilSettings.setDisabled(); | 126 fCommon.fStencilSettings.setDisabled(); |
130 fCommon.fFirstCoverageStage = kNumStages; | 127 fCommon.fFirstCoverageStage = kNumStages; |
131 fCommon.fCoverage = 0xffffffff; | 128 fCommon.fCoverage = 0xffffffff; |
132 fCommon.fColorFilterMode = SkXfermode::kDst_Mode; | 129 fCommon.fColorFilterMode = SkXfermode::kDst_Mode; |
133 fCommon.fColorFilterColor = 0x0; | 130 fCommon.fColorFilterColor = 0x0; |
134 fCommon.fDrawFace = kBoth_DrawFace; | 131 fCommon.fDrawFace = kBoth_DrawFace; |
135 } | 132 } |
136 | 133 |
137 /** | 134 /** |
138 * Initializes the GrDrawState based on a GrPaint. Note that GrDrawState | 135 * Initializes the GrDrawState based on a GrPaint. Note that GrDrawState |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 * Additional Bits that can be specified in GrAttribBindings. | 263 * Additional Bits that can be specified in GrAttribBindings. |
267 */ | 264 */ |
268 enum AttribBindingsBits { | 265 enum AttribBindingsBits { |
269 /** explicit local coords are provided (instead of using pre-view-matrix
positions) */ | 266 /** explicit local coords are provided (instead of using pre-view-matrix
positions) */ |
270 kLocalCoords_AttribBindingsBit = 0x1, | 267 kLocalCoords_AttribBindingsBit = 0x1, |
271 /* program uses colors (GrColor) */ | 268 /* program uses colors (GrColor) */ |
272 kColor_AttribBindingsBit = 0x2, | 269 kColor_AttribBindingsBit = 0x2, |
273 /* program uses coverage (GrColor) | 270 /* program uses coverage (GrColor) |
274 */ | 271 */ |
275 kCoverage_AttribBindingsBit = 0x4, | 272 kCoverage_AttribBindingsBit = 0x4, |
276 /* program uses edge data. Distance to the edge is used to | |
277 * compute a coverage. See GrDrawState::setVertexEdgeType(). | |
278 */ | |
279 kEdge_AttribBindingsBit = 0x8, | |
280 // for below assert | 273 // for below assert |
281 kDummyAttribBindingsBit, | 274 kDummyAttribBindingsBit, |
282 kHighAttribBindingsBit = kDummyAttribBindingsBit - 1 | 275 kHighAttribBindingsBit = kDummyAttribBindingsBit - 1 |
283 }; | 276 }; |
284 // make sure we haven't exceeded the number of bits in GrAttribBindings. | 277 // make sure we haven't exceeded the number of bits in GrAttribBindings. |
285 GR_STATIC_ASSERT(kHighAttribBindingsBit < ((uint64_t)1 << 8*sizeof(GrAttribB
indings))); | 278 GR_STATIC_ASSERT(kHighAttribBindingsBit < ((uint64_t)1 << 8*sizeof(GrAttribB
indings))); |
286 | 279 |
287 enum AttribBindings { | 280 enum AttribBindings { |
288 kDefault_AttribBindings = 0 | 281 kDefault_AttribBindings = 0 |
289 }; | 282 }; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 * look up the vertex attribute data from the array, and potentially as the | 318 * look up the vertex attribute data from the array, and potentially as the |
326 * attribute index if we're binding attributes in GL. | 319 * attribute index if we're binding attributes in GL. |
327 * | 320 * |
328 * Indices which do not have active attribute bindings will be ignored. | 321 * Indices which do not have active attribute bindings will be ignored. |
329 */ | 322 */ |
330 | 323 |
331 enum AttribIndex { | 324 enum AttribIndex { |
332 kPosition_AttribIndex = 0, | 325 kPosition_AttribIndex = 0, |
333 kColor_AttribIndex, | 326 kColor_AttribIndex, |
334 kCoverage_AttribIndex, | 327 kCoverage_AttribIndex, |
335 kEdge_AttribIndex, | |
336 kLocalCoords_AttribIndex, | 328 kLocalCoords_AttribIndex, |
337 | 329 |
338 kLast_AttribIndex = kLocalCoords_AttribIndex | 330 kLast_AttribIndex = kLocalCoords_AttribIndex |
339 }; | 331 }; |
340 static const int kAttribIndexCount = kLast_AttribIndex + 1; | 332 static const int kAttribIndexCount = kLast_AttribIndex + 1; |
341 | 333 |
342 // these are used when vertex color and coverage isn't set | 334 // these are used when vertex color and coverage isn't set |
343 enum { | 335 enum { |
344 kColorOverrideAttribIndexValue = GrDrawState::kVertexAttribCnt, | 336 kColorOverrideAttribIndexValue = GrDrawState::kVertexAttribCnt, |
345 kCoverageOverrideAttribIndexValue = GrDrawState::kVertexAttribCnt+1, | 337 kCoverageOverrideAttribIndexValue = GrDrawState::kVertexAttribCnt+1, |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 fCommon.fStencilSettings.setDisabled(); | 932 fCommon.fStencilSettings.setDisabled(); |
941 } | 933 } |
942 | 934 |
943 const GrStencilSettings& getStencil() const { return fCommon.fStencilSetting
s; } | 935 const GrStencilSettings& getStencil() const { return fCommon.fStencilSetting
s; } |
944 | 936 |
945 GrStencilSettings* stencil() { return &fCommon.fStencilSettings; } | 937 GrStencilSettings* stencil() { return &fCommon.fStencilSettings; } |
946 | 938 |
947 /// @} | 939 /// @} |
948 | 940 |
949 /////////////////////////////////////////////////////////////////////////// | 941 /////////////////////////////////////////////////////////////////////////// |
950 // @name Edge AA | |
951 // Edge equations can be specified to perform anti-aliasing. Because the | |
952 // edges are specified as per-vertex data, vertices that are shared by | |
953 // multiple edges must be split. | |
954 // | |
955 //// | |
956 | |
957 /** | |
958 * When specifying edges as vertex data this enum specifies what type of | |
959 * edges are in use. The edges are always 4 SkScalars in memory, even when | |
960 * the edge type requires fewer than 4. | |
961 * | |
962 * TODO: Fix the fact that HairLine and Circle edge types use y-down coords. | |
963 * (either adjust in VS or use origin_upper_left in GLSL) | |
964 */ | |
965 enum VertexEdgeType { | |
966 /* 1-pixel wide line | |
967 2D implicit line eq (a*x + b*y +c = 0). 4th component unused */ | |
968 kHairLine_EdgeType, | |
969 /* Quadratic specified by u^2-v canonical coords (only 2 | |
970 components used). Coverage based on signed distance with negative | |
971 being inside, positive outside. Edge specified in window space | |
972 (y-down) */ | |
973 kQuad_EdgeType, | |
974 /* Same as above but for hairline quadratics. Uses unsigned distance. | |
975 Coverage is min(0, 1-distance). */ | |
976 kHairQuad_EdgeType, | |
977 | |
978 kVertexEdgeTypeCnt | |
979 }; | |
980 | |
981 /** | |
982 * Determines the interpretation per-vertex edge data when the | |
983 * kEdge_AttribBindingsBit is set (see GrDrawTarget). When per-vertex edges | |
984 * are not specified the value of this setting has no effect. | |
985 */ | |
986 void setVertexEdgeType(VertexEdgeType type) { | |
987 GrAssert(type >=0 && type < kVertexEdgeTypeCnt); | |
988 fCommon.fVertexEdgeType = type; | |
989 } | |
990 | |
991 VertexEdgeType getVertexEdgeType() const { return fCommon.fVertexEdgeType; } | |
992 | |
993 /// @} | |
994 | |
995 /////////////////////////////////////////////////////////////////////////// | |
996 /// @name State Flags | 942 /// @name State Flags |
997 //// | 943 //// |
998 | 944 |
999 /** | 945 /** |
1000 * Flags that affect rendering. Controlled using enable/disableState(). All | 946 * Flags that affect rendering. Controlled using enable/disableState(). All |
1001 * default to disabled. | 947 * default to disabled. |
1002 */ | 948 */ |
1003 enum StateBits { | 949 enum StateBits { |
1004 /** | 950 /** |
1005 * Perform dithering. TODO: Re-evaluate whether we need this bit | 951 * Perform dithering. TODO: Re-evaluate whether we need this bit |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState.
*/ | 1127 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState.
*/ |
1182 struct CommonState { | 1128 struct CommonState { |
1183 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== | 1129 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== |
1184 GrColor fColor; | 1130 GrColor fColor; |
1185 GrAttribBindings fAttribBindings; | 1131 GrAttribBindings fAttribBindings; |
1186 SkMatrix fViewMatrix; | 1132 SkMatrix fViewMatrix; |
1187 GrBlendCoeff fSrcBlend; | 1133 GrBlendCoeff fSrcBlend; |
1188 GrBlendCoeff fDstBlend; | 1134 GrBlendCoeff fDstBlend; |
1189 GrColor fBlendConstant; | 1135 GrColor fBlendConstant; |
1190 uint32_t fFlagBits; | 1136 uint32_t fFlagBits; |
1191 VertexEdgeType fVertexEdgeType; | |
1192 GrStencilSettings fStencilSettings; | 1137 GrStencilSettings fStencilSettings; |
1193 int fFirstCoverageStage; | 1138 int fFirstCoverageStage; |
1194 GrColor fCoverage; | 1139 GrColor fCoverage; |
1195 SkXfermode::Mode fColorFilterMode; | 1140 SkXfermode::Mode fColorFilterMode; |
1196 GrColor fColorFilterColor; | 1141 GrColor fColorFilterColor; |
1197 DrawFace fDrawFace; | 1142 DrawFace fDrawFace; |
1198 bool operator== (const CommonState& other) const { | 1143 bool operator== (const CommonState& other) const { |
1199 return fColor == other.fColor && | 1144 return fColor == other.fColor && |
1200 fAttribBindings == other.fAttribBindings && | 1145 fAttribBindings == other.fAttribBindings && |
1201 fViewMatrix.cheapEqualTo(other.fViewMatrix) && | 1146 fViewMatrix.cheapEqualTo(other.fViewMatrix) && |
1202 fSrcBlend == other.fSrcBlend && | 1147 fSrcBlend == other.fSrcBlend && |
1203 fDstBlend == other.fDstBlend && | 1148 fDstBlend == other.fDstBlend && |
1204 fBlendConstant == other.fBlendConstant && | 1149 fBlendConstant == other.fBlendConstant && |
1205 fFlagBits == other.fFlagBits && | 1150 fFlagBits == other.fFlagBits && |
1206 fVertexEdgeType == other.fVertexEdgeType && | |
1207 fStencilSettings == other.fStencilSettings && | 1151 fStencilSettings == other.fStencilSettings && |
1208 fFirstCoverageStage == other.fFirstCoverageStage && | 1152 fFirstCoverageStage == other.fFirstCoverageStage && |
1209 fCoverage == other.fCoverage && | 1153 fCoverage == other.fCoverage && |
1210 fColorFilterMode == other.fColorFilterMode && | 1154 fColorFilterMode == other.fColorFilterMode && |
1211 fColorFilterColor == other.fColorFilterColor && | 1155 fColorFilterColor == other.fColorFilterColor && |
1212 fDrawFace == other.fDrawFace; | 1156 fDrawFace == other.fDrawFace; |
1213 } | 1157 } |
1214 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } | 1158 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } |
1215 }; | 1159 }; |
1216 | 1160 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 int fAttribIndices[kAttribIndexCount]; | 1254 int fAttribIndices[kAttribIndexCount]; |
1311 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs; | 1255 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs; |
1312 GrEffectStage fStages[kNumStages]; | 1256 GrEffectStage fStages[kNumStages]; |
1313 | 1257 |
1314 typedef GrRefCnt INHERITED; | 1258 typedef GrRefCnt INHERITED; |
1315 }; | 1259 }; |
1316 | 1260 |
1317 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1261 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1318 | 1262 |
1319 #endif | 1263 #endif |
OLD | NEW |