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

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
« no previous file with comments | « src/core/SkPaintPriv.h ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « src/core/SkPaintPriv.h ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698