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 | 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 | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 15 | void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 16 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 17 | } |
| 18 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 19 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 20 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 21 | } |
| 22 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 23 | void GrPaint::addColorTextureProcessor(GrTexture* texture, |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 24 | const SkMatrix& matrix, |
| 25 | const GrTextureParams& params) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 26 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->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, |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 30 | const SkMatrix& matrix, |
| 31 | const GrTextureParams& params) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 32 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 33 | } |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 34 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 35 | bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame^] | 36 | GrProcOptInfo coverageProcInfo; |
| 37 | coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(), |
| 38 | 0xFFFFFFFF, kRGBA_GrColorComponentFlags, true); |
| 39 | GrProcOptInfo colorProcInfo; |
| 40 | colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor, |
| 41 | kRGBA_GrColorComponentFlags, false); |
| 42 | |
| 43 | GrXPFactory::InvariantOutput output; |
| 44 | fXPFactory->getInvariantOutput(colorProcInfo, coverageProcInfo, true, &output); |
| 45 | |
| 46 | if (kRGBA_GrColorComponentFlags == output.fBlendedColorFlags && |
| 47 | 0xFF == GrColorUnpackA(output.fBlendedColor)) { |
| 48 | *color = output.fBlendedColor; |
| 49 | return true; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 50 | } |
| 51 | return false; |
| 52 | } |
| 53 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 54 | void GrPaint::resetStages() { |
| 55 | fColorStages.reset(); |
| 56 | fCoverageStages.reset(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 57 | fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 58 | } |
| 59 | |