gfx/skia/trunk/src/core/SkPaintPriv.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkPaintPriv.h"
michael@0 9
michael@0 10 #include "SkBitmap.h"
michael@0 11 #include "SkColorFilter.h"
michael@0 12 #include "SkPaint.h"
michael@0 13 #include "SkShader.h"
michael@0 14
michael@0 15 bool isPaintOpaque(const SkPaint* paint,
michael@0 16 const SkBitmap* bmpReplacesShader) {
michael@0 17 // TODO: SkXfermode should have a virtual isOpaque method, which would
michael@0 18 // make it possible to test modes that do not have a Coeff representation.
michael@0 19
michael@0 20 if (!paint) {
michael@0 21 return bmpReplacesShader ? bmpReplacesShader->isOpaque() : true;
michael@0 22 }
michael@0 23
michael@0 24 SkXfermode::Coeff srcCoeff, dstCoeff;
michael@0 25 if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){
michael@0 26 if (SkXfermode::kDA_Coeff == srcCoeff || SkXfermode::kDC_Coeff == srcCoeff ||
michael@0 27 SkXfermode::kIDA_Coeff == srcCoeff || SkXfermode::kIDC_Coeff == srcCoeff) {
michael@0 28 return false;
michael@0 29 }
michael@0 30 switch (dstCoeff) {
michael@0 31 case SkXfermode::kZero_Coeff:
michael@0 32 return true;
michael@0 33 case SkXfermode::kISA_Coeff:
michael@0 34 if (paint->getAlpha() != 255) {
michael@0 35 break;
michael@0 36 }
michael@0 37 if (bmpReplacesShader) {
michael@0 38 if (!bmpReplacesShader->isOpaque()) {
michael@0 39 break;
michael@0 40 }
michael@0 41 } else if (paint->getShader() && !paint->getShader()->isOpaque()) {
michael@0 42 break;
michael@0 43 }
michael@0 44 if (paint->getColorFilter() &&
michael@0 45 ((paint->getColorFilter()->getFlags() &
michael@0 46 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
michael@0 47 break;
michael@0 48 }
michael@0 49 return true;
michael@0 50 case SkXfermode::kSA_Coeff:
michael@0 51 if (paint->getAlpha() != 0) {
michael@0 52 break;
michael@0 53 }
michael@0 54 if (paint->getColorFilter() &&
michael@0 55 ((paint->getColorFilter()->getFlags() &
michael@0 56 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
michael@0 57 break;
michael@0 58 }
michael@0 59 return true;
michael@0 60 case SkXfermode::kSC_Coeff:
michael@0 61 if (paint->getColor() != 0) { // all components must be 0
michael@0 62 break;
michael@0 63 }
michael@0 64 if (bmpReplacesShader || paint->getShader()) {
michael@0 65 break;
michael@0 66 }
michael@0 67 if (paint->getColorFilter() && (
michael@0 68 (paint->getColorFilter()->getFlags() &
michael@0 69 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
michael@0 70 break;
michael@0 71 }
michael@0 72 return true;
michael@0 73 default:
michael@0 74 break;
michael@0 75 }
michael@0 76 }
michael@0 77 return false;
michael@0 78 }

mercurial