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

Side by Side Diff: src/core/SkPaintPriv.cpp

Issue 1236023004: have canvas send discard instead of retain if the draw would overwrite everything (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"
9
10 #include "SkBitmap.h" 8 #include "SkBitmap.h"
11 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 #include "SkPaintPriv.h"
12 #include "SkImage.h" 11 #include "SkImage.h"
13 #include "SkPaint.h" 12 #include "SkPaint.h"
14 #include "SkShader.h" 13 #include "SkShader.h"
15 14
16 enum ShaderOverrideOpacity {
17 kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitm ap or image)
18 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
19 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be op aque
20 };
21
22 static bool changes_alpha(const SkPaint& paint) { 15 static bool changes_alpha(const SkPaint& paint) {
23 SkColorFilter* cf = paint.getColorFilter(); 16 SkColorFilter* cf = paint.getColorFilter();
24 return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); 17 return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
25 } 18 }
26 19
27 static bool overwrites(const SkPaint* paint, ShaderOverrideOpacity overrideOpaci ty) { 20 bool SkPaintPriv::Overwrites(const SkPaint* paint, ShaderOverrideOpacity overrid eOpacity) {
28 if (!paint) { 21 if (!paint) {
29 // No paint means we default to SRC_OVER, so we overwrite iff our shader -override 22 // No paint means we default to SRC_OVER, so we overwrite iff our shader -override
30 // is opaque, or we don't have one. 23 // is opaque, or we don't have one.
31 return overrideOpacity != kNotOpaque_ShaderOverrideOpacity; 24 return overrideOpacity != kNotOpaque_ShaderOverrideOpacity;
32 } 25 }
33 26
34 SkXfermode::SrcColorOpacity opacityType = SkXfermode::kUnknown_SrcColorOpaci ty; 27 SkXfermode::SrcColorOpacity opacityType = SkXfermode::kUnknown_SrcColorOpaci ty;
35 28
36 if (!changes_alpha(*paint)) { 29 if (!changes_alpha(*paint)) {
37 const unsigned paintAlpha = paint->getAlpha(); 30 const unsigned paintAlpha = paint->getAlpha();
38 if (0xff == paintAlpha && overrideOpacity != kNotOpaque_ShaderOverrideOp acity && 31 if (0xff == paintAlpha && overrideOpacity != kNotOpaque_ShaderOverrideOp acity &&
39 (!paint->getShader() || paint->getShader()->isOpaque())) 32 (!paint->getShader() || paint->getShader()->isOpaque()))
40 { 33 {
41 opacityType = SkXfermode::kOpaque_SrcColorOpacity; 34 opacityType = SkXfermode::kOpaque_SrcColorOpacity;
42 } else if (0 == paintAlpha) { 35 } else if (0 == paintAlpha) {
43 if (overrideOpacity == kNone_ShaderOverrideOpacity && !paint->getSha der()) { 36 if (overrideOpacity == kNone_ShaderOverrideOpacity && !paint->getSha der()) {
44 opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity; 37 opacityType = SkXfermode::kTransparentBlack_SrcColorOpacity;
45 } else { 38 } else {
46 opacityType = SkXfermode::kTransparentAlpha_SrcColorOpacity; 39 opacityType = SkXfermode::kTransparentAlpha_SrcColorOpacity;
47 } 40 }
48 } 41 }
49 } 42 }
50 43
51 return SkXfermode::IsOpaque(paint->getXfermode(), opacityType); 44 return SkXfermode::IsOpaque(paint->getXfermode(), opacityType);
52 } 45 }
53 46
54 bool SkPaintPriv::Overwrites(const SkPaint& paint) {
55 return overwrites(&paint, kNone_ShaderOverrideOpacity);
56 }
57
58 bool SkPaintPriv::Overwrites(const SkBitmap& bitmap, const SkPaint* paint) { 47 bool SkPaintPriv::Overwrites(const SkBitmap& bitmap, const SkPaint* paint) {
59 return overwrites(paint, bitmap.isOpaque() ? kOpaque_ShaderOverrideOpacity 48 return Overwrites(paint, bitmap.isOpaque() ? kOpaque_ShaderOverrideOpacity
60 : kNotOpaque_ShaderOverrideOpacit y); 49 : kNotOpaque_ShaderOverrideOpacit y);
61 } 50 }
62 51
63 bool SkPaintPriv::Overwrites(const SkImage* image, const SkPaint* paint) { 52 bool SkPaintPriv::Overwrites(const SkImage* image, const SkPaint* paint) {
64 return overwrites(paint, image->isOpaque() ? kOpaque_ShaderOverrideOpacity 53 return Overwrites(paint, image->isOpaque() ? kOpaque_ShaderOverrideOpacity
65 : kNotOpaque_ShaderOverrideOpacit y); 54 : kNotOpaque_ShaderOverrideOpacit y);
66 } 55 }
OLDNEW
« src/core/SkCanvas.cpp ('K') | « src/core/SkPaintPriv.h ('k') | src/image/SkSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698