chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
ethannicholas | 891ad66 | 2016-02-12 07:15:45 -0800 | [diff] [blame] | 8 | #include "SkCanvasPriv.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 9 | #include "SkDebugCanvas.h" |
| 10 | #include "SkDrawCommand.h" |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 11 | #include "SkPaintFilterCanvas.h" |
Brian Osman | 255735e | 2018-04-06 14:51:42 -0400 | [diff] [blame] | 12 | #include "SkPicture.h" |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 13 | #include "SkRectPriv.h" |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 14 | #include "SkTextBlob.h" |
Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame] | 15 | #include "SkClipOpPriv.h" |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 16 | |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 17 | #include "GrAuditTrail.h" |
| 18 | #include "GrContext.h" |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 19 | #include "GrRenderTargetContext.h" |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 20 | |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 21 | #define SKDEBUGCANVAS_VERSION 1 |
| 22 | #define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version" |
| 23 | #define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands" |
| 24 | #define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail" |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 25 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 26 | class DebugPaintFilterCanvas : public SkPaintFilterCanvas { |
| 27 | public: |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 28 | DebugPaintFilterCanvas(SkCanvas* canvas, |
Brian Osman | 255735e | 2018-04-06 14:51:42 -0400 | [diff] [blame] | 29 | bool overdrawViz) |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 30 | : INHERITED(canvas) |
Brian Osman | 255735e | 2018-04-06 14:51:42 -0400 | [diff] [blame] | 31 | , fOverdrawViz(overdrawViz) {} |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 32 | |
| 33 | protected: |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 34 | bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override { |
| 35 | if (*paint) { |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 36 | if (fOverdrawViz) { |
| 37 | paint->writable()->setColor(SK_ColorRED); |
| 38 | paint->writable()->setAlpha(0x08); |
| 39 | paint->writable()->setBlendMode(SkBlendMode::kSrcOver); |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 40 | } |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 41 | } |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 42 | return true; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 43 | } |
| 44 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 45 | void onDrawPicture(const SkPicture* picture, |
| 46 | const SkMatrix* matrix, |
| 47 | const SkPaint* paint) override { |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 48 | // 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 | |
| 52 | private: |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 53 | bool fOverdrawViz; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 54 | |
| 55 | typedef SkPaintFilterCanvas INHERITED; |
| 56 | }; |
| 57 | |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 58 | SkDebugCanvas::SkDebugCanvas(int width, int height) |
| 59 | : INHERITED(width, height) |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 60 | , fOverdrawViz(false) |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 61 | , fClipVizColor(SK_ColorTRANSPARENT) |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 62 | , fDrawGpuOpBounds(false) { |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 63 | // 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 Reed | 8008df1 | 2018-01-17 12:20:04 -0500 | [diff] [blame] | 72 | SkIRect largeIRect = SkRectPriv::MakeILarge(); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 73 | largeIRect.inset(1024, 1024); |
robertphillips@google.com | 6c1e49a | 2013-11-10 15:08:45 +0000 | [diff] [blame] | 74 | SkRect large = SkRect::Make(largeIRect); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 75 | #ifdef SK_DEBUG |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 76 | SkASSERT(!large.roundOut().isEmpty()); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 77 | #endif |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 78 | // call the base class' version to avoid adding a draw command |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 79 | this->INHERITED::onClipRect(large, kReplace_SkClipOp, kHard_ClipEdgeStyle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 80 | } |
| 81 | |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 82 | SkDebugCanvas::~SkDebugCanvas() { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 83 | fCommandVector.deleteAll(); |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 84 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 85 | |
| 86 | void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 87 | fCommandVector.push_back(command); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void SkDebugCanvas::draw(SkCanvas* canvas) { |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 91 | if (!fCommandVector.isEmpty()) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 92 | this->drawTo(canvas, fCommandVector.count() - 1); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 96 | void SkDebugCanvas::drawTo(SkCanvas* originalCanvas, int index, int m) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 97 | SkASSERT(!fCommandVector.isEmpty()); |
| 98 | SkASSERT(index < fCommandVector.count()); |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 99 | |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 100 | int saveCount = originalCanvas->save(); |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 101 | |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 102 | SkRect windowRect = SkRect::MakeWH(SkIntToScalar(originalCanvas->getBaseLayerSize().width()), |
| 103 | SkIntToScalar(originalCanvas->getBaseLayerSize().height())); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 104 | |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 105 | originalCanvas->clear(SK_ColorWHITE); |
| 106 | originalCanvas->resetMatrix(); |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 107 | if (!windowRect.isEmpty()) { |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 108 | originalCanvas->clipRect(windowRect, kReplace_SkClipOp); |
commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 109 | } |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 110 | |
Brian Osman | 255735e | 2018-04-06 14:51:42 -0400 | [diff] [blame] | 111 | DebugPaintFilterCanvas filterCanvas(originalCanvas, fOverdrawViz); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 112 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 113 | // If we have a GPU backend we can also visualize the op information |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 114 | GrAuditTrail* at = nullptr; |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 115 | if (fDrawGpuOpBounds || m != -1) { |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 116 | // The audit trail must be obtained from the original canvas. |
| 117 | at = this->getAuditTrail(originalCanvas); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 118 | } |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 119 | |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 120 | for (int i = 0; i <= index; i++) { |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 121 | // We need to flush any pending operations, or they might combine with commands below. |
brianosman | 1c9f922 | 2016-04-15 11:00:51 -0700 | [diff] [blame] | 122 | // 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 Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 124 | filterCanvas.flush(); |
brianosman | 1c9f922 | 2016-04-15 11:00:51 -0700 | [diff] [blame] | 125 | |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 126 | GrAuditTrail::AutoCollectOps* acb = nullptr; |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 127 | if (at) { |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 128 | acb = new GrAuditTrail::AutoCollectOps(at, i); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 129 | } |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 130 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 131 | if (fCommandVector[i]->isVisible()) { |
Brian Osman | 255735e | 2018-04-06 14:51:42 -0400 | [diff] [blame] | 132 | fCommandVector[i]->execute(&filterCanvas); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 133 | } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 134 | if (at && acb) { |
| 135 | delete acb; |
| 136 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 137 | } |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 138 | |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 139 | if (SkColorGetA(fClipVizColor) != 0) { |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 140 | filterCanvas.save(); |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 141 | #define LARGE_COORD 1000000000 |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 142 | filterCanvas.clipRect( |
| 143 | SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD), |
| 144 | kReverseDifference_SkClipOp); |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 145 | SkPaint clipPaint; |
| 146 | clipPaint.setColor(fClipVizColor); |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 147 | filterCanvas.drawPaint(clipPaint); |
| 148 | filterCanvas.restore(); |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 151 | fMatrix = filterCanvas.getTotalMatrix(); |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 152 | fClip = filterCanvas.getDeviceClipBounds(); |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 153 | filterCanvas.restoreToCount(saveCount); |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 154 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 155 | // draw any ops if required and issue a full reset onto GrAuditTrail |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 156 | if (at) { |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 157 | // just in case there is global reordering, we flush the canvas before querying |
| 158 | // GrAuditTrail |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 159 | GrAuditTrail::AutoEnable ae(at); |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 160 | filterCanvas.flush(); |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 161 | |
joshualitt | bdc6b2b | 2016-03-01 14:22:02 -0800 | [diff] [blame] | 162 | // we pick three colorblind-safe colors, 75% alpha |
| 163 | static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A); |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 164 | static const SkColor kCommandOpBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C); |
| 165 | static const SkColor kOtherOpBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00); |
joshualitt | bdc6b2b | 2016-03-01 14:22:02 -0800 | [diff] [blame] | 166 | |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 167 | // 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 Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 171 | GrSurfaceProxy::UniqueID proxyID = rtc->asSurfaceProxy()->uniqueID(); |
joshualitt | 1d7decf | 2016-03-01 07:15:52 -0800 | [diff] [blame] | 172 | |
| 173 | // get the bounding boxes to draw |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 174 | SkTArray<GrAuditTrail::OpInfo> childrenBounds; |
joshualitt | 46b301d | 2016-03-02 08:32:37 -0800 | [diff] [blame] | 175 | if (m == -1) { |
| 176 | at->getBoundsByClientID(&childrenBounds, index); |
| 177 | } else { |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 178 | // the client wants us to draw the mth op |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 179 | at->getBoundsByOpListID(&childrenBounds.push_back(), m); |
joshualitt | 46b301d | 2016-03-02 08:32:37 -0800 | [diff] [blame] | 180 | } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 181 | SkPaint paint; |
| 182 | paint.setStyle(SkPaint::kStroke_Style); |
| 183 | paint.setStrokeWidth(1); |
| 184 | for (int i = 0; i < childrenBounds.count(); i++) { |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 185 | if (childrenBounds[i].fProxyUniqueID != proxyID) { |
joshualitt | 1d7decf | 2016-03-01 07:15:52 -0800 | [diff] [blame] | 186 | // offscreen draw, ignore for now |
| 187 | continue; |
| 188 | } |
joshualitt | bdc6b2b | 2016-03-01 14:22:02 -0800 | [diff] [blame] | 189 | paint.setColor(kTotalBounds); |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 190 | filterCanvas.drawRect(childrenBounds[i].fBounds, paint); |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 191 | for (int j = 0; j < childrenBounds[i].fOps.count(); j++) { |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 192 | const GrAuditTrail::OpInfo::Op& op = childrenBounds[i].fOps[j]; |
| 193 | if (op.fClientID != index) { |
| 194 | paint.setColor(kOtherOpBounds); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 195 | } else { |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 196 | paint.setColor(kCommandOpBounds); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 197 | } |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 198 | filterCanvas.drawRect(op.fBounds, paint); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 199 | } |
| 200 | } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 201 | } |
Ravi Mistry | 99c9796 | 2016-12-21 22:41:03 +0000 | [diff] [blame] | 202 | this->cleanupAuditTrail(originalCanvas); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 203 | } |
| 204 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 205 | void SkDebugCanvas::deleteDrawCommandAt(int index) { |
| 206 | SkASSERT(index < fCommandVector.count()); |
| 207 | delete fCommandVector[index]; |
| 208 | fCommandVector.remove(index); |
| 209 | } |
| 210 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 211 | SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 212 | SkASSERT(index < fCommandVector.count()); |
| 213 | return fCommandVector[index]; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 214 | } |
| 215 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 216 | GrAuditTrail* SkDebugCanvas::getAuditTrail(SkCanvas* canvas) { |
| 217 | GrAuditTrail* at = nullptr; |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 218 | GrContext* ctx = canvas->getGrContext(); |
| 219 | if (ctx) { |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 220 | at = ctx->contextPriv().getAuditTrail(); |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 221 | } |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 222 | return at; |
| 223 | } |
| 224 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 225 | void SkDebugCanvas::drawAndCollectOps(int n, SkCanvas* canvas) { |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 226 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 227 | if (at) { |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 228 | // 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 Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 231 | GrAuditTrail::AutoCollectOps enable(at, i); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 232 | 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 | } |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | void SkDebugCanvas::cleanupAuditTrail(SkCanvas* canvas) { |
| 244 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 245 | if (at) { |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 246 | GrAuditTrail::AutoEnable ae(at); |
| 247 | at->fullReset(); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) { |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 252 | this->drawAndCollectOps(n, canvas); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 253 | |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 254 | // now collect json |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 255 | GrAuditTrail* at = this->getAuditTrail(canvas); |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 256 | Json::Value result = Json::Value(Json::objectValue); |
| 257 | result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION); |
| 258 | Json::Value commands = Json::Value(Json::arrayValue); |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 259 | for (int i = 0; i < this->getSize() && i <= n; i++) { |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 260 | commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager); |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 261 | 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 | } |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 270 | } |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 271 | this->cleanupAuditTrail(canvas); |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 272 | result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; |
| 273 | return result; |
| 274 | } |
| 275 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 276 | Json::Value SkDebugCanvas::toJSONOpList(int n, SkCanvas* canvas) { |
| 277 | this->drawAndCollectOps(n, canvas); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 278 | |
| 279 | Json::Value parsedFromString; |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 280 | GrAuditTrail* at = this->getAuditTrail(canvas); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 281 | if (at) { |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 282 | GrAuditTrail::AutoManageOpList enable(at); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 283 | Json::Reader reader; |
| 284 | SkAssertResult(reader.parse(at->toJson().c_str(), parsedFromString)); |
| 285 | } |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 286 | this->cleanupAuditTrail(canvas); |
| 287 | return parsedFromString; |
| 288 | } |
| 289 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 290 | void SkDebugCanvas::setOverdrawViz(bool overdrawViz) { |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 291 | fOverdrawViz = overdrawViz; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 294 | void SkDebugCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 295 | this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 298 | void SkDebugCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 299 | this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 302 | void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 303 | this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 306 | void SkDebugCanvas::onClipRegion(const SkRegion& region, SkClipOp op) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 307 | this->addDrawCommand(new SkClipRegionCommand(region, op)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 308 | } |
| 309 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 310 | void SkDebugCanvas::didConcat(const SkMatrix& matrix) { |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 311 | this->addDrawCommand(new SkConcatCommand(matrix)); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 312 | this->INHERITED::didConcat(matrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 313 | } |
| 314 | |
reed | 97660cc | 2016-06-28 18:54:19 -0700 | [diff] [blame] | 315 | void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
| 316 | this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value))); |
| 317 | } |
| 318 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 319 | void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, |
| 320 | SkScalar top, const SkPaint* paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 321 | this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Brian Osman | 78a7648 | 2018-05-18 16:59:13 -0400 | [diff] [blame] | 324 | void 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 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 329 | void SkDebugCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 330 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 331 | this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, |
| 332 | (SrcRectConstraint)constraint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 333 | } |
| 334 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 335 | void SkDebugCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 336 | const SkRect& dst, const SkPaint* paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 337 | this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 338 | } |
| 339 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 340 | void SkDebugCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top, |
| 341 | const SkPaint* paint) { |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 342 | this->addDrawCommand(new SkDrawImageCommand(image, left, top, paint)); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 345 | void 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 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 350 | void SkDebugCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 351 | const SkPaint* paint, SrcRectConstraint constraint) { |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 352 | this->addDrawCommand(new SkDrawImageRectCommand(image, src, dst, paint, constraint)); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Brian Osman | c25e269 | 2018-03-12 10:57:28 -0400 | [diff] [blame] | 355 | void 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 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 360 | void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 361 | this->addDrawCommand(new SkDrawOvalCommand(oval, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 362 | } |
| 363 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 364 | void 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 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 369 | void SkDebugCanvas::onDrawPaint(const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 370 | this->addDrawCommand(new SkDrawPaintCommand(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 371 | } |
| 372 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 373 | void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 374 | this->addDrawCommand(new SkDrawPathCommand(path, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Brian Osman | c25e269 | 2018-03-12 10:57:28 -0400 | [diff] [blame] | 377 | void SkDebugCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { |
| 378 | this->addDrawCommand(new SkDrawRegionCommand(region, paint)); |
| 379 | } |
| 380 | |
mtklein | f0f1411 | 2014-12-12 08:46:25 -0800 | [diff] [blame] | 381 | void SkDebugCanvas::onDrawPicture(const SkPicture* picture, |
| 382 | const SkMatrix* matrix, |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 383 | const SkPaint* paint) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 384 | this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint)); |
ethannicholas | 891ad66 | 2016-02-12 07:15:45 -0800 | [diff] [blame] | 385 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 386 | picture->playback(this); |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 387 | this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint))); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 388 | } |
| 389 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 390 | void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count, |
| 391 | const SkPoint pts[], const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 392 | this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 393 | } |
| 394 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 395 | void SkDebugCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 396 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 397 | this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 398 | } |
| 399 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 400 | void SkDebugCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 401 | SkScalar constY, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 402 | this->addDrawCommand( |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 403 | new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 404 | } |
| 405 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 406 | void SkDebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 407 | // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 408 | addDrawCommand(new SkDrawRectCommand(rect, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 409 | } |
| 410 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 411 | void SkDebugCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 412 | this->addDrawCommand(new SkDrawRRectCommand(rrect, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 413 | } |
| 414 | |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 415 | void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 416 | const SkPaint& paint) { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 417 | this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint)); |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 418 | } |
| 419 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 420 | void SkDebugCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 421 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 422 | this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 423 | } |
| 424 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 425 | void SkDebugCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 426 | const SkMatrix* matrix, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 427 | this->addDrawCommand( |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 428 | new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 429 | } |
| 430 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 431 | void 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 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 436 | void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 437 | const SkPaint& paint) { |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 438 | this->addDrawCommand(new SkDrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)), |
| 439 | x, y, paint)); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 440 | } |
| 441 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 442 | void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 443 | const SkPoint texCoords[4], SkBlendMode bmode, |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 444 | const SkPaint& paint) { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 445 | this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, bmode, paint)); |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 448 | void SkDebugCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkVertices::Bone bones[], |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame] | 449 | int boneCount, SkBlendMode bmode, const SkPaint& paint) { |
| 450 | // TODO: ANIMATION NOT LOGGED |
Mike Reed | fed9cfd | 2017-03-17 12:09:04 -0400 | [diff] [blame] | 451 | this->addDrawCommand(new SkDrawVerticesCommand(sk_ref_sp(const_cast<SkVertices*>(vertices)), |
| 452 | bmode, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Brian Osman | 616f1cb | 2018-05-29 11:23:35 -0400 | [diff] [blame] | 455 | void 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 Sollenberger | 6aab2ab | 2018-04-12 12:45:58 -0400 | [diff] [blame] | 462 | void SkDebugCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { |
| 463 | this->addDrawCommand(new SkDrawShadowCommand(path, rec)); |
| 464 | } |
| 465 | |
Brian Osman | c761108 | 2018-05-29 14:55:50 -0400 | [diff] [blame] | 466 | void SkDebugCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
| 467 | this->addDrawCommand(new SkDrawDrawableCommand(drawable, matrix)); |
| 468 | } |
| 469 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 470 | void SkDebugCanvas::willRestore() { |
| 471 | this->addDrawCommand(new SkRestoreCommand()); |
| 472 | this->INHERITED::willRestore(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 475 | void SkDebugCanvas::willSave() { |
| 476 | this->addDrawCommand(new SkSaveCommand()); |
| 477 | this->INHERITED::willSave(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 478 | } |
| 479 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 480 | SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { |
| 481 | this->addDrawCommand(new SkSaveLayerCommand(rec)); |
| 482 | (void)this->INHERITED::getSaveLayerStrategy(rec); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 483 | // No need for a full layer. |
| 484 | return kNoLayer_SaveLayerStrategy; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 485 | } |
| 486 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 487 | void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 488 | this->addDrawCommand(new SkSetMatrixCommand(matrix)); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 489 | this->INHERITED::didSetMatrix(matrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 490 | } |
| 491 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 492 | void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 493 | SkASSERT(index < fCommandVector.count()); |
| 494 | fCommandVector[index]->setVisible(toggle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 495 | } |