aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPaintPriv.cpp
blob: c6957cd1cafe29ba19b76937a3d10999c7680927 (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 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkPaintPriv.h"

#include "SkBitmap.h"
#include "SkColorFilter.h"
#include "SkPaint.h"
#include "SkShader.h"

bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) {
    if (!paint) {
        return contentType != kUnknown_SkPaintBitmapOpacity;
    }
    SkXfermode::SrcColorOpacity opacityType = SkXfermode::kUnknown_SrcColorOpacity;

    if (!paint->getColorFilter() ||
        ((paint->getColorFilter()->getFlags() &
          SkColorFilter::kAlphaUnchanged_Flag) != 0)) {
        if (0xff == paint->getAlpha() &&
            contentType != kUnknown_SkPaintBitmapOpacity &&
            (!paint->getShader() || paint->getShader()->isOpaque())) {
            opacityType = SkXfermode::kOpaque_SrcColorOpacity;
        } else if (0 == paint->getColor() &&
                   contentType == kNoBitmap_SkPaintBitmapOpacity &&
                   !paint->getShader()) {
            opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity;
        } else if (0 == paint->getAlpha()) {
            opacityType = SkXfermode::kTransparentAlpha_SrcColorOpacity;
        }
    }

    return SkXfermode::IsOpaque(paint->getXfermode(), opacityType);
}

bool isPaintOpaque(const SkPaint* paint, const SkBitmap* bmpReplacesShader) {
    SkPaintBitmapOpacity contentType;

    if(!bmpReplacesShader)
        contentType = kNoBitmap_SkPaintBitmapOpacity;
    else if(bmpReplacesShader->isOpaque())
        contentType = kOpaque_SkPaintBitmapOpacity;
    else
        contentType = kUnknown_SkPaintBitmapOpacity;

    return isPaintOpaque(paint, contentType);
}