1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "GrPaint.h" 9 #include "GrXferProcessor.h" 10 #include "effects/GrCoverageSetOpXP.h" 11 #include "effects/GrPorterDuffXferProcessor.h" 12 #include "effects/GrSimpleTextureEffect.h" 13 14 GrPaint::GrPaint(const GrPaint& that) 15 : fXPFactory(that.fXPFactory) 16 , fColorFragmentProcessors(that.fColorFragmentProcessors.count()) 17 , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count()) 18 , fTrivial(that.fTrivial) 19 , fColor(that.fColor) { 20 for (int i = 0; i < that.fColorFragmentProcessors.count(); ++i) { 21 fColorFragmentProcessors.push_back(that.fColorFragmentProcessors[i]->clone()); 22 SkASSERT(fColorFragmentProcessors[i]); 23 } 24 for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) { 25 fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone()); 26 SkASSERT(fCoverageFragmentProcessors[i]); 27 } 28 } 29 30 void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) { 31 this->setXPFactory(GrPorterDuffXPFactory::Get(mode)); 32 } 33 34 void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) { 35 this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage)); 36 } 37 38 void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix) { 39 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix)); 40 } 41 42 void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix, 43 const GrSamplerState& samplerState) { 44 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix, 45 samplerState)); 46 } 47 48 void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy, 49 const SkMatrix& matrix) { 50 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix)); 51 } 52 53 void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy, 54 const SkMatrix& matrix, 55 const GrSamplerState& params) { 56 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix, 57 params)); 58 } 59 60 bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const { 61 // This used to do a more sophisticated analysis but now it just explicitly looks for common 62 // cases. 63 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc); 64 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear); 65 if (kClear == fXPFactory) { 66 *constantColor = SK_PMColor4fTRANSPARENT; 67 return true; 68 } 69 if (this->numColorFragmentProcessors()) { 70 return false; 71 } 72 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) { 73 *constantColor = fColor; 74 return true; 75 } 76 return false; 77 } 78