diff options
Diffstat (limited to 'gfx/skia/skia/src/core/SkXfermodeInterpretation.cpp')
-rw-r--r-- | gfx/skia/skia/src/core/SkXfermodeInterpretation.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gfx/skia/skia/src/core/SkXfermodeInterpretation.cpp b/gfx/skia/skia/src/core/SkXfermodeInterpretation.cpp new file mode 100644 index 0000000000..607f4c995d --- /dev/null +++ b/gfx/skia/skia/src/core/SkXfermodeInterpretation.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "src/core/SkXfermodeInterpretation.h" + +#include "include/core/SkBlendMode.h" +#include "include/core/SkPaint.h" + +static bool just_solid_color(const SkPaint& p) { + return SK_AlphaOPAQUE == p.getAlpha() && !p.getColorFilter() && !p.getShader(); +} + +SkXfermodeInterpretation SkInterpretXfermode(const SkPaint& paint, bool dstIsOpaque) { + const auto bm = paint.asBlendMode(); + if (!bm) { + return kNormal_SkXfermodeInterpretation; + } + switch (bm.value()) { + case SkBlendMode::kSrcOver: + return kSrcOver_SkXfermodeInterpretation; + case SkBlendMode::kSrc: + if (just_solid_color(paint)) { + return kSrcOver_SkXfermodeInterpretation; + } + return kNormal_SkXfermodeInterpretation; + case SkBlendMode::kDst: + return kSkipDrawing_SkXfermodeInterpretation; + case SkBlendMode::kDstOver: + if (dstIsOpaque) { + return kSkipDrawing_SkXfermodeInterpretation; + } + return kNormal_SkXfermodeInterpretation; + case SkBlendMode::kSrcIn: + if (dstIsOpaque && just_solid_color(paint)) { + return kSrcOver_SkXfermodeInterpretation; + } + return kNormal_SkXfermodeInterpretation; + case SkBlendMode::kDstIn: + if (just_solid_color(paint)) { + return kSkipDrawing_SkXfermodeInterpretation; + } + return kNormal_SkXfermodeInterpretation; + default: + return kNormal_SkXfermodeInterpretation; + } +} |