aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPaintPriv.cpp
diff options
context:
space:
mode:
authorGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-24 14:38:23 +0000
committerGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-24 14:38:23 +0000
commitbaa0220dfddda3cd44f0ffb5f95a4a60443eb8c3 (patch)
tree862401b0d34f903df91f8305d86efd8946b4fe67 /src/core/SkPaintPriv.cpp
parent43a6b6a046774576378dfb725e19632a0c8530b7 (diff)
Move code in isPaintOpaque from SkDeferredCanvas.cpp to SkPaintPriv
The purpose of this code move is to make it re-usable in order to implement occlusion culling optimizations in SkPicture similar to what we have now in SkDeferredCanvas. BUG=https://code.google.com/p/chromium/issues/detail?id=164530 Review URL: https://codereview.appspot.com/7196046 git-svn-id: http://skia.googlecode.com/svn/trunk@7361 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkPaintPriv.cpp')
-rw-r--r--src/core/SkPaintPriv.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp
new file mode 100644
index 0000000000..ce05389019
--- /dev/null
+++ b/src/core/SkPaintPriv.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkPaintPriv.h"
+
+#include "SkBitmap.h"
+#include "SkColorFilter.h"
+#include "SkPaint.h"
+#include "SkShader.h"
+
+bool isPaintOpaque(const SkPaint* paint,
+ const SkBitmap* bmpReplacesShader) {
+ // 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;
+ }
+
+ SkXfermode::Coeff srcCoeff, dstCoeff;
+ if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){
+ if (SkXfermode::kDA_Coeff == srcCoeff || SkXfermode::kDC_Coeff == srcCoeff ||
+ SkXfermode::kIDA_Coeff == srcCoeff || SkXfermode::kIDC_Coeff == srcCoeff) {
+ return false;
+ }
+ switch (dstCoeff) {
+ case SkXfermode::kZero_Coeff:
+ return true;
+ case SkXfermode::kISA_Coeff:
+ if (paint->getAlpha() != 255) {
+ break;
+ }
+ if (bmpReplacesShader) {
+ if (!bmpReplacesShader->isOpaque()) {
+ break;
+ }
+ } else if (paint->getShader() && !paint->getShader()->isOpaque()) {
+ break;
+ }
+ if (paint->getColorFilter() &&
+ ((paint->getColorFilter()->getFlags() &
+ SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
+ break;
+ }
+ return true;
+ case SkXfermode::kSA_Coeff:
+ if (paint->getAlpha() != 0) {
+ break;
+ }
+ if (paint->getColorFilter() &&
+ ((paint->getColorFilter()->getFlags() &
+ SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
+ break;
+ }
+ return true;
+ case SkXfermode::kSC_Coeff:
+ if (paint->getColor() != 0) { // all components must be 0
+ break;
+ }
+ if (bmpReplacesShader || paint->getShader()) {
+ break;
+ }
+ if (paint->getColorFilter() && (
+ (paint->getColorFilter()->getFlags() &
+ SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
+ break;
+ }
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}