| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "GrDrawState.h" | 8 #include "GrDrawState.h" |
| 9 | 9 |
| 10 #include "GrInvariantOutput.h" |
| 10 #include "GrOptDrawState.h" | 11 #include "GrOptDrawState.h" |
| 11 #include "GrPaint.h" | 12 #include "GrPaint.h" |
| 12 | 13 |
| 13 //////////////////////////////////////////////////////////////////////////////s | 14 //////////////////////////////////////////////////////////////////////////////s |
| 14 | 15 |
| 15 bool GrDrawState::isEqual(const GrDrawState& that) const { | 16 bool GrDrawState::isEqual(const GrDrawState& that) const { |
| 16 bool usingVertexColors = this->hasColorVertexAttribute(); | 17 bool usingVertexColors = this->hasColorVertexAttribute(); |
| 17 if (!usingVertexColors && this->fColor != that.fColor) { | 18 if (!usingVertexColors && this->fColor != that.fColor) { |
| 18 return false; | 19 return false; |
| 19 } | 20 } |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 bool GrDrawState::hasSolidCoverage() const { | 376 bool GrDrawState::hasSolidCoverage() const { |
| 376 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 377 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
| 377 if (this->isCoverageDrawing()) { | 378 if (this->isCoverageDrawing()) { |
| 378 return true; | 379 return true; |
| 379 } | 380 } |
| 380 | 381 |
| 381 if (this->numCoverageStages() > 0) { | 382 if (this->numCoverageStages() > 0) { |
| 382 return false; | 383 return false; |
| 383 } | 384 } |
| 384 | 385 |
| 385 GrProcessor::InvariantOutput inout; | 386 GrColor color; |
| 386 inout.fIsSingleComponent = true; | 387 GrColorComponentFlags flags; |
| 387 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 388 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
| 388 if (this->hasCoverageVertexAttribute()) { | 389 if (this->hasCoverageVertexAttribute()) { |
| 389 inout.fValidFlags = 0; | 390 color = 0; |
| 391 flags = static_cast<GrColorComponentFlags>(0); |
| 390 } else { | 392 } else { |
| 391 inout.fColor = this->getCoverageColor(); | 393 color = this->getCoverageColor(); |
| 392 inout.fValidFlags = kRGBA_GrColorComponentFlags; | 394 flags = kRGBA_GrColorComponentFlags; |
| 393 } | 395 } |
| 396 GrInvariantOutput inout(color, flags, true); |
| 394 | 397 |
| 395 // check the coverage output from the GP | 398 // check the coverage output from the GP |
| 396 if (this->hasGeometryProcessor()) { | 399 if (this->hasGeometryProcessor()) { |
| 397 fGeometryProcessor->computeInvariantOutput(&inout); | 400 fGeometryProcessor->computeInvariantOutput(&inout); |
| 398 } | 401 } |
| 399 | 402 |
| 400 return inout.isSolidWhite(); | 403 return inout.isSolidWhite(); |
| 401 } | 404 } |
| 402 | 405 |
| 403 ////////////////////////////////////////////////////////////////////////////// | 406 ////////////////////////////////////////////////////////////////////////////// |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 *dstCoeff = kOne_GrBlendCoeff; | 683 *dstCoeff = kOne_GrBlendCoeff; |
| 681 return kCoverageAsAlpha_BlendOptFlag; | 684 return kCoverageAsAlpha_BlendOptFlag; |
| 682 } | 685 } |
| 683 } | 686 } |
| 684 | 687 |
| 685 return kNone_BlendOpt; | 688 return kNone_BlendOpt; |
| 686 } | 689 } |
| 687 | 690 |
| 688 | 691 |
| 689 bool GrDrawState::srcAlphaWillBeOne() const { | 692 bool GrDrawState::srcAlphaWillBeOne() const { |
| 690 GrProcessor::InvariantOutput inoutColor; | 693 GrColor color; |
| 691 inoutColor.fIsSingleComponent = false; | 694 GrColorComponentFlags flags; |
| 692 // Check if per-vertex or constant color may have partial alpha | 695 // Check if per-vertex or constant color may have partial alpha |
| 693 if (this->hasColorVertexAttribute()) { | 696 if (this->hasColorVertexAttribute()) { |
| 694 if (fHints & kVertexColorsAreOpaque_Hint) { | 697 if (fHints & kVertexColorsAreOpaque_Hint) { |
| 695 inoutColor.fValidFlags = kA_GrColorComponentFlag; | 698 flags = kA_GrColorComponentFlag; |
| 696 inoutColor.fColor = 0xFF << GrColor_SHIFT_A; | 699 color = 0xFF << GrColor_SHIFT_A; |
| 697 } else { | 700 } else { |
| 698 inoutColor.fValidFlags = 0; | 701 flags = static_cast<GrColorComponentFlags>(0); |
| 699 // not strictly necessary but we get false alarms from tools about u
ninit. | 702 color = 0; |
| 700 inoutColor.fColor = 0; | |
| 701 } | 703 } |
| 702 } else { | 704 } else { |
| 703 inoutColor.fValidFlags = kRGBA_GrColorComponentFlags; | 705 flags = kRGBA_GrColorComponentFlags; |
| 704 inoutColor.fColor = this->getColor(); | 706 color = this->getColor(); |
| 705 } | 707 } |
| 708 GrInvariantOutput inoutColor(color, flags, false); |
| 706 | 709 |
| 707 // Run through the color stages | 710 // Run through the color stages |
| 708 for (int s = 0; s < this->numColorStages(); ++s) { | 711 for (int s = 0; s < this->numColorStages(); ++s) { |
| 709 const GrProcessor* processor = this->getColorStage(s).getProcessor(); | 712 const GrProcessor* processor = this->getColorStage(s).getProcessor(); |
| 710 processor->computeInvariantOutput(&inoutColor); | 713 processor->computeInvariantOutput(&inoutColor); |
| 711 } | 714 } |
| 712 | 715 |
| 713 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 716 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
| 714 if (this->isCoverageDrawing()) { | 717 if (this->isCoverageDrawing()) { |
| 715 // The shader generated for coverage drawing runs the full coverage comp
utation and then | 718 // The shader generated for coverage drawing runs the full coverage comp
utation and then |
| 716 // makes the shader output be the multiplication of color and coverage.
We mirror that here. | 719 // makes the shader output be the multiplication of color and coverage.
We mirror that here. |
| 717 GrProcessor::InvariantOutput inoutCoverage; | |
| 718 inoutCoverage.fIsSingleComponent = true; | |
| 719 if (this->hasCoverageVertexAttribute()) { | 720 if (this->hasCoverageVertexAttribute()) { |
| 720 inoutCoverage.fValidFlags = 0; | 721 flags = static_cast<GrColorComponentFlags>(0); |
| 721 inoutCoverage.fColor = 0; // suppresses any warnings. | 722 color = 0; |
| 722 } else { | 723 } else { |
| 723 inoutCoverage.fValidFlags = kRGBA_GrColorComponentFlags; | 724 flags = kRGBA_GrColorComponentFlags; |
| 724 inoutCoverage.fColor = this->getCoverageColor(); | 725 color = this->getCoverageColor(); |
| 725 } | 726 } |
| 727 GrInvariantOutput inoutCoverage(color, flags, true); |
| 726 | 728 |
| 727 if (this->hasGeometryProcessor()) { | 729 if (this->hasGeometryProcessor()) { |
| 728 fGeometryProcessor->computeInvariantOutput(&inoutCoverage); | 730 fGeometryProcessor->computeInvariantOutput(&inoutCoverage); |
| 729 } | 731 } |
| 730 | 732 |
| 731 // Run through the coverage stages | 733 // Run through the coverage stages |
| 732 for (int s = 0; s < this->numCoverageStages(); ++s) { | 734 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 733 const GrProcessor* processor = this->getCoverageStage(s).getProcesso
r(); | 735 const GrProcessor* processor = this->getCoverageStage(s).getProcesso
r(); |
| 734 processor->computeInvariantOutput(&inoutCoverage); | 736 processor->computeInvariantOutput(&inoutCoverage); |
| 735 } | 737 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 755 } | 757 } |
| 756 if (kOne_GrBlendCoeff != srcCoeff || | 758 if (kOne_GrBlendCoeff != srcCoeff || |
| 757 kZero_GrBlendCoeff != dstCoeff || | 759 kZero_GrBlendCoeff != dstCoeff || |
| 758 this->willEffectReadDstColor()) { | 760 this->willEffectReadDstColor()) { |
| 759 return true; | 761 return true; |
| 760 } | 762 } |
| 761 | 763 |
| 762 return false; | 764 return false; |
| 763 } | 765 } |
| 764 | 766 |
| OLD | NEW |