| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrPaint.h" | 9 #include "GrPaint.h" |
| 10 | 10 |
| 11 #include "GrBlend.h" | 11 #include "GrBlend.h" |
| 12 #include "GrInvariantOutput.h" | 12 #include "GrProcOptInfo.h" |
| 13 #include "effects/GrSimpleTextureEffect.h" | 13 #include "effects/GrSimpleTextureEffect.h" |
| 14 | 14 |
| 15 void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matri
x) { | 15 void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matri
x) { |
| 16 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unr
ef(); | 16 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unr
ef(); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& ma
trix) { | 19 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& ma
trix) { |
| 20 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->
unref(); | 20 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->
unref(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void GrPaint::addColorTextureProcessor(GrTexture* texture, | 23 void GrPaint::addColorTextureProcessor(GrTexture* texture, |
| 24 const SkMatrix& matrix, | 24 const SkMatrix& matrix, |
| 25 const GrTextureParams& params) { | 25 const GrTextureParams& params) { |
| 26 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, param
s))->unref(); | 26 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, param
s))->unref(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, | 29 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, |
| 30 const SkMatrix& matrix, | 30 const SkMatrix& matrix, |
| 31 const GrTextureParams& params) { | 31 const GrTextureParams& params) { |
| 32 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, pa
rams))->unref(); | 32 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, pa
rams))->unref(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool GrPaint::isOpaque() const { | 35 bool GrPaint::isOpaque() const { |
| 36 return this->getOpaqueAndKnownColor(NULL, NULL); | 36 return this->getOpaqueAndKnownColor(NULL, NULL); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { | 39 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { |
| 40 GrColor tempColor; | 40 GrColor tempColor = 0; |
| 41 uint32_t colorComps; | 41 uint32_t colorComps = 0; |
| 42 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) { | 42 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) { |
| 43 if (kRGBA_GrColorComponentFlags == colorComps) { | 43 if (kRGBA_GrColorComponentFlags == colorComps) { |
| 44 *color = tempColor; | 44 *color = tempColor; |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, | 51 bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, |
| 52 uint32_t* solidColorKnownComponents) const
{ | 52 uint32_t* solidColorKnownComponents) const
{ |
| 53 | 53 |
| 54 // TODO: Share this implementation with GrDrawState | 54 // TODO: Share this implementation with GrDrawState |
| 55 |
| 56 GrProcOptInfo coverageProcInfo; |
| 57 coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCov
erageStages(), |
| 58 0xFFFFFFFF, kRGBA_GrColorComponentFla
gs, true); |
| 55 | 59 |
| 56 GrInvariantOutput inoutCoverage(0xFFFFFFFF, | 60 if (!coverageProcInfo.isSolidWhite()) { |
| 57 kRGBA_GrColorComponentFlags, | |
| 58 true); | |
| 59 int count = fCoverageStages.count(); | |
| 60 for (int i = 0; i < count; ++i) { | |
| 61 fCoverageStages[i].getProcessor()->computeInvariantOutput(&inoutCoverage
); | |
| 62 } | |
| 63 if (!inoutCoverage.isSolidWhite()) { | |
| 64 return false; | 61 return false; |
| 65 } | 62 } |
| 66 | 63 |
| 67 GrInvariantOutput inout(fColor, kRGBA_GrColorComponentFlags, false); | 64 GrProcOptInfo colorProcInfo; |
| 68 count = fColorStages.count(); | 65 colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStag
es(), fColor, |
| 69 for (int i = 0; i < count; ++i) { | 66 kRGBA_GrColorComponentFlags, false); |
| 70 fColorStages[i].getProcessor()->computeInvariantOutput(&inout); | |
| 71 } | |
| 72 | 67 |
| 73 SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents)); | 68 SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents)); |
| 74 | 69 |
| 75 GrBlendCoeff srcCoeff = fSrcBlendCoeff; | 70 GrBlendCoeff srcCoeff = fSrcBlendCoeff; |
| 76 GrBlendCoeff dstCoeff = fDstBlendCoeff; | 71 GrBlendCoeff dstCoeff = fDstBlendCoeff; |
| 77 GrSimplifyBlend(&srcCoeff, &dstCoeff, inout.color(), inout.validFlags(), | 72 GrSimplifyBlend(&srcCoeff, &dstCoeff, colorProcInfo.color(), colorProcInfo.v
alidFlags(), |
| 78 0, 0, 0); | 73 0, 0, 0); |
| 79 | 74 |
| 80 bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoef
f); | 75 bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoef
f); |
| 81 if (solidColor) { | 76 if (solidColor) { |
| 82 if (opaque) { | 77 if (opaque) { |
| 83 switch (srcCoeff) { | 78 switch (srcCoeff) { |
| 84 case kZero_GrBlendCoeff: | 79 case kZero_GrBlendCoeff: |
| 85 *solidColor = 0; | 80 *solidColor = 0; |
| 86 *solidColorKnownComponents = kRGBA_GrColorComponentFlags; | 81 *solidColorKnownComponents = kRGBA_GrColorComponentFlags; |
| 87 break; | 82 break; |
| 88 | 83 |
| 89 case kOne_GrBlendCoeff: | 84 case kOne_GrBlendCoeff: |
| 90 *solidColor = inout.color(); | 85 *solidColor = colorProcInfo.color(); |
| 91 *solidColorKnownComponents = inout.validFlags(); | 86 *solidColorKnownComponents = colorProcInfo.validFlags(); |
| 92 break; | 87 break; |
| 93 | 88 |
| 94 // The src coeff should never refer to the src and if it refers
to dst then opaque | 89 // The src coeff should never refer to the src and if it refers
to dst then opaque |
| 95 // should have been false. | 90 // should have been false. |
| 96 case kSC_GrBlendCoeff: | 91 case kSC_GrBlendCoeff: |
| 97 case kISC_GrBlendCoeff: | 92 case kISC_GrBlendCoeff: |
| 98 case kDC_GrBlendCoeff: | 93 case kDC_GrBlendCoeff: |
| 99 case kIDC_GrBlendCoeff: | 94 case kIDC_GrBlendCoeff: |
| 100 case kSA_GrBlendCoeff: | 95 case kSA_GrBlendCoeff: |
| 101 case kISA_GrBlendCoeff: | 96 case kISA_GrBlendCoeff: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 112 case kIConstA_GrBlendCoeff: | 107 case kIConstA_GrBlendCoeff: |
| 113 *solidColorKnownComponents = 0; | 108 *solidColorKnownComponents = 0; |
| 114 break; | 109 break; |
| 115 } | 110 } |
| 116 } else { | 111 } else { |
| 117 solidColorKnownComponents = 0; | 112 solidColorKnownComponents = 0; |
| 118 } | 113 } |
| 119 } | 114 } |
| 120 return opaque; | 115 return opaque; |
| 121 } | 116 } |
| OLD | NEW |