More genericity: overload isPaintOpaque(SkPaint, SkBitmap)
Instead of taking a Bitmap as an argument this version
takes only the type of content (None/Opaque/Transparent).
This will be used to check the opaqueness of a SkPaint
that draws a SkImage.
BUG=skia:3042
Review URL: https://codereview.chromium.org/663233002
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp
index ce05389..e82c404 100644
--- a/src/core/SkPaintPriv.cpp
+++ b/src/core/SkPaintPriv.cpp
@@ -12,13 +12,12 @@
#include "SkPaint.h"
#include "SkShader.h"
-bool isPaintOpaque(const SkPaint* paint,
- const SkBitmap* bmpReplacesShader) {
+bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) {
// TODO: SkXfermode should have a virtual isOpaque method, which would
// make it possible to test modes that do not have a Coeff representation.
if (!paint) {
- return bmpReplacesShader ? bmpReplacesShader->isOpaque() : true;
+ return contentType != kUnknown_SkPaintBitmapOpacity;
}
SkXfermode::Coeff srcCoeff, dstCoeff;
@@ -34,10 +33,8 @@
if (paint->getAlpha() != 255) {
break;
}
- if (bmpReplacesShader) {
- if (!bmpReplacesShader->isOpaque()) {
- break;
- }
+ if (contentType == kUnknown_SkPaintBitmapOpacity) {
+ break;
} else if (paint->getShader() && !paint->getShader()->isOpaque()) {
break;
}
@@ -61,7 +58,7 @@
if (paint->getColor() != 0) { // all components must be 0
break;
}
- if (bmpReplacesShader || paint->getShader()) {
+ if (contentType != kNoBitmap_SkPaintBitmapOpacity || paint->getShader()) {
break;
}
if (paint->getColorFilter() && (
@@ -76,3 +73,16 @@
}
return false;
}
+
+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);
+}
diff --git a/src/core/SkPaintPriv.h b/src/core/SkPaintPriv.h
index 38c9063..88fc4fc 100644
--- a/src/core/SkPaintPriv.h
+++ b/src/core/SkPaintPriv.h
@@ -12,6 +12,26 @@
class SkPaint;
#include "SkTypes.h"
+
+enum SkPaintBitmapOpacity {
+ // No content replaces the paint's color
+ kNoBitmap_SkPaintBitmapOpacity = 0,
+ // The color replacement is known to be opaque
+ kOpaque_SkPaintBitmapOpacity = 1,
+ // We have no information about the color or it is transparent
+ kUnknown_SkPaintBitmapOpacity = 2
+};
+
+/** Returns true if draw calls that use the paint will completely occlude
+ canvas contents that are covered by the draw.
+ @param paint The paint to be analyzed, NULL is equivalent to
+ the default paint.
+ @param contentType The type of the content that will be drawn,
+ kNoBitmap_SkPaintBitmapOpacity if there is no content in adition to the paint.
+ @return true if paint is opaque
+*/
+bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType);
+
/** Returns true if draw calls that use the paint will completely occlude
canvas contents that are covered by the draw.
@param paint The paint to be analyzed, NULL is equivalent to