OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkClipStack.h" | 8 #include "SkClipStack.h" |
9 #include "SkColorPriv.h" | |
10 #include "SkDebugCanvas.h" | 9 #include "SkDebugCanvas.h" |
11 #include "SkDrawCommand.h" | 10 #include "SkDrawCommand.h" |
12 #include "SkDevice.h" | 11 #include "SkDevice.h" |
13 #include "SkPaintFilterCanvas.h" | 12 #include "SkPaintFilterCanvas.h" |
14 #include "SkXfermode.h" | 13 #include "SkOverdrawMode.h" |
15 | |
16 namespace { | |
17 | |
18 class OverdrawXfermode : public SkXfermode { | |
19 public: | |
20 SkPMColor xferColor(SkPMColor src, SkPMColor dst) const override { | |
21 // This table encodes the color progression of the overdraw visualizatio
n | |
22 static const SkPMColor gTable[] = { | |
23 SkPackARGB32(0x00, 0x00, 0x00, 0x00), | |
24 SkPackARGB32(0xFF, 128, 158, 255), | |
25 SkPackARGB32(0xFF, 170, 185, 212), | |
26 SkPackARGB32(0xFF, 213, 195, 170), | |
27 SkPackARGB32(0xFF, 255, 192, 127), | |
28 SkPackARGB32(0xFF, 255, 185, 85), | |
29 SkPackARGB32(0xFF, 255, 165, 42), | |
30 SkPackARGB32(0xFF, 255, 135, 0), | |
31 SkPackARGB32(0xFF, 255, 95, 0), | |
32 SkPackARGB32(0xFF, 255, 50, 0), | |
33 SkPackARGB32(0xFF, 255, 0, 0) | |
34 }; | |
35 | |
36 | |
37 int idx; | |
38 if (SkColorGetR(dst) < 64) { // 0 | |
39 idx = 0; | |
40 } else if (SkColorGetG(dst) < 25) { // 10 | |
41 idx = 9; // cap at 9 for upcoming increment | |
42 } else if ((SkColorGetB(dst)+21)/42 > 0) { // 1-6 | |
43 idx = 7 - (SkColorGetB(dst)+21)/42; | |
44 } else { // 7-9 | |
45 idx = 10 - (SkColorGetG(dst)+22)/45; | |
46 } | |
47 ++idx; | |
48 SkASSERT(idx < (int)SK_ARRAY_COUNT(gTable)); | |
49 | |
50 return gTable[idx]; | |
51 } | |
52 | |
53 Factory getFactory() const override { return nullptr; } | |
54 #ifndef SK_IGNORE_TO_STRING | |
55 void toString(SkString* str) const override { str->set("OverdrawXfermode");
} | |
56 #endif | |
57 }; | |
58 | 14 |
59 class DebugPaintFilterCanvas : public SkPaintFilterCanvas { | 15 class DebugPaintFilterCanvas : public SkPaintFilterCanvas { |
60 public: | 16 public: |
61 DebugPaintFilterCanvas(int width, | 17 DebugPaintFilterCanvas(int width, |
62 int height, | 18 int height, |
63 bool overdrawViz, | 19 bool overdrawViz, |
64 bool overrideFilterQuality, | 20 bool overrideFilterQuality, |
65 SkFilterQuality quality) | 21 SkFilterQuality quality) |
66 : INHERITED(width, height) | 22 : INHERITED(width, height) |
67 , fOverdrawXfermode(overdrawViz ? new OverdrawXfermode : nullptr) | 23 , fOverdrawXfermode(overdrawViz ? SkOverdrawMode::Create() : nullptr) |
68 , fOverrideFilterQuality(overrideFilterQuality) | 24 , fOverrideFilterQuality(overrideFilterQuality) |
69 , fFilterQuality(quality) {} | 25 , fFilterQuality(quality) {} |
70 | 26 |
71 protected: | 27 protected: |
72 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override { | 28 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override { |
73 if (*paint) { | 29 if (*paint) { |
74 if (nullptr != fOverdrawXfermode.get()) { | 30 if (nullptr != fOverdrawXfermode.get()) { |
75 paint->writable()->setAntiAlias(false); | 31 paint->writable()->setAntiAlias(false); |
76 paint->writable()->setXfermode(fOverdrawXfermode.get()); | 32 paint->writable()->setXfermode(fOverdrawXfermode.get()); |
77 } | 33 } |
(...skipping 14 matching lines...) Expand all Loading... |
92 | 48 |
93 private: | 49 private: |
94 SkAutoTUnref<SkXfermode> fOverdrawXfermode; | 50 SkAutoTUnref<SkXfermode> fOverdrawXfermode; |
95 | 51 |
96 bool fOverrideFilterQuality; | 52 bool fOverrideFilterQuality; |
97 SkFilterQuality fFilterQuality; | 53 SkFilterQuality fFilterQuality; |
98 | 54 |
99 typedef SkPaintFilterCanvas INHERITED; | 55 typedef SkPaintFilterCanvas INHERITED; |
100 }; | 56 }; |
101 | 57 |
102 } | |
103 | |
104 SkDebugCanvas::SkDebugCanvas(int width, int height) | 58 SkDebugCanvas::SkDebugCanvas(int width, int height) |
105 : INHERITED(width, height) | 59 : INHERITED(width, height) |
106 , fPicture(nullptr) | 60 , fPicture(nullptr) |
107 , fFilter(false) | 61 , fFilter(false) |
108 , fMegaVizMode(false) | 62 , fMegaVizMode(false) |
109 , fOverdrawViz(false) | 63 , fOverdrawViz(false) |
110 , fOverrideFilterQuality(false) | 64 , fOverrideFilterQuality(false) |
111 , fFilterQuality(kNone_SkFilterQuality) { | 65 , fFilterQuality(kNone_SkFilterQuality) { |
112 fUserMatrix.reset(); | 66 fUserMatrix.reset(); |
113 | 67 |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 } | 615 } |
662 | 616 |
663 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { | 617 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { |
664 if (fCalledAddStackData) { | 618 if (fCalledAddStackData) { |
665 fClipStackData.appendf("<br>"); | 619 fClipStackData.appendf("<br>"); |
666 addPathData(devPath, "pathOut"); | 620 addPathData(devPath, "pathOut"); |
667 return true; | 621 return true; |
668 } | 622 } |
669 return false; | 623 return false; |
670 } | 624 } |
OLD | NEW |