• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2013 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #include "GrPaint.h"
10 
11 #include "GrBlend.h"
12 #include "effects/GrSimpleTextureEffect.h"
13 
addColorTextureProcessor(GrTexture * texture,const SkMatrix & matrix)14 void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
15     this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
16 }
17 
addCoverageTextureProcessor(GrTexture * texture,const SkMatrix & matrix)18 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
19     this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
20 }
21 
addColorTextureProcessor(GrTexture * texture,const SkMatrix & matrix,const GrTextureParams & params)22 void GrPaint::addColorTextureProcessor(GrTexture* texture,
23                                     const SkMatrix& matrix,
24                                     const GrTextureParams& params) {
25     this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
26 }
27 
addCoverageTextureProcessor(GrTexture * texture,const SkMatrix & matrix,const GrTextureParams & params)28 void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
29                                        const SkMatrix& matrix,
30                                        const GrTextureParams& params) {
31     this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
32 }
33 
isOpaque() const34 bool GrPaint::isOpaque() const {
35     return this->getOpaqueAndKnownColor(NULL, NULL);
36 }
37 
isOpaqueAndConstantColor(GrColor * color) const38 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
39     GrColor tempColor;
40     uint32_t colorComps;
41     if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) {
42         if (kRGBA_GrColorComponentFlags == colorComps) {
43             *color = tempColor;
44             return true;
45         }
46     }
47     return false;
48 }
49 
getOpaqueAndKnownColor(GrColor * solidColor,uint32_t * solidColorKnownComponents) const50 bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor,
51                                      uint32_t* solidColorKnownComponents) const {
52 
53     // TODO: Share this implementation with GrDrawState
54 
55     GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
56     uint32_t coverageComps = kRGBA_GrColorComponentFlags;
57     int count = fCoverageStages.count();
58     for (int i = 0; i < count; ++i) {
59         fCoverageStages[i].getProcessor()->getConstantColorComponents(&coverage, &coverageComps);
60     }
61     if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) {
62         return false;
63     }
64 
65     GrColor color = fColor;
66     uint32_t colorComps = kRGBA_GrColorComponentFlags;
67     count = fColorStages.count();
68     for (int i = 0; i < count; ++i) {
69         fColorStages[i].getProcessor()->getConstantColorComponents(&color, &colorComps);
70     }
71 
72     SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents));
73 
74     GrBlendCoeff srcCoeff = fSrcBlendCoeff;
75     GrBlendCoeff dstCoeff = fDstBlendCoeff;
76     GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0);
77 
78     bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff);
79     if (solidColor) {
80         if (opaque) {
81             switch (srcCoeff) {
82                 case kZero_GrBlendCoeff:
83                     *solidColor = 0;
84                     *solidColorKnownComponents = kRGBA_GrColorComponentFlags;
85                     break;
86 
87                 case kOne_GrBlendCoeff:
88                     *solidColor = color;
89                     *solidColorKnownComponents = colorComps;
90                     break;
91 
92                 // The src coeff should never refer to the src and if it refers to dst then opaque
93                 // should have been false.
94                 case kSC_GrBlendCoeff:
95                 case kISC_GrBlendCoeff:
96                 case kDC_GrBlendCoeff:
97                 case kIDC_GrBlendCoeff:
98                 case kSA_GrBlendCoeff:
99                 case kISA_GrBlendCoeff:
100                 case kDA_GrBlendCoeff:
101                 case kIDA_GrBlendCoeff:
102                 default:
103                     SkFAIL("srcCoeff should not refer to src or dst.");
104                     break;
105 
106                 // TODO: update this once GrPaint actually has a const color.
107                 case kConstC_GrBlendCoeff:
108                 case kIConstC_GrBlendCoeff:
109                 case kConstA_GrBlendCoeff:
110                 case kIConstA_GrBlendCoeff:
111                     *solidColorKnownComponents = 0;
112                     break;
113             }
114         } else {
115             solidColorKnownComponents = 0;
116         }
117     }
118     return opaque;
119 }
120