commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "GrPaint.h" |
| 10 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 11 | #include "GrProcOptInfo.h" |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 12 | #include "effects/GrCoverageSetOpXP.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 13 | #include "effects/GrPorterDuffXferProcessor.h" |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 14 | #include "effects/GrSimpleTextureEffect.h" |
| 15 | |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 16 | GrPaint::GrPaint() |
| 17 | : fAntiAlias(false) |
| 18 | , fDither(false) |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 19 | , fColor(GrColor_WHITE) |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 20 | , fProcDataManager(new GrProcessorDataManager) {} |
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) { |
| 23 | fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage)); |
| 24 | } |
| 25 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 26 | void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame^] | 27 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 28 | matrix))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 29 | } |
| 30 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 31 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame^] | 32 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 33 | matrix))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 34 | } |
| 35 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 36 | void GrPaint::addColorTextureProcessor(GrTexture* texture, |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame] | 37 | const SkMatrix& matrix, |
| 38 | const GrTextureParams& params) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame^] | 39 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 40 | params))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 41 | } |
| 42 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 43 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame] | 44 | const SkMatrix& matrix, |
| 45 | const GrTextureParams& params) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame^] | 46 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 47 | params))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 48 | } |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 49 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 50 | bool GrPaint::isConstantBlendedColor(GrColor* color) const { |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 51 | GrProcOptInfo colorProcInfo; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame^] | 52 | colorProcInfo.calcWithInitialValues(fColorFragmentProcessors.begin(), |
| 53 | this->numColorFragmentProcessors(), fColor, |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 54 | kRGBA_GrColorComponentFlags, false); |
| 55 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 56 | GrXPFactory::InvariantBlendedColor blendedColor; |
| 57 | fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor); |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 58 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 59 | if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) { |
| 60 | *color = blendedColor.fKnownColor; |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 61 | return true; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 62 | } |
| 63 | return false; |
| 64 | } |