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()) |
| 18 | , fDisableOutputConversionToSRGB(that.fDisableOutputConversionToSRGB) |
| 19 | , fAllowSRGBInputs(that.fAllowSRGBInputs) |
| 20 | , fTrivial(that.fTrivial) |
| 21 | , fColor(that.fColor) { |
| 22 | for (int i = 0; i < that.fColorFragmentProcessors.count(); ++i) { |
| 23 | fColorFragmentProcessors.push_back(that.fColorFragmentProcessors[i]->clone()); |
| 24 | SkASSERT(fColorFragmentProcessors[i]); |
| 25 | } |
| 26 | for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) { |
| 27 | fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone()); |
| 28 | SkASSERT(fCoverageFragmentProcessors[i]); |
| 29 | } |
| 30 | } |
| 31 | |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 32 | void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) { |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 33 | this->setXPFactory(GrPorterDuffXPFactory::Get(mode)); |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 34 | } |
| 35 | |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 36 | void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) { |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 37 | this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage)); |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 40 | void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix) { |
| 41 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 44 | void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 45 | const GrSamplerState& samplerState) { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 46 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix, |
| 47 | samplerState)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 50 | void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 51 | const SkMatrix& matrix) { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 52 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 55 | void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 56 | const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 57 | const GrSamplerState& params) { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 58 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix, |
| 59 | params)); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 60 | } |
Brian Salomon | 94cce4c | 2017-02-21 16:32:20 -0500 | [diff] [blame] | 61 | |
| 62 | bool GrPaint::isConstantBlendedColor(GrColor* constantColor) const { |
| 63 | // This used to do a more sophisticated analysis but now it just explicitly looks for common |
| 64 | // cases. |
| 65 | static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc); |
| 66 | static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear); |
| 67 | if (kClear == fXPFactory) { |
| 68 | *constantColor = GrColor_TRANSPARENT_BLACK; |
| 69 | return true; |
| 70 | } |
| 71 | if (this->numColorFragmentProcessors()) { |
| 72 | return false; |
| 73 | } |
| 74 | if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) { |
| 75 | *constantColor = fColor.toGrColor(); |
| 76 | return true; |
| 77 | } |
| 78 | return false; |
| 79 | } |