3 * Copyright 2013 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
12 #include "effects/GrSimpleTextureEffect.h"
14 void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
15 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
16 this->addColorEffect(effect)->unref();
19 void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
20 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
21 this->addCoverageEffect(effect)->unref();
24 void GrPaint::addColorTextureEffect(GrTexture* texture,
25 const SkMatrix& matrix,
26 const GrTextureParams& params) {
27 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
28 this->addColorEffect(effect)->unref();
31 void GrPaint::addCoverageTextureEffect(GrTexture* texture,
32 const SkMatrix& matrix,
33 const GrTextureParams& params) {
34 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
35 this->addCoverageEffect(effect)->unref();
38 bool GrPaint::isOpaque() const {
39 return this->getOpaqueAndKnownColor(NULL, NULL);
42 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
45 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) {
46 if (kRGBA_GrColorComponentFlags == colorComps) {
54 bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor,
55 uint32_t* solidColorKnownComponents) const {
57 // TODO: Share this implementation with GrDrawState
59 GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
60 uint32_t coverageComps = kRGBA_GrColorComponentFlags;
61 int count = fCoverageStages.count();
62 for (int i = 0; i < count; ++i) {
63 (*fCoverageStages[i].getEffect())->getConstantColorComponents(&coverage, &coverageComps);
65 if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) {
69 GrColor color = fColor;
70 uint32_t colorComps = kRGBA_GrColorComponentFlags;
71 count = fColorStages.count();
72 for (int i = 0; i < count; ++i) {
73 (*fColorStages[i].getEffect())->getConstantColorComponents(&color, &colorComps);
76 SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents));
78 GrBlendCoeff srcCoeff = fSrcBlendCoeff;
79 GrBlendCoeff dstCoeff = fDstBlendCoeff;
80 GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0);
82 bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff);
83 if (NULL != solidColor) {
86 case kZero_GrBlendCoeff:
88 *solidColorKnownComponents = kRGBA_GrColorComponentFlags;
91 case kOne_GrBlendCoeff:
93 *solidColorKnownComponents = colorComps;
96 // The src coeff should never refer to the src and if it refers to dst then opaque
97 // should have been false.
98 case kSC_GrBlendCoeff:
99 case kISC_GrBlendCoeff:
100 case kDC_GrBlendCoeff:
101 case kIDC_GrBlendCoeff:
102 case kSA_GrBlendCoeff:
103 case kISA_GrBlendCoeff:
104 case kDA_GrBlendCoeff:
105 case kIDA_GrBlendCoeff:
107 SkFAIL("srcCoeff should not refer to src or dst.");
110 // TODO: update this once GrPaint actually has a const color.
111 case kConstC_GrBlendCoeff:
112 case kIConstC_GrBlendCoeff:
113 case kConstA_GrBlendCoeff:
114 case kIConstA_GrBlendCoeff:
115 *solidColorKnownComponents = 0;
119 solidColorKnownComponents = 0;