blob: 4e71bc340fe53994007f89bcca45c7e3759af26a [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
bsalomon@google.com50c79d82013-01-08 20:31:53 +000017#ifdef SK_BUILD_FOR_WIN
18 // iostream includes xlocale which generates warning 4530 because we're compiling without
19 // exceptions
20 #pragma warning(push)
21 #pragma warning(disable : 4530)
22#endif
23#include <iostream>
24#ifdef SK_BUILD_FOR_WIN
25 #pragma warning(pop)
26#endif
27
reed@google.com6ae24e02012-09-26 13:44:13 +000028static SkBitmap make_noconfig_bm(int width, int height) {
29 SkBitmap bm;
30 bm.setConfig(SkBitmap::kNo_Config, width, height);
31 return bm;
32}
33
34SkDebugCanvas::SkDebugCanvas(int width, int height)
tomhudson@google.com0699e022012-11-27 16:09:42 +000035 : INHERITED(make_noconfig_bm(width, height))
robertphillips@google.comf4741c12013-02-06 20:13:54 +000036 , fOverdrawViz(false)
scroggo@google.com06d6ac62013-02-08 21:16:19 +000037 , fOverdrawFilter(NULL)
38 , fOutstandingSaveCount(0) {
chudy@google.com902ebe52012-06-29 14:21:22 +000039 // TODO(chudy): Free up memory from all draw commands in destructor.
chudy@google.com80a4a602012-07-30 18:54:07 +000040 fWidth = width;
41 fHeight = height;
reed@google.com6ae24e02012-09-26 13:44:13 +000042 // do we need fBm anywhere?
chudy@google.comb9ddd4e2012-07-10 14:14:50 +000043 fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight);
chudy@google.com902ebe52012-06-29 14:21:22 +000044 fFilter = false;
chudy@google.com830b8792012-08-01 15:57:52 +000045 fIndex = 0;
bungeman@google.come8cc6e82013-01-17 16:30:56 +000046 fUserMatrix.reset();
chudy@google.com902ebe52012-06-29 14:21:22 +000047}
48
chudy@google.com9cda6f72012-08-07 15:08:33 +000049SkDebugCanvas::~SkDebugCanvas() {
robertphillips@google.com67baba42013-01-02 20:20:31 +000050 fCommandVector.deleteAll();
robertphillips@google.comf4741c12013-02-06 20:13:54 +000051 SkSafeUnref(fOverdrawFilter);
chudy@google.com9cda6f72012-08-07 15:08:33 +000052}
chudy@google.com902ebe52012-06-29 14:21:22 +000053
54void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
robertphillips@google.com67baba42013-01-02 20:20:31 +000055 fCommandVector.push(command);
chudy@google.com902ebe52012-06-29 14:21:22 +000056}
57
58void SkDebugCanvas::draw(SkCanvas* canvas) {
robertphillips@google.com67baba42013-01-02 20:20:31 +000059 if(!fCommandVector.isEmpty()) {
60 for (int i = 0; i < fCommandVector.count(); i++) {
61 if (fCommandVector[i]->isVisible()) {
62 fCommandVector[i]->execute(canvas);
chudy@google.com0ab03392012-07-28 20:16:11 +000063 }
chudy@google.com902ebe52012-06-29 14:21:22 +000064 }
65 }
robertphillips@google.com67baba42013-01-02 20:20:31 +000066 fIndex = fCommandVector.count() - 1;
chudy@google.com902ebe52012-06-29 14:21:22 +000067}
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;
75 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
76 bitmap.allocPixels();
chudy@google.com902ebe52012-06-29 14:21:22 +000077
chudy@google.com0b5bbb02012-07-31 19:55:32 +000078 SkCanvas canvas(bitmap);
robertphillips@google.com94acc702012-09-06 18:43:21 +000079 canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y));
chudy@google.com830b8792012-08-01 15:57:52 +000080 applyUserTransform(&canvas);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000081
82 int layer = 0;
chudy@google.com751961d2012-07-31 20:07:42 +000083 SkColor prev = bitmap.getColor(0,0);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000084 for (int i = 0; i < index; i++) {
robertphillips@google.com67baba42013-01-02 20:20:31 +000085 if (fCommandVector[i]->isVisible()) {
86 fCommandVector[i]->execute(&canvas);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000087 }
88 if (prev != bitmap.getColor(0,0)) {
89 layer = i;
90 }
91 prev = bitmap.getColor(0,0);
92 }
93 return layer;
94}
95
bsalomon@google.com383e2342013-02-06 21:44:21 +000096static SkPMColor OverdrawXferModeProc(SkPMColor src, SkPMColor dst) {
robertphillips@google.comf4741c12013-02-06 20:13:54 +000097 // This table encodes the color progression of the overdraw visualization
98 static const SkPMColor gTable[] = {
99 SkPackARGB32(0x00, 0x00, 0x00, 0x00),
100 SkPackARGB32(0xFF, 128, 158, 255),
101 SkPackARGB32(0xFF, 170, 185, 212),
102 SkPackARGB32(0xFF, 213, 195, 170),
103 SkPackARGB32(0xFF, 255, 192, 127),
104 SkPackARGB32(0xFF, 255, 185, 85),
105 SkPackARGB32(0xFF, 255, 165, 42),
106 SkPackARGB32(0xFF, 255, 135, 0),
107 SkPackARGB32(0xFF, 255, 95, 0),
108 SkPackARGB32(0xFF, 255, 50, 0),
109 SkPackARGB32(0xFF, 255, 0, 0)
110 };
111
robertphillips@google.com0b256e12013-02-06 20:42:14 +0000112 for (size_t i = 0; i < SK_ARRAY_COUNT(gTable)-1; ++i) {
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000113 if (gTable[i] == dst) {
114 return gTable[i+1];
115 }
116 }
117
118 return gTable[SK_ARRAY_COUNT(gTable)-1];
119}
120
121// The OverdrawFilter modifies every paint to use an SkProcXfermode which
122// in turn invokes OverdrawXferModeProc
123class OverdrawFilter : public SkDrawFilter {
124public:
125 OverdrawFilter() {
126 fXferMode = new SkProcXfermode(OverdrawXferModeProc);
127 }
128
129 virtual ~OverdrawFilter() {
130 delete fXferMode;
131 }
132
133 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
134 p->setXfermode(fXferMode);
135 return true;
136 }
137
138protected:
139 SkXfermode* fXferMode;
140
141private:
142 typedef SkDrawFilter INHERITED;
143};
144
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000145void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000146 SkASSERT(!fCommandVector.isEmpty());
147 SkASSERT(index < fCommandVector.count());
chudy@google.com830b8792012-08-01 15:57:52 +0000148 int i;
149
150 // This only works assuming the canvas and device are the same ones that
151 // were previously drawn into because they need to preserve all saves
152 // and restores.
153 if (fIndex < index) {
154 i = fIndex + 1;
155 } else {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000156 for (int j = 0; j < fOutstandingSaveCount; j++) {
157 canvas->restore();
158 }
chudy@google.com830b8792012-08-01 15:57:52 +0000159 i = 0;
junov@google.comdbfac8a2012-12-06 21:47:40 +0000160 canvas->clear(SK_ColorTRANSPARENT);
chudy@google.com830b8792012-08-01 15:57:52 +0000161 canvas->resetMatrix();
skia.committer@gmail.com04ba4482012-09-07 02:01:30 +0000162 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
robertphillips@google.com94acc702012-09-06 18:43:21 +0000163 SkIntToScalar(fHeight));
chudy@google.com4c7962e2012-08-14 19:38:31 +0000164 canvas->clipRect(rect, SkRegion::kReplace_Op );
chudy@google.com830b8792012-08-01 15:57:52 +0000165 applyUserTransform(canvas);
tomhudson@google.com0699e022012-11-27 16:09:42 +0000166 fOutstandingSaveCount = 0;
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000167
168 // The setting of the draw filter has to go here (rather than in
169 // SkRasterWidget) due to the canvas restores this class performs.
170 // Since the draw filter is stored in the layer stack if we
171 // call setDrawFilter on anything but the root layer odd things happen
172 if (fOverdrawViz) {
173 if (NULL == fOverdrawFilter) {
174 fOverdrawFilter = new OverdrawFilter;
175 }
176
177 if (fOverdrawFilter != canvas->getDrawFilter()) {
178 canvas->setDrawFilter(fOverdrawFilter);
179 }
180 } else {
181 canvas->setDrawFilter(NULL);
182 }
chudy@google.com830b8792012-08-01 15:57:52 +0000183 }
184
185 for (; i <= index; i++) {
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000186 if (i == index && fFilter) {
187 SkPaint p;
188 p.setColor(0xAAFFFFFF);
189 canvas->save();
190 canvas->resetMatrix();
191 SkRect mask;
192 mask.set(SkIntToScalar(0), SkIntToScalar(0),
193 SkIntToScalar(fWidth), SkIntToScalar(fHeight));
194 canvas->clipRect(mask, SkRegion::kReplace_Op, false);
195 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
196 SkIntToScalar(fWidth), SkIntToScalar(fHeight), p);
197 canvas->restore();
198 }
199
robertphillips@google.com67baba42013-01-02 20:20:31 +0000200 if (fCommandVector[i]->isVisible()) {
201 fCommandVector[i]->execute(canvas);
202 fCommandVector[i]->trackSaveState(&fOutstandingSaveCount);
chudy@google.com902ebe52012-06-29 14:21:22 +0000203 }
204 }
chudy@google.coma9e937c2012-08-03 17:32:05 +0000205 fMatrix = canvas->getTotalMatrix();
206 fClip = canvas->getTotalClip().getBounds();
chudy@google.com830b8792012-08-01 15:57:52 +0000207 fIndex = index;
chudy@google.com902ebe52012-06-29 14:21:22 +0000208}
209
210SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000211 SkASSERT(index < fCommandVector.count());
212 return fCommandVector[index];
chudy@google.com902ebe52012-06-29 14:21:22 +0000213}
214
chudy@google.com97cee972012-08-07 20:41:37 +0000215SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000216 SkASSERT(index < fCommandVector.count());
217 return fCommandVector[index]->Info();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000218}
chudy@google.com902ebe52012-06-29 14:21:22 +0000219
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000220bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000221 SkASSERT(index < fCommandVector.count());
222 return fCommandVector[index]->isVisible();
chudy@google.com902ebe52012-06-29 14:21:22 +0000223}
224
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000225const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000226 return fCommandVector;
chudy@google.com902ebe52012-06-29 14:21:22 +0000227}
228
229// TODO(chudy): Free command string memory.
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000230SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000231 SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count());
232 if (!fCommandVector.isEmpty()) {
233 for (int i = 0; i < fCommandVector.count(); i ++) {
234 commandString->push_back() = fCommandVector[i]->toString();
chudy@google.com902ebe52012-06-29 14:21:22 +0000235 }
236 }
237 return commandString;
238}
239
240void SkDebugCanvas::toggleFilter(bool toggle) {
241 fFilter = toggle;
242}
243
244void SkDebugCanvas::clear(SkColor color) {
245 addDrawCommand(new Clear(color));
246}
247
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000248static SkBitmap createBitmap(const SkPath& path) {
249 SkBitmap bitmap;
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +0000250 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000251 SkDebugCanvas::kVizImageWidth,
252 SkDebugCanvas::kVizImageHeight);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000253 bitmap.allocPixels();
254 bitmap.eraseColor(SK_ColorWHITE);
255 SkDevice* device = new SkDevice(bitmap);
256
257 SkCanvas canvas(device);
258 device->unref();
259
260 const SkRect& bounds = path.getBounds();
261
262 if (bounds.width() > bounds.height()) {
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000263 canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds.width()),
264 SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bounds.width()));
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000265 } else {
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000266 canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds.height()),
267 SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bounds.height()));
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000268 }
269 canvas.translate(-bounds.fLeft+2, -bounds.fTop+2);
270
271 SkPaint p;
272 p.setColor(SK_ColorBLACK);
273 p.setStyle(SkPaint::kStroke_Style);
274
275 canvas.drawPath(path, p);
276
277 return bitmap;
278}
279
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000280static SkBitmap createBitmap(const SkBitmap& input, const SkRect* srcRect) {
281 SkBitmap bitmap;
skia.committer@gmail.com8ccf5902012-11-27 02:01:19 +0000282 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000283 SkDebugCanvas::kVizImageWidth,
284 SkDebugCanvas::kVizImageHeight);
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000285 bitmap.allocPixels();
286 bitmap.eraseColor(SK_ColorLTGRAY);
287 SkDevice* device = new SkDevice(bitmap);
288
289 SkCanvas canvas(device);
290 device->unref();
291
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000292 SkScalar xScale = SkIntToScalar(SkDebugCanvas::kVizImageWidth-2) / input.width();
293 SkScalar yScale = SkIntToScalar(SkDebugCanvas::kVizImageHeight-2) / input.height();
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000294
295 if (input.width() > input.height()) {
296 yScale *= input.height() / (float) input.width();
297 } else {
298 xScale *= input.width() / (float) input.height();
299 }
300
skia.committer@gmail.com8ccf5902012-11-27 02:01:19 +0000301 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000302 xScale * input.width(),
303 yScale * input.height());
304
305 canvas.drawBitmapRect(input, NULL, dst);
306
307 if (NULL != srcRect) {
308 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
309 srcRect->fTop * yScale + SK_Scalar1,
310 srcRect->fRight * xScale + SK_Scalar1,
311 srcRect->fBottom * yScale + SK_Scalar1);
312 SkPaint p;
313 p.setColor(SK_ColorRED);
314 p.setStyle(SkPaint::kStroke_Style);
315
316 canvas.drawRect(r, p);
317 }
318
319 return bitmap;
320}
321
chudy@google.com902ebe52012-06-29 14:21:22 +0000322bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
rmistry@google.com44737652012-11-21 18:37:58 +0000323 SkBitmap bitmap = createBitmap(path);
324 addDrawCommand(new ClipPath(path, op, doAA, bitmap));
chudy@google.com902ebe52012-06-29 14:21:22 +0000325 return true;
326}
327
328bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
329 addDrawCommand(new ClipRect(rect, op, doAA));
330 return true;
331}
332
robertphillips@google.com67baba42013-01-02 20:20:31 +0000333bool SkDebugCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
334 addDrawCommand(new ClipRRect(rrect, op, doAA));
335 return true;
336}
337
chudy@google.com902ebe52012-06-29 14:21:22 +0000338bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) {
339 addDrawCommand(new ClipRegion(region, op));
340 return true;
341}
342
343bool SkDebugCanvas::concat(const SkMatrix& matrix) {
344 addDrawCommand(new Concat(matrix));
345 return true;
346}
347
348void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
349 SkScalar top, const SkPaint* paint = NULL) {
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000350 SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
351 addDrawCommand(new DrawBitmap(bitmap, left, top, paint, resizedBitmap));
chudy@google.com902ebe52012-06-29 14:21:22 +0000352}
353
reed@google.com71121732012-09-18 15:14:33 +0000354void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
355 const SkRect* src, const SkRect& dst, const SkPaint* paint) {
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000356 SkBitmap resizedBitmap = createBitmap(bitmap, src);
357 addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint, resizedBitmap));
chudy@google.com902ebe52012-06-29 14:21:22 +0000358}
359
360void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
361 const SkMatrix& matrix, const SkPaint* paint) {
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000362 SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
363 addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint, resizedBitmap));
chudy@google.com902ebe52012-06-29 14:21:22 +0000364}
365
366void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
367 const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000368 SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
369 addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint, resizedBitmap));
chudy@google.com902ebe52012-06-29 14:21:22 +0000370}
371
372void SkDebugCanvas::drawData(const void* data, size_t length) {
373 addDrawCommand(new DrawData(data, length));
374}
375
robertphillips@google.com67baba42013-01-02 20:20:31 +0000376void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
377 addDrawCommand(new DrawOval(oval, paint));
378}
379
chudy@google.com902ebe52012-06-29 14:21:22 +0000380void SkDebugCanvas::drawPaint(const SkPaint& paint) {
381 addDrawCommand(new DrawPaint(paint));
382}
383
384void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
rmistry@google.com44737652012-11-21 18:37:58 +0000385 SkBitmap bitmap = createBitmap(path);
386 addDrawCommand(new DrawPath(path, paint, bitmap));
chudy@google.com902ebe52012-06-29 14:21:22 +0000387}
388
389void SkDebugCanvas::drawPicture(SkPicture& picture) {
390 addDrawCommand(new DrawPicture(picture));
391}
392
393void SkDebugCanvas::drawPoints(PointMode mode, size_t count,
394 const SkPoint pts[], const SkPaint& paint) {
395 addDrawCommand(new DrawPoints(mode, count, pts, paint));
396}
397
398void SkDebugCanvas::drawPosText(const void* text, size_t byteLength,
399 const SkPoint pos[], const SkPaint& paint) {
400 addDrawCommand(new DrawPosText(text, byteLength, pos, paint));
401}
402
403void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength,
404 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
405 addDrawCommand(new DrawPosTextH(text, byteLength, xpos, constY, paint));
406}
407
408void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
409 // NOTE(chudy): Messing up when renamed to DrawRect... Why?
410 addDrawCommand(new DrawRectC(rect, paint));
411}
412
robertphillips@google.com67baba42013-01-02 20:20:31 +0000413void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
414 addDrawCommand(new DrawRRect(rrect, paint));
415}
416
chudy@google.com902ebe52012-06-29 14:21:22 +0000417void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
418 const SkPaint* paint = NULL) {
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000419 SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
420 addDrawCommand(new DrawSprite(bitmap, left, top, paint, resizedBitmap));
chudy@google.com902ebe52012-06-29 14:21:22 +0000421}
422
423void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
424 SkScalar y, const SkPaint& paint) {
425 addDrawCommand(new DrawTextC(text, byteLength, x, y, paint));
426}
427
428void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength,
429 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
430 addDrawCommand(new DrawTextOnPath(text, byteLength, path, matrix, paint));
431}
432
433void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount,
434 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
435 SkXfermode*, const uint16_t indices[], int indexCount,
436 const SkPaint& paint) {
437 addDrawCommand(new DrawVertices(vmode, vertexCount, vertices, texs, colors,
438 NULL, indices, indexCount, paint));
439}
440
441void SkDebugCanvas::restore() {
442 addDrawCommand(new Restore());
443}
444
445bool SkDebugCanvas::rotate(SkScalar degrees) {
446 addDrawCommand(new Rotate(degrees));
447 return true;
448}
449
450int SkDebugCanvas::save(SaveFlags flags) {
451 addDrawCommand(new Save(flags));
452 return true;
453}
454
455int SkDebugCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
456 SaveFlags flags) {
457 addDrawCommand(new SaveLayer(bounds, paint, flags));
458 return true;
459}
460
461bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) {
462 addDrawCommand(new Scale(sx, sy));
463 return true;
464}
465
466void SkDebugCanvas::setMatrix(const SkMatrix& matrix) {
467 addDrawCommand(new SetMatrix(matrix));
468}
469
470bool SkDebugCanvas::skew(SkScalar sx, SkScalar sy) {
471 addDrawCommand(new Skew(sx, sy));
472 return true;
473}
474
475bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) {
476 addDrawCommand(new Translate(dx, dy));
477 return true;
478}
479
chudy@google.com902ebe52012-06-29 14:21:22 +0000480void SkDebugCanvas::toggleCommand(int index, bool toggle) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000481 SkASSERT(index < fCommandVector.count());
482 fCommandVector[index]->setVisible(toggle);
chudy@google.com902ebe52012-06-29 14:21:22 +0000483}