OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkDebugCanvas.h" | 11 #include "SkDebugCanvas.h" |
12 #include "SkDrawCommand.h" | 12 #include "SkDrawCommand.h" |
13 #include "SkDrawFilter.h" | 13 #include "SkDrawFilter.h" |
14 #include "SkDevice.h" | 14 #include "SkDevice.h" |
15 #include "SkXfermode.h" | 15 #include "SkXfermode.h" |
16 | 16 |
17 static SkBitmap make_noconfig_bm(int width, int height) { | 17 static SkBitmap make_noconfig_bm(int width, int height) { |
18 SkBitmap bm; | 18 SkBitmap bm; |
19 bm.setConfig(SkBitmap::kNo_Config, width, height); | 19 bm.setConfig(SkBitmap::kNo_Config, width, height); |
20 return bm; | 20 return bm; |
21 } | 21 } |
22 | 22 |
23 SkDebugCanvas::SkDebugCanvas(int width, int height) | 23 SkDebugCanvas::SkDebugCanvas(int width, int height) |
24 : INHERITED(make_noconfig_bm(width, height)) | 24 : INHERITED(make_noconfig_bm(width, height)) |
25 , fOverdrawViz(false) | 25 , fOverdrawViz(false) |
26 , fOverdrawFilter(NULL) | 26 , fOverdrawFilter(NULL) |
| 27 , fOverrideTexFiltering(false) |
| 28 , fTexOverrideFilter(NULL) |
27 , fOutstandingSaveCount(0) { | 29 , fOutstandingSaveCount(0) { |
28 // TODO(chudy): Free up memory from all draw commands in destructor. | 30 // TODO(chudy): Free up memory from all draw commands in destructor. |
29 fWidth = width; | 31 fWidth = width; |
30 fHeight = height; | 32 fHeight = height; |
31 // do we need fBm anywhere? | 33 // do we need fBm anywhere? |
32 fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight); | 34 fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight); |
33 fFilter = false; | 35 fFilter = false; |
34 fIndex = 0; | 36 fIndex = 0; |
35 fUserMatrix.reset(); | 37 fUserMatrix.reset(); |
36 } | 38 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if (gTable[i] == dst) { | 104 if (gTable[i] == dst) { |
103 return gTable[i+1]; | 105 return gTable[i+1]; |
104 } | 106 } |
105 } | 107 } |
106 | 108 |
107 return gTable[SK_ARRAY_COUNT(gTable)-1]; | 109 return gTable[SK_ARRAY_COUNT(gTable)-1]; |
108 } | 110 } |
109 | 111 |
110 // The OverdrawFilter modifies every paint to use an SkProcXfermode which | 112 // The OverdrawFilter modifies every paint to use an SkProcXfermode which |
111 // in turn invokes OverdrawXferModeProc | 113 // in turn invokes OverdrawXferModeProc |
112 class OverdrawFilter : public SkDrawFilter { | 114 class SkOverdrawFilter : public SkDrawFilter { |
113 public: | 115 public: |
114 OverdrawFilter() { | 116 SkOverdrawFilter() { |
115 fXferMode = new SkProcXfermode(OverdrawXferModeProc); | 117 fXferMode = new SkProcXfermode(OverdrawXferModeProc); |
116 } | 118 } |
117 | 119 |
118 virtual ~OverdrawFilter() { | 120 virtual ~SkOverdrawFilter() { |
119 delete fXferMode; | 121 delete fXferMode; |
120 } | 122 } |
121 | 123 |
122 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE { | 124 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE { |
123 p->setXfermode(fXferMode); | 125 p->setXfermode(fXferMode); |
124 return true; | 126 return true; |
125 } | 127 } |
126 | 128 |
127 protected: | 129 protected: |
128 SkXfermode* fXferMode; | 130 SkXfermode* fXferMode; |
129 | 131 |
130 private: | 132 private: |
131 typedef SkDrawFilter INHERITED; | 133 typedef SkDrawFilter INHERITED; |
132 }; | 134 }; |
133 | 135 |
| 136 // SkTexOverrideFilter modifies every paint to use the specified |
| 137 // texture filtering mode |
| 138 class SkTexOverrideFilter : public SkDrawFilter { |
| 139 public: |
| 140 SkTexOverrideFilter() : fFilterLevel(SkPaint::kNone_FilterLevel) { |
| 141 } |
| 142 |
| 143 void setFilterLevel(SkPaint::FilterLevel filterLevel) { |
| 144 fFilterLevel = filterLevel; |
| 145 } |
| 146 |
| 147 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE { |
| 148 p->setFilterLevel(fFilterLevel); |
| 149 return true; |
| 150 } |
| 151 |
| 152 protected: |
| 153 SkPaint::FilterLevel fFilterLevel; |
| 154 |
| 155 private: |
| 156 typedef SkDrawFilter INHERITED; |
| 157 }; |
| 158 |
134 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { | 159 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { |
135 SkASSERT(!fCommandVector.isEmpty()); | 160 SkASSERT(!fCommandVector.isEmpty()); |
136 SkASSERT(index < fCommandVector.count()); | 161 SkASSERT(index < fCommandVector.count()); |
137 int i; | 162 int i; |
138 | 163 |
139 // This only works assuming the canvas and device are the same ones that | 164 // This only works assuming the canvas and device are the same ones that |
140 // were previously drawn into because they need to preserve all saves | 165 // were previously drawn into because they need to preserve all saves |
141 // and restores. | 166 // and restores. |
142 if (fIndex < index) { | 167 if (fIndex < index) { |
143 i = fIndex + 1; | 168 i = fIndex + 1; |
(...skipping 10 matching lines...) Expand all Loading... |
154 applyUserTransform(canvas); | 179 applyUserTransform(canvas); |
155 fOutstandingSaveCount = 0; | 180 fOutstandingSaveCount = 0; |
156 } | 181 } |
157 | 182 |
158 // The setting of the draw filter has to go here (rather than in | 183 // The setting of the draw filter has to go here (rather than in |
159 // SkRasterWidget) due to the canvas restores this class performs. | 184 // SkRasterWidget) due to the canvas restores this class performs. |
160 // Since the draw filter is stored in the layer stack if we | 185 // Since the draw filter is stored in the layer stack if we |
161 // call setDrawFilter on anything but the root layer odd things happen. | 186 // call setDrawFilter on anything but the root layer odd things happen. |
162 if (fOverdrawViz) { | 187 if (fOverdrawViz) { |
163 if (NULL == fOverdrawFilter) { | 188 if (NULL == fOverdrawFilter) { |
164 fOverdrawFilter = new OverdrawFilter; | 189 fOverdrawFilter = new SkOverdrawFilter; |
165 } | 190 } |
166 | 191 |
167 if (fOverdrawFilter != canvas->getDrawFilter()) { | 192 if (fOverdrawFilter != canvas->getDrawFilter()) { |
168 canvas->setDrawFilter(fOverdrawFilter); | 193 canvas->setDrawFilter(fOverdrawFilter); |
169 } | 194 } |
| 195 } else if (fOverrideTexFiltering) { |
| 196 if (NULL == fTexOverrideFilter) { |
| 197 fTexOverrideFilter = new SkTexOverrideFilter; |
| 198 } |
| 199 |
| 200 if (fTexOverrideFilter != canvas->getDrawFilter()) { |
| 201 canvas->setDrawFilter(fTexOverrideFilter); |
| 202 } |
170 } else { | 203 } else { |
171 canvas->setDrawFilter(NULL); | 204 canvas->setDrawFilter(NULL); |
172 } | 205 } |
173 | 206 |
174 for (; i <= index; i++) { | 207 for (; i <= index; i++) { |
175 if (i == index && fFilter) { | 208 if (i == index && fFilter) { |
176 SkPaint p; | 209 SkPaint p; |
177 p.setColor(0xAAFFFFFF); | 210 p.setColor(0xAAFFFFFF); |
178 canvas->save(); | 211 canvas->save(); |
179 canvas->resetMatrix(); | 212 canvas->resetMatrix(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 commandString->push_back() = fCommandVector[i]->toString(); | 272 commandString->push_back() = fCommandVector[i]->toString(); |
240 } | 273 } |
241 } | 274 } |
242 return commandString; | 275 return commandString; |
243 } | 276 } |
244 | 277 |
245 void SkDebugCanvas::toggleFilter(bool toggle) { | 278 void SkDebugCanvas::toggleFilter(bool toggle) { |
246 fFilter = toggle; | 279 fFilter = toggle; |
247 } | 280 } |
248 | 281 |
| 282 void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::Fil
terLevel level) { |
| 283 if (NULL == fTexOverrideFilter) { |
| 284 fTexOverrideFilter = new SkTexOverrideFilter; |
| 285 } |
| 286 |
| 287 fOverrideTexFiltering = overrideTexFiltering; |
| 288 fTexOverrideFilter->setFilterLevel(level); |
| 289 } |
| 290 |
249 void SkDebugCanvas::clear(SkColor color) { | 291 void SkDebugCanvas::clear(SkColor color) { |
250 addDrawCommand(new SkClearCommand(color)); | 292 addDrawCommand(new SkClearCommand(color)); |
251 } | 293 } |
252 | 294 |
253 bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { | 295 bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
254 addDrawCommand(new SkClipPathCommand(path, op, doAA)); | 296 addDrawCommand(new SkClipPathCommand(path, op, doAA)); |
255 return true; | 297 return true; |
256 } | 298 } |
257 | 299 |
258 bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { | 300 bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 456 |
415 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { | 457 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { |
416 addDrawCommand(new SkTranslateCommand(dx, dy)); | 458 addDrawCommand(new SkTranslateCommand(dx, dy)); |
417 return true; | 459 return true; |
418 } | 460 } |
419 | 461 |
420 void SkDebugCanvas::toggleCommand(int index, bool toggle) { | 462 void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
421 SkASSERT(index < fCommandVector.count()); | 463 SkASSERT(index < fCommandVector.count()); |
422 fCommandVector[index]->setVisible(toggle); | 464 fCommandVector[index]->setVisible(toggle); |
423 } | 465 } |
OLD | NEW |