1 /* 2 * Copyright 2015 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 "SkXfermodeInterpretation.h" 9 #include "SkPaint.h" 10 just_solid_color(const SkPaint & p)11static bool just_solid_color(const SkPaint& p) { 12 return SK_AlphaOPAQUE == p.getAlpha() && !p.getColorFilter() && !p.getShader(); 13 } 14 SkInterpretXfermode(const SkPaint & paint,bool dstIsOpaque)15SkXfermodeInterpretation SkInterpretXfermode(const SkPaint& paint, bool dstIsOpaque) { 16 switch (paint.getBlendMode()) { 17 case SkBlendMode::kSrcOver: 18 return kSrcOver_SkXfermodeInterpretation; 19 case SkBlendMode::kSrc: 20 if (just_solid_color(paint)) { 21 return kSrcOver_SkXfermodeInterpretation; 22 } 23 return kNormal_SkXfermodeInterpretation; 24 case SkBlendMode::kDst: 25 return kSkipDrawing_SkXfermodeInterpretation; 26 case SkBlendMode::kDstOver: 27 if (dstIsOpaque) { 28 return kSkipDrawing_SkXfermodeInterpretation; 29 } 30 return kNormal_SkXfermodeInterpretation; 31 case SkBlendMode::kSrcIn: 32 if (dstIsOpaque && just_solid_color(paint)) { 33 return kSrcOver_SkXfermodeInterpretation; 34 } 35 return kNormal_SkXfermodeInterpretation; 36 case SkBlendMode::kDstIn: 37 if (just_solid_color(paint)) { 38 return kSkipDrawing_SkXfermodeInterpretation; 39 } 40 return kNormal_SkXfermodeInterpretation; 41 default: 42 return kNormal_SkXfermodeInterpretation; 43 } 44 } 45