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