commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 12 | #include "src/gpu/effects/GrTextureEffect.h" |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 13 | |
Brian Salomon | b74ef03 | 2017-08-10 12:46:01 -0400 | [diff] [blame] | 14 | GrPaint::GrPaint(const GrPaint& that) |
| 15 | : fXPFactory(that.fXPFactory) |
| 16 | , fColorFragmentProcessors(that.fColorFragmentProcessors.count()) |
| 17 | , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count()) |
Brian Salomon | b74ef03 | 2017-08-10 12:46:01 -0400 | [diff] [blame] | 18 | , fTrivial(that.fTrivial) |
| 19 | , fColor(that.fColor) { |
| 20 | for (int i = 0; i < that.fColorFragmentProcessors.count(); ++i) { |
| 21 | fColorFragmentProcessors.push_back(that.fColorFragmentProcessors[i]->clone()); |
| 22 | SkASSERT(fColorFragmentProcessors[i]); |
| 23 | } |
| 24 | for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) { |
| 25 | fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone()); |
| 26 | SkASSERT(fCoverageFragmentProcessors[i]); |
| 27 | } |
| 28 | } |
| 29 | |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 30 | void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) { |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 31 | this->setXPFactory(GrPorterDuffXPFactory::Get(mode)); |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 32 | } |
| 33 | |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 34 | void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) { |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 35 | this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage)); |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 38 | bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const { |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 39 | // This used to do a more sophisticated analysis but now it just explicitly looks for common |
| 40 | // cases. |
| 41 | static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc); |
| 42 | static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear); |
| 43 | if (kClear == fXPFactory) { |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 44 | *constantColor = SK_PMColor4fTRANSPARENT; |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 45 | return true; |
| 46 | } |
| 47 | if (this->numColorFragmentProcessors()) { |
| 48 | return false; |
| 49 | } |
| 50 | if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) { |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 51 | *constantColor = fColor; |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 52 | return true; |
| 53 | } |
| 54 | return false; |
| 55 | } |