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 | |
| 8 | #include "GrPaint.h" |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 9 | #include "GrXferProcessor.h" |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 10 | #include "effects/GrCoverageSetOpXP.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 11 | #include "effects/GrPorterDuffXferProcessor.h" |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 12 | #include "effects/GrSimpleTextureEffect.h" |
| 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 | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 38 | void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix) { |
| 39 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 40 | } |
| 41 | |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 42 | void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 43 | const GrSamplerState& samplerState) { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 44 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix, |
| 45 | samplerState)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 48 | void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 49 | const SkMatrix& matrix) { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 50 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 53 | void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 54 | const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 55 | const GrSamplerState& params) { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 56 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix, |
| 57 | params)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 58 | } |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 59 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 60 | bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const { |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 61 | // This used to do a more sophisticated analysis but now it just explicitly looks for common |
| 62 | // cases. |
| 63 | static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc); |
| 64 | static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear); |
| 65 | if (kClear == fXPFactory) { |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 66 | *constantColor = SK_PMColor4fTRANSPARENT; |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 67 | return true; |
| 68 | } |
| 69 | if (this->numColorFragmentProcessors()) { |
| 70 | return false; |
| 71 | } |
| 72 | if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) { |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 73 | *constantColor = fColor; |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 74 | return true; |
| 75 | } |
| 76 | return false; |
| 77 | } |