| Index: src/core/SkPaintPriv.cpp
|
| diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp
|
| index 3ced57392934e1f5b6a5fbb993c9c7f7be9acab9..a4a7327110ff930e48b7986bbe95b5ddf8206f0a 100644
|
| --- a/src/core/SkPaintPriv.cpp
|
| +++ b/src/core/SkPaintPriv.cpp
|
| @@ -13,45 +13,54 @@
|
| #include "SkPaint.h"
|
| #include "SkShader.h"
|
|
|
| -bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) {
|
| +enum ShaderOverrideOpacity {
|
| + kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
|
| + kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
|
| + kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque
|
| +};
|
| +
|
| +static bool changes_alpha(const SkPaint& paint) {
|
| + SkColorFilter* cf = paint.getColorFilter();
|
| + return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
|
| +}
|
| +
|
| +static bool overwrites(const SkPaint* paint, ShaderOverrideOpacity overrideOpacity) {
|
| if (!paint) {
|
| - return contentType != kUnknown_SkPaintBitmapOpacity;
|
| + // 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 (!paint->getColorFilter() ||
|
| - ((paint->getColorFilter()->getFlags() &
|
| - SkColorFilter::kAlphaUnchanged_Flag) != 0)) {
|
| - if (0xff == paint->getAlpha() &&
|
| - contentType != kUnknown_SkPaintBitmapOpacity &&
|
| - (!paint->getShader() || paint->getShader()->isOpaque())) {
|
| + 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 == paint->getColor() &&
|
| - contentType == kNoBitmap_SkPaintBitmapOpacity &&
|
| - !paint->getShader()) {
|
| - opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity;
|
| - } else if (0 == paint->getAlpha()) {
|
| - opacityType = SkXfermode::kTransparentAlpha_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 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;
|
| +bool SkPaintPriv::Overwrites(const SkPaint& paint) {
|
| + return overwrites(&paint, kNone_ShaderOverrideOpacity);
|
| +}
|
|
|
| - return isPaintOpaque(paint, contentType);
|
| +bool SkPaintPriv::Overwrites(const SkBitmap& bitmap, const SkPaint* paint) {
|
| + return overwrites(paint, bitmap.isOpaque() ? kOpaque_ShaderOverrideOpacity
|
| + : kNotOpaque_ShaderOverrideOpacity);
|
| }
|
|
|
| -bool isPaintOpaque(const SkPaint* paint, const SkImage* image) {
|
| - return isPaintOpaque(paint, image->isOpaque() ?
|
| - kOpaque_SkPaintBitmapOpacity : kUnknown_SkPaintBitmapOpacity);
|
| +bool SkPaintPriv::Overwrites(const SkImage* image, const SkPaint* paint) {
|
| + return overwrites(paint, image->isOpaque() ? kOpaque_ShaderOverrideOpacity
|
| + : kNotOpaque_ShaderOverrideOpacity);
|
| }
|
|
|