diff options
author | reed <reed@google.com> | 2015-07-15 13:42:32 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-15 13:42:32 -0700 |
commit | af51e04dc0978d7a93f12ee7588f5af9336c1fcc (patch) | |
tree | 037742b169e4265a73e54ef2bd65c808291f1bbe /src/core/SkPaintPriv.cpp | |
parent | 891f0f35db5c805f57fe070a2f2b515c612eecca (diff) |
rename utility to see if a paint will overwrite its pixels
BUG=skia:
Review URL: https://codereview.chromium.org/1228853005
Diffstat (limited to 'src/core/SkPaintPriv.cpp')
-rw-r--r-- | src/core/SkPaintPriv.cpp | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp index 3ced573929..a4a7327110 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); } |