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 "GrProcOptInfo.h"
12 #include "effects/GrCoverageSetOpXP.h"
13 #include "effects/GrPorterDuffXferProcessor.h"
14 #include "effects/GrSimpleTextureEffect.h"
15 
GrPaint()16 GrPaint::GrPaint()
17     : fAntiAlias(false)
18     , fColor(GrColor_WHITE) {}
19 
setCoverageSetOpXPFactory(SkRegion::Op regionOp,bool invertCoverage)20 void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
21     fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
22 }
23 
addColorTextureProcessor(GrTexture * texture,const SkMatrix & matrix)24 void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
25     this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
26 }
27 
addCoverageTextureProcessor(GrTexture * texture,const SkMatrix & matrix)28 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
29     this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
30 }
31 
addColorTextureProcessor(GrTexture * texture,const SkMatrix & matrix,const GrTextureParams & params)32 void GrPaint::addColorTextureProcessor(GrTexture* texture,
33                                        const SkMatrix& matrix,
34                                        const GrTextureParams& params) {
35     this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture,
36                                                                   matrix, params))->unref();
37 }
38 
addCoverageTextureProcessor(GrTexture * texture,const SkMatrix & matrix,const GrTextureParams & params)39 void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
40                                           const SkMatrix& matrix,
41                                           const GrTextureParams& params) {
42     this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture,
43                                                                      matrix, params))->unref();
44 }
45 
isConstantBlendedColor(GrColor * color) const46 bool GrPaint::isConstantBlendedColor(GrColor* color) const {
47     GrProcOptInfo colorProcInfo;
48     colorProcInfo.calcWithInitialValues(fColorFragmentProcessors.begin(),
49                                         this->numColorFragmentProcessors(), fColor,
50                                         kRGBA_GrColorComponentFlags, false);
51 
52     GrXPFactory::InvariantBlendedColor blendedColor;
53     if (fXPFactory) {
54         fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor);
55     } else {
56         GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(colorProcInfo.color(),
57                                                             colorProcInfo.validFlags(),
58                                                             colorProcInfo.isOpaque(),
59                                                             &blendedColor);
60     }
61 
62     if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) {
63         *color = blendedColor.fKnownColor;
64         return true;
65     }
66     return false;
67 }
68