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 "src/gpu/GrPaint.h" 9 #include "src/gpu/GrXferProcessor.h" 10 #include "src/gpu/effects/GrCoverageSetOpXP.h" 11 #include "src/gpu/effects/GrPorterDuffXferProcessor.h" 12 #include "src/gpu/effects/GrTextureEffect.h" 13 GrPaint(const GrPaint & that)14GrPaint::GrPaint(const GrPaint& that) 15 : fXPFactory(that.fXPFactory) 16 , fTrivial(that.fTrivial) 17 , fColor(that.fColor) { 18 if (that.fColorFragmentProcessor) { 19 fColorFragmentProcessor = that.fColorFragmentProcessor->clone(); 20 SkASSERT(fColorFragmentProcessor); 21 } 22 if (that.fCoverageFragmentProcessor) { 23 fCoverageFragmentProcessor = that.fCoverageFragmentProcessor->clone(); 24 SkASSERT(fCoverageFragmentProcessor); 25 } 26 } 27 setPorterDuffXPFactory(SkBlendMode mode)28void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) { 29 this->setXPFactory(GrPorterDuffXPFactory::Get(mode)); 30 } 31 setCoverageSetOpXPFactory(SkRegion::Op regionOp,bool invertCoverage)32void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) { 33 this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage)); 34 } 35 isConstantBlendedColor(SkPMColor4f * constantColor) const36bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const { 37 // This used to do a more sophisticated analysis but now it just explicitly looks for common 38 // cases. 39 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc); 40 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear); 41 if (kClear == fXPFactory) { 42 *constantColor = SK_PMColor4fTRANSPARENT; 43 return true; 44 } 45 if (this->hasColorFragmentProcessor()) { 46 return false; 47 } 48 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) { 49 *constantColor = fColor; 50 return true; 51 } 52 return false; 53 } 54