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