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::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
15 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
18 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
19 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
22 void GrPaint::addColorTextureProcessor(GrTexture* texture,
23 const SkMatrix& matrix,
24 const GrTextureParams& params) {
25 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
28 void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
29 const SkMatrix& matrix,
30 const GrTextureParams& params) {
31 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
34 bool GrPaint::isOpaque() const {
35 return this->getOpaqueAndKnownColor(NULL, NULL);
38 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
41 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) {
42 if (kRGBA_GrColorComponentFlags == colorComps) {
50 bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor,
51 uint32_t* solidColorKnownComponents) const {
53 // TODO: Share this implementation with GrDrawState
55 GrProcessor::InvariantOutput inout;
56 inout.fColor = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
57 inout.fValidFlags = kRGBA_GrColorComponentFlags;
58 inout.fIsSingleComponent = true;
59 int count = fCoverageStages.count();
60 for (int i = 0; i < count; ++i) {
61 fCoverageStages[i].getProcessor()->computeInvariantOutput(&inout);
63 if (!inout.isSolidWhite()) {
67 inout.fColor = fColor;
68 inout.fValidFlags = kRGBA_GrColorComponentFlags;
69 inout.fIsSingleComponent = false;
70 count = fColorStages.count();
71 for (int i = 0; i < count; ++i) {
72 fColorStages[i].getProcessor()->computeInvariantOutput(&inout);
75 SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents));
77 GrBlendCoeff srcCoeff = fSrcBlendCoeff;
78 GrBlendCoeff dstCoeff = fDstBlendCoeff;
79 GrSimplifyBlend(&srcCoeff, &dstCoeff, inout.fColor, inout.fValidFlags,
82 bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff);
86 case kZero_GrBlendCoeff:
88 *solidColorKnownComponents = kRGBA_GrColorComponentFlags;
91 case kOne_GrBlendCoeff:
92 *solidColor = inout.fColor;
93 *solidColorKnownComponents = inout.fValidFlags;
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;