halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 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) { |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 12 | return SK_AlphaOPAQUE == p.getAlpha() && !p.getColorFilter() && !p.getShader(); |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 13 | } |
| 14 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 15 | SkXfermodeInterpretation SkInterpretXfermode(const SkPaint& paint, bool dstIsOpaque) { |
| 16 | switch (paint.getBlendMode()) { |
| 17 | case SkBlendMode::kSrcOver: |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 18 | return kSrcOver_SkXfermodeInterpretation; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 19 | case SkBlendMode::kSrc: |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 20 | if (just_solid_color(paint)) { |
| 21 | return kSrcOver_SkXfermodeInterpretation; |
| 22 | } |
| 23 | return kNormal_SkXfermodeInterpretation; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 24 | case SkBlendMode::kDst: |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 25 | return kSkipDrawing_SkXfermodeInterpretation; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 26 | case SkBlendMode::kDstOver: |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 27 | if (dstIsOpaque) { |
| 28 | return kSkipDrawing_SkXfermodeInterpretation; |
| 29 | } |
| 30 | return kNormal_SkXfermodeInterpretation; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 31 | case SkBlendMode::kSrcIn: |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 32 | if (dstIsOpaque && just_solid_color(paint)) { |
| 33 | return kSrcOver_SkXfermodeInterpretation; |
| 34 | } |
| 35 | return kNormal_SkXfermodeInterpretation; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 36 | case SkBlendMode::kDstIn: |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 37 | if (just_solid_color(paint)) { |
| 38 | return kSkipDrawing_SkXfermodeInterpretation; |
| 39 | } |
| 40 | return kNormal_SkXfermodeInterpretation; |
| 41 | default: |
| 42 | return kNormal_SkXfermodeInterpretation; |
| 43 | } |
| 44 | } |