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 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 11 | #include "GrBlend.h" |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 12 | #include "effects/GrSimpleTextureEffect.h" |
| 13 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 14 | void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 15 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 16 | } |
| 17 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 18 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 19 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 20 | } |
| 21 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 22 | void GrPaint::addColorTextureProcessor(GrTexture* texture, |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 23 | const SkMatrix& matrix, |
| 24 | const GrTextureParams& params) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 25 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 26 | } |
| 27 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 28 | void GrPaint::addCoverageTextureProcessor(GrTexture* texture, |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 29 | const SkMatrix& matrix, |
| 30 | const GrTextureParams& params) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 31 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 32 | } |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 33 | |
| 34 | bool GrPaint::isOpaque() const { |
| 35 | return this->getOpaqueAndKnownColor(NULL, NULL); |
| 36 | } |
| 37 | |
| 38 | bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { |
| 39 | GrColor tempColor; |
| 40 | uint32_t colorComps; |
| 41 | if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) { |
| 42 | if (kRGBA_GrColorComponentFlags == colorComps) { |
| 43 | *color = tempColor; |
| 44 | return true; |
| 45 | } |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, |
| 51 | uint32_t* solidColorKnownComponents) const { |
| 52 | |
| 53 | // TODO: Share this implementation with GrDrawState |
| 54 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 55 | GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); |
| 56 | uint32_t coverageComps = kRGBA_GrColorComponentFlags; |
| 57 | int count = fCoverageStages.count(); |
| 58 | for (int i = 0; i < count; ++i) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 59 | fCoverageStages[i].getProcessor()->getConstantColorComponents(&coverage, &coverageComps); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 60 | } |
| 61 | if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | GrColor color = fColor; |
| 66 | uint32_t colorComps = kRGBA_GrColorComponentFlags; |
| 67 | count = fColorStages.count(); |
| 68 | for (int i = 0; i < count; ++i) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 69 | fColorStages[i].getProcessor()->getConstantColorComponents(&color, &colorComps); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 70 | } |
| 71 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 72 | SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents)); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 73 | |
| 74 | GrBlendCoeff srcCoeff = fSrcBlendCoeff; |
| 75 | GrBlendCoeff dstCoeff = fDstBlendCoeff; |
| 76 | GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0); |
| 77 | |
| 78 | bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 79 | if (solidColor) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 80 | if (opaque) { |
| 81 | switch (srcCoeff) { |
| 82 | case kZero_GrBlendCoeff: |
| 83 | *solidColor = 0; |
| 84 | *solidColorKnownComponents = kRGBA_GrColorComponentFlags; |
| 85 | break; |
| 86 | |
| 87 | case kOne_GrBlendCoeff: |
| 88 | *solidColor = color; |
| 89 | *solidColorKnownComponents = colorComps; |
| 90 | break; |
| 91 | |
| 92 | // The src coeff should never refer to the src and if it refers to dst then opaque |
| 93 | // should have been false. |
| 94 | case kSC_GrBlendCoeff: |
| 95 | case kISC_GrBlendCoeff: |
| 96 | case kDC_GrBlendCoeff: |
| 97 | case kIDC_GrBlendCoeff: |
| 98 | case kSA_GrBlendCoeff: |
| 99 | case kISA_GrBlendCoeff: |
| 100 | case kDA_GrBlendCoeff: |
| 101 | case kIDA_GrBlendCoeff: |
| 102 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 103 | SkFAIL("srcCoeff should not refer to src or dst."); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 104 | break; |
| 105 | |
| 106 | // TODO: update this once GrPaint actually has a const color. |
| 107 | case kConstC_GrBlendCoeff: |
| 108 | case kIConstC_GrBlendCoeff: |
| 109 | case kConstA_GrBlendCoeff: |
| 110 | case kIConstA_GrBlendCoeff: |
| 111 | *solidColorKnownComponents = 0; |
| 112 | break; |
| 113 | } |
| 114 | } else { |
| 115 | solidColorKnownComponents = 0; |
| 116 | } |
| 117 | } |
| 118 | return opaque; |
| 119 | } |