blob: 18affcb418b89ebda0664e1265eab50326e95b90 [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
commit-bot@chromium.orgcc277b72014-04-17 15:19:32 +000095class OverdrawXfermode : public SkXfermode {
96public:
97 virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const SK_OVERRIDE {
98 // This table encodes the color progression of the overdraw visualization
99 static const SkPMColor gTable[] = {
100 SkPackARGB32(0x00, 0x00, 0x00, 0x00),
101 SkPackARGB32(0xFF, 128, 158, 255),
102 SkPackARGB32(0xFF, 170, 185, 212),
103 SkPackARGB32(0xFF, 213, 195, 170),
104 SkPackARGB32(0xFF, 255, 192, 127),
105 SkPackARGB32(0xFF, 255, 185, 85),
106 SkPackARGB32(0xFF, 255, 165, 42),
107 SkPackARGB32(0xFF, 255, 135, 0),
108 SkPackARGB32(0xFF, 255, 95, 0),
109 SkPackARGB32(0xFF, 255, 50, 0),
110 SkPackARGB32(0xFF, 255, 0, 0)
111 };
skia.committer@gmail.com60bd7512014-04-18 03:03:54 +0000112
commit-bot@chromium.orgcc277b72014-04-17 15:19:32 +0000113 for (size_t i = 0; i < SK_ARRAY_COUNT(gTable)-1; ++i) {
114 if (gTable[i] == dst) {
115 return gTable[i+1];
116 }
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000117 }
skia.committer@gmail.com60bd7512014-04-18 03:03:54 +0000118
commit-bot@chromium.orgcc277b72014-04-17 15:19:32 +0000119 return gTable[SK_ARRAY_COUNT(gTable)-1];
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000120 }
121
commit-bot@chromium.orgcc277b72014-04-17 15:19:32 +0000122 virtual Factory getFactory() const SK_OVERRIDE { return NULL; }
123#ifndef SK_IGNORE_TO_STRING
124 virtual void toString(SkString* str) const { str->set("OverdrawXfermode"); }
125#endif
126};
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000127
128// The OverdrawFilter modifies every paint to use an SkProcXfermode which
129// in turn invokes OverdrawXferModeProc
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000130class SkOverdrawFilter : public SkDrawFilter {
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000131public:
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000132 SkOverdrawFilter() {
commit-bot@chromium.orgcc277b72014-04-17 15:19:32 +0000133 fXferMode = SkNEW(OverdrawXfermode);
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000134 }
135
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000136 virtual ~SkOverdrawFilter() {
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000137 delete fXferMode;
138 }
139
140 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
141 p->setXfermode(fXferMode);
142 return true;
143 }
144
145protected:
146 SkXfermode* fXferMode;
147
148private:
149 typedef SkDrawFilter INHERITED;
150};
151
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +0000152// SkTexOverrideFilter modifies every paint to use the specified
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000153// texture filtering mode
154class SkTexOverrideFilter : public SkDrawFilter {
155public:
156 SkTexOverrideFilter() : fFilterLevel(SkPaint::kNone_FilterLevel) {
157 }
158
159 void setFilterLevel(SkPaint::FilterLevel filterLevel) {
160 fFilterLevel = filterLevel;
161 }
162
163 virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
164 p->setFilterLevel(fFilterLevel);
165 return true;
166 }
167
168protected:
169 SkPaint::FilterLevel fFilterLevel;
170
171private:
172 typedef SkDrawFilter INHERITED;
173};
174
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000175class SkDebugClipVisitor : public SkCanvas::ClipVisitor {
176public:
177 SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {}
178
179 virtual void clipRect(const SkRect& r, SkRegion::Op, bool doAA) SK_OVERRIDE {
180 SkPaint p;
181 p.setColor(SK_ColorRED);
182 p.setStyle(SkPaint::kStroke_Style);
183 p.setAntiAlias(doAA);
184 fCanvas->drawRect(r, p);
185 }
186 virtual void clipRRect(const SkRRect& rr, SkRegion::Op, bool doAA) SK_OVERRIDE {
187 SkPaint p;
188 p.setColor(SK_ColorGREEN);
189 p.setStyle(SkPaint::kStroke_Style);
190 p.setAntiAlias(doAA);
191 fCanvas->drawRRect(rr, p);
192 }
193 virtual void clipPath(const SkPath& path, SkRegion::Op, bool doAA) SK_OVERRIDE {
194 SkPaint p;
195 p.setColor(SK_ColorBLUE);
196 p.setStyle(SkPaint::kStroke_Style);
197 p.setAntiAlias(doAA);
198 fCanvas->drawPath(path, p);
199 }
200
201protected:
202 SkCanvas* fCanvas;
203
204private:
205 typedef SkCanvas::ClipVisitor INHERITED;
206};
207
208// set up the saveLayer commands so that the active ones
209// return true in their 'active' method
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000210void SkDebugCanvas::markActiveCommands(int index) {
211 fActiveLayers.rewind();
212 fActiveCulls.rewind();
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000213
214 for (int i = 0; i < fCommandVector.count(); ++i) {
215 fCommandVector[i]->setActive(false);
216 }
217
218 for (int i = 0; i < index; ++i) {
219 SkDrawCommand::Action result = fCommandVector[i]->action();
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000220 if (SkDrawCommand::kPushLayer_Action == result) {
221 fActiveLayers.push(fCommandVector[i]);
222 } else if (SkDrawCommand::kPopLayer_Action == result) {
223 fActiveLayers.pop();
224 } else if (SkDrawCommand::kPushCull_Action == result) {
225 fActiveCulls.push(fCommandVector[i]);
226 } else if (SkDrawCommand::kPopCull_Action == result) {
227 fActiveCulls.pop();
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000228 }
229 }
230
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000231 for (int i = 0; i < fActiveLayers.count(); ++i) {
232 fActiveLayers[i]->setActive(true);
233 }
234
235 for (int i = 0; i < fActiveCulls.count(); ++i) {
236 fActiveCulls[i]->setActive(true);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000237 }
238}
239
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000240void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000241 SkASSERT(!fCommandVector.isEmpty());
242 SkASSERT(index < fCommandVector.count());
commit-bot@chromium.org1735d662013-12-04 13:42:46 +0000243 int i = 0;
chudy@google.com830b8792012-08-01 15:57:52 +0000244
245 // This only works assuming the canvas and device are the same ones that
246 // were previously drawn into because they need to preserve all saves
247 // and restores.
commit-bot@chromium.org1735d662013-12-04 13:42:46 +0000248 // The visibility filter also requires a full re-draw - otherwise we can
249 // end up drawing the filter repeatedly.
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000250 if (fIndex < index && !fFilter && !fMegaVizMode) {
chudy@google.com830b8792012-08-01 15:57:52 +0000251 i = fIndex + 1;
252 } else {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000253 for (int j = 0; j < fOutstandingSaveCount; j++) {
254 canvas->restore();
255 }
junov@google.comdbfac8a2012-12-06 21:47:40 +0000256 canvas->clear(SK_ColorTRANSPARENT);
chudy@google.com830b8792012-08-01 15:57:52 +0000257 canvas->resetMatrix();
skia.committer@gmail.com04ba4482012-09-07 02:01:30 +0000258 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
robertphillips@google.com94acc702012-09-06 18:43:21 +0000259 SkIntToScalar(fHeight));
chudy@google.com4c7962e2012-08-14 19:38:31 +0000260 canvas->clipRect(rect, SkRegion::kReplace_Op );
chudy@google.com830b8792012-08-01 15:57:52 +0000261 applyUserTransform(canvas);
tomhudson@google.com0699e022012-11-27 16:09:42 +0000262 fOutstandingSaveCount = 0;
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000263 }
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000264
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000265 // The setting of the draw filter has to go here (rather than in
266 // SkRasterWidget) due to the canvas restores this class performs.
267 // Since the draw filter is stored in the layer stack if we
268 // call setDrawFilter on anything but the root layer odd things happen.
269 if (fOverdrawViz) {
270 if (NULL == fOverdrawFilter) {
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000271 fOverdrawFilter = new SkOverdrawFilter;
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000272 }
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000273
274 if (fOverdrawFilter != canvas->getDrawFilter()) {
275 canvas->setDrawFilter(fOverdrawFilter);
276 }
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000277 } else if (fOverrideTexFiltering) {
278 if (NULL == fTexOverrideFilter) {
279 fTexOverrideFilter = new SkTexOverrideFilter;
280 }
281
282 if (fTexOverrideFilter != canvas->getDrawFilter()) {
283 canvas->setDrawFilter(fTexOverrideFilter);
284 }
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000285 } else {
286 canvas->setDrawFilter(NULL);
chudy@google.com830b8792012-08-01 15:57:52 +0000287 }
288
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000289 if (fMegaVizMode) {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000290 this->markActiveCommands(index);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000291 }
292
chudy@google.com830b8792012-08-01 15:57:52 +0000293 for (; i <= index; i++) {
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000294 if (i == index && fFilter) {
295 SkPaint p;
296 p.setColor(0xAAFFFFFF);
297 canvas->save();
298 canvas->resetMatrix();
299 SkRect mask;
300 mask.set(SkIntToScalar(0), SkIntToScalar(0),
301 SkIntToScalar(fWidth), SkIntToScalar(fHeight));
302 canvas->clipRect(mask, SkRegion::kReplace_Op, false);
303 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
304 SkIntToScalar(fWidth), SkIntToScalar(fHeight), p);
305 canvas->restore();
306 }
307
robertphillips@google.com67baba42013-01-02 20:20:31 +0000308 if (fCommandVector[i]->isVisible()) {
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000309 if (fMegaVizMode && fCommandVector[i]->active()) {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000310 // "active" commands execute their visualization behaviors:
311 // All active saveLayers get replaced with saves so all draws go to the
312 // visible canvas.
313 // All active culls draw their cull box
314 fCommandVector[i]->vizExecute(canvas);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000315 } else {
316 fCommandVector[i]->execute(canvas);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000317 }
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000318
319 fCommandVector[i]->trackSaveState(&fOutstandingSaveCount);
chudy@google.com902ebe52012-06-29 14:21:22 +0000320 }
321 }
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000322
323 if (fMegaVizMode) {
324 SkRect r = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight));
325 r.outset(SK_Scalar1, SK_Scalar1);
326
327 canvas->save();
328 // nuke the CTM
329 canvas->setMatrix(SkMatrix::I());
330 // turn off clipping
331 canvas->clipRect(r, SkRegion::kReplace_Op);
332
333 // visualize existing clips
334 SkDebugClipVisitor visitor(canvas);
335
336 canvas->replayClips(&visitor);
337
338 canvas->restore();
339 }
chudy@google.coma9e937c2012-08-03 17:32:05 +0000340 fMatrix = canvas->getTotalMatrix();
commit-bot@chromium.org5c70cdc2014-03-08 03:57:19 +0000341 if (!canvas->getClipDeviceBounds(&fClip)) {
342 fClip.setEmpty();
343 }
chudy@google.com830b8792012-08-01 15:57:52 +0000344 fIndex = index;
chudy@google.com902ebe52012-06-29 14:21:22 +0000345}
346
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000347void SkDebugCanvas::deleteDrawCommandAt(int index) {
348 SkASSERT(index < fCommandVector.count());
349 delete fCommandVector[index];
350 fCommandVector.remove(index);
351}
352
chudy@google.com902ebe52012-06-29 14:21:22 +0000353SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000354 SkASSERT(index < fCommandVector.count());
355 return fCommandVector[index];
chudy@google.com902ebe52012-06-29 14:21:22 +0000356}
357
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000358void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) {
359 SkASSERT(index < fCommandVector.count());
360 delete fCommandVector[index];
361 fCommandVector[index] = command;
362}
363
chudy@google.com97cee972012-08-07 20:41:37 +0000364SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000365 SkASSERT(index < fCommandVector.count());
366 return fCommandVector[index]->Info();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000367}
chudy@google.com902ebe52012-06-29 14:21:22 +0000368
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000369bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000370 SkASSERT(index < fCommandVector.count());
371 return fCommandVector[index]->isVisible();
chudy@google.com902ebe52012-06-29 14:21:22 +0000372}
373
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000374const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000375 return fCommandVector;
chudy@google.com902ebe52012-06-29 14:21:22 +0000376}
377
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000378SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() {
379 return fCommandVector;
380}
381
chudy@google.com902ebe52012-06-29 14:21:22 +0000382// TODO(chudy): Free command string memory.
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000383SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000384 SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count());
385 if (!fCommandVector.isEmpty()) {
386 for (int i = 0; i < fCommandVector.count(); i ++) {
387 commandString->push_back() = fCommandVector[i]->toString();
chudy@google.com902ebe52012-06-29 14:21:22 +0000388 }
389 }
390 return commandString;
391}
392
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000393SkTDArray<size_t>* SkDebugCanvas::getDrawCommandOffsets() const {
394 SkTDArray<size_t>* commandOffsets = new SkTDArray<size_t>;
395 if (!fCommandVector.isEmpty()) {
396 for (int i = 0; i < fCommandVector.count(); i ++) {
397 *commandOffsets->push() = fCommandVector[i]->offset();
398 }
399 }
400 return commandOffsets;
401}
402
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +0000403void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level) {
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000404 if (NULL == fTexOverrideFilter) {
405 fTexOverrideFilter = new SkTexOverrideFilter;
406 }
407
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +0000408 fOverrideTexFiltering = overrideTexFiltering;
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000409 fTexOverrideFilter->setFilterLevel(level);
410}
411
chudy@google.com902ebe52012-06-29 14:21:22 +0000412void SkDebugCanvas::clear(SkColor color) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000413 this->addDrawCommand(new SkClearCommand(color));
chudy@google.com902ebe52012-06-29 14:21:22 +0000414}
415
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000416void SkDebugCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
417 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000418}
419
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000420void SkDebugCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
421 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000422}
423
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000424void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
425 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000426}
427
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000428void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) {
429 this->addDrawCommand(new SkClipRegionCommand(region, op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000430}
431
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000432void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
commit-bot@chromium.orgd9ea09e2014-03-25 17:32:26 +0000433 switch (matrix.getType()) {
434 case SkMatrix::kTranslate_Mask:
435 this->addDrawCommand(new SkTranslateCommand(matrix.getTranslateX(),
436 matrix.getTranslateY()));
437 break;
438 case SkMatrix::kScale_Mask:
439 this->addDrawCommand(new SkScaleCommand(matrix.getScaleX(),
440 matrix.getScaleY()));
441 break;
442 default:
443 this->addDrawCommand(new SkConcatCommand(matrix));
444 break;
445 }
446
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000447 this->INHERITED::didConcat(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000448}
449
450void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000451 SkScalar top, const SkPaint* paint = NULL) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000452 this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000453}
454
reed@google.com71121732012-09-18 15:14:33 +0000455void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000456 const SkRect* src, const SkRect& dst,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000457 const SkPaint* paint,
458 SkCanvas::DrawBitmapRectFlags flags) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000459 this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000460}
461
462void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000463 const SkMatrix& matrix, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000464 this->addDrawCommand(new SkDrawBitmapMatrixCommand(bitmap, matrix, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000465}
466
467void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
468 const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000469 this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000470}
471
472void SkDebugCanvas::drawData(const void* data, size_t length) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000473 this->addDrawCommand(new SkDrawDataCommand(data, length));
chudy@google.com902ebe52012-06-29 14:21:22 +0000474}
475
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000476void SkDebugCanvas::beginCommentGroup(const char* description) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000477 this->addDrawCommand(new SkBeginCommentGroupCommand(description));
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000478}
479
480void SkDebugCanvas::addComment(const char* kywd, const char* value) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000481 this->addDrawCommand(new SkCommentCommand(kywd, value));
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000482}
483
484void SkDebugCanvas::endCommentGroup() {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000485 this->addDrawCommand(new SkEndCommentGroupCommand());
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000486}
487
robertphillips@google.com67baba42013-01-02 20:20:31 +0000488void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000489 this->addDrawCommand(new SkDrawOvalCommand(oval, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000490}
491
chudy@google.com902ebe52012-06-29 14:21:22 +0000492void SkDebugCanvas::drawPaint(const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000493 this->addDrawCommand(new SkDrawPaintCommand(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000494}
495
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000496void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000497 this->addDrawCommand(new SkDrawPathCommand(path, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000498}
499
500void SkDebugCanvas::drawPicture(SkPicture& picture) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000501 this->addDrawCommand(new SkDrawPictureCommand(picture));
chudy@google.com902ebe52012-06-29 14:21:22 +0000502}
503
504void SkDebugCanvas::drawPoints(PointMode mode, size_t count,
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000505 const SkPoint pts[], const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000506 this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000507}
508
509void SkDebugCanvas::drawPosText(const void* text, size_t byteLength,
510 const SkPoint pos[], const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000511 this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000512}
513
514void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength,
515 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000516 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000517 new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000518}
519
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000520void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000521 // NOTE(chudy): Messing up when renamed to DrawRect... Why?
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000522 addDrawCommand(new SkDrawRectCommand(rect, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000523}
524
robertphillips@google.com67baba42013-01-02 20:20:31 +0000525void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000526 this->addDrawCommand(new SkDrawRRectCommand(rrect, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000527}
528
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000529void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
530 const SkPaint& paint) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000531 this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint));
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000532}
533
chudy@google.com902ebe52012-06-29 14:21:22 +0000534void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000535 const SkPaint* paint = NULL) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000536 this->addDrawCommand(new SkDrawSpriteCommand(bitmap, left, top, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000537}
538
539void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
540 SkScalar y, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000541 this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000542}
543
544void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength,
545 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000546 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000547 new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000548}
549
550void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount,
551 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
552 SkXfermode*, const uint16_t indices[], int indexCount,
553 const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000554 this->addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices,
555 texs, colors, NULL, indices, indexCount, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000556}
557
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000558void SkDebugCanvas::onPushCull(const SkRect& cullRect) {
559 this->addDrawCommand(new SkPushCullCommand(cullRect));
560}
561
562void SkDebugCanvas::onPopCull() {
563 this->addDrawCommand(new SkPopCullCommand());
564}
565
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000566void SkDebugCanvas::willRestore() {
567 this->addDrawCommand(new SkRestoreCommand());
568 this->INHERITED::willRestore();
chudy@google.com902ebe52012-06-29 14:21:22 +0000569}
570
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000571void SkDebugCanvas::willSave(SaveFlags flags) {
572 this->addDrawCommand(new SkSaveCommand(flags));
573 this->INHERITED::willSave(flags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000574}
575
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000576SkCanvas::SaveLayerStrategy SkDebugCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
577 SaveFlags flags) {
578 this->addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags));
579 this->INHERITED::willSaveLayer(bounds, paint, flags);
580 // No need for a full layer.
581 return kNoLayer_SaveLayerStrategy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000582}
583
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000584void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000585 this->addDrawCommand(new SkSetMatrixCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000586 this->INHERITED::didSetMatrix(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000587}
588
chudy@google.com902ebe52012-06-29 14:21:22 +0000589void SkDebugCanvas::toggleCommand(int index, bool toggle) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000590 SkASSERT(index < fCommandVector.count());
591 fCommandVector[index]->setVisible(toggle);
chudy@google.com902ebe52012-06-29 14:21:22 +0000592}