blob: 93163c95790163e2d6e0110fca1c76f87c39530d [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
ethannicholas891ad662016-02-12 07:15:45 -08008#include "SkCanvasPriv.h"
chudy@google.com902ebe52012-06-29 14:21:22 +00009#include "SkDebugCanvas.h"
10#include "SkDrawCommand.h"
fmalita37283c22016-09-13 10:00:23 -070011#include "SkPaintFilterCanvas.h"
Brian Osman255735e2018-04-06 14:51:42 -040012#include "SkPicture.h"
Mike Reed274218e2018-01-08 15:05:02 -050013#include "SkRectPriv.h"
fmalita37283c22016-09-13 10:00:23 -070014#include "SkTextBlob.h"
Mike Reedebfce6d2016-12-12 10:02:12 -050015#include "SkClipOpPriv.h"
fmalita65cdb572015-03-26 07:24:48 -070016
joshualitt10d8fc22016-02-29 11:15:06 -080017#if SK_SUPPORT_GPU
18#include "GrAuditTrail.h"
19#include "GrContext.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050020#include "GrRenderTargetContext.h"
joshualitt10d8fc22016-02-29 11:15:06 -080021#endif
22
joshualitte43f7e62016-03-04 10:45:05 -080023#define SKDEBUGCANVAS_VERSION 1
24#define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version"
25#define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands"
26#define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail"
ethannicholas402cd912016-02-10 12:57:30 -080027
fmalita65cdb572015-03-26 07:24:48 -070028class DebugPaintFilterCanvas : public SkPaintFilterCanvas {
29public:
Ben Wagnerc03e1c52016-10-17 15:20:02 -040030 DebugPaintFilterCanvas(SkCanvas* canvas,
Brian Osman255735e2018-04-06 14:51:42 -040031 bool overdrawViz)
Ben Wagnerc03e1c52016-10-17 15:20:02 -040032 : INHERITED(canvas)
Brian Osman255735e2018-04-06 14:51:42 -040033 , fOverdrawViz(overdrawViz) {}
fmalita65cdb572015-03-26 07:24:48 -070034
35protected:
fmalita32cdc322016-01-12 07:21:11 -080036 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override {
37 if (*paint) {
Ben Wagnerc03e1c52016-10-17 15:20:02 -040038 if (fOverdrawViz) {
39 paint->writable()->setColor(SK_ColorRED);
40 paint->writable()->setAlpha(0x08);
41 paint->writable()->setBlendMode(SkBlendMode::kSrcOver);
fmalitabad23dc2016-01-11 13:58:29 -080042 }
fmalita65cdb572015-03-26 07:24:48 -070043 }
fmalitabad23dc2016-01-11 13:58:29 -080044 return true;
fmalita65cdb572015-03-26 07:24:48 -070045 }
46
mtkleinf0599002015-07-13 06:18:39 -070047 void onDrawPicture(const SkPicture* picture,
48 const SkMatrix* matrix,
49 const SkPaint* paint) override {
fmalita65cdb572015-03-26 07:24:48 -070050 // We need to replay the picture onto this canvas in order to filter its internal paints.
51 this->SkCanvas::onDrawPicture(picture, matrix, paint);
52 }
53
54private:
Ben Wagnerc03e1c52016-10-17 15:20:02 -040055 bool fOverdrawViz;
fmalita65cdb572015-03-26 07:24:48 -070056
57 typedef SkPaintFilterCanvas INHERITED;
58};
59
kkinnunen26e54002015-01-05 12:58:56 -080060SkDebugCanvas::SkDebugCanvas(int width, int height)
61 : INHERITED(width, height)
robertphillips@google.comf4741c12013-02-06 20:13:54 +000062 , fOverdrawViz(false)
joshualitt10d8fc22016-02-29 11:15:06 -080063 , fClipVizColor(SK_ColorTRANSPARENT)
Brian Salomon144a5c52016-12-20 16:48:59 -050064 , fDrawGpuOpBounds(false) {
robertphillips@google.com8b157172013-11-07 22:20:31 +000065 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped
66 // operations. This can lead to problems in the debugger which expects all
67 // the operations in the captured skp to appear in the debug canvas. To
68 // circumvent this we create a wide open clip here (an empty clip rect
69 // is not sufficient).
70 // Internally, the SkRect passed to clipRect is converted to an SkIRect and
71 // rounded out. The following code creates a nearly maximal rect that will
72 // not get collapsed by the coming conversions (Due to precision loss the
73 // inset has to be surprisingly large).
Mike Reed8008df12018-01-17 12:20:04 -050074 SkIRect largeIRect = SkRectPriv::MakeILarge();
robertphillips@google.com8b157172013-11-07 22:20:31 +000075 largeIRect.inset(1024, 1024);
robertphillips@google.com6c1e49a2013-11-10 15:08:45 +000076 SkRect large = SkRect::Make(largeIRect);
robertphillips@google.com8b157172013-11-07 22:20:31 +000077#ifdef SK_DEBUG
reedb07a94f2014-11-19 05:03:18 -080078 SkASSERT(!large.roundOut().isEmpty());
robertphillips@google.com8b157172013-11-07 22:20:31 +000079#endif
robertphillips@google.com8f90a892014-02-28 18:19:39 +000080 // call the base class' version to avoid adding a draw command
Mike Reedc1f77742016-12-09 09:00:50 -050081 this->INHERITED::onClipRect(large, kReplace_SkClipOp, kHard_ClipEdgeStyle);
chudy@google.com902ebe52012-06-29 14:21:22 +000082}
83
chudy@google.com9cda6f72012-08-07 15:08:33 +000084SkDebugCanvas::~SkDebugCanvas() {
robertphillips@google.com67baba42013-01-02 20:20:31 +000085 fCommandVector.deleteAll();
chudy@google.com9cda6f72012-08-07 15:08:33 +000086}
chudy@google.com902ebe52012-06-29 14:21:22 +000087
88void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
robertphillips@google.com67baba42013-01-02 20:20:31 +000089 fCommandVector.push(command);
chudy@google.com902ebe52012-06-29 14:21:22 +000090}
91
92void SkDebugCanvas::draw(SkCanvas* canvas) {
commit-bot@chromium.org1735d662013-12-04 13:42:46 +000093 if (!fCommandVector.isEmpty()) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000094 this->drawTo(canvas, fCommandVector.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +000095 }
96}
97
Ravi Mistry99c97962016-12-21 22:41:03 +000098void SkDebugCanvas::drawTo(SkCanvas* originalCanvas, int index, int m) {
robertphillips@google.com67baba42013-01-02 20:20:31 +000099 SkASSERT(!fCommandVector.isEmpty());
100 SkASSERT(index < fCommandVector.count());
kkinnunen26a00de2015-01-13 23:09:19 -0800101
Ravi Mistry99c97962016-12-21 22:41:03 +0000102 int saveCount = originalCanvas->save();
kkinnunen26a00de2015-01-13 23:09:19 -0800103
Ravi Mistry99c97962016-12-21 22:41:03 +0000104 SkRect windowRect = SkRect::MakeWH(SkIntToScalar(originalCanvas->getBaseLayerSize().width()),
105 SkIntToScalar(originalCanvas->getBaseLayerSize().height()));
chudy@google.com830b8792012-08-01 15:57:52 +0000106
Ravi Mistry99c97962016-12-21 22:41:03 +0000107 originalCanvas->clear(SK_ColorWHITE);
108 originalCanvas->resetMatrix();
kkinnunen26a00de2015-01-13 23:09:19 -0800109 if (!windowRect.isEmpty()) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000110 originalCanvas->clipRect(windowRect, kReplace_SkClipOp);
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000111 }
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000112
Brian Osman255735e2018-04-06 14:51:42 -0400113 DebugPaintFilterCanvas filterCanvas(originalCanvas, fOverdrawViz);
halcanary9d524f22016-03-29 09:03:52 -0700114
joshualitt40836102016-03-11 11:45:53 -0800115#if SK_SUPPORT_GPU
Brian Salomon144a5c52016-12-20 16:48:59 -0500116 // If we have a GPU backend we can also visualize the op information
joshualitt10d8fc22016-02-29 11:15:06 -0800117 GrAuditTrail* at = nullptr;
Brian Salomon144a5c52016-12-20 16:48:59 -0500118 if (fDrawGpuOpBounds || m != -1) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000119 // The audit trail must be obtained from the original canvas.
120 at = this->getAuditTrail(originalCanvas);
joshualitt10d8fc22016-02-29 11:15:06 -0800121 }
joshualitt40836102016-03-11 11:45:53 -0800122#endif
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000123
kkinnunen26a00de2015-01-13 23:09:19 -0800124 for (int i = 0; i <= index; i++) {
joshualitt10d8fc22016-02-29 11:15:06 -0800125#if SK_SUPPORT_GPU
Brian Salomon144a5c52016-12-20 16:48:59 -0500126 // We need to flush any pending operations, or they might combine with commands below.
brianosman1c9f9222016-04-15 11:00:51 -0700127 // Previous operations were not registered with the audit trail when they were
128 // created, so if we allow them to combine, the audit trail will fail to find them.
Ravi Mistry99c97962016-12-21 22:41:03 +0000129 filterCanvas.flush();
brianosman1c9f9222016-04-15 11:00:51 -0700130
Brian Salomon42ad83a2016-12-20 16:14:45 -0500131 GrAuditTrail::AutoCollectOps* acb = nullptr;
joshualitt10d8fc22016-02-29 11:15:06 -0800132 if (at) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500133 acb = new GrAuditTrail::AutoCollectOps(at, i);
joshualitt10d8fc22016-02-29 11:15:06 -0800134 }
135#endif
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000136
robertphillips@google.com67baba42013-01-02 20:20:31 +0000137 if (fCommandVector[i]->isVisible()) {
Brian Osman255735e2018-04-06 14:51:42 -0400138 fCommandVector[i]->execute(&filterCanvas);
chudy@google.com902ebe52012-06-29 14:21:22 +0000139 }
joshualitt10d8fc22016-02-29 11:15:06 -0800140#if SK_SUPPORT_GPU
141 if (at && acb) {
142 delete acb;
143 }
144#endif
chudy@google.com902ebe52012-06-29 14:21:22 +0000145 }
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000146
ethannicholas0a0520a2016-02-12 12:06:53 -0800147 if (SkColorGetA(fClipVizColor) != 0) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000148 filterCanvas.save();
ethannicholas0a0520a2016-02-12 12:06:53 -0800149 #define LARGE_COORD 1000000000
Ravi Mistry99c97962016-12-21 22:41:03 +0000150 filterCanvas.clipRect(
151 SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD),
152 kReverseDifference_SkClipOp);
ethannicholas0a0520a2016-02-12 12:06:53 -0800153 SkPaint clipPaint;
154 clipPaint.setColor(fClipVizColor);
Ravi Mistry99c97962016-12-21 22:41:03 +0000155 filterCanvas.drawPaint(clipPaint);
156 filterCanvas.restore();
ethannicholas0a0520a2016-02-12 12:06:53 -0800157 }
158
Ravi Mistry99c97962016-12-21 22:41:03 +0000159 fMatrix = filterCanvas.getTotalMatrix();
Mike Reed918e1442017-01-23 11:39:45 -0500160 fClip = filterCanvas.getDeviceClipBounds();
Ravi Mistry99c97962016-12-21 22:41:03 +0000161 filterCanvas.restoreToCount(saveCount);
fmalita65cdb572015-03-26 07:24:48 -0700162
joshualitt10d8fc22016-02-29 11:15:06 -0800163#if SK_SUPPORT_GPU
Brian Salomon144a5c52016-12-20 16:48:59 -0500164 // draw any ops if required and issue a full reset onto GrAuditTrail
joshualitt10d8fc22016-02-29 11:15:06 -0800165 if (at) {
joshualitte43f7e62016-03-04 10:45:05 -0800166 // just in case there is global reordering, we flush the canvas before querying
167 // GrAuditTrail
joshualittb0666ad2016-03-08 10:43:41 -0800168 GrAuditTrail::AutoEnable ae(at);
Ravi Mistry99c97962016-12-21 22:41:03 +0000169 filterCanvas.flush();
joshualitte43f7e62016-03-04 10:45:05 -0800170
joshualittbdc6b2b2016-03-01 14:22:02 -0800171 // we pick three colorblind-safe colors, 75% alpha
172 static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A);
Brian Salomon144a5c52016-12-20 16:48:59 -0500173 static const SkColor kCommandOpBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C);
174 static const SkColor kOtherOpBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00);
joshualittbdc6b2b2016-03-01 14:22:02 -0800175
Ravi Mistry99c97962016-12-21 22:41:03 +0000176 // get the render target of the top device (from the original canvas) so we can ignore ops
177 // drawn offscreen
178 GrRenderTargetContext* rtc =
179 originalCanvas->internal_private_accessTopLayerRenderTargetContext();
Robert Phillips318c4192017-05-17 09:36:38 -0400180 GrSurfaceProxy::UniqueID proxyID = rtc->asSurfaceProxy()->uniqueID();
joshualitt1d7decf2016-03-01 07:15:52 -0800181
182 // get the bounding boxes to draw
Brian Salomon42ad83a2016-12-20 16:14:45 -0500183 SkTArray<GrAuditTrail::OpInfo> childrenBounds;
joshualitt46b301d2016-03-02 08:32:37 -0800184 if (m == -1) {
185 at->getBoundsByClientID(&childrenBounds, index);
186 } else {
Brian Salomon144a5c52016-12-20 16:48:59 -0500187 // the client wants us to draw the mth op
Brian Salomon42ad83a2016-12-20 16:14:45 -0500188 at->getBoundsByOpListID(&childrenBounds.push_back(), m);
joshualitt46b301d2016-03-02 08:32:37 -0800189 }
joshualitt10d8fc22016-02-29 11:15:06 -0800190 SkPaint paint;
191 paint.setStyle(SkPaint::kStroke_Style);
192 paint.setStrokeWidth(1);
193 for (int i = 0; i < childrenBounds.count(); i++) {
Robert Phillips318c4192017-05-17 09:36:38 -0400194 if (childrenBounds[i].fProxyUniqueID != proxyID) {
joshualitt1d7decf2016-03-01 07:15:52 -0800195 // offscreen draw, ignore for now
196 continue;
197 }
joshualittbdc6b2b2016-03-01 14:22:02 -0800198 paint.setColor(kTotalBounds);
Ravi Mistry99c97962016-12-21 22:41:03 +0000199 filterCanvas.drawRect(childrenBounds[i].fBounds, paint);
Brian Salomon42ad83a2016-12-20 16:14:45 -0500200 for (int j = 0; j < childrenBounds[i].fOps.count(); j++) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500201 const GrAuditTrail::OpInfo::Op& op = childrenBounds[i].fOps[j];
202 if (op.fClientID != index) {
203 paint.setColor(kOtherOpBounds);
joshualitt10d8fc22016-02-29 11:15:06 -0800204 } else {
Brian Salomon144a5c52016-12-20 16:48:59 -0500205 paint.setColor(kCommandOpBounds);
joshualitt10d8fc22016-02-29 11:15:06 -0800206 }
Ravi Mistry99c97962016-12-21 22:41:03 +0000207 filterCanvas.drawRect(op.fBounds, paint);
joshualitt10d8fc22016-02-29 11:15:06 -0800208 }
209 }
joshualitt10d8fc22016-02-29 11:15:06 -0800210 }
joshualitt10d8fc22016-02-29 11:15:06 -0800211#endif
Ravi Mistry99c97962016-12-21 22:41:03 +0000212 this->cleanupAuditTrail(originalCanvas);
chudy@google.com902ebe52012-06-29 14:21:22 +0000213}
214
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000215void SkDebugCanvas::deleteDrawCommandAt(int index) {
216 SkASSERT(index < fCommandVector.count());
217 delete fCommandVector[index];
218 fCommandVector.remove(index);
219}
220
chudy@google.com902ebe52012-06-29 14:21:22 +0000221SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000222 SkASSERT(index < fCommandVector.count());
223 return fCommandVector[index];
chudy@google.com902ebe52012-06-29 14:21:22 +0000224}
225
joshualittae47aee2016-03-10 13:29:36 -0800226GrAuditTrail* SkDebugCanvas::getAuditTrail(SkCanvas* canvas) {
227 GrAuditTrail* at = nullptr;
joshualitte43f7e62016-03-04 10:45:05 -0800228#if SK_SUPPORT_GPU
robertphillips175dd9b2016-04-28 14:32:04 -0700229 GrContext* ctx = canvas->getGrContext();
230 if (ctx) {
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500231 at = ctx->contextPriv().getAuditTrail();
joshualitte43f7e62016-03-04 10:45:05 -0800232 }
233#endif
joshualittae47aee2016-03-10 13:29:36 -0800234 return at;
235}
236
Brian Salomon144a5c52016-12-20 16:48:59 -0500237void SkDebugCanvas::drawAndCollectOps(int n, SkCanvas* canvas) {
joshualitt40836102016-03-11 11:45:53 -0800238#if SK_SUPPORT_GPU
joshualittae47aee2016-03-10 13:29:36 -0800239 GrAuditTrail* at = this->getAuditTrail(canvas);
240 if (at) {
joshualittae47aee2016-03-10 13:29:36 -0800241 // loop over all of the commands and draw them, this is to collect reordering
242 // information
243 for (int i = 0; i < this->getSize() && i <= n; i++) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500244 GrAuditTrail::AutoCollectOps enable(at, i);
joshualittae47aee2016-03-10 13:29:36 -0800245 fCommandVector[i]->execute(canvas);
246 }
247
248 // in case there is some kind of global reordering
249 {
250 GrAuditTrail::AutoEnable ae(at);
251 canvas->flush();
252 }
joshualittae47aee2016-03-10 13:29:36 -0800253 }
joshualitt40836102016-03-11 11:45:53 -0800254#endif
joshualittae47aee2016-03-10 13:29:36 -0800255}
256
257void SkDebugCanvas::cleanupAuditTrail(SkCanvas* canvas) {
258 GrAuditTrail* at = this->getAuditTrail(canvas);
259 if (at) {
260#if SK_SUPPORT_GPU
261 GrAuditTrail::AutoEnable ae(at);
262 at->fullReset();
263#endif
264 }
265}
266
267Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500268 this->drawAndCollectOps(n, canvas);
halcanary9d524f22016-03-29 09:03:52 -0700269
joshualitte43f7e62016-03-04 10:45:05 -0800270 // now collect json
joshualitt40836102016-03-11 11:45:53 -0800271#if SK_SUPPORT_GPU
joshualittae47aee2016-03-10 13:29:36 -0800272 GrAuditTrail* at = this->getAuditTrail(canvas);
joshualitt40836102016-03-11 11:45:53 -0800273#endif
ethannicholas402cd912016-02-10 12:57:30 -0800274 Json::Value result = Json::Value(Json::objectValue);
275 result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION);
276 Json::Value commands = Json::Value(Json::arrayValue);
ethannicholas0a0520a2016-02-12 12:06:53 -0800277 for (int i = 0; i < this->getSize() && i <= n; i++) {
joshualitte43f7e62016-03-04 10:45:05 -0800278 commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager);
279#if SK_SUPPORT_GPU
280 if (at) {
281 // TODO if this is inefficient we could add a method to GrAuditTrail which takes
282 // a Json::Value and is only compiled in this file
283 Json::Value parsedFromString;
284 Json::Reader reader;
285 SkAssertResult(reader.parse(at->toJson(i).c_str(), parsedFromString));
286
287 commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString;
288 }
289#endif
ethannicholas402cd912016-02-10 12:57:30 -0800290 }
joshualittae47aee2016-03-10 13:29:36 -0800291 this->cleanupAuditTrail(canvas);
ethannicholas402cd912016-02-10 12:57:30 -0800292 result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands;
293 return result;
294}
295
Brian Salomon144a5c52016-12-20 16:48:59 -0500296Json::Value SkDebugCanvas::toJSONOpList(int n, SkCanvas* canvas) {
297 this->drawAndCollectOps(n, canvas);
joshualittae47aee2016-03-10 13:29:36 -0800298
299 Json::Value parsedFromString;
joshualittae47aee2016-03-10 13:29:36 -0800300#if SK_SUPPORT_GPU
joshualitt40836102016-03-11 11:45:53 -0800301 GrAuditTrail* at = this->getAuditTrail(canvas);
joshualittae47aee2016-03-10 13:29:36 -0800302 if (at) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500303 GrAuditTrail::AutoManageOpList enable(at);
joshualittae47aee2016-03-10 13:29:36 -0800304 Json::Reader reader;
305 SkAssertResult(reader.parse(at->toJson().c_str(), parsedFromString));
306 }
307#endif
308 this->cleanupAuditTrail(canvas);
309 return parsedFromString;
310}
311
fmalita65cdb572015-03-26 07:24:48 -0700312void SkDebugCanvas::setOverdrawViz(bool overdrawViz) {
fmalita65cdb572015-03-26 07:24:48 -0700313 fOverdrawViz = overdrawViz;
fmalita65cdb572015-03-26 07:24:48 -0700314}
315
Mike Reedc1f77742016-12-09 09:00:50 -0500316void SkDebugCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000317 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000318}
319
Mike Reedc1f77742016-12-09 09:00:50 -0500320void SkDebugCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000321 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000322}
323
Mike Reedc1f77742016-12-09 09:00:50 -0500324void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000325 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000326}
327
Mike Reedc1f77742016-12-09 09:00:50 -0500328void SkDebugCanvas::onClipRegion(const SkRegion& region, SkClipOp op) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000329 this->addDrawCommand(new SkClipRegionCommand(region, op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000330}
331
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000332void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
robertphillips9bafc302015-02-13 11:13:00 -0800333 this->addDrawCommand(new SkConcatCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000334 this->INHERITED::didConcat(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000335}
336
reed97660cc2016-06-28 18:54:19 -0700337void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
338 this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value)));
339}
340
reed41af9662015-01-05 07:49:08 -0800341void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left,
342 SkScalar top, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000343 this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000344}
345
Brian Osman78a76482018-05-18 16:59:13 -0400346void SkDebugCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
347 const SkRect& dst, const SkPaint* paint) {
348 this->addDrawCommand(new SkDrawBitmapLatticeCommand(bitmap, lattice, dst, paint));
349}
350
reed41af9662015-01-05 07:49:08 -0800351void SkDebugCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700352 const SkPaint* paint, SrcRectConstraint constraint) {
reeda5517e22015-07-14 10:54:12 -0700353 this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint,
354 (SrcRectConstraint)constraint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000355}
356
reed41af9662015-01-05 07:49:08 -0800357void SkDebugCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
358 const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000359 this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000360}
361
reed41af9662015-01-05 07:49:08 -0800362void SkDebugCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
363 const SkPaint* paint) {
fmalita651c9202015-07-22 10:23:01 -0700364 this->addDrawCommand(new SkDrawImageCommand(image, left, top, paint));
reed41af9662015-01-05 07:49:08 -0800365}
366
Stan Ilievac42aeb2017-01-12 16:20:50 -0500367void SkDebugCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
368 const SkRect& dst, const SkPaint* paint) {
369 this->addDrawCommand(new SkDrawImageLatticeCommand(image, lattice, dst, paint));
370}
371
reed41af9662015-01-05 07:49:08 -0800372void SkDebugCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700373 const SkPaint* paint, SrcRectConstraint constraint) {
fmalita651c9202015-07-22 10:23:01 -0700374 this->addDrawCommand(new SkDrawImageRectCommand(image, src, dst, paint, constraint));
reed41af9662015-01-05 07:49:08 -0800375}
376
Brian Osmanc25e2692018-03-12 10:57:28 -0400377void SkDebugCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center,
378 const SkRect& dst, const SkPaint* paint) {
379 this->addDrawCommand(new SkDrawImageNineCommand(image, center, dst, paint));
380}
381
reed41af9662015-01-05 07:49:08 -0800382void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000383 this->addDrawCommand(new SkDrawOvalCommand(oval, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000384}
385
bsalomonac3aa242016-08-19 11:25:19 -0700386void SkDebugCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
387 bool useCenter, const SkPaint& paint) {
388 this->addDrawCommand(new SkDrawArcCommand(oval, startAngle, sweepAngle, useCenter, paint));
389}
390
reed41af9662015-01-05 07:49:08 -0800391void SkDebugCanvas::onDrawPaint(const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000392 this->addDrawCommand(new SkDrawPaintCommand(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000393}
394
reed41af9662015-01-05 07:49:08 -0800395void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000396 this->addDrawCommand(new SkDrawPathCommand(path, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000397}
398
Brian Osmanc25e2692018-03-12 10:57:28 -0400399void SkDebugCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
400 this->addDrawCommand(new SkDrawRegionCommand(region, paint));
401}
402
mtkleinf0f14112014-12-12 08:46:25 -0800403void SkDebugCanvas::onDrawPicture(const SkPicture* picture,
404 const SkMatrix* matrix,
robertphillipsb3f319f2014-08-13 10:46:23 -0700405 const SkPaint* paint) {
fmalita160ebb22015-04-01 20:58:37 -0700406 this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint));
ethannicholas891ad662016-02-12 07:15:45 -0800407 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
408 picture->playback(this);
fmalita160ebb22015-04-01 20:58:37 -0700409 this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint)));
chudy@google.com902ebe52012-06-29 14:21:22 +0000410}
411
reed41af9662015-01-05 07:49:08 -0800412void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count,
413 const SkPoint pts[], const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000414 this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000415}
416
reed@google.come0d9ce82014-04-23 04:00:17 +0000417void SkDebugCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
418 const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000419 this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000420}
421
reed@google.come0d9ce82014-04-23 04:00:17 +0000422void SkDebugCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
423 SkScalar constY, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000424 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000425 new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000426}
427
reed41af9662015-01-05 07:49:08 -0800428void SkDebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000429 // NOTE(chudy): Messing up when renamed to DrawRect... Why?
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000430 addDrawCommand(new SkDrawRectCommand(rect, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000431}
432
reed41af9662015-01-05 07:49:08 -0800433void SkDebugCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000434 this->addDrawCommand(new SkDrawRRectCommand(rrect, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000435}
436
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000437void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
438 const SkPaint& paint) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000439 this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint));
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000440}
441
reed@google.come0d9ce82014-04-23 04:00:17 +0000442void SkDebugCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
443 const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000444 this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000445}
446
reed@google.come0d9ce82014-04-23 04:00:17 +0000447void SkDebugCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
448 const SkMatrix* matrix, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000449 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000450 new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000451}
452
reed45561a02016-07-07 12:47:17 -0700453void SkDebugCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
454 const SkRect* cull, const SkPaint& paint) {
455 this->addDrawCommand(new SkDrawTextRSXformCommand(text, byteLength, xform, cull, paint));
456}
457
fmalitab7425172014-08-26 07:56:44 -0700458void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
459 const SkPaint& paint) {
fmalita37283c22016-09-13 10:00:23 -0700460 this->addDrawCommand(new SkDrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)),
461 x, y, paint));
fmalitab7425172014-08-26 07:56:44 -0700462}
463
robertphillips9bafc302015-02-13 11:13:00 -0800464void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400465 const SkPoint texCoords[4], SkBlendMode bmode,
robertphillips9bafc302015-02-13 11:13:00 -0800466 const SkPaint& paint) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400467 this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, bmode, paint));
robertphillips9bafc302015-02-13 11:13:00 -0800468}
469
Mike Reedfed9cfd2017-03-17 12:09:04 -0400470void SkDebugCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode,
471 const SkPaint& paint) {
472 this->addDrawCommand(new SkDrawVerticesCommand(sk_ref_sp(const_cast<SkVertices*>(vertices)),
473 bmode, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000474}
475
Brian Osman616f1cb2018-05-29 11:23:35 -0400476void SkDebugCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[], const SkRect tex[],
477 const SkColor colors[], int count, SkBlendMode bmode,
478 const SkRect* cull, const SkPaint* paint) {
479 this->addDrawCommand(new SkDrawAtlasCommand(image, xform, tex, colors, count, bmode, cull,
480 paint));
481}
482
Derek Sollenberger6aab2ab2018-04-12 12:45:58 -0400483void SkDebugCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
484 this->addDrawCommand(new SkDrawShadowCommand(path, rec));
485}
486
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000487void SkDebugCanvas::willRestore() {
488 this->addDrawCommand(new SkRestoreCommand());
489 this->INHERITED::willRestore();
chudy@google.com902ebe52012-06-29 14:21:22 +0000490}
491
Florin Malita5f6102d2014-06-30 10:13:28 -0400492void SkDebugCanvas::willSave() {
493 this->addDrawCommand(new SkSaveCommand());
494 this->INHERITED::willSave();
chudy@google.com902ebe52012-06-29 14:21:22 +0000495}
496
reed4960eee2015-12-18 07:09:18 -0800497SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
498 this->addDrawCommand(new SkSaveLayerCommand(rec));
499 (void)this->INHERITED::getSaveLayerStrategy(rec);
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000500 // No need for a full layer.
501 return kNoLayer_SaveLayerStrategy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000502}
503
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000504void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000505 this->addDrawCommand(new SkSetMatrixCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000506 this->INHERITED::didSetMatrix(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000507}
508
chudy@google.com902ebe52012-06-29 14:21:22 +0000509void SkDebugCanvas::toggleCommand(int index, bool toggle) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000510 SkASSERT(index < fCommandVector.count());
511 fCommandVector[index]->setVisible(toggle);
chudy@google.com902ebe52012-06-29 14:21:22 +0000512}