blob: 0f2b9e0f05bf3cda5d883dab6c43a56efb4b8b7f [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
robertphillips@google.comf4741c12013-02-06 20:13:54 +000010#include "SkColorPriv.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000011#include "SkDebugCanvas.h"
12#include "SkDrawCommand.h"
robertphillips@google.comf4741c12013-02-06 20:13:54 +000013#include "SkDrawFilter.h"
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000014#include "SkDevice.h"
robertphillips@google.comf4741c12013-02-06 20:13:54 +000015#include "SkXfermode.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000016
reed@google.com6ae24e02012-09-26 13:44:13 +000017SkDebugCanvas::SkDebugCanvas(int width, int height)
commit-bot@chromium.orge2543102014-01-31 19:42:58 +000018 : INHERITED(width, height)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000019 , fPicture(NULL)
commit-bot@chromium.org1735d662013-12-04 13:42:46 +000020 , fWidth(width)
21 , fHeight(height)
22 , fFilter(false)
commit-bot@chromium.org768ac852014-03-03 16:32:17 +000023 , fMegaVizMode(false)
commit-bot@chromium.org1735d662013-12-04 13:42:46 +000024 , fIndex(0)
robertphillips@google.comf4741c12013-02-06 20:13:54 +000025 , fOverdrawViz(false)
scroggo@google.com06d6ac62013-02-08 21:16:19 +000026 , fOverdrawFilter(NULL)
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000027 , fOverrideTexFiltering(false)
28 , fTexOverrideFilter(NULL)
scroggo@google.com06d6ac62013-02-08 21:16:19 +000029 , fOutstandingSaveCount(0) {
bungeman@google.come8cc6e82013-01-17 16:30:56 +000030 fUserMatrix.reset();
robertphillips@google.com8b157172013-11-07 22:20:31 +000031
32 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped
33 // operations. This can lead to problems in the debugger which expects all
34 // the operations in the captured skp to appear in the debug canvas. To
35 // circumvent this we create a wide open clip here (an empty clip rect
36 // is not sufficient).
37 // Internally, the SkRect passed to clipRect is converted to an SkIRect and
38 // rounded out. The following code creates a nearly maximal rect that will
39 // not get collapsed by the coming conversions (Due to precision loss the
40 // inset has to be surprisingly large).
41 SkIRect largeIRect = SkIRect::MakeLargest();
42 largeIRect.inset(1024, 1024);
robertphillips@google.com6c1e49a2013-11-10 15:08:45 +000043 SkRect large = SkRect::Make(largeIRect);
robertphillips@google.com8b157172013-11-07 22:20:31 +000044#ifdef SK_DEBUG
45 large.roundOut(&largeIRect);
46 SkASSERT(!largeIRect.isEmpty());
47#endif
robertphillips@google.com8f90a892014-02-28 18:19:39 +000048 // call the base class' version to avoid adding a draw command
49 this->INHERITED::onClipRect(large, SkRegion::kReplace_Op, kHard_ClipEdgeStyle);
chudy@google.com902ebe52012-06-29 14:21:22 +000050}
51
chudy@google.com9cda6f72012-08-07 15:08:33 +000052SkDebugCanvas::~SkDebugCanvas() {
robertphillips@google.com67baba42013-01-02 20:20:31 +000053 fCommandVector.deleteAll();
robertphillips@google.comf4741c12013-02-06 20:13:54 +000054 SkSafeUnref(fOverdrawFilter);
commit-bot@chromium.org1735d662013-12-04 13:42:46 +000055 SkSafeUnref(fTexOverrideFilter);
chudy@google.com9cda6f72012-08-07 15:08:33 +000056}
chudy@google.com902ebe52012-06-29 14:21:22 +000057
58void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000059 command->setOffset(this->getOpID());
robertphillips@google.com67baba42013-01-02 20:20:31 +000060 fCommandVector.push(command);
chudy@google.com902ebe52012-06-29 14:21:22 +000061}
62
63void SkDebugCanvas::draw(SkCanvas* canvas) {
commit-bot@chromium.org1735d662013-12-04 13:42:46 +000064 if (!fCommandVector.isEmpty()) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000065 this->drawTo(canvas, fCommandVector.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +000066 }
67}
68
chudy@google.com830b8792012-08-01 15:57:52 +000069void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) {
bungeman@google.come8cc6e82013-01-17 16:30:56 +000070 canvas->concat(fUserMatrix);
chudy@google.com830b8792012-08-01 15:57:52 +000071}
72
73int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) {
chudy@google.com0b5bbb02012-07-31 19:55:32 +000074 SkBitmap bitmap;
reed@google.com9ebcac52014-01-24 18:53:42 +000075 bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1));
chudy@google.com902ebe52012-06-29 14:21:22 +000076
chudy@google.com0b5bbb02012-07-31 19:55:32 +000077 SkCanvas canvas(bitmap);
robertphillips@google.com94acc702012-09-06 18:43:21 +000078 canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y));
chudy@google.com830b8792012-08-01 15:57:52 +000079 applyUserTransform(&canvas);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000080
81 int layer = 0;
chudy@google.com751961d2012-07-31 20:07:42 +000082 SkColor prev = bitmap.getColor(0,0);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000083 for (int i = 0; i < index; i++) {
robertphillips@google.com67baba42013-01-02 20:20:31 +000084 if (fCommandVector[i]->isVisible()) {
85 fCommandVector[i]->execute(&canvas);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000086 }
87 if (prev != bitmap.getColor(0,0)) {
88 layer = i;
89 }
90 prev = bitmap.getColor(0,0);
91 }
92 return layer;
93}
94
bsalomon@google.com383e2342013-02-06 21:44:21 +000095static SkPMColor OverdrawXferModeProc(SkPMColor src, SkPMColor dst) {
robertphillips@google.comf4741c12013-02-06 20:13:54 +000096 // This table encodes the color progression of the overdraw visualization
97 static const SkPMColor gTable[] = {
98 SkPackARGB32(0x00, 0x00, 0x00, 0x00),
99 SkPackARGB32(0xFF, 128, 158, 255),
100 SkPackARGB32(0xFF, 170, 185, 212),
101 SkPackARGB32(0xFF, 213, 195, 170),
102 SkPackARGB32(0xFF, 255, 192, 127),
103 SkPackARGB32(0xFF, 255, 185, 85),
104 SkPackARGB32(0xFF, 255, 165, 42),
105 SkPackARGB32(0xFF, 255, 135, 0),
106 SkPackARGB32(0xFF, 255, 95, 0),
107 SkPackARGB32(0xFF, 255, 50, 0),
108 SkPackARGB32(0xFF, 255, 0, 0)
109 };
110
robertphillips@google.com0b256e12013-02-06 20:42:14 +0000111 for (size_t i = 0; i < SK_ARRAY_COUNT(gTable)-1; ++i) {
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000112 if (gTable[i] == dst) {
113 return gTable[i+1];
114 }
115 }
116
117 return gTable[SK_ARRAY_COUNT(gTable)-1];
118}
119
120// The OverdrawFilter modifies every paint to use an SkProcXfermode which
121// in turn invokes OverdrawXferModeProc
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000122class SkOverdrawFilter : public SkDrawFilter {
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000123public:
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000124 SkOverdrawFilter() {
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +0000125 fXferMode = SkProcXfermode::Create(OverdrawXferModeProc);
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000126 }
127
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000128 virtual ~SkOverdrawFilter() {
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000129 delete fXferMode;
130 }
131
132 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
133 p->setXfermode(fXferMode);
134 return true;
135 }
136
137protected:
138 SkXfermode* fXferMode;
139
140private:
141 typedef SkDrawFilter INHERITED;
142};
143
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +0000144// SkTexOverrideFilter modifies every paint to use the specified
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000145// texture filtering mode
146class SkTexOverrideFilter : public SkDrawFilter {
147public:
148 SkTexOverrideFilter() : fFilterLevel(SkPaint::kNone_FilterLevel) {
149 }
150
151 void setFilterLevel(SkPaint::FilterLevel filterLevel) {
152 fFilterLevel = filterLevel;
153 }
154
155 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
156 p->setFilterLevel(fFilterLevel);
157 return true;
158 }
159
160protected:
161 SkPaint::FilterLevel fFilterLevel;
162
163private:
164 typedef SkDrawFilter INHERITED;
165};
166
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000167class SkDebugClipVisitor : public SkCanvas::ClipVisitor {
168public:
169 SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {}
170
171 virtual void clipRect(const SkRect& r, SkRegion::Op, bool doAA) SK_OVERRIDE {
172 SkPaint p;
173 p.setColor(SK_ColorRED);
174 p.setStyle(SkPaint::kStroke_Style);
175 p.setAntiAlias(doAA);
176 fCanvas->drawRect(r, p);
177 }
178 virtual void clipRRect(const SkRRect& rr, SkRegion::Op, bool doAA) SK_OVERRIDE {
179 SkPaint p;
180 p.setColor(SK_ColorGREEN);
181 p.setStyle(SkPaint::kStroke_Style);
182 p.setAntiAlias(doAA);
183 fCanvas->drawRRect(rr, p);
184 }
185 virtual void clipPath(const SkPath& path, SkRegion::Op, bool doAA) SK_OVERRIDE {
186 SkPaint p;
187 p.setColor(SK_ColorBLUE);
188 p.setStyle(SkPaint::kStroke_Style);
189 p.setAntiAlias(doAA);
190 fCanvas->drawPath(path, p);
191 }
192
193protected:
194 SkCanvas* fCanvas;
195
196private:
197 typedef SkCanvas::ClipVisitor INHERITED;
198};
199
200// set up the saveLayer commands so that the active ones
201// return true in their 'active' method
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000202void SkDebugCanvas::markActiveCommands(int index) {
203 fActiveLayers.rewind();
204 fActiveCulls.rewind();
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000205
206 for (int i = 0; i < fCommandVector.count(); ++i) {
207 fCommandVector[i]->setActive(false);
208 }
209
210 for (int i = 0; i < index; ++i) {
211 SkDrawCommand::Action result = fCommandVector[i]->action();
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000212 if (SkDrawCommand::kPushLayer_Action == result) {
213 fActiveLayers.push(fCommandVector[i]);
214 } else if (SkDrawCommand::kPopLayer_Action == result) {
215 fActiveLayers.pop();
216 } else if (SkDrawCommand::kPushCull_Action == result) {
217 fActiveCulls.push(fCommandVector[i]);
218 } else if (SkDrawCommand::kPopCull_Action == result) {
219 fActiveCulls.pop();
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000220 }
221 }
222
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000223 for (int i = 0; i < fActiveLayers.count(); ++i) {
224 fActiveLayers[i]->setActive(true);
225 }
226
227 for (int i = 0; i < fActiveCulls.count(); ++i) {
228 fActiveCulls[i]->setActive(true);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000229 }
230}
231
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000232void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000233 SkASSERT(!fCommandVector.isEmpty());
234 SkASSERT(index < fCommandVector.count());
commit-bot@chromium.org1735d662013-12-04 13:42:46 +0000235 int i = 0;
chudy@google.com830b8792012-08-01 15:57:52 +0000236
237 // This only works assuming the canvas and device are the same ones that
238 // were previously drawn into because they need to preserve all saves
239 // and restores.
commit-bot@chromium.org1735d662013-12-04 13:42:46 +0000240 // The visibility filter also requires a full re-draw - otherwise we can
241 // end up drawing the filter repeatedly.
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000242 if (fIndex < index && !fFilter && !fMegaVizMode) {
chudy@google.com830b8792012-08-01 15:57:52 +0000243 i = fIndex + 1;
244 } else {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000245 for (int j = 0; j < fOutstandingSaveCount; j++) {
246 canvas->restore();
247 }
junov@google.comdbfac8a2012-12-06 21:47:40 +0000248 canvas->clear(SK_ColorTRANSPARENT);
chudy@google.com830b8792012-08-01 15:57:52 +0000249 canvas->resetMatrix();
skia.committer@gmail.com04ba4482012-09-07 02:01:30 +0000250 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
robertphillips@google.com94acc702012-09-06 18:43:21 +0000251 SkIntToScalar(fHeight));
chudy@google.com4c7962e2012-08-14 19:38:31 +0000252 canvas->clipRect(rect, SkRegion::kReplace_Op );
chudy@google.com830b8792012-08-01 15:57:52 +0000253 applyUserTransform(canvas);
tomhudson@google.com0699e022012-11-27 16:09:42 +0000254 fOutstandingSaveCount = 0;
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000255 }
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000256
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000257 // The setting of the draw filter has to go here (rather than in
258 // SkRasterWidget) due to the canvas restores this class performs.
259 // Since the draw filter is stored in the layer stack if we
260 // call setDrawFilter on anything but the root layer odd things happen.
261 if (fOverdrawViz) {
262 if (NULL == fOverdrawFilter) {
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000263 fOverdrawFilter = new SkOverdrawFilter;
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000264 }
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000265
266 if (fOverdrawFilter != canvas->getDrawFilter()) {
267 canvas->setDrawFilter(fOverdrawFilter);
268 }
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000269 } else if (fOverrideTexFiltering) {
270 if (NULL == fTexOverrideFilter) {
271 fTexOverrideFilter = new SkTexOverrideFilter;
272 }
273
274 if (fTexOverrideFilter != canvas->getDrawFilter()) {
275 canvas->setDrawFilter(fTexOverrideFilter);
276 }
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000277 } else {
278 canvas->setDrawFilter(NULL);
chudy@google.com830b8792012-08-01 15:57:52 +0000279 }
280
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000281 if (fMegaVizMode) {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000282 this->markActiveCommands(index);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000283 }
284
chudy@google.com830b8792012-08-01 15:57:52 +0000285 for (; i <= index; i++) {
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000286 if (i == index && fFilter) {
287 SkPaint p;
288 p.setColor(0xAAFFFFFF);
289 canvas->save();
290 canvas->resetMatrix();
291 SkRect mask;
292 mask.set(SkIntToScalar(0), SkIntToScalar(0),
293 SkIntToScalar(fWidth), SkIntToScalar(fHeight));
294 canvas->clipRect(mask, SkRegion::kReplace_Op, false);
295 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
296 SkIntToScalar(fWidth), SkIntToScalar(fHeight), p);
297 canvas->restore();
298 }
299
robertphillips@google.com67baba42013-01-02 20:20:31 +0000300 if (fCommandVector[i]->isVisible()) {
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000301 if (fMegaVizMode && fCommandVector[i]->active()) {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000302 // "active" commands execute their visualization behaviors:
303 // All active saveLayers get replaced with saves so all draws go to the
304 // visible canvas.
305 // All active culls draw their cull box
306 fCommandVector[i]->vizExecute(canvas);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000307 } else {
308 fCommandVector[i]->execute(canvas);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000309 }
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000310
311 fCommandVector[i]->trackSaveState(&fOutstandingSaveCount);
chudy@google.com902ebe52012-06-29 14:21:22 +0000312 }
313 }
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000314
315 if (fMegaVizMode) {
316 SkRect r = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight));
317 r.outset(SK_Scalar1, SK_Scalar1);
318
319 canvas->save();
320 // nuke the CTM
321 canvas->setMatrix(SkMatrix::I());
322 // turn off clipping
323 canvas->clipRect(r, SkRegion::kReplace_Op);
324
325 // visualize existing clips
326 SkDebugClipVisitor visitor(canvas);
327
328 canvas->replayClips(&visitor);
329
330 canvas->restore();
331 }
chudy@google.coma9e937c2012-08-03 17:32:05 +0000332 fMatrix = canvas->getTotalMatrix();
commit-bot@chromium.org5c70cdc2014-03-08 03:57:19 +0000333 if (!canvas->getClipDeviceBounds(&fClip)) {
334 fClip.setEmpty();
335 }
chudy@google.com830b8792012-08-01 15:57:52 +0000336 fIndex = index;
chudy@google.com902ebe52012-06-29 14:21:22 +0000337}
338
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000339void SkDebugCanvas::deleteDrawCommandAt(int index) {
340 SkASSERT(index < fCommandVector.count());
341 delete fCommandVector[index];
342 fCommandVector.remove(index);
343}
344
chudy@google.com902ebe52012-06-29 14:21:22 +0000345SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000346 SkASSERT(index < fCommandVector.count());
347 return fCommandVector[index];
chudy@google.com902ebe52012-06-29 14:21:22 +0000348}
349
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000350void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) {
351 SkASSERT(index < fCommandVector.count());
352 delete fCommandVector[index];
353 fCommandVector[index] = command;
354}
355
chudy@google.com97cee972012-08-07 20:41:37 +0000356SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000357 SkASSERT(index < fCommandVector.count());
358 return fCommandVector[index]->Info();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000359}
chudy@google.com902ebe52012-06-29 14:21:22 +0000360
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000361bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000362 SkASSERT(index < fCommandVector.count());
363 return fCommandVector[index]->isVisible();
chudy@google.com902ebe52012-06-29 14:21:22 +0000364}
365
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000366const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000367 return fCommandVector;
chudy@google.com902ebe52012-06-29 14:21:22 +0000368}
369
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000370SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() {
371 return fCommandVector;
372}
373
chudy@google.com902ebe52012-06-29 14:21:22 +0000374// TODO(chudy): Free command string memory.
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000375SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000376 SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count());
377 if (!fCommandVector.isEmpty()) {
378 for (int i = 0; i < fCommandVector.count(); i ++) {
379 commandString->push_back() = fCommandVector[i]->toString();
chudy@google.com902ebe52012-06-29 14:21:22 +0000380 }
381 }
382 return commandString;
383}
384
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000385SkTDArray<size_t>* SkDebugCanvas::getDrawCommandOffsets() const {
386 SkTDArray<size_t>* commandOffsets = new SkTDArray<size_t>;
387 if (!fCommandVector.isEmpty()) {
388 for (int i = 0; i < fCommandVector.count(); i ++) {
389 *commandOffsets->push() = fCommandVector[i]->offset();
390 }
391 }
392 return commandOffsets;
393}
394
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +0000395void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level) {
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000396 if (NULL == fTexOverrideFilter) {
397 fTexOverrideFilter = new SkTexOverrideFilter;
398 }
399
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +0000400 fOverrideTexFiltering = overrideTexFiltering;
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000401 fTexOverrideFilter->setFilterLevel(level);
402}
403
chudy@google.com902ebe52012-06-29 14:21:22 +0000404void SkDebugCanvas::clear(SkColor color) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000405 this->addDrawCommand(new SkClearCommand(color));
chudy@google.com902ebe52012-06-29 14:21:22 +0000406}
407
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000408void SkDebugCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
409 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000410}
411
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000412void SkDebugCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
413 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000414}
415
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000416void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
417 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000418}
419
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000420void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) {
421 this->addDrawCommand(new SkClipRegionCommand(region, op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000422}
423
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000424void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
commit-bot@chromium.orgd9ea09e2014-03-25 17:32:26 +0000425 switch (matrix.getType()) {
426 case SkMatrix::kTranslate_Mask:
427 this->addDrawCommand(new SkTranslateCommand(matrix.getTranslateX(),
428 matrix.getTranslateY()));
429 break;
430 case SkMatrix::kScale_Mask:
431 this->addDrawCommand(new SkScaleCommand(matrix.getScaleX(),
432 matrix.getScaleY()));
433 break;
434 default:
435 this->addDrawCommand(new SkConcatCommand(matrix));
436 break;
437 }
438
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000439 this->INHERITED::didConcat(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000440}
441
442void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000443 SkScalar top, const SkPaint* paint = NULL) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000444 this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000445}
446
reed@google.com71121732012-09-18 15:14:33 +0000447void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000448 const SkRect* src, const SkRect& dst,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000449 const SkPaint* paint,
450 SkCanvas::DrawBitmapRectFlags flags) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000451 this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000452}
453
454void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000455 const SkMatrix& matrix, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000456 this->addDrawCommand(new SkDrawBitmapMatrixCommand(bitmap, matrix, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000457}
458
459void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
460 const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000461 this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000462}
463
464void SkDebugCanvas::drawData(const void* data, size_t length) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000465 this->addDrawCommand(new SkDrawDataCommand(data, length));
chudy@google.com902ebe52012-06-29 14:21:22 +0000466}
467
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000468void SkDebugCanvas::beginCommentGroup(const char* description) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000469 this->addDrawCommand(new SkBeginCommentGroupCommand(description));
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000470}
471
472void SkDebugCanvas::addComment(const char* kywd, const char* value) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000473 this->addDrawCommand(new SkCommentCommand(kywd, value));
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000474}
475
476void SkDebugCanvas::endCommentGroup() {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000477 this->addDrawCommand(new SkEndCommentGroupCommand());
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000478}
479
robertphillips@google.com67baba42013-01-02 20:20:31 +0000480void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000481 this->addDrawCommand(new SkDrawOvalCommand(oval, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000482}
483
chudy@google.com902ebe52012-06-29 14:21:22 +0000484void SkDebugCanvas::drawPaint(const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000485 this->addDrawCommand(new SkDrawPaintCommand(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000486}
487
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000488void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000489 this->addDrawCommand(new SkDrawPathCommand(path, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000490}
491
492void SkDebugCanvas::drawPicture(SkPicture& picture) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000493 this->addDrawCommand(new SkDrawPictureCommand(picture));
chudy@google.com902ebe52012-06-29 14:21:22 +0000494}
495
496void SkDebugCanvas::drawPoints(PointMode mode, size_t count,
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000497 const SkPoint pts[], const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000498 this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000499}
500
501void SkDebugCanvas::drawPosText(const void* text, size_t byteLength,
502 const SkPoint pos[], const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000503 this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000504}
505
506void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength,
507 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000508 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000509 new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000510}
511
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000512void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000513 // NOTE(chudy): Messing up when renamed to DrawRect... Why?
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000514 addDrawCommand(new SkDrawRectCommand(rect, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000515}
516
robertphillips@google.com67baba42013-01-02 20:20:31 +0000517void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000518 this->addDrawCommand(new SkDrawRRectCommand(rrect, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000519}
520
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000521void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
522 const SkPaint& paint) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000523 this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint));
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000524}
525
chudy@google.com902ebe52012-06-29 14:21:22 +0000526void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000527 const SkPaint* paint = NULL) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000528 this->addDrawCommand(new SkDrawSpriteCommand(bitmap, left, top, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000529}
530
531void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
532 SkScalar y, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000533 this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000534}
535
536void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength,
537 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000538 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000539 new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000540}
541
542void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount,
543 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
544 SkXfermode*, const uint16_t indices[], int indexCount,
545 const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000546 this->addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices,
547 texs, colors, NULL, indices, indexCount, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000548}
549
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000550void SkDebugCanvas::onPushCull(const SkRect& cullRect) {
551 this->addDrawCommand(new SkPushCullCommand(cullRect));
552}
553
554void SkDebugCanvas::onPopCull() {
555 this->addDrawCommand(new SkPopCullCommand());
556}
557
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000558void SkDebugCanvas::willRestore() {
559 this->addDrawCommand(new SkRestoreCommand());
560 this->INHERITED::willRestore();
chudy@google.com902ebe52012-06-29 14:21:22 +0000561}
562
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000563void SkDebugCanvas::willSave(SaveFlags flags) {
564 this->addDrawCommand(new SkSaveCommand(flags));
565 this->INHERITED::willSave(flags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000566}
567
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000568SkCanvas::SaveLayerStrategy SkDebugCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
569 SaveFlags flags) {
570 this->addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags));
571 this->INHERITED::willSaveLayer(bounds, paint, flags);
572 // No need for a full layer.
573 return kNoLayer_SaveLayerStrategy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000574}
575
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000576void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000577 this->addDrawCommand(new SkSetMatrixCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000578 this->INHERITED::didSetMatrix(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000579}
580
chudy@google.com902ebe52012-06-29 14:21:22 +0000581void SkDebugCanvas::toggleCommand(int index, bool toggle) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000582 SkASSERT(index < fCommandVector.count());
583 fCommandVector[index]->setVisible(toggle);
chudy@google.com902ebe52012-06-29 14:21:22 +0000584}