Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: src/core/SkPaintPriv.cpp

Issue 1228853005: rename utility to see if a paint will overwrite its pixels (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkPaintPriv.cpp
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp
index 3ced57392934e1f5b6a5fbb993c9c7f7be9acab9..4249f83281b892eefe8b2f0bb89fcdc54f0ed80c 100644
--- a/src/core/SkPaintPriv.cpp
+++ b/src/core/SkPaintPriv.cpp
@@ -13,45 +13,45 @@
#include "SkPaint.h"
#include "SkShader.h"
-bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) {
+static bool changes_alpha(const SkPaint& paint) {
+ SkColorFilter* cf = paint.getColorFilter();
+ return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
+}
+
+bool SkPaintPriv::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 &&
robertphillips 2015/07/15 15:53:51 Can this go on the prior line ?
reed1 2015/07/15 18:03:03 Done.
+ 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;
-
- return isPaintOpaque(paint, contentType);
+bool SkPaintPriv::Overwrites(const SkPaint* paint, const SkBitmap& bitmap) {
+ 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 SkPaint* paint, const SkImage* image) {
+ return Overwrites(paint, image->isOpaque() ? kOpaque_ShaderOverrideOpacity
+ : kNotOpaque_ShaderOverrideOpacity);
}

Powered by Google App Engine
This is Rietveld 408576698