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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPaintPriv.h" 8 #include "SkPaintPriv.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkColorFilter.h" 11 #include "SkColorFilter.h"
12 #include "SkImage.h" 12 #include "SkImage.h"
13 #include "SkPaint.h" 13 #include "SkPaint.h"
14 #include "SkShader.h" 14 #include "SkShader.h"
15 15
16 bool isPaintOpaque(const SkPaint* paint, SkPaintBitmapOpacity contentType) { 16 static bool changes_alpha(const SkPaint& paint) {
17 SkColorFilter* cf = paint.getColorFilter();
18 return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
19 }
20
21 bool SkPaintPriv::Overwrites(const SkPaint* paint, ShaderOverrideOpacity overrid eOpacity) {
17 if (!paint) { 22 if (!paint) {
18 return contentType != kUnknown_SkPaintBitmapOpacity; 23 // No paint means we default to SRC_OVER, so we overwrite iff our shader -override
24 // is opaque, or we don't have one.
25 return overrideOpacity != kNotOpaque_ShaderOverrideOpacity;
19 } 26 }
27
20 SkXfermode::SrcColorOpacity opacityType = SkXfermode::kUnknown_SrcColorOpaci ty; 28 SkXfermode::SrcColorOpacity opacityType = SkXfermode::kUnknown_SrcColorOpaci ty;
21 29
22 if (!paint->getColorFilter() || 30 if (!changes_alpha(*paint)) {
23 ((paint->getColorFilter()->getFlags() & 31 const unsigned paintAlpha = paint->getAlpha();
24 SkColorFilter::kAlphaUnchanged_Flag) != 0)) { 32 if (0xff == paintAlpha &&
robertphillips 2015/07/15 15:53:51 Can this go on the prior line ?
reed1 2015/07/15 18:03:03 Done.
25 if (0xff == paint->getAlpha() && 33 overrideOpacity != kNotOpaque_ShaderOverrideOpacity &&
26 contentType != kUnknown_SkPaintBitmapOpacity && 34 (!paint->getShader() || paint->getShader()->isOpaque()))
27 (!paint->getShader() || paint->getShader()->isOpaque())) { 35 {
28 opacityType = SkXfermode::kOpaque_SrcColorOpacity; 36 opacityType = SkXfermode::kOpaque_SrcColorOpacity;
29 } else if (0 == paint->getColor() && 37 } else if (0 == paintAlpha) {
30 contentType == kNoBitmap_SkPaintBitmapOpacity && 38 if (overrideOpacity == kNone_ShaderOverrideOpacity && !paint->getSha der()) {
31 !paint->getShader()) { 39 opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity;
32 opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity; 40 } else {
33 } else if (0 == paint->getAlpha()) { 41 opacityType = SkXfermode::kTransparentAlpha_SrcColorOpacity;
34 opacityType = SkXfermode::kTransparentAlpha_SrcColorOpacity; 42 }
35 } 43 }
36 } 44 }
37 45
38 return SkXfermode::IsOpaque(paint->getXfermode(), opacityType); 46 return SkXfermode::IsOpaque(paint->getXfermode(), opacityType);
39 } 47 }
40 48
41 bool isPaintOpaque(const SkPaint* paint, const SkBitmap* bmpReplacesShader) { 49 bool SkPaintPriv::Overwrites(const SkPaint* paint, const SkBitmap& bitmap) {
42 SkPaintBitmapOpacity contentType; 50 return Overwrites(paint, bitmap.isOpaque() ? kOpaque_ShaderOverrideOpacity
43 51 : kNotOpaque_ShaderOverrideOpacit y);
44 if(!bmpReplacesShader)
45 contentType = kNoBitmap_SkPaintBitmapOpacity;
46 else if(bmpReplacesShader->isOpaque())
47 contentType = kOpaque_SkPaintBitmapOpacity;
48 else
49 contentType = kUnknown_SkPaintBitmapOpacity;
50
51 return isPaintOpaque(paint, contentType);
52 } 52 }
53 53
54 bool isPaintOpaque(const SkPaint* paint, const SkImage* image) { 54 bool SkPaintPriv::Overwrites(const SkPaint* paint, const SkImage* image) {
55 return isPaintOpaque(paint, image->isOpaque() ? 55 return Overwrites(paint, image->isOpaque() ? kOpaque_ShaderOverrideOpacity
56 kOpaque_SkPaintBitmapOpacity : kUnknown_SkPaintBitmapOp acity); 56 : kNotOpaque_ShaderOverrideOpacit y);
57 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698