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 | |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 55 | GrProcessor::InvariantOutput inout; |
| 56 | inout.fColor = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); |
| 57 | inout.fValidFlags = kRGBA_GrColorComponentFlags; |
| 58 | inout.fIsSingleComponent = false; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 59 | int count = fCoverageStages.count(); |
| 60 | for (int i = 0; i < count; ++i) { |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 61 | fCoverageStages[i].getProcessor()->computeInvariantOutput(&inout); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 62 | } |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 63 | if (!inout.isSolidWhite()) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 64 | return false; |
| 65 | } |
| 66 | |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 67 | inout.fColor = fColor; |
| 68 | inout.fValidFlags = kRGBA_GrColorComponentFlags; |
| 69 | inout.fIsSingleComponent = false; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 70 | count = fColorStages.count(); |
| 71 | for (int i = 0; i < count; ++i) { |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 72 | fColorStages[i].getProcessor()->computeInvariantOutput(&inout); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 73 | } |
| 74 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 75 | SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents)); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 76 | |
| 77 | GrBlendCoeff srcCoeff = fSrcBlendCoeff; |
| 78 | GrBlendCoeff dstCoeff = fDstBlendCoeff; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 79 | GrSimplifyBlend(&srcCoeff, &dstCoeff, inout.fColor, inout.fValidFlags, |
| 80 | 0, 0, 0); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 81 | |
| 82 | bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 83 | if (solidColor) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 84 | if (opaque) { |
| 85 | switch (srcCoeff) { |
| 86 | case kZero_GrBlendCoeff: |
| 87 | *solidColor = 0; |
| 88 | *solidColorKnownComponents = kRGBA_GrColorComponentFlags; |
| 89 | break; |
| 90 | |
| 91 | case kOne_GrBlendCoeff: |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 92 | *solidColor = inout.fColor; |
| 93 | *solidColorKnownComponents = inout.fValidFlags; |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 94 | break; |
| 95 | |
| 96 | // The src coeff should never refer to the src and if it refers to dst then opaque |
| 97 | // should have been false. |
| 98 | case kSC_GrBlendCoeff: |
| 99 | case kISC_GrBlendCoeff: |
| 100 | case kDC_GrBlendCoeff: |
| 101 | case kIDC_GrBlendCoeff: |
| 102 | case kSA_GrBlendCoeff: |
| 103 | case kISA_GrBlendCoeff: |
| 104 | case kDA_GrBlendCoeff: |
| 105 | case kIDA_GrBlendCoeff: |
| 106 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 107 | SkFAIL("srcCoeff should not refer to src or dst."); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 108 | break; |
| 109 | |
| 110 | // TODO: update this once GrPaint actually has a const color. |
| 111 | case kConstC_GrBlendCoeff: |
| 112 | case kIConstC_GrBlendCoeff: |
| 113 | case kConstA_GrBlendCoeff: |
| 114 | case kIConstA_GrBlendCoeff: |
| 115 | *solidColorKnownComponents = 0; |
| 116 | break; |
| 117 | } |
| 118 | } else { |
| 119 | solidColorKnownComponents = 0; |
| 120 | } |
| 121 | } |
| 122 | return opaque; |
| 123 | } |