2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkPaintPriv.h"
11 #include "SkColorFilter.h"
15 bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) {
16 // TODO: SkXfermode should have a virtual isOpaque method, which would
17 // make it possible to test modes that do not have a Coeff representation.
20 return contentType != kUnknown_SkPaintBitmapOpacity;
23 SkXfermode::Coeff srcCoeff, dstCoeff;
24 if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){
25 if (SkXfermode::kDA_Coeff == srcCoeff || SkXfermode::kDC_Coeff == srcCoeff ||
26 SkXfermode::kIDA_Coeff == srcCoeff || SkXfermode::kIDC_Coeff == srcCoeff) {
30 case SkXfermode::kZero_Coeff:
32 case SkXfermode::kISA_Coeff:
33 if (paint->getAlpha() != 255) {
36 if (contentType == kUnknown_SkPaintBitmapOpacity) {
38 } else if (paint->getShader() && !paint->getShader()->isOpaque()) {
41 if (paint->getColorFilter() &&
42 ((paint->getColorFilter()->getFlags() &
43 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
47 case SkXfermode::kSA_Coeff:
48 if (paint->getAlpha() != 0) {
51 if (paint->getColorFilter() &&
52 ((paint->getColorFilter()->getFlags() &
53 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
57 case SkXfermode::kSC_Coeff:
58 if (paint->getColor() != 0) { // all components must be 0
61 if (contentType != kNoBitmap_SkPaintBitmapOpacity || paint->getShader()) {
64 if (paint->getColorFilter() && (
65 (paint->getColorFilter()->getFlags() &
66 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
77 bool isPaintOpaque(const SkPaint* paint, const SkBitmap* bmpReplacesShader) {
78 SkPaintBitmapOpacity contentType;
80 if(!bmpReplacesShader)
81 contentType = kNoBitmap_SkPaintBitmapOpacity;
82 else if(bmpReplacesShader->isOpaque())
83 contentType = kOpaque_SkPaintBitmapOpacity;
85 contentType = kUnknown_SkPaintBitmapOpacity;
87 return isPaintOpaque(paint, contentType);