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 | |
| 35 | bool GrPaint::isOpaque() const { |
| 36 | return this->getOpaqueAndKnownColor(NULL, NULL); |
| 37 | } |
| 38 | |
| 39 | bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 40 | GrColor tempColor = 0; |
| 41 | uint32_t colorComps = 0; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 42 | if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) { |
| 43 | if (kRGBA_GrColorComponentFlags == colorComps) { |
| 44 | *color = tempColor; |
| 45 | return true; |
| 46 | } |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 51 | void GrPaint::resetStages() { |
| 52 | fColorStages.reset(); |
| 53 | fCoverageStages.reset(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 54 | fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 55 | } |
| 56 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 57 | bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, |
| 58 | uint32_t* solidColorKnownComponents) const { |
| 59 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 60 | GrProcOptInfo coverageProcInfo; |
| 61 | coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(), |
| 62 | 0xFFFFFFFF, kRGBA_GrColorComponentFlags, true); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 63 | GrProcOptInfo colorProcInfo; |
| 64 | colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor, |
| 65 | kRGBA_GrColorComponentFlags, false); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 66 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 67 | return fXPFactory->getOpaqueAndKnownColor(colorProcInfo, coverageProcInfo, solidColor, |
| 68 | solidColorKnownComponents); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 69 | } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 70 | |