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 , fWidth(width) |
| 26 , fHeight(height) |
| 27 , fFilter(false) |
| 28 , fIndex(0) |
25 , fOverdrawViz(false) | 29 , fOverdrawViz(false) |
26 , fOverdrawFilter(NULL) | 30 , fOverdrawFilter(NULL) |
27 , fOverrideTexFiltering(false) | 31 , fOverrideTexFiltering(false) |
28 , fTexOverrideFilter(NULL) | 32 , fTexOverrideFilter(NULL) |
29 , fOutstandingSaveCount(0) { | 33 , fOutstandingSaveCount(0) { |
30 // TODO(chudy): Free up memory from all draw commands in destructor. | |
31 fWidth = width; | |
32 fHeight = height; | |
33 // do we need fBm anywhere? | |
34 fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight); | |
35 fFilter = false; | |
36 fIndex = 0; | |
37 fUserMatrix.reset(); | 34 fUserMatrix.reset(); |
38 | 35 |
39 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped | 36 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped |
40 // operations. This can lead to problems in the debugger which expects all | 37 // operations. This can lead to problems in the debugger which expects all |
41 // the operations in the captured skp to appear in the debug canvas. To | 38 // the operations in the captured skp to appear in the debug canvas. To |
42 // circumvent this we create a wide open clip here (an empty clip rect | 39 // circumvent this we create a wide open clip here (an empty clip rect |
43 // is not sufficient). | 40 // is not sufficient). |
44 // Internally, the SkRect passed to clipRect is converted to an SkIRect and | 41 // Internally, the SkRect passed to clipRect is converted to an SkIRect and |
45 // rounded out. The following code creates a nearly maximal rect that will | 42 // rounded out. The following code creates a nearly maximal rect that will |
46 // not get collapsed by the coming conversions (Due to precision loss the | 43 // not get collapsed by the coming conversions (Due to precision loss the |
47 // inset has to be surprisingly large). | 44 // inset has to be surprisingly large). |
48 SkIRect largeIRect = SkIRect::MakeLargest(); | 45 SkIRect largeIRect = SkIRect::MakeLargest(); |
49 largeIRect.inset(1024, 1024); | 46 largeIRect.inset(1024, 1024); |
50 SkRect large = SkRect::Make(largeIRect); | 47 SkRect large = SkRect::Make(largeIRect); |
51 #ifdef SK_DEBUG | 48 #ifdef SK_DEBUG |
52 large.roundOut(&largeIRect); | 49 large.roundOut(&largeIRect); |
53 SkASSERT(!largeIRect.isEmpty()); | 50 SkASSERT(!largeIRect.isEmpty()); |
54 #endif | 51 #endif |
55 INHERITED::clipRect(large, SkRegion::kReplace_Op, false); | 52 INHERITED::clipRect(large, SkRegion::kReplace_Op, false); |
56 } | 53 } |
57 | 54 |
58 SkDebugCanvas::~SkDebugCanvas() { | 55 SkDebugCanvas::~SkDebugCanvas() { |
59 fCommandVector.deleteAll(); | 56 fCommandVector.deleteAll(); |
60 SkSafeUnref(fOverdrawFilter); | 57 SkSafeUnref(fOverdrawFilter); |
| 58 SkSafeUnref(fTexOverrideFilter); |
61 } | 59 } |
62 | 60 |
63 void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { | 61 void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { |
64 fCommandVector.push(command); | 62 fCommandVector.push(command); |
65 } | 63 } |
66 | 64 |
67 void SkDebugCanvas::draw(SkCanvas* canvas) { | 65 void SkDebugCanvas::draw(SkCanvas* canvas) { |
68 if(!fCommandVector.isEmpty()) { | 66 if (!fCommandVector.isEmpty()) { |
69 for (int i = 0; i < fCommandVector.count(); i++) { | 67 drawTo(canvas, fCommandVector.count() - 1); |
70 if (fCommandVector[i]->isVisible()) { | |
71 fCommandVector[i]->execute(canvas); | |
72 } | |
73 } | |
74 } | 68 } |
75 fIndex = fCommandVector.count() - 1; | |
76 } | 69 } |
77 | 70 |
78 void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { | 71 void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { |
79 canvas->concat(fUserMatrix); | 72 canvas->concat(fUserMatrix); |
80 } | 73 } |
81 | 74 |
82 int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { | 75 int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { |
83 SkBitmap bitmap; | 76 SkBitmap bitmap; |
84 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 77 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
85 bitmap.allocPixels(); | 78 bitmap.allocPixels(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 protected: | 163 protected: |
171 SkPaint::FilterLevel fFilterLevel; | 164 SkPaint::FilterLevel fFilterLevel; |
172 | 165 |
173 private: | 166 private: |
174 typedef SkDrawFilter INHERITED; | 167 typedef SkDrawFilter INHERITED; |
175 }; | 168 }; |
176 | 169 |
177 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { | 170 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { |
178 SkASSERT(!fCommandVector.isEmpty()); | 171 SkASSERT(!fCommandVector.isEmpty()); |
179 SkASSERT(index < fCommandVector.count()); | 172 SkASSERT(index < fCommandVector.count()); |
180 int i; | 173 int i = 0; |
181 | 174 |
182 // This only works assuming the canvas and device are the same ones that | 175 // This only works assuming the canvas and device are the same ones that |
183 // were previously drawn into because they need to preserve all saves | 176 // were previously drawn into because they need to preserve all saves |
184 // and restores. | 177 // and restores. |
185 if (fIndex < index) { | 178 // The visibility filter also requires a full re-draw - otherwise we can |
| 179 // end up drawing the filter repeatedly. |
| 180 if (fIndex < index && !fFilter) { |
186 i = fIndex + 1; | 181 i = fIndex + 1; |
187 } else { | 182 } else { |
188 for (int j = 0; j < fOutstandingSaveCount; j++) { | 183 for (int j = 0; j < fOutstandingSaveCount; j++) { |
189 canvas->restore(); | 184 canvas->restore(); |
190 } | 185 } |
191 i = 0; | |
192 canvas->clear(SK_ColorTRANSPARENT); | 186 canvas->clear(SK_ColorTRANSPARENT); |
193 canvas->resetMatrix(); | 187 canvas->resetMatrix(); |
194 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), | 188 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), |
195 SkIntToScalar(fHeight)); | 189 SkIntToScalar(fHeight)); |
196 canvas->clipRect(rect, SkRegion::kReplace_Op ); | 190 canvas->clipRect(rect, SkRegion::kReplace_Op ); |
197 applyUserTransform(canvas); | 191 applyUserTransform(canvas); |
198 fOutstandingSaveCount = 0; | 192 fOutstandingSaveCount = 0; |
199 } | 193 } |
200 | 194 |
201 // The setting of the draw filter has to go here (rather than in | 195 // The setting of the draw filter has to go here (rather than in |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 468 |
475 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { | 469 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { |
476 addDrawCommand(new SkTranslateCommand(dx, dy)); | 470 addDrawCommand(new SkTranslateCommand(dx, dy)); |
477 return true; | 471 return true; |
478 } | 472 } |
479 | 473 |
480 void SkDebugCanvas::toggleCommand(int index, bool toggle) { | 474 void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
481 SkASSERT(index < fCommandVector.count()); | 475 SkASSERT(index < fCommandVector.count()); |
482 fCommandVector[index]->setVisible(toggle); | 476 fCommandVector[index]->setVisible(toggle); |
483 } | 477 } |
OLD | NEW |