blob: 6725cb49befd4c191bda3b817d7a7eb82d0915ce (
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
52
53
54
55
|
/*
* 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 "SkBitmap.h"
#include "SkColorFilter.h"
#include "SkPaintPriv.h"
#include "SkImage.h"
#include "SkPaint.h"
#include "SkShader.h"
static bool changes_alpha(const SkPaint& paint) {
SkColorFilter* cf = paint.getColorFilter();
return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
}
bool SkPaintPriv::Overwrites(const SkPaint* paint, ShaderOverrideOpacity overrideOpacity) {
if (!paint) {
// No paint means we default to SRC_OVER, so we overwrite iff our shader-override
// is opaque, or we don't have one.
return overrideOpacity != kNotOpaque_ShaderOverrideOpacity;
}
SkXfermode::SrcColorOpacity opacityType = SkXfermode::kUnknown_SrcColorOpacity;
if (!changes_alpha(*paint)) {
const unsigned paintAlpha = paint->getAlpha();
if (0xff == paintAlpha && overrideOpacity != kNotOpaque_ShaderOverrideOpacity &&
(!paint->getShader() || paint->getShader()->isOpaque()))
{
opacityType = SkXfermode::kOpaque_SrcColorOpacity;
} else if (0 == paintAlpha) {
if (overrideOpacity == kNone_ShaderOverrideOpacity && !paint->getShader()) {
opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity;
} else {
opacityType = SkXfermode::kTransparentAlpha_SrcColorOpacity;
}
}
}
return SkXfermode::IsOpaque(paint->getXfermode(), opacityType);
}
bool SkPaintPriv::Overwrites(const SkBitmap& bitmap, const SkPaint* paint) {
return Overwrites(paint, bitmap.isOpaque() ? kOpaque_ShaderOverrideOpacity
: kNotOpaque_ShaderOverrideOpacity);
}
bool SkPaintPriv::Overwrites(const SkImage* image, const SkPaint* paint) {
return Overwrites(paint, image->isOpaque() ? kOpaque_ShaderOverrideOpacity
: kNotOpaque_ShaderOverrideOpacity);
}
|