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 |
| 11 |
11 #include "GrBlend.h" | 12 #include "GrBlend.h" |
12 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
13 #include "GrGpuResourceRef.h" | 14 #include "GrGpuResourceRef.h" |
14 #include "GrRODrawState.h" | 15 #include "GrProcessorStage.h" |
| 16 #include "GrRenderTarget.h" |
| 17 #include "GrStencil.h" |
| 18 #include "SkMatrix.h" |
15 #include "effects/GrSimpleTextureEffect.h" | 19 #include "effects/GrSimpleTextureEffect.h" |
16 | 20 |
| 21 class GrDrawTargetCaps; |
17 class GrOptDrawState; | 22 class GrOptDrawState; |
| 23 class GrPaint; |
| 24 class GrTexture; |
18 | 25 |
19 /** | 26 class GrDrawState : public SkRefCnt { |
20 * Modifiable subclass derived from GrRODrawState. The majority of the data that
represents a draw | |
21 * state is stored in the parent class. GrDrawState contains methods for setting
, adding to, etc. | |
22 * various data members of the draw state. This class is used to configure the s
tate used when | |
23 * issuing draws via GrDrawTarget. | |
24 */ | |
25 class GrDrawState : public GrRODrawState { | |
26 public: | 27 public: |
27 SK_DECLARE_INST_COUNT(GrDrawState) | 28 SK_DECLARE_INST_COUNT(GrDrawState) |
28 | 29 |
29 GrDrawState() : fCachedOptState(NULL) { | 30 GrDrawState() : fCachedOptState(NULL) { |
30 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 31 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
31 this->reset(); | 32 this->reset(); |
32 } | 33 } |
33 | 34 |
34 GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) { | 35 GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) { |
35 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 36 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
(...skipping 27 matching lines...) Expand all Loading... |
63 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint | 64 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint |
64 * equivalents are set to default values with the exception of vertex attrib
ute state which | 65 * equivalents are set to default values with the exception of vertex attrib
ute state which |
65 * is unmodified by this function and clipping which will be enabled. | 66 * is unmodified by this function and clipping which will be enabled. |
66 */ | 67 */ |
67 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); | 68 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); |
68 | 69 |
69 /////////////////////////////////////////////////////////////////////////// | 70 /////////////////////////////////////////////////////////////////////////// |
70 /// @name Vertex Attributes | 71 /// @name Vertex Attributes |
71 //// | 72 //// |
72 | 73 |
| 74 enum { |
| 75 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, |
| 76 }; |
| 77 |
| 78 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } |
| 79 int getVertexAttribCount() const { return fVACount; } |
| 80 |
| 81 size_t getVertexStride() const { return fVAStride; } |
| 82 |
| 83 bool hasLocalCoordAttribute() const { |
| 84 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri
bBinding]; |
| 85 } |
| 86 bool hasColorVertexAttribute() const { |
| 87 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind
ing]; |
| 88 } |
| 89 bool hasCoverageVertexAttribute() const { |
| 90 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB
inding]; |
| 91 } |
| 92 |
| 93 const int* getFixedFunctionVertexAttribIndices() const { |
| 94 return fFixedFunctionVertexAttribIndices; |
| 95 } |
| 96 |
| 97 bool validateVertexAttribs() const; |
| 98 |
73 /** | 99 /** |
74 * The format of vertices is represented as an array of GrVertexAttribs, wit
h each representing | 100 * The format of vertices is represented as an array of GrVertexAttribs, wit
h each representing |
75 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in | 101 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in |
76 * GrTypesPriv.h). | 102 * GrTypesPriv.h). |
77 * | 103 * |
78 * The mapping of attributes with kEffect bindings to GrProcessor inputs is
specified when | 104 * The mapping of attributes with kEffect bindings to GrProcessor inputs is
specified when |
79 * setEffect is called. | 105 * setEffect is called. |
80 */ | 106 */ |
81 | 107 |
82 /** | 108 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by | 146 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by |
121 * the fragment shader. | 147 * the fragment shader. |
122 * | 148 * |
123 * This function considers the current draw state and the draw target's capa
bilities to | 149 * This function considers the current draw state and the draw target's capa
bilities to |
124 * determine whether coverage can be handled correctly. This function assume
s that the caller | 150 * determine whether coverage can be handled correctly. This function assume
s that the caller |
125 * intends to specify fractional pixel coverage (via setCoverage(), through
a coverage vertex | 151 * intends to specify fractional pixel coverage (via setCoverage(), through
a coverage vertex |
126 * attribute, or a coverage effect) but may not have specified it yet. | 152 * attribute, or a coverage effect) but may not have specified it yet. |
127 */ | 153 */ |
128 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; | 154 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; |
129 | 155 |
| 156 /** |
| 157 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. |
| 158 */ |
| 159 bool hasSolidCoverage() const; |
| 160 |
130 /// @} | 161 /// @} |
131 | 162 |
132 /////////////////////////////////////////////////////////////////////////// | 163 /////////////////////////////////////////////////////////////////////////// |
133 /// @name Color | 164 /// @name Color |
134 //// | 165 //// |
135 | 166 |
| 167 GrColor getColor() const { return fColor; } |
| 168 |
136 /** | 169 /** |
137 * Sets color for next draw to a premultiplied-alpha color. | 170 * Sets color for next draw to a premultiplied-alpha color. |
138 * | 171 * |
139 * @param color the color to set. | 172 * @param color the color to set. |
140 */ | 173 */ |
141 void setColor(GrColor color) { | 174 void setColor(GrColor color) { |
142 if (color != fColor) { | 175 if (color != fColor) { |
143 fColor = color; | 176 fColor = color; |
144 this->invalidateOptState(); | 177 this->invalidateOptState(); |
145 } | 178 } |
146 } | 179 } |
147 | 180 |
148 /** | 181 /** |
149 * Sets the color to be used for the next draw to be | 182 * Sets the color to be used for the next draw to be |
150 * (r,g,b,a) = (alpha, alpha, alpha, alpha). | 183 * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
151 * | 184 * |
152 * @param alpha The alpha value to set as the color. | 185 * @param alpha The alpha value to set as the color. |
153 */ | 186 */ |
154 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) |
a); } | 187 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) |
a); } |
155 | 188 |
156 /// @} | 189 /// @} |
157 | 190 |
158 /////////////////////////////////////////////////////////////////////////// | 191 /////////////////////////////////////////////////////////////////////////// |
159 /// @name Coverage | 192 /// @name Coverage |
160 //// | 193 //// |
161 | 194 |
| 195 uint8_t getCoverage() const { return fCoverage; } |
| 196 |
| 197 GrColor getCoverageColor() const { |
| 198 return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); |
| 199 } |
| 200 |
162 /** | 201 /** |
163 * Sets a constant fractional coverage to be applied to the draw. The | 202 * Sets a constant fractional coverage to be applied to the draw. The |
164 * initial value (after construction or reset()) is 0xff. The constant | 203 * initial value (after construction or reset()) is 0xff. The constant |
165 * coverage is ignored when per-vertex coverage is provided. | 204 * coverage is ignored when per-vertex coverage is provided. |
166 */ | 205 */ |
167 void setCoverage(uint8_t coverage) { | 206 void setCoverage(uint8_t coverage) { |
168 if (coverage != fCoverage) { | 207 if (coverage != fCoverage) { |
169 fCoverage = coverage; | 208 fCoverage = coverage; |
170 this->invalidateOptState(); | 209 this->invalidateOptState(); |
171 } | 210 } |
(...skipping 28 matching lines...) Expand all Loading... |
200 /// pixel coverage rather than as input to the src/dst color blend step. | 239 /// pixel coverage rather than as input to the src/dst color blend step. |
201 /// | 240 /// |
202 /// The input color to the first color-stage is either the constant color or
interpolated | 241 /// The input color to the first color-stage is either the constant color or
interpolated |
203 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage | 242 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage |
204 /// (usually full-coverage) or interpolated per-vertex coverage. | 243 /// (usually full-coverage) or interpolated per-vertex coverage. |
205 /// | 244 /// |
206 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the | 245 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the |
207 /// the color / coverage distinction. | 246 /// the color / coverage distinction. |
208 //// | 247 //// |
209 | 248 |
| 249 int numColorStages() const { return fColorStages.count(); } |
| 250 int numCoverageStages() const { return fCoverageStages.count(); } |
| 251 int numTotalStages() const { |
| 252 return this->numColorStages() + this->numCoverageStages() + |
| 253 (this->hasGeometryProcessor() ? 1 : 0); |
| 254 } |
| 255 |
| 256 bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()
); } |
| 257 const GrGeometryStage* getGeometryProcessor() const { return fGeometryProces
sor.get(); } |
| 258 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } |
| 259 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
| 260 |
| 261 /** |
| 262 * Checks whether any of the effects will read the dst pixel color. |
| 263 */ |
| 264 bool willEffectReadDstColor() const; |
| 265 |
210 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { | 266 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
211 SkASSERT(effect); | 267 SkASSERT(effect); |
212 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 268 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
213 this->invalidateOptState(); | 269 this->invalidateOptState(); |
214 return effect; | 270 return effect; |
215 } | 271 } |
216 | 272 |
217 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { | 273 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
218 SkASSERT(effect); | 274 SkASSERT(effect); |
219 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); | 275 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 int fColorEffectCnt; | 344 int fColorEffectCnt; |
289 int fCoverageEffectCnt; | 345 int fCoverageEffectCnt; |
290 }; | 346 }; |
291 | 347 |
292 /// @} | 348 /// @} |
293 | 349 |
294 /////////////////////////////////////////////////////////////////////////// | 350 /////////////////////////////////////////////////////////////////////////// |
295 /// @name Blending | 351 /// @name Blending |
296 //// | 352 //// |
297 | 353 |
| 354 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; } |
| 355 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; } |
| 356 |
| 357 /** |
| 358 * Retrieves the last value set by setBlendConstant() |
| 359 * @return the blending constant value |
| 360 */ |
| 361 GrColor getBlendConstant() const { return fBlendConstant; } |
| 362 |
| 363 /** |
| 364 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional |
| 365 * coverage before the blend will give the correct final destination color.
In general it |
| 366 * will not as coverage is applied after blending. |
| 367 */ |
| 368 bool canTweakAlphaForCoverage() const; |
| 369 |
298 /** | 370 /** |
299 * Sets the blending function coefficients. | 371 * Sets the blending function coefficients. |
300 * | 372 * |
301 * The blend function will be: | 373 * The blend function will be: |
302 * D' = sat(S*srcCoef + D*dstCoef) | 374 * D' = sat(S*srcCoef + D*dstCoef) |
303 * | 375 * |
304 * where D is the existing destination color, S is the incoming source | 376 * where D is the existing destination color, S is the incoming source |
305 * color, and D' is the new destination color that will be written. sat() | 377 * color, and D' is the new destination color that will be written. sat() |
306 * is the saturation function. | 378 * is the saturation function. |
307 * | 379 * |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 413 } |
342 } | 414 } |
343 | 415 |
344 /// @} | 416 /// @} |
345 | 417 |
346 /////////////////////////////////////////////////////////////////////////// | 418 /////////////////////////////////////////////////////////////////////////// |
347 /// @name View Matrix | 419 /// @name View Matrix |
348 //// | 420 //// |
349 | 421 |
350 /** | 422 /** |
| 423 * Retrieves the current view matrix |
| 424 * @return the current view matrix. |
| 425 */ |
| 426 const SkMatrix& getViewMatrix() const { return fViewMatrix; } |
| 427 |
| 428 /** |
| 429 * Retrieves the inverse of the current view matrix. |
| 430 * |
| 431 * If the current view matrix is invertible, return true, and if matrix |
| 432 * is non-null, copy the inverse into it. If the current view matrix is |
| 433 * non-invertible, return false and ignore the matrix parameter. |
| 434 * |
| 435 * @param matrix if not null, will receive a copy of the current inverse. |
| 436 */ |
| 437 bool getViewInverse(SkMatrix* matrix) const { |
| 438 SkMatrix inverse; |
| 439 if (fViewMatrix.invert(&inverse)) { |
| 440 if (matrix) { |
| 441 *matrix = inverse; |
| 442 } |
| 443 return true; |
| 444 } |
| 445 return false; |
| 446 } |
| 447 |
| 448 /** |
351 * Sets the view matrix to identity and updates any installed effects to com
pensate for the | 449 * Sets the view matrix to identity and updates any installed effects to com
pensate for the |
352 * coord system change. | 450 * coord system change. |
353 */ | 451 */ |
354 bool setIdentityViewMatrix(); | 452 bool setIdentityViewMatrix(); |
355 | 453 |
356 //////////////////////////////////////////////////////////////////////////// | 454 //////////////////////////////////////////////////////////////////////////// |
357 | 455 |
358 /** | 456 /** |
359 * Preconcats the current view matrix and restores the previous view matrix
in the destructor. | 457 * Preconcats the current view matrix and restores the previous view matrix
in the destructor. |
360 * Effect matrices are automatically adjusted to compensate and adjusted bac
k in the destructor. | 458 * Effect matrices are automatically adjusted to compensate and adjusted bac
k in the destructor. |
(...skipping 30 matching lines...) Expand all Loading... |
391 SkAutoSTArray<8, GrProcessorStage::SavedCoordChange> fSavedCoordChange
s; | 489 SkAutoSTArray<8, GrProcessorStage::SavedCoordChange> fSavedCoordChange
s; |
392 }; | 490 }; |
393 | 491 |
394 /// @} | 492 /// @} |
395 | 493 |
396 /////////////////////////////////////////////////////////////////////////// | 494 /////////////////////////////////////////////////////////////////////////// |
397 /// @name Render Target | 495 /// @name Render Target |
398 //// | 496 //// |
399 | 497 |
400 /** | 498 /** |
| 499 * Retrieves the currently set render-target. |
| 500 * |
| 501 * @return The currently set render target. |
| 502 */ |
| 503 GrRenderTarget* getRenderTarget() const { |
| 504 return static_cast<GrRenderTarget*>(fRenderTarget.getResource()); |
| 505 } |
| 506 |
| 507 /** |
401 * Sets the render-target used at the next drawing call | 508 * Sets the render-target used at the next drawing call |
402 * | 509 * |
403 * @param target The render target to set. | 510 * @param target The render target to set. |
404 */ | 511 */ |
405 void setRenderTarget(GrRenderTarget* target) { | 512 void setRenderTarget(GrRenderTarget* target) { |
406 fRenderTarget.set(SkSafeRef(target), GrIORef::kWrite_IOType); | 513 fRenderTarget.set(SkSafeRef(target), GrIORef::kWrite_IOType); |
407 this->invalidateOptState(); | 514 this->invalidateOptState(); |
408 } | 515 } |
409 | 516 |
410 /// @} | 517 /// @} |
411 | 518 |
412 /////////////////////////////////////////////////////////////////////////// | 519 /////////////////////////////////////////////////////////////////////////// |
413 /// @name Stencil | 520 /// @name Stencil |
414 //// | 521 //// |
415 | 522 |
| 523 const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 524 |
416 /** | 525 /** |
417 * Sets the stencil settings to use for the next draw. | 526 * Sets the stencil settings to use for the next draw. |
418 * Changing the clip has the side-effect of possibly zeroing | 527 * Changing the clip has the side-effect of possibly zeroing |
419 * out the client settable stencil bits. So multipass algorithms | 528 * out the client settable stencil bits. So multipass algorithms |
420 * using stencil should not change the clip between passes. | 529 * using stencil should not change the clip between passes. |
421 * @param settings the stencil settings to use. | 530 * @param settings the stencil settings to use. |
422 */ | 531 */ |
423 void setStencil(const GrStencilSettings& settings) { | 532 void setStencil(const GrStencilSettings& settings) { |
424 if (settings != fStencilSettings) { | 533 if (settings != fStencilSettings) { |
425 fStencilSettings = settings; | 534 fStencilSettings = settings; |
(...skipping 12 matching lines...) Expand all Loading... |
438 } | 547 } |
439 | 548 |
440 GrStencilSettings* stencil() { return &fStencilSettings; } | 549 GrStencilSettings* stencil() { return &fStencilSettings; } |
441 | 550 |
442 /// @} | 551 /// @} |
443 | 552 |
444 /////////////////////////////////////////////////////////////////////////// | 553 /////////////////////////////////////////////////////////////////////////// |
445 /// @name State Flags | 554 /// @name State Flags |
446 //// | 555 //// |
447 | 556 |
| 557 /** |
| 558 * Flags that affect rendering. Controlled using enable/disableState(). All |
| 559 * default to disabled. |
| 560 */ |
| 561 enum StateBits { |
| 562 /** |
| 563 * Perform dithering. TODO: Re-evaluate whether we need this bit |
| 564 */ |
| 565 kDither_StateBit = 0x01, |
| 566 /** |
| 567 * Perform HW anti-aliasing. This means either HW FSAA, if supported by
the render target, |
| 568 * or smooth-line rendering if a line primitive is drawn and line smooth
ing is supported by |
| 569 * the 3D API. |
| 570 */ |
| 571 kHWAntialias_StateBit = 0x02, |
| 572 /** |
| 573 * Draws will respect the clip, otherwise the clip is ignored. |
| 574 */ |
| 575 kClip_StateBit = 0x04, |
| 576 /** |
| 577 * Disables writing to the color buffer. Useful when performing stencil |
| 578 * operations. |
| 579 */ |
| 580 kNoColorWrites_StateBit = 0x08, |
| 581 |
| 582 /** |
| 583 * Usually coverage is applied after color blending. The color is blende
d using the coeffs |
| 584 * specified by setBlendFunc(). The blended color is then combined with
dst using coeffs |
| 585 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing
a coverage mask. In |
| 586 * this case there is no distinction between coverage and color and the
caller needs direct |
| 587 * control over the blend coeffs. When set, there will be a single blend
step controlled by |
| 588 * setBlendFunc() which will use coverage*color as the src color. |
| 589 */ |
| 590 kCoverageDrawing_StateBit = 0x10, |
| 591 |
| 592 // Users of the class may add additional bits to the vector |
| 593 kDummyStateBit, |
| 594 kLastPublicStateBit = kDummyStateBit-1, |
| 595 }; |
| 596 |
| 597 uint32_t getFlagBits() const { return fFlagBits; } |
| 598 |
| 599 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f
FlagBits); } |
| 600 |
| 601 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
| 602 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } |
| 603 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } |
| 604 |
448 void resetStateFlags() { | 605 void resetStateFlags() { |
449 if (0 != fFlagBits) { | 606 if (0 != fFlagBits) { |
450 fFlagBits = 0; | 607 fFlagBits = 0; |
451 this->invalidateOptState(); | 608 this->invalidateOptState(); |
452 } | 609 } |
453 } | 610 } |
454 | 611 |
455 /** | 612 /** |
456 * Enable render state settings. | 613 * Enable render state settings. |
457 * | 614 * |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 this->disableState(stateBits); | 646 this->disableState(stateBits); |
490 } | 647 } |
491 } | 648 } |
492 | 649 |
493 /// @} | 650 /// @} |
494 | 651 |
495 /////////////////////////////////////////////////////////////////////////// | 652 /////////////////////////////////////////////////////////////////////////// |
496 /// @name Face Culling | 653 /// @name Face Culling |
497 //// | 654 //// |
498 | 655 |
| 656 enum DrawFace { |
| 657 kInvalid_DrawFace = -1, |
| 658 |
| 659 kBoth_DrawFace, |
| 660 kCCW_DrawFace, |
| 661 kCW_DrawFace, |
| 662 }; |
| 663 |
| 664 /** |
| 665 * Gets whether the target is drawing clockwise, counterclockwise, |
| 666 * or both faces. |
| 667 * @return the current draw face(s). |
| 668 */ |
| 669 DrawFace getDrawFace() const { return fDrawFace; } |
| 670 |
499 /** | 671 /** |
500 * Controls whether clockwise, counterclockwise, or both faces are drawn. | 672 * Controls whether clockwise, counterclockwise, or both faces are drawn. |
501 * @param face the face(s) to draw. | 673 * @param face the face(s) to draw. |
502 */ | 674 */ |
503 void setDrawFace(DrawFace face) { | 675 void setDrawFace(DrawFace face) { |
504 SkASSERT(kInvalid_DrawFace != face); | 676 SkASSERT(kInvalid_DrawFace != face); |
505 fDrawFace = face; | 677 fDrawFace = face; |
506 } | 678 } |
507 | 679 |
508 /// @} | 680 /// @} |
509 | 681 |
510 /////////////////////////////////////////////////////////////////////////// | 682 /////////////////////////////////////////////////////////////////////////// |
511 /// @name Hints | 683 /// @name Hints |
512 /// Hints that when provided can enable optimizations. | 684 /// Hints that when provided can enable optimizations. |
513 //// | 685 //// |
514 | 686 |
| 687 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; |
| 688 |
515 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f
Hints & ~hint); } | 689 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f
Hints & ~hint); } |
516 | 690 |
| 691 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH
ints; } |
| 692 |
517 /// @} | 693 /// @} |
518 | 694 |
519 /////////////////////////////////////////////////////////////////////////// | 695 /////////////////////////////////////////////////////////////////////////// |
520 | 696 |
521 /** Return type for CombineIfPossible. */ | 697 /** Return type for CombineIfPossible. */ |
522 enum CombinedState { | 698 enum CombinedState { |
523 /** The GrDrawStates cannot be combined. */ | 699 /** The GrDrawStates cannot be combined. */ |
524 kIncompatible_CombinedState, | 700 kIncompatible_CombinedState, |
525 /** Either draw state can be used in place of the other. */ | 701 /** Either draw state can be used in place of the other. */ |
526 kAOrB_CombinedState, | 702 kAOrB_CombinedState, |
(...skipping 14 matching lines...) Expand all Loading... |
541 | 717 |
542 /** | 718 /** |
543 * Returns a snapshot of the current optimized state. If the current drawSta
te has a valid | 719 * Returns a snapshot of the current optimized state. If the current drawSta
te has a valid |
544 * cached optimiezed state it will simply return a pointer to it otherwise i
t will create a new | 720 * cached optimiezed state it will simply return a pointer to it otherwise i
t will create a new |
545 * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership i
s given to the | 721 * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership i
s given to the |
546 * caller. | 722 * caller. |
547 */ | 723 */ |
548 GrOptDrawState* createOptState(const GrDrawTargetCaps&) const; | 724 GrOptDrawState* createOptState(const GrDrawTargetCaps&) const; |
549 | 725 |
550 private: | 726 private: |
| 727 /** |
| 728 * Converts refs on GrGpuResources owned directly or indirectly by this GrDr
awState into |
| 729 * pending reads and writes. This should be called when a GrDrawState is rec
orded into |
| 730 * a GrDrawTarget for later execution. Subclasses of GrDrawState may add set
ters. However, |
| 731 * once this call has been made the GrDrawState is immutable. It is also no
longer copyable. |
| 732 * In the future this conversion will automatically happen when converting a
GrDrawState into |
| 733 * an optimized draw state. |
| 734 */ |
| 735 void convertToPendingExec(); |
| 736 |
| 737 friend class GrDrawTarget; |
| 738 |
| 739 bool isEqual(const GrDrawState& that) const; |
| 740 |
| 741 /** |
| 742 * Optimizations for blending / coverage to that can be applied based on the
current state. |
| 743 */ |
| 744 enum BlendOptFlags { |
| 745 /** |
| 746 * No optimization |
| 747 */ |
| 748 kNone_BlendOpt = 0, |
| 749 /** |
| 750 * Don't draw at all |
| 751 */ |
| 752 kSkipDraw_BlendOptFlag = 0x1, |
| 753 /** |
| 754 * The coverage value does not have to be computed separately from alpha
, the the output |
| 755 * color can be the modulation of the two. |
| 756 */ |
| 757 kCoverageAsAlpha_BlendOptFlag = 0x2, |
| 758 /** |
| 759 * Instead of emitting a src color, emit coverage in the alpha channel a
nd r,g,b are |
| 760 * "don't cares". |
| 761 */ |
| 762 kEmitCoverage_BlendOptFlag = 0x4, |
| 763 /** |
| 764 * Emit transparent black instead of the src color, no need to compute c
overage. |
| 765 */ |
| 766 kEmitTransBlack_BlendOptFlag = 0x8, |
| 767 }; |
| 768 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
| 769 |
| 770 /** |
| 771 * Determines what optimizations can be applied based on the blend. The coef
ficients may have |
| 772 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
f are optional |
| 773 * params that receive the tweaked coefficients. Normally the function looks
at the current |
| 774 * state to see if coverage is enabled. By setting forceCoverage the caller
can speculatively |
| 775 * determine the blend optimizations that would be used if there was partial
pixel coverage. |
| 776 * |
| 777 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j
ust buffer for |
| 778 * playback) must call this function and respect the flags that replace the
output color. |
| 779 * |
| 780 * If the cached BlendOptFlags does not have the invalidate bit set, then ge
tBlendOpts will |
| 781 * simply returned the cached flags and coefficients. Otherwise it will calc
ulate the values. |
| 782 */ |
| 783 BlendOptFlags getBlendOpts(bool forceCoverage = false, |
| 784 GrBlendCoeff* srcCoeff = NULL, |
| 785 GrBlendCoeff* dstCoeff = NULL) const; |
| 786 |
| 787 /** |
| 788 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 789 */ |
| 790 bool srcAlphaWillBeOne() const; |
| 791 |
551 void invalidateOptState() const; | 792 void invalidateOptState() const; |
552 | 793 |
553 void onReset(const SkMatrix* initialViewMatrix); | 794 void onReset(const SkMatrix* initialViewMatrix); |
554 | 795 |
555 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 796 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
556 // This is used to assert that this condition holds. | 797 // This is used to assert that this condition holds. |
557 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 798 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
558 | 799 |
559 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
e_t stride); | 800 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
e_t stride); |
560 | 801 |
| 802 typedef GrTGpuResourceRef<GrRenderTarget> ProgramRenderTarget; |
| 803 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== |
| 804 ProgramRenderTarget fRenderTarget; |
| 805 GrColor fColor; |
| 806 SkMatrix fViewMatrix; |
| 807 GrColor fBlendConstant; |
| 808 uint32_t fFlagBits; |
| 809 const GrVertexAttrib* fVAPtr; |
| 810 int fVACount; |
| 811 size_t fVAStride; |
| 812 GrStencilSettings fStencilSettings; |
| 813 uint8_t fCoverage; |
| 814 DrawFace fDrawFace; |
| 815 GrBlendCoeff fSrcBlend; |
| 816 GrBlendCoeff fDstBlend; |
| 817 |
| 818 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 819 SkAutoTDelete<GrGeometryStage> fGeometryProcessor; |
| 820 FragmentStageArray fColorStages; |
| 821 FragmentStageArray fCoverageStages; |
| 822 |
| 823 uint32_t fHints; |
| 824 |
| 825 // This is simply a different representation of info in fVertexAttribs and t
hus does |
| 826 // not need to be compared in op==. |
| 827 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; |
| 828 |
561 mutable GrOptDrawState* fCachedOptState; | 829 mutable GrOptDrawState* fCachedOptState; |
562 mutable uint32_t fCachedCapsID; | 830 mutable uint32_t fCachedCapsID; |
563 | 831 |
564 typedef GrRODrawState INHERITED; | 832 typedef SkRefCnt INHERITED; |
565 }; | 833 }; |
566 | 834 |
| 835 //GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
| 836 |
567 #endif | 837 #endif |
OLD | NEW |