| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 */ | 96 */ |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Sets vertex attributes for next draw. The object driving the templatizat
ion | 99 * Sets vertex attributes for next draw. The object driving the templatizat
ion |
| 100 * should be a global GrVertexAttrib array that is never changed. | 100 * should be a global GrVertexAttrib array that is never changed. |
| 101 */ | 101 */ |
| 102 template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { | 102 template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { |
| 103 this->setVertexAttribs(A, count); | 103 this->setVertexAttribs(A, count); |
| 104 } | 104 } |
| 105 | 105 |
| 106 const GrVertexAttrib* getVertexAttribs() const { return fCommon.fVAPtr; } | 106 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } |
| 107 int getVertexAttribCount() const { return fCommon.fVACount; } | 107 int getVertexAttribCount() const { return fVACount; } |
| 108 | 108 |
| 109 size_t getVertexSize() const; | 109 size_t getVertexSize() const; |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * Sets default vertex attributes for next draw. The default is a single at
tribute: | 112 * Sets default vertex attributes for next draw. The default is a single at
tribute: |
| 113 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} | 113 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} |
| 114 */ | 114 */ |
| 115 void setDefaultVertexAttribs(); | 115 void setDefaultVertexAttribs(); |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * Getters for index into getVertexAttribs() for particular bindings. -1 is
returned if the | 118 * Getters for index into getVertexAttribs() for particular bindings. -1 is
returned if the |
| 119 * binding does not appear in the current attribs. These bindings should app
ear only once in | 119 * binding does not appear in the current attribs. These bindings should app
ear only once in |
| 120 * the attrib array. | 120 * the attrib array. |
| 121 */ | 121 */ |
| 122 | 122 |
| 123 int positionAttributeIndex() const { | 123 int positionAttributeIndex() const { |
| 124 return fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttri
bBinding]; | 124 return fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding
]; |
| 125 } | 125 } |
| 126 int localCoordAttributeIndex() const { | 126 int localCoordAttributeIndex() const { |
| 127 return fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAtt
ribBinding]; | 127 return fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBindi
ng]; |
| 128 } | 128 } |
| 129 int colorVertexAttributeIndex() const { | 129 int colorVertexAttributeIndex() const { |
| 130 return fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBi
nding]; | 130 return fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding]; |
| 131 } | 131 } |
| 132 int coverageVertexAttributeIndex() const { | 132 int coverageVertexAttributeIndex() const { |
| 133 return fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttri
bBinding]; | 133 return fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding
]; |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool hasLocalCoordAttribute() const { | 136 bool hasLocalCoordAttribute() const { |
| 137 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVer
texAttribBinding]; | 137 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri
bBinding]; |
| 138 } | 138 } |
| 139 bool hasColorVertexAttribute() const { | 139 bool hasColorVertexAttribute() const { |
| 140 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAt
tribBinding]; | 140 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind
ing]; |
| 141 } | 141 } |
| 142 bool hasCoverageVertexAttribute() const { | 142 bool hasCoverageVertexAttribute() const { |
| 143 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVerte
xAttribBinding]; | 143 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB
inding]; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool validateVertexAttribs() const; | 146 bool validateVertexAttribs() const; |
| 147 | 147 |
| 148 /** | 148 /** |
| 149 * Helper to save/restore vertex attribs | 149 * Helper to save/restore vertex attribs |
| 150 */ | 150 */ |
| 151 class AutoVertexAttribRestore { | 151 class AutoVertexAttribRestore { |
| 152 public: | 152 public: |
| 153 AutoVertexAttribRestore(GrDrawState* drawState) { | 153 AutoVertexAttribRestore(GrDrawState* drawState) { |
| 154 SkASSERT(NULL != drawState); | 154 SkASSERT(NULL != drawState); |
| 155 fDrawState = drawState; | 155 fDrawState = drawState; |
| 156 fVAPtr = drawState->fCommon.fVAPtr; | 156 fVAPtr = drawState->fVAPtr; |
| 157 fVACount = drawState->fCommon.fVACount; | 157 fVACount = drawState->fVACount; |
| 158 fDrawState->setDefaultVertexAttribs(); | 158 fDrawState->setDefaultVertexAttribs(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 ~AutoVertexAttribRestore(){ | 161 ~AutoVertexAttribRestore(){ |
| 162 fDrawState->setVertexAttribs(fVAPtr, fVACount); | 162 fDrawState->setVertexAttribs(fVAPtr, fVACount); |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 GrDrawState* fDrawState; | 166 GrDrawState* fDrawState; |
| 167 const GrVertexAttrib* fVAPtr; | 167 const GrVertexAttrib* fVAPtr; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 242 |
| 243 /////////////////////////////////////////////////////////////////////////// | 243 /////////////////////////////////////////////////////////////////////////// |
| 244 /// @name Color | 244 /// @name Color |
| 245 //// | 245 //// |
| 246 | 246 |
| 247 /** | 247 /** |
| 248 * Sets color for next draw to a premultiplied-alpha color. | 248 * Sets color for next draw to a premultiplied-alpha color. |
| 249 * | 249 * |
| 250 * @param color the color to set. | 250 * @param color the color to set. |
| 251 */ | 251 */ |
| 252 void setColor(GrColor color) { fCommon.fColor = color; } | 252 void setColor(GrColor color) { fColor = color; } |
| 253 | 253 |
| 254 GrColor getColor() const { return fCommon.fColor; } | 254 GrColor getColor() const { return fColor; } |
| 255 | 255 |
| 256 /** | 256 /** |
| 257 * Sets the color to be used for the next draw to be | 257 * Sets the color to be used for the next draw to be |
| 258 * (r,g,b,a) = (alpha, alpha, alpha, alpha). | 258 * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
| 259 * | 259 * |
| 260 * @param alpha The alpha value to set as the color. | 260 * @param alpha The alpha value to set as the color. |
| 261 */ | 261 */ |
| 262 void setAlpha(uint8_t a) { | 262 void setAlpha(uint8_t a) { |
| 263 this->setColor((a << 24) | (a << 16) | (a << 8) | a); | 263 this->setColor((a << 24) | (a << 16) | (a << 8) | a); |
| 264 } | 264 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 /////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////// |
| 301 /// @name Coverage | 301 /// @name Coverage |
| 302 //// | 302 //// |
| 303 | 303 |
| 304 /** | 304 /** |
| 305 * Sets a constant fractional coverage to be applied to the draw. The | 305 * Sets a constant fractional coverage to be applied to the draw. The |
| 306 * initial value (after construction or reset()) is 0xff. The constant | 306 * initial value (after construction or reset()) is 0xff. The constant |
| 307 * coverage is ignored when per-vertex coverage is provided. | 307 * coverage is ignored when per-vertex coverage is provided. |
| 308 */ | 308 */ |
| 309 void setCoverage(uint8_t coverage) { | 309 void setCoverage(uint8_t coverage) { |
| 310 fCommon.fCoverage = GrColorPackRGBA(coverage, coverage, coverage, covera
ge); | 310 fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
| 311 } | 311 } |
| 312 | 312 |
| 313 uint8_t getCoverage() const { | 313 uint8_t getCoverage() const { |
| 314 return GrColorUnpackR(fCommon.fCoverage); | 314 return GrColorUnpackR(fCoverage); |
| 315 } | 315 } |
| 316 | 316 |
| 317 GrColor getCoverageColor() const { | 317 GrColor getCoverageColor() const { |
| 318 return fCommon.fCoverage; | 318 return fCoverage; |
| 319 } | 319 } |
| 320 | 320 |
| 321 /// @} | 321 /// @} |
| 322 | 322 |
| 323 /////////////////////////////////////////////////////////////////////////// | 323 /////////////////////////////////////////////////////////////////////////// |
| 324 /// @name Effect Stages | 324 /// @name Effect Stages |
| 325 /// Each stage hosts a GrEffect. The effect produces an output color or cove
rage in the fragment | 325 /// Each stage hosts a GrEffect. The effect produces an output color or cove
rage in the fragment |
| 326 /// shader. Its inputs are the output from the previous stage as well as som
e variables | 326 /// shader. Its inputs are the output from the previous stage as well as som
e variables |
| 327 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | 327 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, |
| 328 /// the fragment position, local coordinates). | 328 /// the fragment position, local coordinates). |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 * D' = sat(S*srcCoef + D*dstCoef) | 444 * D' = sat(S*srcCoef + D*dstCoef) |
| 445 * | 445 * |
| 446 * where D is the existing destination color, S is the incoming source | 446 * where D is the existing destination color, S is the incoming source |
| 447 * color, and D' is the new destination color that will be written. sat() | 447 * color, and D' is the new destination color that will be written. sat() |
| 448 * is the saturation function. | 448 * is the saturation function. |
| 449 * | 449 * |
| 450 * @param srcCoef coefficient applied to the src color. | 450 * @param srcCoef coefficient applied to the src color. |
| 451 * @param dstCoef coefficient applied to the dst color. | 451 * @param dstCoef coefficient applied to the dst color. |
| 452 */ | 452 */ |
| 453 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 453 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
| 454 fCommon.fSrcBlend = srcCoeff; | 454 fSrcBlend = srcCoeff; |
| 455 fCommon.fDstBlend = dstCoeff; | 455 fDstBlend = dstCoeff; |
| 456 #ifdef SK_DEBUG | 456 #ifdef SK_DEBUG |
| 457 if (GrBlendCoeffRefsDst(dstCoeff)) { | 457 if (GrBlendCoeffRefsDst(dstCoeff)) { |
| 458 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove
rage stages.\n"); | 458 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove
rage stages.\n"); |
| 459 } | 459 } |
| 460 if (GrBlendCoeffRefsSrc(srcCoeff)) { | 460 if (GrBlendCoeffRefsSrc(srcCoeff)) { |
| 461 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove
rage stages.\n"); | 461 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove
rage stages.\n"); |
| 462 } | 462 } |
| 463 #endif | 463 #endif |
| 464 } | 464 } |
| 465 | 465 |
| 466 GrBlendCoeff getSrcBlendCoeff() const { return fCommon.fSrcBlend; } | 466 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; } |
| 467 GrBlendCoeff getDstBlendCoeff() const { return fCommon.fDstBlend; } | 467 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; } |
| 468 | 468 |
| 469 void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff, | 469 void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff, |
| 470 GrBlendCoeff* dstBlendCoeff) const { | 470 GrBlendCoeff* dstBlendCoeff) const { |
| 471 *srcBlendCoeff = fCommon.fSrcBlend; | 471 *srcBlendCoeff = fSrcBlend; |
| 472 *dstBlendCoeff = fCommon.fDstBlend; | 472 *dstBlendCoeff = fDstBlend; |
| 473 } | 473 } |
| 474 | 474 |
| 475 /** | 475 /** |
| 476 * Sets the blending function constant referenced by the following blending | 476 * Sets the blending function constant referenced by the following blending |
| 477 * coefficients: | 477 * coefficients: |
| 478 * kConstC_GrBlendCoeff | 478 * kConstC_GrBlendCoeff |
| 479 * kIConstC_GrBlendCoeff | 479 * kIConstC_GrBlendCoeff |
| 480 * kConstA_GrBlendCoeff | 480 * kConstA_GrBlendCoeff |
| 481 * kIConstA_GrBlendCoeff | 481 * kIConstA_GrBlendCoeff |
| 482 * | 482 * |
| 483 * @param constant the constant to set | 483 * @param constant the constant to set |
| 484 */ | 484 */ |
| 485 void setBlendConstant(GrColor constant) { fCommon.fBlendConstant = constant;
} | 485 void setBlendConstant(GrColor constant) { fBlendConstant = constant; } |
| 486 | 486 |
| 487 /** | 487 /** |
| 488 * Retrieves the last value set by setBlendConstant() | 488 * Retrieves the last value set by setBlendConstant() |
| 489 * @return the blending constant value | 489 * @return the blending constant value |
| 490 */ | 490 */ |
| 491 GrColor getBlendConstant() const { return fCommon.fBlendConstant; } | 491 GrColor getBlendConstant() const { return fBlendConstant; } |
| 492 | 492 |
| 493 /** | 493 /** |
| 494 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 494 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional |
| 495 * coverage before the blend will give the correct final destination color.
In general it | 495 * coverage before the blend will give the correct final destination color.
In general it |
| 496 * will not as coverage is applied after blending. | 496 * will not as coverage is applied after blending. |
| 497 */ | 497 */ |
| 498 bool canTweakAlphaForCoverage() const; | 498 bool canTweakAlphaForCoverage() const; |
| 499 | 499 |
| 500 /** | 500 /** |
| 501 * Optimizations for blending / coverage to that can be applied based on the
current state. | 501 * Optimizations for blending / coverage to that can be applied based on the
current state. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 /** | 553 /** |
| 554 * Sets the view matrix to identity and updates any installed effects to com
pensate for the | 554 * Sets the view matrix to identity and updates any installed effects to com
pensate for the |
| 555 * coord system change. | 555 * coord system change. |
| 556 */ | 556 */ |
| 557 bool setIdentityViewMatrix(); | 557 bool setIdentityViewMatrix(); |
| 558 | 558 |
| 559 /** | 559 /** |
| 560 * Retrieves the current view matrix | 560 * Retrieves the current view matrix |
| 561 * @return the current view matrix. | 561 * @return the current view matrix. |
| 562 */ | 562 */ |
| 563 const SkMatrix& getViewMatrix() const { return fCommon.fViewMatrix; } | 563 const SkMatrix& getViewMatrix() const { return fViewMatrix; } |
| 564 | 564 |
| 565 /** | 565 /** |
| 566 * Retrieves the inverse of the current view matrix. | 566 * Retrieves the inverse of the current view matrix. |
| 567 * | 567 * |
| 568 * If the current view matrix is invertible, return true, and if matrix | 568 * If the current view matrix is invertible, return true, and if matrix |
| 569 * is non-null, copy the inverse into it. If the current view matrix is | 569 * is non-null, copy the inverse into it. If the current view matrix is |
| 570 * non-invertible, return false and ignore the matrix parameter. | 570 * non-invertible, return false and ignore the matrix parameter. |
| 571 * | 571 * |
| 572 * @param matrix if not null, will receive a copy of the current inverse. | 572 * @param matrix if not null, will receive a copy of the current inverse. |
| 573 */ | 573 */ |
| 574 bool getViewInverse(SkMatrix* matrix) const { | 574 bool getViewInverse(SkMatrix* matrix) const { |
| 575 // TODO: determine whether we really need to leave matrix unmodified | 575 // TODO: determine whether we really need to leave matrix unmodified |
| 576 // at call sites when inversion fails. | 576 // at call sites when inversion fails. |
| 577 SkMatrix inverse; | 577 SkMatrix inverse; |
| 578 if (fCommon.fViewMatrix.invert(&inverse)) { | 578 if (fViewMatrix.invert(&inverse)) { |
| 579 if (matrix) { | 579 if (matrix) { |
| 580 *matrix = inverse; | 580 *matrix = inverse; |
| 581 } | 581 } |
| 582 return true; | 582 return true; |
| 583 } | 583 } |
| 584 return false; | 584 return false; |
| 585 } | 585 } |
| 586 | 586 |
| 587 //////////////////////////////////////////////////////////////////////////// | 587 //////////////////////////////////////////////////////////////////////////// |
| 588 | 588 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 //// | 685 //// |
| 686 | 686 |
| 687 /** | 687 /** |
| 688 * Sets the stencil settings to use for the next draw. | 688 * Sets the stencil settings to use for the next draw. |
| 689 * Changing the clip has the side-effect of possibly zeroing | 689 * Changing the clip has the side-effect of possibly zeroing |
| 690 * out the client settable stencil bits. So multipass algorithms | 690 * out the client settable stencil bits. So multipass algorithms |
| 691 * using stencil should not change the clip between passes. | 691 * using stencil should not change the clip between passes. |
| 692 * @param settings the stencil settings to use. | 692 * @param settings the stencil settings to use. |
| 693 */ | 693 */ |
| 694 void setStencil(const GrStencilSettings& settings) { | 694 void setStencil(const GrStencilSettings& settings) { |
| 695 fCommon.fStencilSettings = settings; | 695 fStencilSettings = settings; |
| 696 } | 696 } |
| 697 | 697 |
| 698 /** | 698 /** |
| 699 * Shortcut to disable stencil testing and ops. | 699 * Shortcut to disable stencil testing and ops. |
| 700 */ | 700 */ |
| 701 void disableStencil() { | 701 void disableStencil() { |
| 702 fCommon.fStencilSettings.setDisabled(); | 702 fStencilSettings.setDisabled(); |
| 703 } | 703 } |
| 704 | 704 |
| 705 const GrStencilSettings& getStencil() const { return fCommon.fStencilSetting
s; } | 705 const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 706 | 706 |
| 707 GrStencilSettings* stencil() { return &fCommon.fStencilSettings; } | 707 GrStencilSettings* stencil() { return &fStencilSettings; } |
| 708 | 708 |
| 709 /// @} | 709 /// @} |
| 710 | 710 |
| 711 /////////////////////////////////////////////////////////////////////////// | 711 /////////////////////////////////////////////////////////////////////////// |
| 712 /// @name State Flags | 712 /// @name State Flags |
| 713 //// | 713 //// |
| 714 | 714 |
| 715 /** | 715 /** |
| 716 * Flags that affect rendering. Controlled using enable/disableState(). All | 716 * Flags that affect rendering. Controlled using enable/disableState(). All |
| 717 * default to disabled. | 717 * default to disabled. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 746 * setBlendFunc() which will use coverage*color as the src color. | 746 * setBlendFunc() which will use coverage*color as the src color. |
| 747 */ | 747 */ |
| 748 kCoverageDrawing_StateBit = 0x10, | 748 kCoverageDrawing_StateBit = 0x10, |
| 749 | 749 |
| 750 // Users of the class may add additional bits to the vector | 750 // Users of the class may add additional bits to the vector |
| 751 kDummyStateBit, | 751 kDummyStateBit, |
| 752 kLastPublicStateBit = kDummyStateBit-1, | 752 kLastPublicStateBit = kDummyStateBit-1, |
| 753 }; | 753 }; |
| 754 | 754 |
| 755 void resetStateFlags() { | 755 void resetStateFlags() { |
| 756 fCommon.fFlagBits = 0; | 756 fFlagBits = 0; |
| 757 } | 757 } |
| 758 | 758 |
| 759 /** | 759 /** |
| 760 * Enable render state settings. | 760 * Enable render state settings. |
| 761 * | 761 * |
| 762 * @param stateBits bitfield of StateBits specifying the states to enable | 762 * @param stateBits bitfield of StateBits specifying the states to enable |
| 763 */ | 763 */ |
| 764 void enableState(uint32_t stateBits) { | 764 void enableState(uint32_t stateBits) { |
| 765 fCommon.fFlagBits |= stateBits; | 765 fFlagBits |= stateBits; |
| 766 } | 766 } |
| 767 | 767 |
| 768 /** | 768 /** |
| 769 * Disable render state settings. | 769 * Disable render state settings. |
| 770 * | 770 * |
| 771 * @param stateBits bitfield of StateBits specifying the states to disable | 771 * @param stateBits bitfield of StateBits specifying the states to disable |
| 772 */ | 772 */ |
| 773 void disableState(uint32_t stateBits) { | 773 void disableState(uint32_t stateBits) { |
| 774 fCommon.fFlagBits &= ~(stateBits); | 774 fFlagBits &= ~(stateBits); |
| 775 } | 775 } |
| 776 | 776 |
| 777 /** | 777 /** |
| 778 * Enable or disable stateBits based on a boolean. | 778 * Enable or disable stateBits based on a boolean. |
| 779 * | 779 * |
| 780 * @param stateBits bitfield of StateBits to enable or disable | 780 * @param stateBits bitfield of StateBits to enable or disable |
| 781 * @param enable if true enable stateBits, otherwise disable | 781 * @param enable if true enable stateBits, otherwise disable |
| 782 */ | 782 */ |
| 783 void setState(uint32_t stateBits, bool enable) { | 783 void setState(uint32_t stateBits, bool enable) { |
| 784 if (enable) { | 784 if (enable) { |
| 785 this->enableState(stateBits); | 785 this->enableState(stateBits); |
| 786 } else { | 786 } else { |
| 787 this->disableState(stateBits); | 787 this->disableState(stateBits); |
| 788 } | 788 } |
| 789 } | 789 } |
| 790 | 790 |
| 791 bool isDitherState() const { | 791 bool isDitherState() const { |
| 792 return 0 != (fCommon.fFlagBits & kDither_StateBit); | 792 return 0 != (fFlagBits & kDither_StateBit); |
| 793 } | 793 } |
| 794 | 794 |
| 795 bool isHWAntialiasState() const { | 795 bool isHWAntialiasState() const { |
| 796 return 0 != (fCommon.fFlagBits & kHWAntialias_StateBit); | 796 return 0 != (fFlagBits & kHWAntialias_StateBit); |
| 797 } | 797 } |
| 798 | 798 |
| 799 bool isClipState() const { | 799 bool isClipState() const { |
| 800 return 0 != (fCommon.fFlagBits & kClip_StateBit); | 800 return 0 != (fFlagBits & kClip_StateBit); |
| 801 } | 801 } |
| 802 | 802 |
| 803 bool isColorWriteDisabled() const { | 803 bool isColorWriteDisabled() const { |
| 804 return 0 != (fCommon.fFlagBits & kNoColorWrites_StateBit); | 804 return 0 != (fFlagBits & kNoColorWrites_StateBit); |
| 805 } | 805 } |
| 806 | 806 |
| 807 bool isCoverageDrawing() const { | 807 bool isCoverageDrawing() const { |
| 808 return 0 != (fCommon.fFlagBits & kCoverageDrawing_StateBit); | 808 return 0 != (fFlagBits & kCoverageDrawing_StateBit); |
| 809 } | 809 } |
| 810 | 810 |
| 811 bool isStateFlagEnabled(uint32_t stateBit) const { | 811 bool isStateFlagEnabled(uint32_t stateBit) const { |
| 812 return 0 != (stateBit & fCommon.fFlagBits); | 812 return 0 != (stateBit & fFlagBits); |
| 813 } | 813 } |
| 814 | 814 |
| 815 /// @} | 815 /// @} |
| 816 | 816 |
| 817 /////////////////////////////////////////////////////////////////////////// | 817 /////////////////////////////////////////////////////////////////////////// |
| 818 /// @name Face Culling | 818 /// @name Face Culling |
| 819 //// | 819 //// |
| 820 | 820 |
| 821 enum DrawFace { | 821 enum DrawFace { |
| 822 kInvalid_DrawFace = -1, | 822 kInvalid_DrawFace = -1, |
| 823 | 823 |
| 824 kBoth_DrawFace, | 824 kBoth_DrawFace, |
| 825 kCCW_DrawFace, | 825 kCCW_DrawFace, |
| 826 kCW_DrawFace, | 826 kCW_DrawFace, |
| 827 }; | 827 }; |
| 828 | 828 |
| 829 /** | 829 /** |
| 830 * Controls whether clockwise, counterclockwise, or both faces are drawn. | 830 * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 831 * @param face the face(s) to draw. | 831 * @param face the face(s) to draw. |
| 832 */ | 832 */ |
| 833 void setDrawFace(DrawFace face) { | 833 void setDrawFace(DrawFace face) { |
| 834 SkASSERT(kInvalid_DrawFace != face); | 834 SkASSERT(kInvalid_DrawFace != face); |
| 835 fCommon.fDrawFace = face; | 835 fDrawFace = face; |
| 836 } | 836 } |
| 837 | 837 |
| 838 /** | 838 /** |
| 839 * Gets whether the target is drawing clockwise, counterclockwise, | 839 * Gets whether the target is drawing clockwise, counterclockwise, |
| 840 * or both faces. | 840 * or both faces. |
| 841 * @return the current draw face(s). | 841 * @return the current draw face(s). |
| 842 */ | 842 */ |
| 843 DrawFace getDrawFace() const { return fCommon.fDrawFace; } | 843 DrawFace getDrawFace() const { return fDrawFace; } |
| 844 | 844 |
| 845 /// @} | 845 /// @} |
| 846 | 846 |
| 847 /////////////////////////////////////////////////////////////////////////// | 847 /////////////////////////////////////////////////////////////////////////// |
| 848 | 848 |
| 849 bool operator ==(const GrDrawState& s) const { | 849 bool operator ==(const GrDrawState& that) const { |
| 850 if (fRenderTarget.get() != s.fRenderTarget.get() || | 850 if (fRenderTarget.get() != that.fRenderTarget.get() || |
| 851 fColorStages.count() != s.fColorStages.count() || | 851 fColorStages.count() != that.fColorStages.count() || |
| 852 fCoverageStages.count() != s.fCoverageStages.count() || | 852 fCoverageStages.count() != that.fCoverageStages.count() || |
| 853 fCommon != s.fCommon) { | 853 fColor != that.fColor || |
| 854 !fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
| 855 fSrcBlend != that.fSrcBlend || |
| 856 fDstBlend != that.fDstBlend || |
| 857 fBlendConstant != that.fBlendConstant || |
| 858 fFlagBits != that.fFlagBits || |
| 859 fVACount != that.fVACount || |
| 860 memcmp(fVAPtr, that.fVAPtr, fVACount * sizeof(GrVertexAttrib)) || |
| 861 fStencilSettings != that.fStencilSettings || |
| 862 fCoverage != that.fCoverage || |
| 863 fDrawFace != that.fDrawFace) { |
| 854 return false; | 864 return false; |
| 855 } | 865 } |
| 856 for (int i = 0; i < fColorStages.count(); i++) { | 866 for (int i = 0; i < fColorStages.count(); i++) { |
| 857 if (fColorStages[i] != s.fColorStages[i]) { | 867 if (fColorStages[i] != that.fColorStages[i]) { |
| 858 return false; | 868 return false; |
| 859 } | 869 } |
| 860 } | 870 } |
| 861 for (int i = 0; i < fCoverageStages.count(); i++) { | 871 for (int i = 0; i < fCoverageStages.count(); i++) { |
| 862 if (fCoverageStages[i] != s.fCoverageStages[i]) { | 872 if (fCoverageStages[i] != that.fCoverageStages[i]) { |
| 863 return false; | 873 return false; |
| 864 } | 874 } |
| 865 } | 875 } |
| 876 SkASSERT(0 == memcmp(fFixedFunctionVertexAttribIndices, |
| 877 that.fFixedFunctionVertexAttribIndices, |
| 878 sizeof(fFixedFunctionVertexAttribIndices))); |
| 866 return true; | 879 return true; |
| 867 } | 880 } |
| 868 bool operator !=(const GrDrawState& s) const { return !(*this == s); } | 881 bool operator !=(const GrDrawState& s) const { return !(*this == s); } |
| 869 | 882 |
| 870 GrDrawState& operator= (const GrDrawState& s) { | 883 GrDrawState& operator= (const GrDrawState& that) { |
| 871 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 884 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 872 this->setRenderTarget(s.fRenderTarget.get()); | 885 this->setRenderTarget(that.fRenderTarget.get()); |
| 873 fCommon = s.fCommon; | 886 fColor = that.fColor; |
| 874 fColorStages = s.fColorStages; | 887 fViewMatrix = that.fViewMatrix; |
| 875 fCoverageStages = s.fCoverageStages; | 888 fSrcBlend = that.fSrcBlend; |
| 889 fDstBlend = that.fDstBlend; |
| 890 fBlendConstant = that.fBlendConstant; |
| 891 fFlagBits = that.fFlagBits; |
| 892 fVACount = that.fVACount; |
| 893 fVAPtr = that.fVAPtr; |
| 894 fStencilSettings = that.fStencilSettings; |
| 895 fCoverage = that.fCoverage; |
| 896 fDrawFace = that.fDrawFace; |
| 897 fColorStages = that.fColorStages; |
| 898 fCoverageStages = that.fCoverageStages; |
| 899 |
| 900 memcpy(fFixedFunctionVertexAttribIndices, |
| 901 that.fFixedFunctionVertexAttribIndices, |
| 902 sizeof(fFixedFunctionVertexAttribIndices)); |
| 876 return *this; | 903 return *this; |
| 877 } | 904 } |
| 878 | 905 |
| 879 private: | 906 private: |
| 880 | 907 |
| 881 void onReset(const SkMatrix* initialViewMatrix) { | 908 void onReset(const SkMatrix* initialViewMatrix) { |
| 882 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 909 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 883 fColorStages.reset(); | 910 fColorStages.reset(); |
| 884 fCoverageStages.reset(); | 911 fCoverageStages.reset(); |
| 885 | 912 |
| 886 fRenderTarget.reset(NULL); | 913 fRenderTarget.reset(NULL); |
| 887 | 914 |
| 888 this->setDefaultVertexAttribs(); | 915 this->setDefaultVertexAttribs(); |
| 889 | 916 |
| 890 fCommon.fColor = 0xffffffff; | 917 fColor = 0xffffffff; |
| 891 if (NULL == initialViewMatrix) { | 918 if (NULL == initialViewMatrix) { |
| 892 fCommon.fViewMatrix.reset(); | 919 fViewMatrix.reset(); |
| 893 } else { | 920 } else { |
| 894 fCommon.fViewMatrix = *initialViewMatrix; | 921 fViewMatrix = *initialViewMatrix; |
| 895 } | 922 } |
| 896 fCommon.fSrcBlend = kOne_GrBlendCoeff; | 923 fSrcBlend = kOne_GrBlendCoeff; |
| 897 fCommon.fDstBlend = kZero_GrBlendCoeff; | 924 fDstBlend = kZero_GrBlendCoeff; |
| 898 fCommon.fBlendConstant = 0x0; | 925 fBlendConstant = 0x0; |
| 899 fCommon.fFlagBits = 0x0; | 926 fFlagBits = 0x0; |
| 900 fCommon.fStencilSettings.setDisabled(); | 927 fStencilSettings.setDisabled(); |
| 901 fCommon.fCoverage = 0xffffffff; | 928 fCoverage = 0xffffffff; |
| 902 fCommon.fDrawFace = kBoth_DrawFace; | 929 fDrawFace = kBoth_DrawFace; |
| 903 } | 930 } |
| 904 | 931 |
| 905 /** This will be removed soon. The fields will become members of GrDrawState
. */ | |
| 906 struct CommonState { | |
| 907 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== | |
| 908 GrColor fColor; | |
| 909 SkMatrix fViewMatrix; | |
| 910 GrBlendCoeff fSrcBlend; | |
| 911 GrBlendCoeff fDstBlend; | |
| 912 GrColor fBlendConstant; | |
| 913 uint32_t fFlagBits; | |
| 914 const GrVertexAttrib* fVAPtr; | |
| 915 int fVACount; | |
| 916 GrStencilSettings fStencilSettings; | |
| 917 GrColor fCoverage; | |
| 918 DrawFace fDrawFace; | |
| 919 | 932 |
| 920 // This is simply a different representation of info in fVertexAttribs a
nd thus does | 933 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== |
| 921 // not need to be compared in op==. | |
| 922 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindin
gCnt]; | |
| 923 | |
| 924 bool operator== (const CommonState& other) const { | |
| 925 bool result = fColor == other.fColor && | |
| 926 fViewMatrix.cheapEqualTo(other.fViewMatrix) && | |
| 927 fSrcBlend == other.fSrcBlend && | |
| 928 fDstBlend == other.fDstBlend && | |
| 929 fBlendConstant == other.fBlendConstant && | |
| 930 fFlagBits == other.fFlagBits && | |
| 931 fVACount == other.fVACount && | |
| 932 !memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVert
exAttrib)) && | |
| 933 fStencilSettings == other.fStencilSettings && | |
| 934 fCoverage == other.fCoverage && | |
| 935 fDrawFace == other.fDrawFace; | |
| 936 SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, | |
| 937 other.fFixedFunctionVertexAttribIndi
ces, | |
| 938 sizeof(fFixedFunctionVertexAttribInd
ices))); | |
| 939 return result; | |
| 940 } | |
| 941 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } | |
| 942 }; | |
| 943 | |
| 944 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 934 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 945 CommonState fCommon; | 935 GrColor fColor; |
| 936 SkMatrix fViewMatrix; |
| 937 GrBlendCoeff fSrcBlend; |
| 938 GrBlendCoeff fDstBlend; |
| 939 GrColor fBlendConstant; |
| 940 uint32_t fFlagBits; |
| 941 const GrVertexAttrib* fVAPtr; |
| 942 int fVACount; |
| 943 GrStencilSettings fStencilSettings; |
| 944 GrColor fCoverage; |
| 945 DrawFace fDrawFace; |
| 946 | 946 |
| 947 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 947 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
| 948 EffectStageArray fColorStages; | 948 EffectStageArray fColorStages; |
| 949 EffectStageArray fCoverageStages; | 949 EffectStageArray fCoverageStages; |
| 950 | 950 |
| 951 // This is simply a different representation of info in fVertexAttribs and t
hus does |
| 952 // not need to be compared in op==. |
| 953 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; |
| 954 |
| 951 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 955 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 952 // This is used to assert that this condition holds. | 956 // This is used to assert that this condition holds. |
| 953 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 957 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 954 | 958 |
| 955 /** | 959 /** |
| 956 * Sets vertex attributes for next draw. | 960 * Sets vertex attributes for next draw. |
| 957 * | 961 * |
| 958 * @param attribs the array of vertex attributes to set. | 962 * @param attribs the array of vertex attributes to set. |
| 959 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | 963 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
| 960 */ | 964 */ |
| 961 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 965 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
| 962 | 966 |
| 963 typedef SkRefCnt INHERITED; | 967 typedef SkRefCnt INHERITED; |
| 964 }; | 968 }; |
| 965 | 969 |
| 966 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 970 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
| 967 | 971 |
| 968 #endif | 972 #endif |
| OLD | NEW |