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 "effects/GrSimpleTextureEffect.h" | 12 #include "effects/GrSimpleTextureEffect.h" |
12 | 13 |
13 void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix)
{ | 14 void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix)
{ |
14 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); | 15 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); |
15 this->addColorEffect(effect)->unref(); | 16 this->addColorEffect(effect)->unref(); |
16 } | 17 } |
17 | 18 |
18 void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matri
x) { | 19 void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matri
x) { |
19 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); | 20 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); |
20 this->addCoverageEffect(effect)->unref(); | 21 this->addCoverageEffect(effect)->unref(); |
21 } | 22 } |
22 | 23 |
23 void GrPaint::addColorTextureEffect(GrTexture* texture, | 24 void GrPaint::addColorTextureEffect(GrTexture* texture, |
24 const SkMatrix& matrix, | 25 const SkMatrix& matrix, |
25 const GrTextureParams& params) { | 26 const GrTextureParams& params) { |
26 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params)
; | 27 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params)
; |
27 this->addColorEffect(effect)->unref(); | 28 this->addColorEffect(effect)->unref(); |
28 } | 29 } |
29 | 30 |
30 void GrPaint::addCoverageTextureEffect(GrTexture* texture, | 31 void GrPaint::addCoverageTextureEffect(GrTexture* texture, |
31 const SkMatrix& matrix, | 32 const SkMatrix& matrix, |
32 const GrTextureParams& params) { | 33 const GrTextureParams& params) { |
33 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params)
; | 34 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params)
; |
34 this->addCoverageEffect(effect)->unref(); | 35 this->addCoverageEffect(effect)->unref(); |
35 } | 36 } |
| 37 |
| 38 bool GrPaint::isOpaque() const { |
| 39 return this->getOpaqueAndKnownColor(NULL, NULL); |
| 40 } |
| 41 |
| 42 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { |
| 43 GrColor tempColor; |
| 44 uint32_t colorComps; |
| 45 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) { |
| 46 if (kRGBA_GrColorComponentFlags == colorComps) { |
| 47 *color = tempColor; |
| 48 return true; |
| 49 } |
| 50 } |
| 51 return false; |
| 52 } |
| 53 |
| 54 bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, |
| 55 uint32_t* solidColorKnownComponents) const
{ |
| 56 |
| 57 // TODO: Share this implementation with GrDrawState |
| 58 |
| 59 // Since fColorFilterXfermode is going away soon, we aren't attempting to ha
ndle anything but |
| 60 // the default setting. |
| 61 if (SkXfermode::kDst_Mode != fColorFilterXfermode) { |
| 62 return false; |
| 63 } |
| 64 |
| 65 GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverag
e); |
| 66 uint32_t coverageComps = kRGBA_GrColorComponentFlags; |
| 67 int count = fCoverageStages.count(); |
| 68 for (int i = 0; i < count; ++i) { |
| 69 (*fCoverageStages[i].getEffect())->getConstantColorComponents(&coverage,
&coverageComps); |
| 70 } |
| 71 if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage)
{ |
| 72 return false; |
| 73 } |
| 74 |
| 75 GrColor color = fColor; |
| 76 uint32_t colorComps = kRGBA_GrColorComponentFlags; |
| 77 count = fColorStages.count(); |
| 78 for (int i = 0; i < count; ++i) { |
| 79 (*fColorStages[i].getEffect())->getConstantColorComponents(&color, &colo
rComps); |
| 80 } |
| 81 |
| 82 GrAssert((NULL == solidColor) == (NULL == solidColorKnownComponents)); |
| 83 if (NULL != solidColor) { |
| 84 *solidColor = color; |
| 85 *solidColorKnownComponents = colorComps; |
| 86 } |
| 87 |
| 88 GrBlendCoeff srcCoeff = fSrcBlendCoeff; |
| 89 GrBlendCoeff dstCoeff = fDstBlendCoeff; |
| 90 GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0); |
| 91 return kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff); |
| 92 } |
OLD | NEW |