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 11 static bool just_solid_color(const SkPaint& p) { 12 return SK_AlphaOPAQUE == p.getAlpha() 13 && !p.getColorFilter() && !p.getShader(); 14 } 15 16 SkXfermodeInterpretation SkInterpretXfermode(const SkPaint& paint, 17 bool dstIsOpaque) { 18 const SkXfermode* xfer = paint.getXfermode(); 19 SkXfermode::Mode mode; 20 if (!SkXfermode::AsMode(xfer, &mode)) { 21 return kNormal_SkXfermodeInterpretation; 22 } 23 switch (mode) { 24 case SkXfermode::kSrcOver_Mode: 25 return kSrcOver_SkXfermodeInterpretation; 26 case SkXfermode::kSrc_Mode: 27 if (just_solid_color(paint)) { 28 return kSrcOver_SkXfermodeInterpretation; 29 } 30 return kNormal_SkXfermodeInterpretation; 31 case SkXfermode::kDst_Mode: 32 return kSkipDrawing_SkXfermodeInterpretation; 33 case SkXfermode::kDstOver_Mode: 34 if (dstIsOpaque) { 35 return kSkipDrawing_SkXfermodeInterpretation; 36 } 37 return kNormal_SkXfermodeInterpretation; 38 case SkXfermode::kSrcIn_Mode: 39 if (dstIsOpaque && just_solid_color(paint)) { 40 return kSrcOver_SkXfermodeInterpretation; 41 } 42 return kNormal_SkXfermodeInterpretation; 43 case SkXfermode::kDstIn_Mode: 44 if (just_solid_color(paint)) { 45 return kSkipDrawing_SkXfermodeInterpretation; 46 } 47 return kNormal_SkXfermodeInterpretation; 48 default: 49 return kNormal_SkXfermodeInterpretation; 50 } 51 } 52