blob: 96c0de2776f694227293c3a9cbd2c8d789d60eba [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"
Brian Osmand8a90f92019-01-28 13:41:19 -050011#include "SkJSONWriter.h"
fmalita37283c22016-09-13 10:00:23 -070012#include "SkPaintFilterCanvas.h"
Brian Osman255735e2018-04-06 14:51:42 -040013#include "SkPicture.h"
Mike Reed274218e2018-01-08 15:05:02 -050014#include "SkRectPriv.h"
fmalita37283c22016-09-13 10:00:23 -070015#include "SkTextBlob.h"
Mike Reedebfce6d2016-12-12 10:02:12 -050016#include "SkClipOpPriv.h"
fmalita65cdb572015-03-26 07:24:48 -070017
joshualitt10d8fc22016-02-29 11:15:06 -080018#include "GrAuditTrail.h"
19#include "GrContext.h"
Robert Phillipsbe9aff22019-02-15 11:33:22 -050020#include "GrContextPriv.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050021#include "GrRenderTargetContext.h"
joshualitt10d8fc22016-02-29 11:15:06 -080022
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) {
Mike Reed5edcd312018-08-08 11:23:41 -040089 fCommandVector.push_back(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
Brian Salomon144a5c52016-12-20 16:48:59 -0500115 // If we have a GPU backend we can also visualize the op information
joshualitt10d8fc22016-02-29 11:15:06 -0800116 GrAuditTrail* at = nullptr;
Brian Salomon144a5c52016-12-20 16:48:59 -0500117 if (fDrawGpuOpBounds || m != -1) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000118 // The audit trail must be obtained from the original canvas.
119 at = this->getAuditTrail(originalCanvas);
joshualitt10d8fc22016-02-29 11:15:06 -0800120 }
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000121
kkinnunen26a00de2015-01-13 23:09:19 -0800122 for (int i = 0; i <= index; i++) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500123 // We need to flush any pending operations, or they might combine with commands below.
brianosman1c9f9222016-04-15 11:00:51 -0700124 // Previous operations were not registered with the audit trail when they were
125 // created, so if we allow them to combine, the audit trail will fail to find them.
Ravi Mistry99c97962016-12-21 22:41:03 +0000126 filterCanvas.flush();
brianosman1c9f9222016-04-15 11:00:51 -0700127
Brian Salomon42ad83a2016-12-20 16:14:45 -0500128 GrAuditTrail::AutoCollectOps* acb = nullptr;
joshualitt10d8fc22016-02-29 11:15:06 -0800129 if (at) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500130 acb = new GrAuditTrail::AutoCollectOps(at, i);
joshualitt10d8fc22016-02-29 11:15:06 -0800131 }
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000132
robertphillips@google.com67baba42013-01-02 20:20:31 +0000133 if (fCommandVector[i]->isVisible()) {
Brian Osman255735e2018-04-06 14:51:42 -0400134 fCommandVector[i]->execute(&filterCanvas);
chudy@google.com902ebe52012-06-29 14:21:22 +0000135 }
joshualitt10d8fc22016-02-29 11:15:06 -0800136 if (at && acb) {
137 delete acb;
138 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000139 }
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000140
ethannicholas0a0520a2016-02-12 12:06:53 -0800141 if (SkColorGetA(fClipVizColor) != 0) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000142 filterCanvas.save();
ethannicholas0a0520a2016-02-12 12:06:53 -0800143 #define LARGE_COORD 1000000000
Ravi Mistry99c97962016-12-21 22:41:03 +0000144 filterCanvas.clipRect(
145 SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD),
146 kReverseDifference_SkClipOp);
ethannicholas0a0520a2016-02-12 12:06:53 -0800147 SkPaint clipPaint;
148 clipPaint.setColor(fClipVizColor);
Ravi Mistry99c97962016-12-21 22:41:03 +0000149 filterCanvas.drawPaint(clipPaint);
150 filterCanvas.restore();
ethannicholas0a0520a2016-02-12 12:06:53 -0800151 }
152
Ravi Mistry99c97962016-12-21 22:41:03 +0000153 fMatrix = filterCanvas.getTotalMatrix();
Mike Reed918e1442017-01-23 11:39:45 -0500154 fClip = filterCanvas.getDeviceClipBounds();
Ravi Mistry99c97962016-12-21 22:41:03 +0000155 filterCanvas.restoreToCount(saveCount);
fmalita65cdb572015-03-26 07:24:48 -0700156
Brian Salomon144a5c52016-12-20 16:48:59 -0500157 // draw any ops if required and issue a full reset onto GrAuditTrail
joshualitt10d8fc22016-02-29 11:15:06 -0800158 if (at) {
joshualitte43f7e62016-03-04 10:45:05 -0800159 // just in case there is global reordering, we flush the canvas before querying
160 // GrAuditTrail
joshualittb0666ad2016-03-08 10:43:41 -0800161 GrAuditTrail::AutoEnable ae(at);
Ravi Mistry99c97962016-12-21 22:41:03 +0000162 filterCanvas.flush();
joshualitte43f7e62016-03-04 10:45:05 -0800163
joshualittbdc6b2b2016-03-01 14:22:02 -0800164 // we pick three colorblind-safe colors, 75% alpha
165 static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A);
Brian Salomon144a5c52016-12-20 16:48:59 -0500166 static const SkColor kCommandOpBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C);
167 static const SkColor kOtherOpBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00);
joshualittbdc6b2b2016-03-01 14:22:02 -0800168
Ravi Mistry99c97962016-12-21 22:41:03 +0000169 // get the render target of the top device (from the original canvas) so we can ignore ops
170 // drawn offscreen
171 GrRenderTargetContext* rtc =
172 originalCanvas->internal_private_accessTopLayerRenderTargetContext();
Robert Phillips318c4192017-05-17 09:36:38 -0400173 GrSurfaceProxy::UniqueID proxyID = rtc->asSurfaceProxy()->uniqueID();
joshualitt1d7decf2016-03-01 07:15:52 -0800174
175 // get the bounding boxes to draw
Brian Salomon42ad83a2016-12-20 16:14:45 -0500176 SkTArray<GrAuditTrail::OpInfo> childrenBounds;
joshualitt46b301d2016-03-02 08:32:37 -0800177 if (m == -1) {
178 at->getBoundsByClientID(&childrenBounds, index);
179 } else {
Brian Salomon144a5c52016-12-20 16:48:59 -0500180 // the client wants us to draw the mth op
Brian Salomon42ad83a2016-12-20 16:14:45 -0500181 at->getBoundsByOpListID(&childrenBounds.push_back(), m);
joshualitt46b301d2016-03-02 08:32:37 -0800182 }
joshualitt10d8fc22016-02-29 11:15:06 -0800183 SkPaint paint;
184 paint.setStyle(SkPaint::kStroke_Style);
185 paint.setStrokeWidth(1);
186 for (int i = 0; i < childrenBounds.count(); i++) {
Robert Phillips318c4192017-05-17 09:36:38 -0400187 if (childrenBounds[i].fProxyUniqueID != proxyID) {
joshualitt1d7decf2016-03-01 07:15:52 -0800188 // offscreen draw, ignore for now
189 continue;
190 }
joshualittbdc6b2b2016-03-01 14:22:02 -0800191 paint.setColor(kTotalBounds);
Ravi Mistry99c97962016-12-21 22:41:03 +0000192 filterCanvas.drawRect(childrenBounds[i].fBounds, paint);
Brian Salomon42ad83a2016-12-20 16:14:45 -0500193 for (int j = 0; j < childrenBounds[i].fOps.count(); j++) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500194 const GrAuditTrail::OpInfo::Op& op = childrenBounds[i].fOps[j];
195 if (op.fClientID != index) {
196 paint.setColor(kOtherOpBounds);
joshualitt10d8fc22016-02-29 11:15:06 -0800197 } else {
Brian Salomon144a5c52016-12-20 16:48:59 -0500198 paint.setColor(kCommandOpBounds);
joshualitt10d8fc22016-02-29 11:15:06 -0800199 }
Ravi Mistry99c97962016-12-21 22:41:03 +0000200 filterCanvas.drawRect(op.fBounds, paint);
joshualitt10d8fc22016-02-29 11:15:06 -0800201 }
202 }
joshualitt10d8fc22016-02-29 11:15:06 -0800203 }
Ravi Mistry99c97962016-12-21 22:41:03 +0000204 this->cleanupAuditTrail(originalCanvas);
chudy@google.com902ebe52012-06-29 14:21:22 +0000205}
206
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000207void SkDebugCanvas::deleteDrawCommandAt(int index) {
208 SkASSERT(index < fCommandVector.count());
209 delete fCommandVector[index];
210 fCommandVector.remove(index);
211}
212
chudy@google.com902ebe52012-06-29 14:21:22 +0000213SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000214 SkASSERT(index < fCommandVector.count());
215 return fCommandVector[index];
chudy@google.com902ebe52012-06-29 14:21:22 +0000216}
217
joshualittae47aee2016-03-10 13:29:36 -0800218GrAuditTrail* SkDebugCanvas::getAuditTrail(SkCanvas* canvas) {
219 GrAuditTrail* at = nullptr;
robertphillips175dd9b2016-04-28 14:32:04 -0700220 GrContext* ctx = canvas->getGrContext();
221 if (ctx) {
Robert Phillipsd6841482019-02-08 10:29:20 -0500222 at = ctx->priv().auditTrail();
joshualitte43f7e62016-03-04 10:45:05 -0800223 }
joshualittae47aee2016-03-10 13:29:36 -0800224 return at;
225}
226
Brian Salomon144a5c52016-12-20 16:48:59 -0500227void SkDebugCanvas::drawAndCollectOps(int n, SkCanvas* canvas) {
joshualittae47aee2016-03-10 13:29:36 -0800228 GrAuditTrail* at = this->getAuditTrail(canvas);
229 if (at) {
joshualittae47aee2016-03-10 13:29:36 -0800230 // loop over all of the commands and draw them, this is to collect reordering
231 // information
232 for (int i = 0; i < this->getSize() && i <= n; i++) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500233 GrAuditTrail::AutoCollectOps enable(at, i);
joshualittae47aee2016-03-10 13:29:36 -0800234 fCommandVector[i]->execute(canvas);
235 }
236
237 // in case there is some kind of global reordering
238 {
239 GrAuditTrail::AutoEnable ae(at);
240 canvas->flush();
241 }
joshualittae47aee2016-03-10 13:29:36 -0800242 }
243}
244
245void SkDebugCanvas::cleanupAuditTrail(SkCanvas* canvas) {
246 GrAuditTrail* at = this->getAuditTrail(canvas);
247 if (at) {
joshualittae47aee2016-03-10 13:29:36 -0800248 GrAuditTrail::AutoEnable ae(at);
249 at->fullReset();
joshualittae47aee2016-03-10 13:29:36 -0800250 }
251}
252
Brian Osmand8a90f92019-01-28 13:41:19 -0500253void SkDebugCanvas::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManager, int n,
254 SkCanvas* canvas) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500255 this->drawAndCollectOps(n, canvas);
halcanary9d524f22016-03-29 09:03:52 -0700256
joshualitte43f7e62016-03-04 10:45:05 -0800257 // now collect json
joshualittae47aee2016-03-10 13:29:36 -0800258 GrAuditTrail* at = this->getAuditTrail(canvas);
Brian Osmand8a90f92019-01-28 13:41:19 -0500259 writer.appendS32(SKDEBUGCANVAS_ATTRIBUTE_VERSION, SKDEBUGCANVAS_VERSION);
260 writer.beginArray(SKDEBUGCANVAS_ATTRIBUTE_COMMANDS);
joshualitte43f7e62016-03-04 10:45:05 -0800261
Brian Osmand8a90f92019-01-28 13:41:19 -0500262 for (int i = 0; i < this->getSize() && i <= n; i++) {
263 writer.beginObject(); // command
264 this->getDrawCommandAt(i)->toJSON(writer, urlDataManager);
265
266 if (at) {
267 writer.appendName(SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL);
268 at->toJson(writer, i);
joshualitte43f7e62016-03-04 10:45:05 -0800269 }
Brian Osmand8a90f92019-01-28 13:41:19 -0500270 writer.endObject(); // command
ethannicholas402cd912016-02-10 12:57:30 -0800271 }
Brian Osmand8a90f92019-01-28 13:41:19 -0500272
273 writer.endArray(); // commands
joshualittae47aee2016-03-10 13:29:36 -0800274 this->cleanupAuditTrail(canvas);
ethannicholas402cd912016-02-10 12:57:30 -0800275}
276
Brian Osmand8a90f92019-01-28 13:41:19 -0500277void SkDebugCanvas::toJSONOpList(SkJSONWriter& writer, int n, SkCanvas* canvas) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500278 this->drawAndCollectOps(n, canvas);
joshualittae47aee2016-03-10 13:29:36 -0800279
joshualitt40836102016-03-11 11:45:53 -0800280 GrAuditTrail* at = this->getAuditTrail(canvas);
joshualittae47aee2016-03-10 13:29:36 -0800281 if (at) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500282 GrAuditTrail::AutoManageOpList enable(at);
Brian Osmand8a90f92019-01-28 13:41:19 -0500283 at->toJson(writer);
284 } else {
285 writer.beginObject();
286 writer.endObject();
joshualittae47aee2016-03-10 13:29:36 -0800287 }
joshualittae47aee2016-03-10 13:29:36 -0800288 this->cleanupAuditTrail(canvas);
joshualittae47aee2016-03-10 13:29:36 -0800289}
290
fmalita65cdb572015-03-26 07:24:48 -0700291void SkDebugCanvas::setOverdrawViz(bool overdrawViz) {
fmalita65cdb572015-03-26 07:24:48 -0700292 fOverdrawViz = overdrawViz;
fmalita65cdb572015-03-26 07:24:48 -0700293}
294
Mike Reedc1f77742016-12-09 09:00:50 -0500295void SkDebugCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000296 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000297}
298
Mike Reedc1f77742016-12-09 09:00:50 -0500299void SkDebugCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000300 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000301}
302
Mike Reedc1f77742016-12-09 09:00:50 -0500303void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000304 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000305}
306
Mike Reedc1f77742016-12-09 09:00:50 -0500307void SkDebugCanvas::onClipRegion(const SkRegion& region, SkClipOp op) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000308 this->addDrawCommand(new SkClipRegionCommand(region, op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000309}
310
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000311void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
robertphillips9bafc302015-02-13 11:13:00 -0800312 this->addDrawCommand(new SkConcatCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000313 this->INHERITED::didConcat(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000314}
315
reed97660cc2016-06-28 18:54:19 -0700316void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
317 this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value)));
318}
319
reed41af9662015-01-05 07:49:08 -0800320void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left,
321 SkScalar top, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000322 this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000323}
324
Brian Osman78a76482018-05-18 16:59:13 -0400325void SkDebugCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
326 const SkRect& dst, const SkPaint* paint) {
327 this->addDrawCommand(new SkDrawBitmapLatticeCommand(bitmap, lattice, dst, paint));
328}
329
reed41af9662015-01-05 07:49:08 -0800330void SkDebugCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700331 const SkPaint* paint, SrcRectConstraint constraint) {
reeda5517e22015-07-14 10:54:12 -0700332 this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint,
333 (SrcRectConstraint)constraint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000334}
335
reed41af9662015-01-05 07:49:08 -0800336void SkDebugCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
337 const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000338 this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000339}
340
reed41af9662015-01-05 07:49:08 -0800341void SkDebugCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
342 const SkPaint* paint) {
fmalita651c9202015-07-22 10:23:01 -0700343 this->addDrawCommand(new SkDrawImageCommand(image, left, top, paint));
reed41af9662015-01-05 07:49:08 -0800344}
345
Stan Ilievac42aeb2017-01-12 16:20:50 -0500346void SkDebugCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
347 const SkRect& dst, const SkPaint* paint) {
348 this->addDrawCommand(new SkDrawImageLatticeCommand(image, lattice, dst, paint));
349}
350
reed41af9662015-01-05 07:49:08 -0800351void SkDebugCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700352 const SkPaint* paint, SrcRectConstraint constraint) {
fmalita651c9202015-07-22 10:23:01 -0700353 this->addDrawCommand(new SkDrawImageRectCommand(image, src, dst, paint, constraint));
reed41af9662015-01-05 07:49:08 -0800354}
355
Brian Osmanc25e2692018-03-12 10:57:28 -0400356void SkDebugCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center,
357 const SkRect& dst, const SkPaint* paint) {
358 this->addDrawCommand(new SkDrawImageNineCommand(image, center, dst, paint));
359}
360
Brian Salomond003d222018-11-26 13:25:05 -0500361void SkDebugCanvas::onDrawImageSet(const SkCanvas::ImageSetEntry set[], int count,
Brian Salomond7065e72018-10-12 11:42:02 -0400362 SkFilterQuality filterQuality, SkBlendMode mode) {
Brian Salomond003d222018-11-26 13:25:05 -0500363 this->addDrawCommand(new SkDrawImageSetCommand(set, count, filterQuality, mode));
Brian Salomond7065e72018-10-12 11:42:02 -0400364}
365
reed41af9662015-01-05 07:49:08 -0800366void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000367 this->addDrawCommand(new SkDrawOvalCommand(oval, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000368}
369
bsalomonac3aa242016-08-19 11:25:19 -0700370void SkDebugCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
371 bool useCenter, const SkPaint& paint) {
372 this->addDrawCommand(new SkDrawArcCommand(oval, startAngle, sweepAngle, useCenter, paint));
373}
374
reed41af9662015-01-05 07:49:08 -0800375void SkDebugCanvas::onDrawPaint(const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000376 this->addDrawCommand(new SkDrawPaintCommand(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000377}
378
reed41af9662015-01-05 07:49:08 -0800379void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000380 this->addDrawCommand(new SkDrawPathCommand(path, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000381}
382
Brian Osmanc25e2692018-03-12 10:57:28 -0400383void SkDebugCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
384 this->addDrawCommand(new SkDrawRegionCommand(region, paint));
385}
386
mtkleinf0f14112014-12-12 08:46:25 -0800387void SkDebugCanvas::onDrawPicture(const SkPicture* picture,
388 const SkMatrix* matrix,
robertphillipsb3f319f2014-08-13 10:46:23 -0700389 const SkPaint* paint) {
fmalita160ebb22015-04-01 20:58:37 -0700390 this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint));
ethannicholas891ad662016-02-12 07:15:45 -0800391 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
392 picture->playback(this);
fmalita160ebb22015-04-01 20:58:37 -0700393 this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint)));
chudy@google.com902ebe52012-06-29 14:21:22 +0000394}
395
reed41af9662015-01-05 07:49:08 -0800396void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count,
397 const SkPoint pts[], const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000398 this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000399}
400
reed41af9662015-01-05 07:49:08 -0800401void SkDebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000402 // NOTE(chudy): Messing up when renamed to DrawRect... Why?
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000403 addDrawCommand(new SkDrawRectCommand(rect, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000404}
405
Michael Ludwig75451902019-01-23 11:14:29 -0500406void SkDebugCanvas::onDrawEdgeAARect(const SkRect& rect, SkCanvas::QuadAAFlags aa, SkColor color,
407 SkBlendMode mode) {
408 this->addDrawCommand(new SkDrawEdgeAARectCommand(rect, aa, color, mode));
409}
410
reed41af9662015-01-05 07:49:08 -0800411void SkDebugCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000412 this->addDrawCommand(new SkDrawRRectCommand(rrect, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000413}
414
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000415void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
416 const SkPaint& paint) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000417 this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint));
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000418}
419
fmalitab7425172014-08-26 07:56:44 -0700420void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
421 const SkPaint& paint) {
fmalita37283c22016-09-13 10:00:23 -0700422 this->addDrawCommand(new SkDrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)),
423 x, y, paint));
fmalitab7425172014-08-26 07:56:44 -0700424}
425
robertphillips9bafc302015-02-13 11:13:00 -0800426void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400427 const SkPoint texCoords[4], SkBlendMode bmode,
robertphillips9bafc302015-02-13 11:13:00 -0800428 const SkPaint& paint) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400429 this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, bmode, paint));
robertphillips9bafc302015-02-13 11:13:00 -0800430}
431
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400432void SkDebugCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkVertices::Bone bones[],
Ruiqi Maof5101492018-06-29 14:32:21 -0400433 int boneCount, SkBlendMode bmode, const SkPaint& paint) {
434 // TODO: ANIMATION NOT LOGGED
Mike Reedfed9cfd2017-03-17 12:09:04 -0400435 this->addDrawCommand(new SkDrawVerticesCommand(sk_ref_sp(const_cast<SkVertices*>(vertices)),
436 bmode, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000437}
438
Brian Osman616f1cb2018-05-29 11:23:35 -0400439void SkDebugCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[], const SkRect tex[],
440 const SkColor colors[], int count, SkBlendMode bmode,
441 const SkRect* cull, const SkPaint* paint) {
442 this->addDrawCommand(new SkDrawAtlasCommand(image, xform, tex, colors, count, bmode, cull,
443 paint));
444}
445
Derek Sollenberger6aab2ab2018-04-12 12:45:58 -0400446void SkDebugCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
447 this->addDrawCommand(new SkDrawShadowCommand(path, rec));
448}
449
Brian Osmanc7611082018-05-29 14:55:50 -0400450void SkDebugCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
451 this->addDrawCommand(new SkDrawDrawableCommand(drawable, matrix));
452}
453
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000454void SkDebugCanvas::willRestore() {
455 this->addDrawCommand(new SkRestoreCommand());
456 this->INHERITED::willRestore();
chudy@google.com902ebe52012-06-29 14:21:22 +0000457}
458
Florin Malita5f6102d2014-06-30 10:13:28 -0400459void SkDebugCanvas::willSave() {
460 this->addDrawCommand(new SkSaveCommand());
461 this->INHERITED::willSave();
chudy@google.com902ebe52012-06-29 14:21:22 +0000462}
463
reed4960eee2015-12-18 07:09:18 -0800464SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
465 this->addDrawCommand(new SkSaveLayerCommand(rec));
466 (void)this->INHERITED::getSaveLayerStrategy(rec);
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000467 // No need for a full layer.
468 return kNoLayer_SaveLayerStrategy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000469}
470
Mike Reed148b7fd2018-12-18 17:38:18 -0500471bool SkDebugCanvas::onDoSaveBehind(const SkRect* subset) {
472 // TODO
473 return false;
474}
475
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000476void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000477 this->addDrawCommand(new SkSetMatrixCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000478 this->INHERITED::didSetMatrix(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000479}
480
chudy@google.com902ebe52012-06-29 14:21:22 +0000481void SkDebugCanvas::toggleCommand(int index, bool toggle) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000482 SkASSERT(index < fCommandVector.count());
483 fCommandVector[index]->setVisible(toggle);
chudy@google.com902ebe52012-06-29 14:21:22 +0000484}