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" |
| 9 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 10 | #include "GrProcOptInfo.h" |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 11 | #include "effects/GrCoverageSetOpXP.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 12 | #include "effects/GrPorterDuffXferProcessor.h" |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 13 | #include "effects/GrSimpleTextureEffect.h" |
| 14 | |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 15 | GrPaint::GrPaint() |
| 16 | : fAntiAlias(false) |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 17 | , fDisableOutputConversionToSRGB(false) |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 18 | , fAllowSRGBInputs(false) |
brianosman | a4535a3 | 2016-06-24 12:50:19 -0700 | [diff] [blame] | 19 | , fColor(GrColor4f::FromGrColor(GrColor_WHITE)) {} |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 20 | |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 21 | void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 22 | fXPFactory = GrCoverageSetOpXPFactory::Make(regionOp, invertCoverage); |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 23 | } |
| 24 | |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 25 | void GrPaint::addColorTextureProcessor(GrTexture* texture, |
| 26 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 27 | const SkMatrix& matrix) { |
| 28 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, |
| 29 | std::move(colorSpaceXform), |
| 30 | matrix)); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 31 | } |
| 32 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 33 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 34 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix)); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 35 | } |
| 36 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 37 | void GrPaint::addColorTextureProcessor(GrTexture* texture, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 38 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame] | 39 | const SkMatrix& matrix, |
| 40 | const GrTextureParams& params) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 41 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, |
| 42 | std::move(colorSpaceXform), |
| 43 | matrix, params)); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 44 | } |
| 45 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 46 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame] | 47 | const SkMatrix& matrix, |
| 48 | const GrTextureParams& params) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 49 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix, |
| 50 | params)); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 51 | } |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 52 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 53 | bool GrPaint::isConstantBlendedColor(GrColor* color) const { |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 54 | GrProcOptInfo colorProcInfo; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 55 | colorProcInfo.calcWithInitialValues( |
| 56 | sk_sp_address_as_pointer_address(fColorFragmentProcessors.begin()), |
brianosman | a4535a3 | 2016-06-24 12:50:19 -0700 | [diff] [blame] | 57 | this->numColorFragmentProcessors(), this->getColor(), kRGBA_GrColorComponentFlags, false); |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 58 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 59 | GrXPFactory::InvariantBlendedColor blendedColor; |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 60 | if (fXPFactory) { |
| 61 | fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor); |
| 62 | } else { |
| 63 | GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(colorProcInfo.color(), |
| 64 | colorProcInfo.validFlags(), |
| 65 | colorProcInfo.isOpaque(), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 66 | &blendedColor); |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 67 | } |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 68 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 69 | if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) { |
| 70 | *color = blendedColor.fKnownColor; |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 71 | return true; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 72 | } |
| 73 | return false; |
| 74 | } |