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