blob: 94b6ea96dd2b9845ce91279c313c57664302aa3c [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#include "GrAuditTrail.h"
18#include "GrContext.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050019#include "GrRenderTargetContext.h"
joshualitt10d8fc22016-02-29 11:15:06 -080020
joshualitte43f7e62016-03-04 10:45:05 -080021#define SKDEBUGCANVAS_VERSION 1
22#define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version"
23#define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands"
24#define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail"
ethannicholas402cd912016-02-10 12:57:30 -080025
fmalita65cdb572015-03-26 07:24:48 -070026class DebugPaintFilterCanvas : public SkPaintFilterCanvas {
27public:
Ben Wagnerc03e1c52016-10-17 15:20:02 -040028 DebugPaintFilterCanvas(SkCanvas* canvas,
Brian Osman255735e2018-04-06 14:51:42 -040029 bool overdrawViz)
Ben Wagnerc03e1c52016-10-17 15:20:02 -040030 : INHERITED(canvas)
Brian Osman255735e2018-04-06 14:51:42 -040031 , fOverdrawViz(overdrawViz) {}
fmalita65cdb572015-03-26 07:24:48 -070032
33protected:
fmalita32cdc322016-01-12 07:21:11 -080034 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override {
35 if (*paint) {
Ben Wagnerc03e1c52016-10-17 15:20:02 -040036 if (fOverdrawViz) {
37 paint->writable()->setColor(SK_ColorRED);
38 paint->writable()->setAlpha(0x08);
39 paint->writable()->setBlendMode(SkBlendMode::kSrcOver);
fmalitabad23dc2016-01-11 13:58:29 -080040 }
fmalita65cdb572015-03-26 07:24:48 -070041 }
fmalitabad23dc2016-01-11 13:58:29 -080042 return true;
fmalita65cdb572015-03-26 07:24:48 -070043 }
44
mtkleinf0599002015-07-13 06:18:39 -070045 void onDrawPicture(const SkPicture* picture,
46 const SkMatrix* matrix,
47 const SkPaint* paint) override {
fmalita65cdb572015-03-26 07:24:48 -070048 // We need to replay the picture onto this canvas in order to filter its internal paints.
49 this->SkCanvas::onDrawPicture(picture, matrix, paint);
50 }
51
52private:
Ben Wagnerc03e1c52016-10-17 15:20:02 -040053 bool fOverdrawViz;
fmalita65cdb572015-03-26 07:24:48 -070054
55 typedef SkPaintFilterCanvas INHERITED;
56};
57
kkinnunen26e54002015-01-05 12:58:56 -080058SkDebugCanvas::SkDebugCanvas(int width, int height)
59 : INHERITED(width, height)
robertphillips@google.comf4741c12013-02-06 20:13:54 +000060 , fOverdrawViz(false)
joshualitt10d8fc22016-02-29 11:15:06 -080061 , fClipVizColor(SK_ColorTRANSPARENT)
Brian Salomon144a5c52016-12-20 16:48:59 -050062 , fDrawGpuOpBounds(false) {
robertphillips@google.com8b157172013-11-07 22:20:31 +000063 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped
64 // operations. This can lead to problems in the debugger which expects all
65 // the operations in the captured skp to appear in the debug canvas. To
66 // circumvent this we create a wide open clip here (an empty clip rect
67 // is not sufficient).
68 // Internally, the SkRect passed to clipRect is converted to an SkIRect and
69 // rounded out. The following code creates a nearly maximal rect that will
70 // not get collapsed by the coming conversions (Due to precision loss the
71 // inset has to be surprisingly large).
Mike Reed8008df12018-01-17 12:20:04 -050072 SkIRect largeIRect = SkRectPriv::MakeILarge();
robertphillips@google.com8b157172013-11-07 22:20:31 +000073 largeIRect.inset(1024, 1024);
robertphillips@google.com6c1e49a2013-11-10 15:08:45 +000074 SkRect large = SkRect::Make(largeIRect);
robertphillips@google.com8b157172013-11-07 22:20:31 +000075#ifdef SK_DEBUG
reedb07a94f2014-11-19 05:03:18 -080076 SkASSERT(!large.roundOut().isEmpty());
robertphillips@google.com8b157172013-11-07 22:20:31 +000077#endif
robertphillips@google.com8f90a892014-02-28 18:19:39 +000078 // call the base class' version to avoid adding a draw command
Mike Reedc1f77742016-12-09 09:00:50 -050079 this->INHERITED::onClipRect(large, kReplace_SkClipOp, kHard_ClipEdgeStyle);
chudy@google.com902ebe52012-06-29 14:21:22 +000080}
81
chudy@google.com9cda6f72012-08-07 15:08:33 +000082SkDebugCanvas::~SkDebugCanvas() {
robertphillips@google.com67baba42013-01-02 20:20:31 +000083 fCommandVector.deleteAll();
chudy@google.com9cda6f72012-08-07 15:08:33 +000084}
chudy@google.com902ebe52012-06-29 14:21:22 +000085
86void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
Mike Reed5edcd312018-08-08 11:23:41 -040087 fCommandVector.push_back(command);
chudy@google.com902ebe52012-06-29 14:21:22 +000088}
89
90void SkDebugCanvas::draw(SkCanvas* canvas) {
commit-bot@chromium.org1735d662013-12-04 13:42:46 +000091 if (!fCommandVector.isEmpty()) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000092 this->drawTo(canvas, fCommandVector.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +000093 }
94}
95
Ravi Mistry99c97962016-12-21 22:41:03 +000096void SkDebugCanvas::drawTo(SkCanvas* originalCanvas, int index, int m) {
robertphillips@google.com67baba42013-01-02 20:20:31 +000097 SkASSERT(!fCommandVector.isEmpty());
98 SkASSERT(index < fCommandVector.count());
kkinnunen26a00de2015-01-13 23:09:19 -080099
Ravi Mistry99c97962016-12-21 22:41:03 +0000100 int saveCount = originalCanvas->save();
kkinnunen26a00de2015-01-13 23:09:19 -0800101
Ravi Mistry99c97962016-12-21 22:41:03 +0000102 SkRect windowRect = SkRect::MakeWH(SkIntToScalar(originalCanvas->getBaseLayerSize().width()),
103 SkIntToScalar(originalCanvas->getBaseLayerSize().height()));
chudy@google.com830b8792012-08-01 15:57:52 +0000104
Ravi Mistry99c97962016-12-21 22:41:03 +0000105 originalCanvas->clear(SK_ColorWHITE);
106 originalCanvas->resetMatrix();
kkinnunen26a00de2015-01-13 23:09:19 -0800107 if (!windowRect.isEmpty()) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000108 originalCanvas->clipRect(windowRect, kReplace_SkClipOp);
commit-bot@chromium.orga27622c2013-08-05 16:31:27 +0000109 }
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000110
Brian Osman255735e2018-04-06 14:51:42 -0400111 DebugPaintFilterCanvas filterCanvas(originalCanvas, fOverdrawViz);
halcanary9d524f22016-03-29 09:03:52 -0700112
Brian Salomon144a5c52016-12-20 16:48:59 -0500113 // If we have a GPU backend we can also visualize the op information
joshualitt10d8fc22016-02-29 11:15:06 -0800114 GrAuditTrail* at = nullptr;
Brian Salomon144a5c52016-12-20 16:48:59 -0500115 if (fDrawGpuOpBounds || m != -1) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000116 // The audit trail must be obtained from the original canvas.
117 at = this->getAuditTrail(originalCanvas);
joshualitt10d8fc22016-02-29 11:15:06 -0800118 }
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000119
kkinnunen26a00de2015-01-13 23:09:19 -0800120 for (int i = 0; i <= index; i++) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500121 // We need to flush any pending operations, or they might combine with commands below.
brianosman1c9f9222016-04-15 11:00:51 -0700122 // Previous operations were not registered with the audit trail when they were
123 // created, so if we allow them to combine, the audit trail will fail to find them.
Ravi Mistry99c97962016-12-21 22:41:03 +0000124 filterCanvas.flush();
brianosman1c9f9222016-04-15 11:00:51 -0700125
Brian Salomon42ad83a2016-12-20 16:14:45 -0500126 GrAuditTrail::AutoCollectOps* acb = nullptr;
joshualitt10d8fc22016-02-29 11:15:06 -0800127 if (at) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500128 acb = new GrAuditTrail::AutoCollectOps(at, i);
joshualitt10d8fc22016-02-29 11:15:06 -0800129 }
chudy@google.com0b5bbb02012-07-31 19:55:32 +0000130
robertphillips@google.com67baba42013-01-02 20:20:31 +0000131 if (fCommandVector[i]->isVisible()) {
Brian Osman255735e2018-04-06 14:51:42 -0400132 fCommandVector[i]->execute(&filterCanvas);
chudy@google.com902ebe52012-06-29 14:21:22 +0000133 }
joshualitt10d8fc22016-02-29 11:15:06 -0800134 if (at && acb) {
135 delete acb;
136 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000137 }
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000138
ethannicholas0a0520a2016-02-12 12:06:53 -0800139 if (SkColorGetA(fClipVizColor) != 0) {
Ravi Mistry99c97962016-12-21 22:41:03 +0000140 filterCanvas.save();
ethannicholas0a0520a2016-02-12 12:06:53 -0800141 #define LARGE_COORD 1000000000
Ravi Mistry99c97962016-12-21 22:41:03 +0000142 filterCanvas.clipRect(
143 SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD),
144 kReverseDifference_SkClipOp);
ethannicholas0a0520a2016-02-12 12:06:53 -0800145 SkPaint clipPaint;
146 clipPaint.setColor(fClipVizColor);
Ravi Mistry99c97962016-12-21 22:41:03 +0000147 filterCanvas.drawPaint(clipPaint);
148 filterCanvas.restore();
ethannicholas0a0520a2016-02-12 12:06:53 -0800149 }
150
Ravi Mistry99c97962016-12-21 22:41:03 +0000151 fMatrix = filterCanvas.getTotalMatrix();
Mike Reed918e1442017-01-23 11:39:45 -0500152 fClip = filterCanvas.getDeviceClipBounds();
Ravi Mistry99c97962016-12-21 22:41:03 +0000153 filterCanvas.restoreToCount(saveCount);
fmalita65cdb572015-03-26 07:24:48 -0700154
Brian Salomon144a5c52016-12-20 16:48:59 -0500155 // draw any ops if required and issue a full reset onto GrAuditTrail
joshualitt10d8fc22016-02-29 11:15:06 -0800156 if (at) {
joshualitte43f7e62016-03-04 10:45:05 -0800157 // just in case there is global reordering, we flush the canvas before querying
158 // GrAuditTrail
joshualittb0666ad2016-03-08 10:43:41 -0800159 GrAuditTrail::AutoEnable ae(at);
Ravi Mistry99c97962016-12-21 22:41:03 +0000160 filterCanvas.flush();
joshualitte43f7e62016-03-04 10:45:05 -0800161
joshualittbdc6b2b2016-03-01 14:22:02 -0800162 // we pick three colorblind-safe colors, 75% alpha
163 static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A);
Brian Salomon144a5c52016-12-20 16:48:59 -0500164 static const SkColor kCommandOpBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C);
165 static const SkColor kOtherOpBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00);
joshualittbdc6b2b2016-03-01 14:22:02 -0800166
Ravi Mistry99c97962016-12-21 22:41:03 +0000167 // get the render target of the top device (from the original canvas) so we can ignore ops
168 // drawn offscreen
169 GrRenderTargetContext* rtc =
170 originalCanvas->internal_private_accessTopLayerRenderTargetContext();
Robert Phillips318c4192017-05-17 09:36:38 -0400171 GrSurfaceProxy::UniqueID proxyID = rtc->asSurfaceProxy()->uniqueID();
joshualitt1d7decf2016-03-01 07:15:52 -0800172
173 // get the bounding boxes to draw
Brian Salomon42ad83a2016-12-20 16:14:45 -0500174 SkTArray<GrAuditTrail::OpInfo> childrenBounds;
joshualitt46b301d2016-03-02 08:32:37 -0800175 if (m == -1) {
176 at->getBoundsByClientID(&childrenBounds, index);
177 } else {
Brian Salomon144a5c52016-12-20 16:48:59 -0500178 // the client wants us to draw the mth op
Brian Salomon42ad83a2016-12-20 16:14:45 -0500179 at->getBoundsByOpListID(&childrenBounds.push_back(), m);
joshualitt46b301d2016-03-02 08:32:37 -0800180 }
joshualitt10d8fc22016-02-29 11:15:06 -0800181 SkPaint paint;
182 paint.setStyle(SkPaint::kStroke_Style);
183 paint.setStrokeWidth(1);
184 for (int i = 0; i < childrenBounds.count(); i++) {
Robert Phillips318c4192017-05-17 09:36:38 -0400185 if (childrenBounds[i].fProxyUniqueID != proxyID) {
joshualitt1d7decf2016-03-01 07:15:52 -0800186 // offscreen draw, ignore for now
187 continue;
188 }
joshualittbdc6b2b2016-03-01 14:22:02 -0800189 paint.setColor(kTotalBounds);
Ravi Mistry99c97962016-12-21 22:41:03 +0000190 filterCanvas.drawRect(childrenBounds[i].fBounds, paint);
Brian Salomon42ad83a2016-12-20 16:14:45 -0500191 for (int j = 0; j < childrenBounds[i].fOps.count(); j++) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500192 const GrAuditTrail::OpInfo::Op& op = childrenBounds[i].fOps[j];
193 if (op.fClientID != index) {
194 paint.setColor(kOtherOpBounds);
joshualitt10d8fc22016-02-29 11:15:06 -0800195 } else {
Brian Salomon144a5c52016-12-20 16:48:59 -0500196 paint.setColor(kCommandOpBounds);
joshualitt10d8fc22016-02-29 11:15:06 -0800197 }
Ravi Mistry99c97962016-12-21 22:41:03 +0000198 filterCanvas.drawRect(op.fBounds, paint);
joshualitt10d8fc22016-02-29 11:15:06 -0800199 }
200 }
joshualitt10d8fc22016-02-29 11:15:06 -0800201 }
Ravi Mistry99c97962016-12-21 22:41:03 +0000202 this->cleanupAuditTrail(originalCanvas);
chudy@google.com902ebe52012-06-29 14:21:22 +0000203}
204
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000205void SkDebugCanvas::deleteDrawCommandAt(int index) {
206 SkASSERT(index < fCommandVector.count());
207 delete fCommandVector[index];
208 fCommandVector.remove(index);
209}
210
chudy@google.com902ebe52012-06-29 14:21:22 +0000211SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000212 SkASSERT(index < fCommandVector.count());
213 return fCommandVector[index];
chudy@google.com902ebe52012-06-29 14:21:22 +0000214}
215
joshualittae47aee2016-03-10 13:29:36 -0800216GrAuditTrail* SkDebugCanvas::getAuditTrail(SkCanvas* canvas) {
217 GrAuditTrail* at = nullptr;
robertphillips175dd9b2016-04-28 14:32:04 -0700218 GrContext* ctx = canvas->getGrContext();
219 if (ctx) {
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500220 at = ctx->contextPriv().getAuditTrail();
joshualitte43f7e62016-03-04 10:45:05 -0800221 }
joshualittae47aee2016-03-10 13:29:36 -0800222 return at;
223}
224
Brian Salomon144a5c52016-12-20 16:48:59 -0500225void SkDebugCanvas::drawAndCollectOps(int n, SkCanvas* canvas) {
joshualittae47aee2016-03-10 13:29:36 -0800226 GrAuditTrail* at = this->getAuditTrail(canvas);
227 if (at) {
joshualittae47aee2016-03-10 13:29:36 -0800228 // loop over all of the commands and draw them, this is to collect reordering
229 // information
230 for (int i = 0; i < this->getSize() && i <= n; i++) {
Brian Salomon42ad83a2016-12-20 16:14:45 -0500231 GrAuditTrail::AutoCollectOps enable(at, i);
joshualittae47aee2016-03-10 13:29:36 -0800232 fCommandVector[i]->execute(canvas);
233 }
234
235 // in case there is some kind of global reordering
236 {
237 GrAuditTrail::AutoEnable ae(at);
238 canvas->flush();
239 }
joshualittae47aee2016-03-10 13:29:36 -0800240 }
241}
242
243void SkDebugCanvas::cleanupAuditTrail(SkCanvas* canvas) {
244 GrAuditTrail* at = this->getAuditTrail(canvas);
245 if (at) {
joshualittae47aee2016-03-10 13:29:36 -0800246 GrAuditTrail::AutoEnable ae(at);
247 at->fullReset();
joshualittae47aee2016-03-10 13:29:36 -0800248 }
249}
250
251Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) {
Brian Salomon144a5c52016-12-20 16:48:59 -0500252 this->drawAndCollectOps(n, canvas);
halcanary9d524f22016-03-29 09:03:52 -0700253
joshualitte43f7e62016-03-04 10:45:05 -0800254 // now collect json
joshualittae47aee2016-03-10 13:29:36 -0800255 GrAuditTrail* at = this->getAuditTrail(canvas);
ethannicholas402cd912016-02-10 12:57:30 -0800256 Json::Value result = Json::Value(Json::objectValue);
257 result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION);
258 Json::Value commands = Json::Value(Json::arrayValue);
ethannicholas0a0520a2016-02-12 12:06:53 -0800259 for (int i = 0; i < this->getSize() && i <= n; i++) {
joshualitte43f7e62016-03-04 10:45:05 -0800260 commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager);
joshualitte43f7e62016-03-04 10:45:05 -0800261 if (at) {
262 // TODO if this is inefficient we could add a method to GrAuditTrail which takes
263 // a Json::Value and is only compiled in this file
264 Json::Value parsedFromString;
265 Json::Reader reader;
266 SkAssertResult(reader.parse(at->toJson(i).c_str(), parsedFromString));
267
268 commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString;
269 }
ethannicholas402cd912016-02-10 12:57:30 -0800270 }
joshualittae47aee2016-03-10 13:29:36 -0800271 this->cleanupAuditTrail(canvas);
ethannicholas402cd912016-02-10 12:57:30 -0800272 result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands;
273 return result;
274}
275
Brian Salomon144a5c52016-12-20 16:48:59 -0500276Json::Value SkDebugCanvas::toJSONOpList(int n, SkCanvas* canvas) {
277 this->drawAndCollectOps(n, canvas);
joshualittae47aee2016-03-10 13:29:36 -0800278
279 Json::Value parsedFromString;
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);
joshualittae47aee2016-03-10 13:29:36 -0800283 Json::Reader reader;
284 SkAssertResult(reader.parse(at->toJson().c_str(), parsedFromString));
285 }
joshualittae47aee2016-03-10 13:29:36 -0800286 this->cleanupAuditTrail(canvas);
287 return parsedFromString;
288}
289
fmalita65cdb572015-03-26 07:24:48 -0700290void SkDebugCanvas::setOverdrawViz(bool overdrawViz) {
fmalita65cdb572015-03-26 07:24:48 -0700291 fOverdrawViz = overdrawViz;
fmalita65cdb572015-03-26 07:24:48 -0700292}
293
Mike Reedc1f77742016-12-09 09:00:50 -0500294void SkDebugCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000295 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000296}
297
Mike Reedc1f77742016-12-09 09:00:50 -0500298void SkDebugCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000299 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
chudy@google.com902ebe52012-06-29 14:21:22 +0000300}
301
Mike Reedc1f77742016-12-09 09:00:50 -0500302void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000303 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000304}
305
Mike Reedc1f77742016-12-09 09:00:50 -0500306void SkDebugCanvas::onClipRegion(const SkRegion& region, SkClipOp op) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000307 this->addDrawCommand(new SkClipRegionCommand(region, op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000308}
309
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000310void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
robertphillips9bafc302015-02-13 11:13:00 -0800311 this->addDrawCommand(new SkConcatCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000312 this->INHERITED::didConcat(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000313}
314
reed97660cc2016-06-28 18:54:19 -0700315void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
316 this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value)));
317}
318
reed41af9662015-01-05 07:49:08 -0800319void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left,
320 SkScalar top, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000321 this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000322}
323
Brian Osman78a76482018-05-18 16:59:13 -0400324void SkDebugCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
325 const SkRect& dst, const SkPaint* paint) {
326 this->addDrawCommand(new SkDrawBitmapLatticeCommand(bitmap, lattice, dst, paint));
327}
328
reed41af9662015-01-05 07:49:08 -0800329void SkDebugCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700330 const SkPaint* paint, SrcRectConstraint constraint) {
reeda5517e22015-07-14 10:54:12 -0700331 this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint,
332 (SrcRectConstraint)constraint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000333}
334
reed41af9662015-01-05 07:49:08 -0800335void SkDebugCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
336 const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000337 this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000338}
339
reed41af9662015-01-05 07:49:08 -0800340void SkDebugCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
341 const SkPaint* paint) {
fmalita651c9202015-07-22 10:23:01 -0700342 this->addDrawCommand(new SkDrawImageCommand(image, left, top, paint));
reed41af9662015-01-05 07:49:08 -0800343}
344
Stan Ilievac42aeb2017-01-12 16:20:50 -0500345void SkDebugCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
346 const SkRect& dst, const SkPaint* paint) {
347 this->addDrawCommand(new SkDrawImageLatticeCommand(image, lattice, dst, paint));
348}
349
reed41af9662015-01-05 07:49:08 -0800350void SkDebugCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700351 const SkPaint* paint, SrcRectConstraint constraint) {
fmalita651c9202015-07-22 10:23:01 -0700352 this->addDrawCommand(new SkDrawImageRectCommand(image, src, dst, paint, constraint));
reed41af9662015-01-05 07:49:08 -0800353}
354
Brian Osmanc25e2692018-03-12 10:57:28 -0400355void SkDebugCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center,
356 const SkRect& dst, const SkPaint* paint) {
357 this->addDrawCommand(new SkDrawImageNineCommand(image, center, dst, paint));
358}
359
reed41af9662015-01-05 07:49:08 -0800360void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000361 this->addDrawCommand(new SkDrawOvalCommand(oval, paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000362}
363
bsalomonac3aa242016-08-19 11:25:19 -0700364void SkDebugCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
365 bool useCenter, const SkPaint& paint) {
366 this->addDrawCommand(new SkDrawArcCommand(oval, startAngle, sweepAngle, useCenter, paint));
367}
368
reed41af9662015-01-05 07:49:08 -0800369void SkDebugCanvas::onDrawPaint(const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000370 this->addDrawCommand(new SkDrawPaintCommand(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000371}
372
reed41af9662015-01-05 07:49:08 -0800373void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000374 this->addDrawCommand(new SkDrawPathCommand(path, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000375}
376
Brian Osmanc25e2692018-03-12 10:57:28 -0400377void SkDebugCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
378 this->addDrawCommand(new SkDrawRegionCommand(region, paint));
379}
380
mtkleinf0f14112014-12-12 08:46:25 -0800381void SkDebugCanvas::onDrawPicture(const SkPicture* picture,
382 const SkMatrix* matrix,
robertphillipsb3f319f2014-08-13 10:46:23 -0700383 const SkPaint* paint) {
fmalita160ebb22015-04-01 20:58:37 -0700384 this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint));
ethannicholas891ad662016-02-12 07:15:45 -0800385 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
386 picture->playback(this);
fmalita160ebb22015-04-01 20:58:37 -0700387 this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint)));
chudy@google.com902ebe52012-06-29 14:21:22 +0000388}
389
reed41af9662015-01-05 07:49:08 -0800390void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count,
391 const SkPoint pts[], const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000392 this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000393}
394
reed@google.come0d9ce82014-04-23 04:00:17 +0000395void SkDebugCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
396 const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000397 this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000398}
399
reed@google.come0d9ce82014-04-23 04:00:17 +0000400void SkDebugCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
401 SkScalar constY, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000402 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000403 new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000404}
405
reed41af9662015-01-05 07:49:08 -0800406void SkDebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000407 // NOTE(chudy): Messing up when renamed to DrawRect... Why?
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000408 addDrawCommand(new SkDrawRectCommand(rect, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000409}
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
reed@google.come0d9ce82014-04-23 04:00:17 +0000420void SkDebugCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
421 const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000422 this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000423}
424
reed@google.come0d9ce82014-04-23 04:00:17 +0000425void SkDebugCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
426 const SkMatrix* matrix, const SkPaint& paint) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000427 this->addDrawCommand(
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000428 new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000429}
430
reed45561a02016-07-07 12:47:17 -0700431void SkDebugCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
432 const SkRect* cull, const SkPaint& paint) {
433 this->addDrawCommand(new SkDrawTextRSXformCommand(text, byteLength, xform, cull, paint));
434}
435
fmalitab7425172014-08-26 07:56:44 -0700436void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
437 const SkPaint& paint) {
fmalita37283c22016-09-13 10:00:23 -0700438 this->addDrawCommand(new SkDrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)),
439 x, y, paint));
fmalitab7425172014-08-26 07:56:44 -0700440}
441
robertphillips9bafc302015-02-13 11:13:00 -0800442void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400443 const SkPoint texCoords[4], SkBlendMode bmode,
robertphillips9bafc302015-02-13 11:13:00 -0800444 const SkPaint& paint) {
Mike Reed7d954ad2016-10-28 15:42:34 -0400445 this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, bmode, paint));
robertphillips9bafc302015-02-13 11:13:00 -0800446}
447
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400448void SkDebugCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkVertices::Bone bones[],
Ruiqi Maof5101492018-06-29 14:32:21 -0400449 int boneCount, SkBlendMode bmode, const SkPaint& paint) {
450 // TODO: ANIMATION NOT LOGGED
Mike Reedfed9cfd2017-03-17 12:09:04 -0400451 this->addDrawCommand(new SkDrawVerticesCommand(sk_ref_sp(const_cast<SkVertices*>(vertices)),
452 bmode, paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000453}
454
Brian Osman616f1cb2018-05-29 11:23:35 -0400455void SkDebugCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[], const SkRect tex[],
456 const SkColor colors[], int count, SkBlendMode bmode,
457 const SkRect* cull, const SkPaint* paint) {
458 this->addDrawCommand(new SkDrawAtlasCommand(image, xform, tex, colors, count, bmode, cull,
459 paint));
460}
461
Derek Sollenberger6aab2ab2018-04-12 12:45:58 -0400462void SkDebugCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
463 this->addDrawCommand(new SkDrawShadowCommand(path, rec));
464}
465
Brian Osmanc7611082018-05-29 14:55:50 -0400466void SkDebugCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
467 this->addDrawCommand(new SkDrawDrawableCommand(drawable, matrix));
468}
469
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000470void SkDebugCanvas::willRestore() {
471 this->addDrawCommand(new SkRestoreCommand());
472 this->INHERITED::willRestore();
chudy@google.com902ebe52012-06-29 14:21:22 +0000473}
474
Florin Malita5f6102d2014-06-30 10:13:28 -0400475void SkDebugCanvas::willSave() {
476 this->addDrawCommand(new SkSaveCommand());
477 this->INHERITED::willSave();
chudy@google.com902ebe52012-06-29 14:21:22 +0000478}
479
reed4960eee2015-12-18 07:09:18 -0800480SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
481 this->addDrawCommand(new SkSaveLayerCommand(rec));
482 (void)this->INHERITED::getSaveLayerStrategy(rec);
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000483 // No need for a full layer.
484 return kNoLayer_SaveLayerStrategy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000485}
486
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000487void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000488 this->addDrawCommand(new SkSetMatrixCommand(matrix));
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000489 this->INHERITED::didSetMatrix(matrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000490}
491
chudy@google.com902ebe52012-06-29 14:21:22 +0000492void SkDebugCanvas::toggleCommand(int index, bool toggle) {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000493 SkASSERT(index < fCommandVector.count());
494 fCommandVector[index]->setVisible(toggle);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495}