blob: ce0538901922fde98f8e6e9695a7cdd1fab5caee (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/*
* 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,
const SkBitmap* bmpReplacesShader) {
// TODO: SkXfermode should have a virtual isOpaque method, which would
// make it possible to test modes that do not have a Coeff representation.
if (!paint) {
return bmpReplacesShader ? bmpReplacesShader->isOpaque() : true;
}
SkXfermode::Coeff srcCoeff, dstCoeff;
if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){
if (SkXfermode::kDA_Coeff == srcCoeff || SkXfermode::kDC_Coeff == srcCoeff ||
SkXfermode::kIDA_Coeff == srcCoeff || SkXfermode::kIDC_Coeff == srcCoeff) {
return false;
}
switch (dstCoeff) {
case SkXfermode::kZero_Coeff:
return true;
case SkXfermode::kISA_Coeff:
if (paint->getAlpha() != 255) {
break;
}
if (bmpReplacesShader) {
if (!bmpReplacesShader->isOpaque()) {
break;
}
} else if (paint->getShader() && !paint->getShader()->isOpaque()) {
break;
}
if (paint->getColorFilter() &&
((paint->getColorFilter()->getFlags() &
SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
break;
}
return true;
case SkXfermode::kSA_Coeff:
if (paint->getAlpha() != 0) {
break;
}
if (paint->getColorFilter() &&
((paint->getColorFilter()->getFlags() &
SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
break;
}
return true;
case SkXfermode::kSC_Coeff:
if (paint->getColor() != 0) { // all components must be 0
break;
}
if (bmpReplacesShader || paint->getShader()) {
break;
}
if (paint->getColorFilter() && (
(paint->getColorFilter()->getFlags() &
SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
break;
}
return true;
default:
break;
}
}
return false;
}
|