blob: 3a1da368d7c54d0926d82b3804bd084b7053dd1a [file] [log] [blame]
halcanarya6814332015-05-27 08:53:36 -07001/*
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
11static bool just_solid_color(const SkPaint& p) {
reed374772b2016-10-05 17:33:02 -070012 return SK_AlphaOPAQUE == p.getAlpha() && !p.getColorFilter() && !p.getShader();
halcanarya6814332015-05-27 08:53:36 -070013}
14
reed374772b2016-10-05 17:33:02 -070015SkXfermodeInterpretation SkInterpretXfermode(const SkPaint& paint, bool dstIsOpaque) {
16 switch (paint.getBlendMode()) {
17 case SkBlendMode::kSrcOver:
halcanarya6814332015-05-27 08:53:36 -070018 return kSrcOver_SkXfermodeInterpretation;
reed374772b2016-10-05 17:33:02 -070019 case SkBlendMode::kSrc:
halcanarya6814332015-05-27 08:53:36 -070020 if (just_solid_color(paint)) {
21 return kSrcOver_SkXfermodeInterpretation;
22 }
23 return kNormal_SkXfermodeInterpretation;
reed374772b2016-10-05 17:33:02 -070024 case SkBlendMode::kDst:
halcanarya6814332015-05-27 08:53:36 -070025 return kSkipDrawing_SkXfermodeInterpretation;
reed374772b2016-10-05 17:33:02 -070026 case SkBlendMode::kDstOver:
halcanarya6814332015-05-27 08:53:36 -070027 if (dstIsOpaque) {
28 return kSkipDrawing_SkXfermodeInterpretation;
29 }
30 return kNormal_SkXfermodeInterpretation;
reed374772b2016-10-05 17:33:02 -070031 case SkBlendMode::kSrcIn:
halcanarya6814332015-05-27 08:53:36 -070032 if (dstIsOpaque && just_solid_color(paint)) {
33 return kSrcOver_SkXfermodeInterpretation;
34 }
35 return kNormal_SkXfermodeInterpretation;
reed374772b2016-10-05 17:33:02 -070036 case SkBlendMode::kDstIn:
halcanarya6814332015-05-27 08:53:36 -070037 if (just_solid_color(paint)) {
38 return kSkipDrawing_SkXfermodeInterpretation;
39 }
40 return kNormal_SkXfermodeInterpretation;
41 default:
42 return kNormal_SkXfermodeInterpretation;
43 }
44}