GrPaint.cpp revision 66017f6cc52770c04078dc74ddcda27349002652
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 11#include "GrBlend.h" 12#include "effects/GrSimpleTextureEffect.h" 13 14void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { 15 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); 16 this->addColorEffect(effect)->unref(); 17} 18 19void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) { 20 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); 21 this->addCoverageEffect(effect)->unref(); 22} 23 24void GrPaint::addColorTextureEffect(GrTexture* texture, 25 const SkMatrix& matrix, 26 const GrTextureParams& params) { 27 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params); 28 this->addColorEffect(effect)->unref(); 29} 30 31void GrPaint::addCoverageTextureEffect(GrTexture* texture, 32 const SkMatrix& matrix, 33 const GrTextureParams& params) { 34 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params); 35 this->addCoverageEffect(effect)->unref(); 36} 37 38bool GrPaint::isOpaque() const { 39 return this->getOpaqueAndKnownColor(NULL, NULL); 40} 41 42bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { 43 GrColor tempColor; 44 uint32_t colorComps; 45 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) { 46 if (kRGBA_GrColorComponentFlags == colorComps) { 47 *color = tempColor; 48 return true; 49 } 50 } 51 return false; 52} 53 54bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, 55 uint32_t* solidColorKnownComponents) const { 56 57 // TODO: Share this implementation with GrDrawState 58 59 // Since fColorFilterXfermode is going away soon, we aren't attempting to handle anything but 60 // the default setting. 61 if (SkXfermode::kDst_Mode != fColorFilterXfermode) { 62 return false; 63 } 64 65 GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); 66 uint32_t coverageComps = kRGBA_GrColorComponentFlags; 67 int count = fCoverageStages.count(); 68 for (int i = 0; i < count; ++i) { 69 (*fCoverageStages[i].getEffect())->getConstantColorComponents(&coverage, &coverageComps); 70 } 71 if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) { 72 return false; 73 } 74 75 GrColor color = fColor; 76 uint32_t colorComps = kRGBA_GrColorComponentFlags; 77 count = fColorStages.count(); 78 for (int i = 0; i < count; ++i) { 79 (*fColorStages[i].getEffect())->getConstantColorComponents(&color, &colorComps); 80 } 81 82 GrAssert((NULL == solidColor) == (NULL == solidColorKnownComponents)); 83 if (NULL != solidColor) { 84 *solidColor = color; 85 *solidColorKnownComponents = colorComps; 86 } 87 88 GrBlendCoeff srcCoeff = fSrcBlendCoeff; 89 GrBlendCoeff dstCoeff = fDstBlendCoeff; 90 GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0); 91 return kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff); 92} 93