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 "include/core/SkPaint.h" 9 #include "src/core/SkXfermodeInterpretation.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 const auto bm = paint.asBlendMode(); 17 if (!bm) { 18 return kNormal_SkXfermodeInterpretation; 19 } 20 switch (bm.value()) { 21 case SkBlendMode::kSrcOver: 22 return kSrcOver_SkXfermodeInterpretation; 23 case SkBlendMode::kSrc: 24 if (just_solid_color(paint)) { 25 return kSrcOver_SkXfermodeInterpretation; 26 } 27 return kNormal_SkXfermodeInterpretation; 28 case SkBlendMode::kDst: 29 return kSkipDrawing_SkXfermodeInterpretation; 30 case SkBlendMode::kDstOver: 31 if (dstIsOpaque) { 32 return kSkipDrawing_SkXfermodeInterpretation; 33 } 34 return kNormal_SkXfermodeInterpretation; 35 case SkBlendMode::kSrcIn: 36 if (dstIsOpaque && just_solid_color(paint)) { 37 return kSrcOver_SkXfermodeInterpretation; 38 } 39 return kNormal_SkXfermodeInterpretation; 40 case SkBlendMode::kDstIn: 41 if (just_solid_color(paint)) { 42 return kSkipDrawing_SkXfermodeInterpretation; 43 } 44 return kNormal_SkXfermodeInterpretation; 45 default: 46 return kNormal_SkXfermodeInterpretation; 47 } 48 } 49