Chromium Code Reviews| 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, SkPaintBitmapOpacity contentType) { | 15 bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) { |
| 16 // TODO: SkXfermode should have a virtual isOpaque method, which would | |
| 17 // make it possible to test modes that do not have a Coeff representation. | |
| 18 | |
| 19 if (!paint) { | 16 if (!paint) { |
| 20 return contentType != kUnknown_SkPaintBitmapOpacity; | 17 return contentType != kUnknown_SkPaintBitmapOpacity; |
| 21 } | 18 } |
| 19 SkXfermode::SrcColorOpacity opacityType = SkXfermode::kUnknown_SrcColorOpaci ty; | |
| 22 | 20 |
| 23 SkXfermode::Coeff srcCoeff, dstCoeff; | 21 if (!paint->getColorFilter() || |
| 24 if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){ | 22 ((paint->getColorFilter()->getFlags() & |
| 25 if (SkXfermode::kDA_Coeff == srcCoeff || SkXfermode::kDC_Coeff == srcCoe ff || | 23 SkColorFilter::kAlphaUnchanged_Flag) != 0)) { |
| 26 SkXfermode::kIDA_Coeff == srcCoeff || SkXfermode::kIDC_Coeff == srcC oeff) { | 24 if (255 == paint->getAlpha() && |
|
bsalomon
2015/01/21 17:51:07
I think we usually use 0xff
| |
| 27 return false; | 25 contentType != kUnknown_SkPaintBitmapOpacity && |
| 28 } | 26 (!paint->getShader() || paint->getShader()->isOpaque())) { |
| 29 switch (dstCoeff) { | 27 opacityType = SkXfermode::kOpaque_SrcColorOpacity; |
| 30 case SkXfermode::kZero_Coeff: | 28 } else if (0 == paint->getColor() && |
| 31 return true; | 29 contentType == kNoBitmap_SkPaintBitmapOpacity && |
| 32 case SkXfermode::kISA_Coeff: | 30 !paint->getShader()) { |
| 33 if (paint->getAlpha() != 255) { | 31 opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity; |
| 34 break; | 32 } else if (0 == paint->getAlpha()) { |
| 35 } | 33 opacityType = SkXfermode::kTransparentAlpha_SrcColorOpacity; |
| 36 if (contentType == kUnknown_SkPaintBitmapOpacity) { | |
| 37 break; | |
| 38 } else if (paint->getShader() && !paint->getShader()->isOpaque()) { | |
| 39 break; | |
| 40 } | |
| 41 if (paint->getColorFilter() && | |
| 42 ((paint->getColorFilter()->getFlags() & | |
| 43 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { | |
| 44 break; | |
| 45 } | |
| 46 return true; | |
| 47 case SkXfermode::kSA_Coeff: | |
| 48 if (paint->getAlpha() != 0) { | |
| 49 break; | |
| 50 } | |
| 51 if (paint->getColorFilter() && | |
| 52 ((paint->getColorFilter()->getFlags() & | |
| 53 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { | |
| 54 break; | |
| 55 } | |
| 56 return true; | |
| 57 case SkXfermode::kSC_Coeff: | |
| 58 if (paint->getColor() != 0) { // all components must be 0 | |
| 59 break; | |
| 60 } | |
| 61 if (contentType != kNoBitmap_SkPaintBitmapOpacity || paint->getShade r()) { | |
| 62 break; | |
| 63 } | |
| 64 if (paint->getColorFilter() && ( | |
| 65 (paint->getColorFilter()->getFlags() & | |
| 66 SkColorFilter::kAlphaUnchanged_Flag) == 0)) { | |
| 67 break; | |
| 68 } | |
| 69 return true; | |
| 70 default: | |
| 71 break; | |
| 72 } | 34 } |
| 73 } | 35 } |
| 74 return false; | 36 |
| 37 return SkXfermode::IsOpaque(paint->getXfermode(), opacityType); | |
| 75 } | 38 } |
| 76 | 39 |
| 77 bool isPaintOpaque(const SkPaint* paint, const SkBitmap* bmpReplacesShader) { | 40 bool isPaintOpaque(const SkPaint* paint, const SkBitmap* bmpReplacesShader) { |
| 78 SkPaintBitmapOpacity contentType; | 41 SkPaintBitmapOpacity contentType; |
| 79 | 42 |
| 80 if(!bmpReplacesShader) | 43 if(!bmpReplacesShader) |
| 81 contentType = kNoBitmap_SkPaintBitmapOpacity; | 44 contentType = kNoBitmap_SkPaintBitmapOpacity; |
| 82 else if(bmpReplacesShader->isOpaque()) | 45 else if(bmpReplacesShader->isOpaque()) |
| 83 contentType = kOpaque_SkPaintBitmapOpacity; | 46 contentType = kOpaque_SkPaintBitmapOpacity; |
| 84 else | 47 else |
| 85 contentType = kUnknown_SkPaintBitmapOpacity; | 48 contentType = kUnknown_SkPaintBitmapOpacity; |
| 86 | 49 |
| 87 return isPaintOpaque(paint, contentType); | 50 return isPaintOpaque(paint, contentType); |
| 88 } | 51 } |
| OLD | NEW |