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) |
joshualitt | af2533a | 2015-09-09 10:00:12 -0700 | [diff] [blame] | 19 | , fColor(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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 25 | void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 26 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, matrix)); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 27 | } |
| 28 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 29 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 30 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, 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::addColorTextureProcessor(GrTexture* texture, |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame] | 34 | const SkMatrix& matrix, |
| 35 | const GrTextureParams& params) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 36 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, matrix, params)); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 37 | } |
| 38 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 39 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame] | 40 | const SkMatrix& matrix, |
| 41 | const GrTextureParams& params) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 42 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, matrix, params)); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 43 | } |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 44 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 45 | bool GrPaint::isConstantBlendedColor(GrColor* color) const { |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 46 | GrProcOptInfo colorProcInfo; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 47 | colorProcInfo.calcWithInitialValues( |
| 48 | sk_sp_address_as_pointer_address(fColorFragmentProcessors.begin()), |
| 49 | this->numColorFragmentProcessors(), fColor, kRGBA_GrColorComponentFlags, false); |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 50 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 51 | GrXPFactory::InvariantBlendedColor blendedColor; |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 52 | if (fXPFactory) { |
| 53 | fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor); |
| 54 | } else { |
| 55 | GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(colorProcInfo.color(), |
| 56 | colorProcInfo.validFlags(), |
| 57 | colorProcInfo.isOpaque(), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 58 | &blendedColor); |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 59 | } |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 60 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 61 | if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) { |
| 62 | *color = blendedColor.fKnownColor; |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 63 | return true; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 64 | } |
| 65 | return false; |
| 66 | } |