• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "GrPaint.h"
9 #include "GrXferProcessor.h"
10 #include "effects/GrCoverageSetOpXP.h"
11 #include "effects/GrPorterDuffXferProcessor.h"
12 #include "effects/GrSimpleTextureEffect.h"
13 
setPorterDuffXPFactory(SkBlendMode mode)14 void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
15     this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
16 }
17 
setCoverageSetOpXPFactory(SkRegion::Op regionOp,bool invertCoverage)18 void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
19     this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
20 }
21 
addColorTextureProcessor(sk_sp<GrTextureProxy> proxy,sk_sp<GrColorSpaceXform> colorSpaceXform,const SkMatrix & matrix)22 void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy,
23                                        sk_sp<GrColorSpaceXform> colorSpaceXform,
24                                        const SkMatrix& matrix) {
25     this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
26                                                                 std::move(colorSpaceXform),
27                                                                 matrix));
28 }
29 
addColorTextureProcessor(sk_sp<GrTextureProxy> proxy,sk_sp<GrColorSpaceXform> colorSpaceXform,const SkMatrix & matrix,const GrSamplerParams & params)30 void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy,
31                                        sk_sp<GrColorSpaceXform> colorSpaceXform,
32                                        const SkMatrix& matrix,
33                                        const GrSamplerParams& params) {
34     this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
35                                                                 std::move(colorSpaceXform),
36                                                                 matrix, params));
37 }
38 
addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,const SkMatrix & matrix)39 void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
40                                           const SkMatrix& matrix) {
41     this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
42                                                                    nullptr, matrix));
43 }
44 
addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,const SkMatrix & matrix,const GrSamplerParams & params)45 void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
46                                           const SkMatrix& matrix,
47                                           const GrSamplerParams& params) {
48     this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
49                                                                    nullptr, matrix, params));
50 }
51 
isConstantBlendedColor(GrColor * constantColor) const52 bool GrPaint::isConstantBlendedColor(GrColor* constantColor) const {
53     // This used to do a more sophisticated analysis but now it just explicitly looks for common
54     // cases.
55     static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
56     static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
57     if (kClear == fXPFactory) {
58         *constantColor = GrColor_TRANSPARENT_BLACK;
59         return true;
60     }
61     if (this->numColorFragmentProcessors()) {
62         return false;
63     }
64     if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
65         *constantColor = fColor.toGrColor();
66         return true;
67     }
68     return false;
69 }
70