OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPaintPriv.h" | 8 #include "SkPaintPriv.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkColorFilter.h" | 11 #include "SkColorFilter.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 | 14 |
15 bool isPaintOpaque(const SkPaint* paint, | 15 bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) { |
16 const SkBitmap* bmpReplacesShader) { | |
17 // TODO: SkXfermode should have a virtual isOpaque method, which would | 16 // TODO: SkXfermode should have a virtual isOpaque method, which would |
18 // make it possible to test modes that do not have a Coeff representation. | 17 // make it possible to test modes that do not have a Coeff representation. |
19 | 18 |
20 if (!paint) { | 19 if (!paint) { |
21 return bmpReplacesShader ? bmpReplacesShader->isOpaque() : true; | 20 return contentType != kUnknown_SkPaintBitmapOpacity; |
22 } | 21 } |
23 | 22 |
24 SkXfermode::Coeff srcCoeff, dstCoeff; | 23 SkXfermode::Coeff srcCoeff, dstCoeff; |
25 if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){ | 24 if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){ |
26 if (SkXfermode::kDA_Coeff == srcCoeff || SkXfermode::kDC_Coeff == srcCoe
ff || | 25 if (SkXfermode::kDA_Coeff == srcCoeff || SkXfermode::kDC_Coeff == srcCoe
ff || |
27 SkXfermode::kIDA_Coeff == srcCoeff || SkXfermode::kIDC_Coeff == srcC
oeff) { | 26 SkXfermode::kIDA_Coeff == srcCoeff || SkXfermode::kIDC_Coeff == srcC
oeff) { |
28 return false; | 27 return false; |
29 } | 28 } |
30 switch (dstCoeff) { | 29 switch (dstCoeff) { |
31 case SkXfermode::kZero_Coeff: | 30 case SkXfermode::kZero_Coeff: |
32 return true; | 31 return true; |
33 case SkXfermode::kISA_Coeff: | 32 case SkXfermode::kISA_Coeff: |
34 if (paint->getAlpha() != 255) { | 33 if (paint->getAlpha() != 255) { |
35 break; | 34 break; |
36 } | 35 } |
37 if (bmpReplacesShader) { | 36 if (contentType == kUnknown_SkPaintBitmapOpacity) { |
38 if (!bmpReplacesShader->isOpaque()) { | 37 break; |
39 break; | |
40 } | |
41 } else if (paint->getShader() && !paint->getShader()->isOpaque()) { | 38 } else if (paint->getShader() && !paint->getShader()->isOpaque()) { |
42 break; | 39 break; |
43 } | 40 } |
44 if (paint->getColorFilter() && | 41 if (paint->getColorFilter() && |
45 ((paint->getColorFilter()->getFlags() & | 42 ((paint->getColorFilter()->getFlags() & |
46 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { | 43 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { |
47 break; | 44 break; |
48 } | 45 } |
49 return true; | 46 return true; |
50 case SkXfermode::kSA_Coeff: | 47 case SkXfermode::kSA_Coeff: |
51 if (paint->getAlpha() != 0) { | 48 if (paint->getAlpha() != 0) { |
52 break; | 49 break; |
53 } | 50 } |
54 if (paint->getColorFilter() && | 51 if (paint->getColorFilter() && |
55 ((paint->getColorFilter()->getFlags() & | 52 ((paint->getColorFilter()->getFlags() & |
56 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { | 53 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { |
57 break; | 54 break; |
58 } | 55 } |
59 return true; | 56 return true; |
60 case SkXfermode::kSC_Coeff: | 57 case SkXfermode::kSC_Coeff: |
61 if (paint->getColor() != 0) { // all components must be 0 | 58 if (paint->getColor() != 0) { // all components must be 0 |
62 break; | 59 break; |
63 } | 60 } |
64 if (bmpReplacesShader || paint->getShader()) { | 61 if (contentType != kNoBitmap_SkPaintBitmapOpacity || paint->getShade
r()) { |
65 break; | 62 break; |
66 } | 63 } |
67 if (paint->getColorFilter() && ( | 64 if (paint->getColorFilter() && ( |
68 (paint->getColorFilter()->getFlags() & | 65 (paint->getColorFilter()->getFlags() & |
69 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { | 66 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { |
70 break; | 67 break; |
71 } | 68 } |
72 return true; | 69 return true; |
73 default: | 70 default: |
74 break; | 71 break; |
75 } | 72 } |
76 } | 73 } |
77 return false; | 74 return false; |
78 } | 75 } |
| 76 |
| 77 bool isPaintOpaque(const SkPaint* paint, const SkBitmap* bmpReplacesShader) { |
| 78 SkPaintBitmapOpacity contentType; |
| 79 |
| 80 if(!bmpReplacesShader) |
| 81 contentType = kNoBitmap_SkPaintBitmapOpacity; |
| 82 else if(bmpReplacesShader->isOpaque()) |
| 83 contentType = kOpaque_SkPaintBitmapOpacity; |
| 84 else |
| 85 contentType = kUnknown_SkPaintBitmapOpacity; |
| 86 |
| 87 return isPaintOpaque(paint, contentType); |
| 88 } |
OLD | NEW |