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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) { | 52 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) { |
53 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 53 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
54 *this = state; | 54 *this = state; |
55 if (!preConcatMatrix.isIdentity()) { | 55 if (!preConcatMatrix.isIdentity()) { |
56 for (int i = 0; i < fColorStages.count(); ++i) { | 56 for (int i = 0; i < fColorStages.count(); ++i) { |
57 fColorStages[i].localCoordChange(preConcatMatrix); | 57 fColorStages[i].localCoordChange(preConcatMatrix); |
58 } | 58 } |
59 for (int i = 0; i < fCoverageStages.count(); ++i) { | 59 for (int i = 0; i < fCoverageStages.count(); ++i) { |
60 fCoverageStages[i].localCoordChange(preConcatMatrix); | 60 fCoverageStages[i].localCoordChange(preConcatMatrix); |
61 } | 61 } |
62 fBlendOptFlags = kInvalid_BlendOptFlag; | |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } | 66 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } |
66 | 67 |
67 /** | 68 /** |
68 * Resets to the default state. GrEffects will be removed from all stages. | 69 * Resets to the default state. GrEffects will be removed from all stages. |
69 */ | 70 */ |
70 void reset() { this->onReset(NULL); } | 71 void reset() { this->onReset(NULL); } |
71 | 72 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 /// @name Coverage | 302 /// @name Coverage |
302 //// | 303 //// |
303 | 304 |
304 /** | 305 /** |
305 * Sets a constant fractional coverage to be applied to the draw. The | 306 * Sets a constant fractional coverage to be applied to the draw. The |
306 * initial value (after construction or reset()) is 0xff. The constant | 307 * initial value (after construction or reset()) is 0xff. The constant |
307 * coverage is ignored when per-vertex coverage is provided. | 308 * coverage is ignored when per-vertex coverage is provided. |
308 */ | 309 */ |
309 void setCoverage(uint8_t coverage) { | 310 void setCoverage(uint8_t coverage) { |
310 fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); | 311 fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
312 fBlendOptFlags = kInvalid_BlendOptFlag; | |
311 } | 313 } |
312 | 314 |
313 uint8_t getCoverage() const { | 315 uint8_t getCoverage() const { |
314 return GrColorUnpackR(fCoverage); | 316 return GrColorUnpackR(fCoverage); |
315 } | 317 } |
316 | 318 |
317 GrColor getCoverageColor() const { | 319 GrColor getCoverageColor() const { |
318 return fCoverage; | 320 return fCoverage; |
319 } | 321 } |
320 | 322 |
(...skipping 15 matching lines...) Expand all Loading... | |
336 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage | 338 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage |
337 /// (usually full-coverage) or interpolated per-vertex coverage. | 339 /// (usually full-coverage) or interpolated per-vertex coverage. |
338 /// | 340 /// |
339 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the | 341 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the |
340 /// the color / coverage distinction. | 342 /// the color / coverage distinction. |
341 //// | 343 //// |
342 | 344 |
343 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) { | 345 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) { |
344 SkASSERT(NULL != effect); | 346 SkASSERT(NULL != effect); |
345 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); | 347 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); |
348 fBlendOptFlags = kInvalid_BlendOptFlag; | |
346 return effect; | 349 return effect; |
347 } | 350 } |
348 | 351 |
349 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) { | 352 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) { |
350 SkASSERT(NULL != effect); | 353 SkASSERT(NULL != effect); |
351 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); | 354 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); |
355 fBlendOptFlags = kInvalid_BlendOptFlag; | |
352 return effect; | 356 return effect; |
353 } | 357 } |
354 | 358 |
355 /** | 359 /** |
356 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates. | 360 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates. |
357 */ | 361 */ |
358 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 362 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { |
359 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref(); | 363 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref(); |
360 } | 364 } |
361 | 365 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 * 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 |
443 * 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() |
444 * is the saturation function. | 448 * is the saturation function. |
445 * | 449 * |
446 * @param srcCoef coefficient applied to the src color. | 450 * @param srcCoef coefficient applied to the src color. |
447 * @param dstCoef coefficient applied to the dst color. | 451 * @param dstCoef coefficient applied to the dst color. |
448 */ | 452 */ |
449 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 453 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
450 fSrcBlend = srcCoeff; | 454 fSrcBlend = srcCoeff; |
451 fDstBlend = dstCoeff; | 455 fDstBlend = dstCoeff; |
456 fBlendOptFlags = kInvalid_BlendOptFlag; | |
452 #ifdef SK_DEBUG | 457 #ifdef SK_DEBUG |
453 if (GrBlendCoeffRefsDst(dstCoeff)) { | 458 if (GrBlendCoeffRefsDst(dstCoeff)) { |
454 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); | 459 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); |
455 } | 460 } |
456 if (GrBlendCoeffRefsSrc(srcCoeff)) { | 461 if (GrBlendCoeffRefsSrc(srcCoeff)) { |
457 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); | 462 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); |
458 } | 463 } |
459 #endif | 464 #endif |
460 } | 465 } |
461 | 466 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 kCoverageAsAlpha_BlendOptFlag = 0x4, | 521 kCoverageAsAlpha_BlendOptFlag = 0x4, |
517 /** | 522 /** |
518 * Instead of emitting a src color, emit coverage in the alpha channel a nd r,g,b are | 523 * Instead of emitting a src color, emit coverage in the alpha channel a nd r,g,b are |
519 * "don't cares". | 524 * "don't cares". |
520 */ | 525 */ |
521 kEmitCoverage_BlendOptFlag = 0x8, | 526 kEmitCoverage_BlendOptFlag = 0x8, |
522 /** | 527 /** |
523 * Emit transparent black instead of the src color, no need to compute c overage. | 528 * Emit transparent black instead of the src color, no need to compute c overage. |
524 */ | 529 */ |
525 kEmitTransBlack_BlendOptFlag = 0x10, | 530 kEmitTransBlack_BlendOptFlag = 0x10, |
531 /** | |
532 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by | |
533 * the get BlendOpts function. | |
534 */ | |
535 kInvalid_BlendOptFlag = 0x20, | |
526 }; | 536 }; |
527 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | 537 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
528 | 538 |
529 /** | 539 /** |
530 * Determines what optimizations can be applied based on the blend. The coef ficients may have | 540 * Determines what optimizations can be applied based on the blend. The coef ficients may have |
531 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional | 541 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional |
532 * params that receive the tweaked coefficients. Normally the function looks at the current | 542 * params that receive the tweaked coefficients. Normally the function looks at the current |
533 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively | 543 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively |
534 * determine the blend optimizations that would be used if there was partial pixel coverage. | 544 * determine the blend optimizations that would be used if there was partial pixel coverage. |
535 * | 545 * |
536 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for | 546 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for |
537 * playback) must call this function and respect the flags that replace the output color. | 547 * playback) must call this function and respect the flags that replace the output color. |
548 * | |
549 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will | |
550 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values. | |
538 */ | 551 */ |
539 BlendOptFlags getBlendOpts(bool forceCoverage = false, | 552 BlendOptFlags getBlendOpts(bool forceCoverage = false, |
540 GrBlendCoeff* srcCoeff = NULL, | 553 GrBlendCoeff* srcCoeff = NULL, |
541 GrBlendCoeff* dstCoeff = NULL) const; | 554 GrBlendCoeff* dstCoeff = NULL) const; |
542 | 555 |
543 /// @} | 556 /// @} |
544 | 557 |
545 /////////////////////////////////////////////////////////////////////////// | 558 /////////////////////////////////////////////////////////////////////////// |
546 /// @name View Matrix | 559 /// @name View Matrix |
547 //// | 560 //// |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 | 695 |
683 /** | 696 /** |
684 * Sets the stencil settings to use for the next draw. | 697 * Sets the stencil settings to use for the next draw. |
685 * Changing the clip has the side-effect of possibly zeroing | 698 * Changing the clip has the side-effect of possibly zeroing |
686 * out the client settable stencil bits. So multipass algorithms | 699 * out the client settable stencil bits. So multipass algorithms |
687 * using stencil should not change the clip between passes. | 700 * using stencil should not change the clip between passes. |
688 * @param settings the stencil settings to use. | 701 * @param settings the stencil settings to use. |
689 */ | 702 */ |
690 void setStencil(const GrStencilSettings& settings) { | 703 void setStencil(const GrStencilSettings& settings) { |
691 fStencilSettings = settings; | 704 fStencilSettings = settings; |
705 fBlendOptFlags = kInvalid_BlendOptFlag; | |
692 } | 706 } |
693 | 707 |
694 /** | 708 /** |
695 * Shortcut to disable stencil testing and ops. | 709 * Shortcut to disable stencil testing and ops. |
696 */ | 710 */ |
697 void disableStencil() { | 711 void disableStencil() { |
698 fStencilSettings.setDisabled(); | 712 fStencilSettings.setDisabled(); |
713 fBlendOptFlags = kInvalid_BlendOptFlag; | |
699 } | 714 } |
700 | 715 |
701 const GrStencilSettings& getStencil() const { return fStencilSettings; } | 716 const GrStencilSettings& getStencil() const { return fStencilSettings; } |
702 | 717 |
703 GrStencilSettings* stencil() { return &fStencilSettings; } | 718 GrStencilSettings* stencil() { return &fStencilSettings; } |
704 | 719 |
705 /// @} | 720 /// @} |
706 | 721 |
707 /////////////////////////////////////////////////////////////////////////// | 722 /////////////////////////////////////////////////////////////////////////// |
708 /// @name State Flags | 723 /// @name State Flags |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 */ | 758 */ |
744 kCoverageDrawing_StateBit = 0x10, | 759 kCoverageDrawing_StateBit = 0x10, |
745 | 760 |
746 // Users of the class may add additional bits to the vector | 761 // Users of the class may add additional bits to the vector |
747 kDummyStateBit, | 762 kDummyStateBit, |
748 kLastPublicStateBit = kDummyStateBit-1, | 763 kLastPublicStateBit = kDummyStateBit-1, |
749 }; | 764 }; |
750 | 765 |
751 void resetStateFlags() { | 766 void resetStateFlags() { |
752 fFlagBits = 0; | 767 fFlagBits = 0; |
768 fBlendOptFlags = kInvalid_BlendOptFlag; | |
753 } | 769 } |
754 | 770 |
755 /** | 771 /** |
756 * Enable render state settings. | 772 * Enable render state settings. |
757 * | 773 * |
758 * @param stateBits bitfield of StateBits specifying the states to enable | 774 * @param stateBits bitfield of StateBits specifying the states to enable |
759 */ | 775 */ |
760 void enableState(uint32_t stateBits) { | 776 void enableState(uint32_t stateBits) { |
761 fFlagBits |= stateBits; | 777 fFlagBits |= stateBits; |
778 fBlendOptFlags = kInvalid_BlendOptFlag; | |
762 } | 779 } |
763 | 780 |
764 /** | 781 /** |
765 * Disable render state settings. | 782 * Disable render state settings. |
766 * | 783 * |
767 * @param stateBits bitfield of StateBits specifying the states to disable | 784 * @param stateBits bitfield of StateBits specifying the states to disable |
768 */ | 785 */ |
769 void disableState(uint32_t stateBits) { | 786 void disableState(uint32_t stateBits) { |
770 fFlagBits &= ~(stateBits); | 787 fFlagBits &= ~(stateBits); |
788 fBlendOptFlags = kInvalid_BlendOptFlag; | |
771 } | 789 } |
772 | 790 |
773 /** | 791 /** |
774 * Enable or disable stateBits based on a boolean. | 792 * Enable or disable stateBits based on a boolean. |
775 * | 793 * |
776 * @param stateBits bitfield of StateBits to enable or disable | 794 * @param stateBits bitfield of StateBits to enable or disable |
777 * @param enable if true enable stateBits, otherwise disable | 795 * @param enable if true enable stateBits, otherwise disable |
778 */ | 796 */ |
779 void setState(uint32_t stateBits, bool enable) { | 797 void setState(uint32_t stateBits, bool enable) { |
780 if (enable) { | 798 if (enable) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
885 fDstBlend = that.fDstBlend; | 903 fDstBlend = that.fDstBlend; |
886 fBlendConstant = that.fBlendConstant; | 904 fBlendConstant = that.fBlendConstant; |
887 fFlagBits = that.fFlagBits; | 905 fFlagBits = that.fFlagBits; |
888 fVACount = that.fVACount; | 906 fVACount = that.fVACount; |
889 fVAPtr = that.fVAPtr; | 907 fVAPtr = that.fVAPtr; |
890 fStencilSettings = that.fStencilSettings; | 908 fStencilSettings = that.fStencilSettings; |
891 fCoverage = that.fCoverage; | 909 fCoverage = that.fCoverage; |
892 fDrawFace = that.fDrawFace; | 910 fDrawFace = that.fDrawFace; |
893 fColorStages = that.fColorStages; | 911 fColorStages = that.fColorStages; |
894 fCoverageStages = that.fCoverageStages; | 912 fCoverageStages = that.fCoverageStages; |
913 fOptSrcBlend = that.fOptSrcBlend; | |
914 fOptDstBlend = that.fOptDstBlend; | |
915 fBlendOptFlags = that.fBlendOptFlags; | |
895 | 916 |
896 memcpy(fFixedFunctionVertexAttribIndices, | 917 memcpy(fFixedFunctionVertexAttribIndices, |
897 that.fFixedFunctionVertexAttribIndices, | 918 that.fFixedFunctionVertexAttribIndices, |
898 sizeof(fFixedFunctionVertexAttribIndices)); | 919 sizeof(fFixedFunctionVertexAttribIndices)); |
899 return *this; | 920 return *this; |
900 } | 921 } |
901 | 922 |
902 private: | 923 private: |
903 | 924 |
904 void onReset(const SkMatrix* initialViewMatrix) { | 925 void onReset(const SkMatrix* initialViewMatrix) { |
(...skipping 11 matching lines...) Expand all Loading... | |
916 } else { | 937 } else { |
917 fViewMatrix = *initialViewMatrix; | 938 fViewMatrix = *initialViewMatrix; |
918 } | 939 } |
919 fSrcBlend = kOne_GrBlendCoeff; | 940 fSrcBlend = kOne_GrBlendCoeff; |
920 fDstBlend = kZero_GrBlendCoeff; | 941 fDstBlend = kZero_GrBlendCoeff; |
921 fBlendConstant = 0x0; | 942 fBlendConstant = 0x0; |
922 fFlagBits = 0x0; | 943 fFlagBits = 0x0; |
923 fStencilSettings.setDisabled(); | 944 fStencilSettings.setDisabled(); |
924 fCoverage = 0xffffffff; | 945 fCoverage = 0xffffffff; |
925 fDrawFace = kBoth_DrawFace; | 946 fDrawFace = kBoth_DrawFace; |
947 | |
948 fOptSrcBlend = kOne_GrBlendCoeff; | |
bsalomon
2014/07/17 18:41:03
Do we even need to set the blend flags here?
egdaniel
2014/07/17 19:35:50
By blend flags are you referring to the Src and Ds
| |
949 fOptDstBlend = kZero_GrBlendCoeff; | |
950 fBlendOptFlags = kInvalid_BlendOptFlag; | |
926 } | 951 } |
927 | 952 |
953 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | |
954 GrBlendCoeff* srcCoeff = NULL, | |
955 GrBlendCoeff* dstCoeff = NULL) const; | |
928 | 956 |
929 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== | 957 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== |
930 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 958 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
931 GrColor fColor; | 959 GrColor fColor; |
932 SkMatrix fViewMatrix; | 960 SkMatrix fViewMatrix; |
933 GrBlendCoeff fSrcBlend; | 961 GrBlendCoeff fSrcBlend; |
934 GrBlendCoeff fDstBlend; | 962 GrBlendCoeff fDstBlend; |
935 GrColor fBlendConstant; | 963 GrColor fBlendConstant; |
936 uint32_t fFlagBits; | 964 uint32_t fFlagBits; |
937 const GrVertexAttrib* fVAPtr; | 965 const GrVertexAttrib* fVAPtr; |
938 int fVACount; | 966 int fVACount; |
939 GrStencilSettings fStencilSettings; | 967 GrStencilSettings fStencilSettings; |
940 GrColor fCoverage; | 968 GrColor fCoverage; |
941 DrawFace fDrawFace; | 969 DrawFace fDrawFace; |
942 | 970 |
943 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 971 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
944 EffectStageArray fColorStages; | 972 EffectStageArray fColorStages; |
945 EffectStageArray fCoverageStages; | 973 EffectStageArray fCoverageStages; |
974 | |
975 mutable GrBlendCoeff fOptSrcBlend; | |
976 mutable GrBlendCoeff fOptDstBlend; | |
977 mutable BlendOptFlags fBlendOptFlags; | |
946 | 978 |
947 // This is simply a different representation of info in fVertexAttribs and t hus does | 979 // This is simply a different representation of info in fVertexAttribs and t hus does |
948 // not need to be compared in op==. | 980 // not need to be compared in op==. |
949 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; | 981 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; |
950 | 982 |
951 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. | 983 // 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. | 984 // This is used to assert that this condition holds. |
953 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 985 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
954 | 986 |
955 /** | 987 /** |
956 * Sets vertex attributes for next draw. | 988 * Sets vertex attributes for next draw. |
957 * | 989 * |
958 * @param attribs the array of vertex attributes to set. | 990 * @param attribs the array of vertex attributes to set. |
959 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. | 991 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. |
960 */ | 992 */ |
961 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 993 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
962 | 994 |
963 typedef SkRefCnt INHERITED; | 995 typedef SkRefCnt INHERITED; |
964 }; | 996 }; |
965 | 997 |
966 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 998 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
967 | 999 |
968 #endif | 1000 #endif |
OLD | NEW |