aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkXfermodeInterpretation.cpp
blob: 1b2c8e32e6315cef7ceefafd9f11379585f8a6ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * 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 "SkXfermodeInterpretation.h"
#include "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 SkXfermode* xfer = paint.getXfermode();
    SkXfermode::Mode mode;
    if (!SkXfermode::AsMode(xfer, &mode)) {
        return kNormal_SkXfermodeInterpretation;
    }
    switch (mode) {
        case SkXfermode::kSrcOver_Mode:
            return kSrcOver_SkXfermodeInterpretation;
        case SkXfermode::kSrc_Mode:
            if (just_solid_color(paint)) {
                return kSrcOver_SkXfermodeInterpretation;
            }
            return kNormal_SkXfermodeInterpretation;
        case SkXfermode::kDst_Mode:
            return kSkipDrawing_SkXfermodeInterpretation;
        case SkXfermode::kDstOver_Mode:
            if (dstIsOpaque) {
                return kSkipDrawing_SkXfermodeInterpretation;
            }
            return kNormal_SkXfermodeInterpretation;
        case SkXfermode::kSrcIn_Mode:
            if (dstIsOpaque && just_solid_color(paint)) {
                return kSrcOver_SkXfermodeInterpretation;
            }
            return kNormal_SkXfermodeInterpretation;
        case SkXfermode::kDstIn_Mode:
            if (just_solid_color(paint)) {
                return kSkipDrawing_SkXfermodeInterpretation;
            }
            return kNormal_SkXfermodeInterpretation;
        default:
            return kNormal_SkXfermodeInterpretation;
    }
}