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 "src/gpu/GrPaint.h" |
9 | #include "src/gpu/GrXferProcessor.h" |
10 | #include "src/gpu/effects/GrCoverageSetOpXP.h" |
11 | #include "src/gpu/effects/GrPorterDuffXferProcessor.h" |
12 | #include "src/gpu/effects/GrTextureEffect.h" |
13 | |
14 | GrPaint::GrPaint(const GrPaint& that) |
15 | : fXPFactory(that.fXPFactory) |
16 | , fTrivial(that.fTrivial) |
17 | , fColor(that.fColor) { |
18 | if (that.fColorFragmentProcessor) { |
19 | fColorFragmentProcessor = that.fColorFragmentProcessor->clone(); |
20 | SkASSERT(fColorFragmentProcessor); |
21 | } |
22 | if (that.fCoverageFragmentProcessor) { |
23 | fCoverageFragmentProcessor = that.fCoverageFragmentProcessor->clone(); |
24 | SkASSERT(fCoverageFragmentProcessor); |
25 | } |
26 | } |
27 | |
28 | void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) { |
29 | this->setXPFactory(GrPorterDuffXPFactory::Get(mode)); |
30 | } |
31 | |
32 | void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) { |
33 | this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage)); |
34 | } |
35 | |
36 | bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const { |
37 | // This used to do a more sophisticated analysis but now it just explicitly looks for common |
38 | // cases. |
39 | static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc); |
40 | static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear); |
41 | if (kClear == fXPFactory) { |
42 | *constantColor = SK_PMColor4fTRANSPARENT; |
43 | return true; |
44 | } |
45 | if (this->hasColorFragmentProcessor()) { |
46 | return false; |
47 | } |
48 | if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) { |
49 | *constantColor = fColor; |
50 | return true; |
51 | } |
52 | return false; |
53 | } |
54 |