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