Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [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 | |
Brian Salomon | 8f7d953 | 2020-12-23 09:16:59 -0500 | [diff] [blame] | 8 | #include "tools/debugger/DebugCanvas.h" |
| 9 | |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 10 | #include "include/core/SkPaint.h" |
| 11 | #include "include/core/SkPath.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkPicture.h" |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 13 | #include "include/core/SkPoint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkTextBlob.h" |
Robert Phillips | 2c21a11 | 2020-11-20 13:49:37 -0500 | [diff] [blame] | 15 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/utils/SkPaintFilterCanvas.h" |
| 17 | #include "src/core/SkCanvasPriv.h" |
| 18 | #include "src/core/SkClipOpPriv.h" |
| 19 | #include "src/core/SkRectPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrAuditTrail.h" |
Robert Phillips | b27b38b | 2020-07-10 16:23:47 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrRecordingContextPriv.h" |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 22 | #include "src/gpu/GrSurfaceDrawContext.h" |
Brian Salomon | 8f7d953 | 2020-12-23 09:16:59 -0500 | [diff] [blame] | 23 | #include "src/utils/SkJSONWriter.h" |
| 24 | #include "tools/debugger/DebugLayerManager.h" |
| 25 | #include "tools/debugger/DrawCommand.h" |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 26 | |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 27 | #include <string> |
| 28 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 29 | #define SKDEBUGCANVAS_VERSION 1 |
| 30 | #define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version" |
| 31 | #define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands" |
| 32 | #define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail" |
| 33 | |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 34 | namespace { |
| 35 | // Constants used in Annotations by Android for keeping track of layers |
| 36 | static constexpr char kOffscreenLayerDraw[] = "OffscreenLayerDraw"; |
| 37 | static constexpr char kSurfaceID[] = "SurfaceID"; |
Nathaniel Nifong | 12b2c27 | 2020-01-10 14:38:00 -0500 | [diff] [blame] | 38 | static constexpr char kAndroidClip[] = "AndroidDeviceClipRestriction"; |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 39 | |
| 40 | static SkPath arrowHead = SkPath::Polygon({ |
| 41 | { 0, 0}, |
| 42 | { 6, -15}, |
| 43 | { 0, -12}, |
| 44 | {-6, -15}, |
| 45 | }, true); |
| 46 | |
| 47 | void drawArrow(SkCanvas* canvas, const SkPoint& a, const SkPoint& b, const SkPaint& paint) { |
Nathaniel Nifong | 0f7aa54 | 2020-09-02 15:40:37 -0400 | [diff] [blame] | 48 | canvas->translate(0.5, 0.5); |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 49 | canvas->drawLine(a, b, paint); |
| 50 | canvas->save(); |
| 51 | canvas->translate(b.fX, b.fY); |
| 52 | SkScalar angle = SkScalarATan2((b.fY - a.fY), b.fX - a.fX); |
| 53 | canvas->rotate(angle * 180 / SK_ScalarPI - 90); |
| 54 | // arrow head |
| 55 | canvas->drawPath(arrowHead, paint); |
| 56 | canvas->restore(); |
Nathaniel Nifong | 0f7aa54 | 2020-09-02 15:40:37 -0400 | [diff] [blame] | 57 | canvas->restore(); |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 58 | } |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 59 | } // namespace |
| 60 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 61 | class DebugPaintFilterCanvas : public SkPaintFilterCanvas { |
| 62 | public: |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 63 | DebugPaintFilterCanvas(SkCanvas* canvas) : INHERITED(canvas) {} |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 64 | |
| 65 | protected: |
Ben Wagner | f55fa0d | 2018-08-27 18:11:57 -0400 | [diff] [blame] | 66 | bool onFilter(SkPaint& paint) const override { |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 67 | paint.setColor(SK_ColorRED); |
| 68 | paint.setAlpha(0x08); |
| 69 | paint.setBlendMode(SkBlendMode::kSrcOver); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 70 | return true; |
| 71 | } |
| 72 | |
| 73 | void onDrawPicture(const SkPicture* picture, |
| 74 | const SkMatrix* matrix, |
| 75 | const SkPaint* paint) override { |
| 76 | // We need to replay the picture onto this canvas in order to filter its internal paints. |
| 77 | this->SkCanvas::onDrawPicture(picture, matrix, paint); |
| 78 | } |
| 79 | |
| 80 | private: |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 81 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 82 | using INHERITED = SkPaintFilterCanvas; |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | DebugCanvas::DebugCanvas(int width, int height) |
| 86 | : INHERITED(width, height) |
| 87 | , fOverdrawViz(false) |
| 88 | , fClipVizColor(SK_ColorTRANSPARENT) |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 89 | , fDrawGpuOpBounds(false) |
Nathaniel Nifong | 12b2c27 | 2020-01-10 14:38:00 -0500 | [diff] [blame] | 90 | , fShowAndroidClip(false) |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 91 | , fShowOrigin(false) |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 92 | , fnextDrawPictureLayerId(-1) |
Nathaniel Nifong | 12b2c27 | 2020-01-10 14:38:00 -0500 | [diff] [blame] | 93 | , fnextDrawImageRectLayerId(-1) |
| 94 | , fAndroidClip(SkRect::MakeEmpty()) { |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 95 | // SkPicturePlayback uses the base-class' quickReject calls to cull clipped |
| 96 | // operations. This can lead to problems in the debugger which expects all |
| 97 | // the operations in the captured skp to appear in the debug canvas. To |
| 98 | // circumvent this we create a wide open clip here (an empty clip rect |
| 99 | // is not sufficient). |
| 100 | // Internally, the SkRect passed to clipRect is converted to an SkIRect and |
| 101 | // rounded out. The following code creates a nearly maximal rect that will |
| 102 | // not get collapsed by the coming conversions (Due to precision loss the |
| 103 | // inset has to be surprisingly large). |
| 104 | SkIRect largeIRect = SkRectPriv::MakeILarge(); |
| 105 | largeIRect.inset(1024, 1024); |
| 106 | SkRect large = SkRect::Make(largeIRect); |
| 107 | #ifdef SK_DEBUG |
| 108 | SkASSERT(!large.roundOut().isEmpty()); |
| 109 | #endif |
| 110 | // call the base class' version to avoid adding a draw command |
Michael Ludwig | e4b7969 | 2020-09-16 13:55:05 -0400 | [diff] [blame] | 111 | this->INHERITED::onClipRect(large, SkClipOp::kIntersect, kHard_ClipEdgeStyle); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 112 | } |
| 113 | |
John Stiles | 214de11 | 2020-07-29 17:26:28 -0400 | [diff] [blame] | 114 | DebugCanvas::DebugCanvas(SkIRect bounds) |
| 115 | : DebugCanvas(bounds.width(), bounds.height()) {} |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 116 | |
| 117 | DebugCanvas::~DebugCanvas() { fCommandVector.deleteAll(); } |
| 118 | |
| 119 | void DebugCanvas::addDrawCommand(DrawCommand* command) { fCommandVector.push_back(command); } |
| 120 | |
| 121 | void DebugCanvas::draw(SkCanvas* canvas) { |
| 122 | if (!fCommandVector.isEmpty()) { |
| 123 | this->drawTo(canvas, fCommandVector.count() - 1); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void DebugCanvas::drawTo(SkCanvas* originalCanvas, int index, int m) { |
| 128 | SkASSERT(!fCommandVector.isEmpty()); |
| 129 | SkASSERT(index < fCommandVector.count()); |
| 130 | |
| 131 | int saveCount = originalCanvas->save(); |
| 132 | |
| 133 | SkRect windowRect = SkRect::MakeWH(SkIntToScalar(originalCanvas->getBaseLayerSize().width()), |
| 134 | SkIntToScalar(originalCanvas->getBaseLayerSize().height())); |
| 135 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 136 | originalCanvas->resetMatrix(); |
| 137 | if (!windowRect.isEmpty()) { |
| 138 | originalCanvas->clipRect(windowRect, kReplace_SkClipOp); |
| 139 | } |
| 140 | |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 141 | DebugPaintFilterCanvas filterCanvas(originalCanvas); |
| 142 | SkCanvas* finalCanvas = fOverdrawViz ? &filterCanvas : originalCanvas; |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 143 | |
Robert Phillips | 2c21a11 | 2020-11-20 13:49:37 -0500 | [diff] [blame] | 144 | auto dContext = GrAsDirectContext(finalCanvas->recordingContext()); |
| 145 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 146 | // If we have a GPU backend we can also visualize the op information |
| 147 | GrAuditTrail* at = nullptr; |
| 148 | if (fDrawGpuOpBounds || m != -1) { |
| 149 | // The audit trail must be obtained from the original canvas. |
| 150 | at = this->getAuditTrail(originalCanvas); |
| 151 | } |
| 152 | |
| 153 | for (int i = 0; i <= index; i++) { |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 154 | GrAuditTrail::AutoCollectOps* acb = nullptr; |
| 155 | if (at) { |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 156 | // We need to flush any pending operations, or they might combine with commands below. |
| 157 | // Previous operations were not registered with the audit trail when they were |
| 158 | // created, so if we allow them to combine, the audit trail will fail to find them. |
Robert Phillips | 2c21a11 | 2020-11-20 13:49:37 -0500 | [diff] [blame] | 159 | if (dContext) { |
| 160 | dContext->flush(); |
| 161 | } |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 162 | acb = new GrAuditTrail::AutoCollectOps(at, i); |
| 163 | } |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 164 | if (fCommandVector[i]->isVisible()) { |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 165 | fCommandVector[i]->execute(finalCanvas); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 166 | } |
| 167 | if (at && acb) { |
| 168 | delete acb; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (SkColorGetA(fClipVizColor) != 0) { |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 173 | finalCanvas->save(); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 174 | SkPaint clipPaint; |
| 175 | clipPaint.setColor(fClipVizColor); |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 176 | finalCanvas->drawPaint(clipPaint); |
| 177 | finalCanvas->restore(); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 178 | } |
| 179 | |
Mike Reed | 1a4140e | 2020-12-03 11:21:31 -0500 | [diff] [blame] | 180 | fMatrix = finalCanvas->getLocalToDevice(); |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 181 | fClip = finalCanvas->getDeviceClipBounds(); |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 182 | if (fShowOrigin) { |
| 183 | const SkPaint originXPaint = SkPaint({1.0, 0, 0, 1.0}); |
| 184 | const SkPaint originYPaint = SkPaint({0, 1.0, 0, 1.0}); |
| 185 | // Draw an origin cross at the origin before restoring to assist in visualizing the |
| 186 | // current matrix. |
| 187 | drawArrow(finalCanvas, {-50, 0}, {50, 0}, originXPaint); |
| 188 | drawArrow(finalCanvas, {0, -50}, {0, 50}, originYPaint); |
| 189 | } |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 190 | finalCanvas->restoreToCount(saveCount); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 191 | |
Nathaniel Nifong | 12b2c27 | 2020-01-10 14:38:00 -0500 | [diff] [blame] | 192 | if (fShowAndroidClip) { |
| 193 | // Draw visualization of android device clip restriction |
| 194 | SkPaint androidClipPaint; |
| 195 | androidClipPaint.setARGB(80, 255, 100, 0); |
| 196 | finalCanvas->drawRect(fAndroidClip, androidClipPaint); |
| 197 | } |
| 198 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 199 | // draw any ops if required and issue a full reset onto GrAuditTrail |
| 200 | if (at) { |
| 201 | // just in case there is global reordering, we flush the canvas before querying |
| 202 | // GrAuditTrail |
| 203 | GrAuditTrail::AutoEnable ae(at); |
Robert Phillips | 2c21a11 | 2020-11-20 13:49:37 -0500 | [diff] [blame] | 204 | if (dContext) { |
| 205 | dContext->flush(); |
| 206 | } |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 207 | |
| 208 | // we pick three colorblind-safe colors, 75% alpha |
| 209 | static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A); |
| 210 | static const SkColor kCommandOpBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C); |
| 211 | static const SkColor kOtherOpBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00); |
| 212 | |
| 213 | // get the render target of the top device (from the original canvas) so we can ignore ops |
| 214 | // drawn offscreen |
Brian Salomon | 8f7d953 | 2020-12-23 09:16:59 -0500 | [diff] [blame] | 215 | GrSurfaceDrawContext* sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(originalCanvas); |
| 216 | GrSurfaceProxy::UniqueID proxyID = sdc->asSurfaceProxy()->uniqueID(); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 217 | |
| 218 | // get the bounding boxes to draw |
| 219 | SkTArray<GrAuditTrail::OpInfo> childrenBounds; |
| 220 | if (m == -1) { |
| 221 | at->getBoundsByClientID(&childrenBounds, index); |
| 222 | } else { |
| 223 | // the client wants us to draw the mth op |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 224 | at->getBoundsByOpsTaskID(&childrenBounds.push_back(), m); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 225 | } |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 226 | // Shift the rects half a pixel, so they appear as exactly 1px thick lines. |
| 227 | finalCanvas->save(); |
| 228 | finalCanvas->translate(0.5, -0.5); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 229 | SkPaint paint; |
| 230 | paint.setStyle(SkPaint::kStroke_Style); |
| 231 | paint.setStrokeWidth(1); |
| 232 | for (int i = 0; i < childrenBounds.count(); i++) { |
| 233 | if (childrenBounds[i].fProxyUniqueID != proxyID) { |
| 234 | // offscreen draw, ignore for now |
| 235 | continue; |
| 236 | } |
| 237 | paint.setColor(kTotalBounds); |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 238 | finalCanvas->drawRect(childrenBounds[i].fBounds, paint); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 239 | for (int j = 0; j < childrenBounds[i].fOps.count(); j++) { |
| 240 | const GrAuditTrail::OpInfo::Op& op = childrenBounds[i].fOps[j]; |
| 241 | if (op.fClientID != index) { |
| 242 | paint.setColor(kOtherOpBounds); |
| 243 | } else { |
| 244 | paint.setColor(kCommandOpBounds); |
| 245 | } |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 246 | finalCanvas->drawRect(op.fBounds, paint); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 247 | } |
| 248 | } |
Nathaniel Nifong | c84ad83 | 2019-12-11 15:24:48 -0500 | [diff] [blame] | 249 | finalCanvas->restore(); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 250 | } |
| 251 | this->cleanupAuditTrail(originalCanvas); |
| 252 | } |
| 253 | |
| 254 | void DebugCanvas::deleteDrawCommandAt(int index) { |
| 255 | SkASSERT(index < fCommandVector.count()); |
| 256 | delete fCommandVector[index]; |
| 257 | fCommandVector.remove(index); |
| 258 | } |
| 259 | |
Nathaniel Nifong | 0b448da | 2020-09-16 10:35:22 -0400 | [diff] [blame] | 260 | DrawCommand* DebugCanvas::getDrawCommandAt(int index) const { |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 261 | SkASSERT(index < fCommandVector.count()); |
| 262 | return fCommandVector[index]; |
| 263 | } |
| 264 | |
| 265 | GrAuditTrail* DebugCanvas::getAuditTrail(SkCanvas* canvas) { |
| 266 | GrAuditTrail* at = nullptr; |
Robert Phillips | b27b38b | 2020-07-10 16:23:47 -0400 | [diff] [blame] | 267 | auto ctx = canvas->recordingContext(); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 268 | if (ctx) { |
| 269 | at = ctx->priv().auditTrail(); |
| 270 | } |
| 271 | return at; |
| 272 | } |
| 273 | |
Nathaniel Nifong | a072b7b | 2019-12-13 13:51:14 -0500 | [diff] [blame] | 274 | void DebugCanvas::drawAndCollectOps(SkCanvas* canvas) { |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 275 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 276 | if (at) { |
| 277 | // loop over all of the commands and draw them, this is to collect reordering |
| 278 | // information |
Nathaniel Nifong | a072b7b | 2019-12-13 13:51:14 -0500 | [diff] [blame] | 279 | for (int i = 0; i < this->getSize(); i++) { |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 280 | GrAuditTrail::AutoCollectOps enable(at, i); |
| 281 | fCommandVector[i]->execute(canvas); |
| 282 | } |
| 283 | |
| 284 | // in case there is some kind of global reordering |
| 285 | { |
| 286 | GrAuditTrail::AutoEnable ae(at); |
Robert Phillips | 2c21a11 | 2020-11-20 13:49:37 -0500 | [diff] [blame] | 287 | |
| 288 | auto dContext = GrAsDirectContext(canvas->recordingContext()); |
| 289 | if (dContext) { |
| 290 | dContext->flush(); |
| 291 | } |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void DebugCanvas::cleanupAuditTrail(SkCanvas* canvas) { |
| 297 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 298 | if (at) { |
| 299 | GrAuditTrail::AutoEnable ae(at); |
| 300 | at->fullReset(); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | void DebugCanvas::toJSON(SkJSONWriter& writer, |
| 305 | UrlDataManager& urlDataManager, |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 306 | SkCanvas* canvas) { |
Nathaniel Nifong | a072b7b | 2019-12-13 13:51:14 -0500 | [diff] [blame] | 307 | this->drawAndCollectOps(canvas); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 308 | |
| 309 | // now collect json |
| 310 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 311 | writer.appendS32(SKDEBUGCANVAS_ATTRIBUTE_VERSION, SKDEBUGCANVAS_VERSION); |
| 312 | writer.beginArray(SKDEBUGCANVAS_ATTRIBUTE_COMMANDS); |
| 313 | |
Nathaniel Nifong | a072b7b | 2019-12-13 13:51:14 -0500 | [diff] [blame] | 314 | for (int i = 0; i < this->getSize(); i++) { |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 315 | writer.beginObject(); // command |
| 316 | this->getDrawCommandAt(i)->toJSON(writer, urlDataManager); |
| 317 | |
| 318 | if (at) { |
| 319 | writer.appendName(SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL); |
| 320 | at->toJson(writer, i); |
| 321 | } |
| 322 | writer.endObject(); // command |
| 323 | } |
| 324 | |
| 325 | writer.endArray(); // commands |
| 326 | this->cleanupAuditTrail(canvas); |
| 327 | } |
| 328 | |
Nathaniel Nifong | a072b7b | 2019-12-13 13:51:14 -0500 | [diff] [blame] | 329 | void DebugCanvas::toJSONOpsTask(SkJSONWriter& writer, SkCanvas* canvas) { |
| 330 | this->drawAndCollectOps(canvas); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 331 | |
| 332 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 333 | if (at) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 334 | GrAuditTrail::AutoManageOpsTask enable(at); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 335 | at->toJson(writer); |
| 336 | } else { |
| 337 | writer.beginObject(); |
| 338 | writer.endObject(); |
| 339 | } |
| 340 | this->cleanupAuditTrail(canvas); |
| 341 | } |
| 342 | |
| 343 | void DebugCanvas::setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; } |
| 344 | |
| 345 | void DebugCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 346 | this->addDrawCommand(new ClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void DebugCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 350 | this->addDrawCommand(new ClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void DebugCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 354 | this->addDrawCommand(new ClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void DebugCanvas::onClipRegion(const SkRegion& region, SkClipOp op) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 358 | this->addDrawCommand(new ClipRegionCommand(region, op)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 359 | } |
| 360 | |
Mike Reed | 121c2af | 2020-03-10 14:02:56 -0400 | [diff] [blame] | 361 | void DebugCanvas::onClipShader(sk_sp<SkShader> cs, SkClipOp op) { |
| 362 | this->addDrawCommand(new ClipShaderCommand(std::move(cs), op)); |
| 363 | } |
| 364 | |
Mike Reed | 7d45a7a | 2020-04-18 10:27:52 -0400 | [diff] [blame] | 365 | void DebugCanvas::didConcat44(const SkM44& m) { |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 366 | this->addDrawCommand(new Concat44Command(m)); |
Mike Reed | a3a704a | 2020-01-10 17:21:40 -0500 | [diff] [blame] | 367 | this->INHERITED::didConcat44(m); |
| 368 | } |
| 369 | |
| 370 | void DebugCanvas::didScale(SkScalar x, SkScalar y) { |
Mike Reed | 420a9ba | 2020-11-25 13:37:30 -0500 | [diff] [blame] | 371 | this->didConcat44(SkM44::Scale(x, y)); |
Mike Reed | a3a704a | 2020-01-10 17:21:40 -0500 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void DebugCanvas::didTranslate(SkScalar x, SkScalar y) { |
Mike Reed | 420a9ba | 2020-11-25 13:37:30 -0500 | [diff] [blame] | 375 | this->didConcat44(SkM44::Translate(x, y)); |
Mike Reed | a3a704a | 2020-01-10 17:21:40 -0500 | [diff] [blame] | 376 | } |
| 377 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 378 | void DebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 379 | // Parse layer-releated annotations added in SkiaPipeline.cpp and RenderNodeDrawable.cpp |
| 380 | // the format of the annotations is <Indicator|RenderNodeId> |
| 381 | SkTArray<SkString> tokens; |
| 382 | SkStrSplit(key, "|", kStrict_SkStrSplitMode, &tokens); |
| 383 | if (tokens.size() == 2) { |
| 384 | if (tokens[0].equals(kOffscreenLayerDraw)) { |
Nathaniel Nifong | 642a10b | 2020-08-20 12:33:46 -0400 | [diff] [blame] | 385 | // Indicates that the next drawPicture command contains the SkPicture to render the |
| 386 | // node at this id in an offscreen buffer. |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 387 | fnextDrawPictureLayerId = std::stoi(tokens[1].c_str()); |
| 388 | fnextDrawPictureDirtyRect = rect.roundOut(); |
| 389 | return; // don't record it |
| 390 | } else if (tokens[0].equals(kSurfaceID)) { |
| 391 | // Indicates that the following drawImageRect should draw the offscreen buffer. |
| 392 | fnextDrawImageRectLayerId = std::stoi(tokens[1].c_str()); |
| 393 | return; // don't record it |
| 394 | } |
| 395 | } |
Nathaniel Nifong | 12b2c27 | 2020-01-10 14:38:00 -0500 | [diff] [blame] | 396 | if (strcmp(kAndroidClip, key) == 0) { |
| 397 | // Store this frame's android device clip restriction for visualization later. |
| 398 | // This annotation stands in place of the androidFramework_setDeviceClipRestriction |
| 399 | // which is unrecordable. |
| 400 | fAndroidClip = rect; |
| 401 | } |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 402 | this->addDrawCommand(new DrawAnnotationCommand(rect, key, sk_ref_sp(value))); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 403 | } |
| 404 | |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 405 | void DebugCanvas::onDrawImage2(const SkImage* image, |
| 406 | SkScalar left, |
| 407 | SkScalar top, |
Mike Reed | 18aeb57 | 2021-01-19 17:58:25 -0500 | [diff] [blame] | 408 | const SkSamplingOptions& sampling, |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 409 | const SkPaint* paint) { |
Mike Reed | 18aeb57 | 2021-01-19 17:58:25 -0500 | [diff] [blame] | 410 | this->addDrawCommand(new DrawImageCommand(image, left, top, sampling, paint)); |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | void DebugCanvas::onDrawImageLattice2(const SkImage* image, |
| 414 | const Lattice& lattice, |
| 415 | const SkRect& dst, |
| 416 | SkFilterMode filter, // todo |
| 417 | const SkPaint* paint) { |
Mike Reed | 9911630 | 2021-01-25 11:37:10 -0500 | [diff] [blame] | 418 | this->addDrawCommand(new DrawImageLatticeCommand(image, lattice, dst, filter, paint)); |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void DebugCanvas::onDrawImageRect2(const SkImage* image, |
| 422 | const SkRect& src, |
| 423 | const SkRect& dst, |
Mike Reed | 18aeb57 | 2021-01-19 17:58:25 -0500 | [diff] [blame] | 424 | const SkSamplingOptions& sampling, |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 425 | const SkPaint* paint, |
| 426 | SrcRectConstraint constraint) { |
| 427 | if (fnextDrawImageRectLayerId != -1 && fLayerManager) { |
| 428 | // This drawImageRect command would have drawn the offscreen buffer for a layer. |
| 429 | // On Android, we recorded an SkPicture of the commands that drew to the layer. |
| 430 | // To render the layer as it would have looked on the frame this DebugCanvas draws, we need |
| 431 | // to call fLayerManager->getLayerAsImage(id). This must be done just before |
| 432 | // drawTo(command), since it depends on the index into the layer's commands |
| 433 | // (managed by fLayerManager) |
| 434 | // Instead of adding a DrawImageRectCommand, we need a deferred command, that when |
| 435 | // executed, will call drawImageRect(fLayerManager->getLayerAsImage()) |
| 436 | this->addDrawCommand(new DrawImageRectLayerCommand( |
Mike Reed | e02d7f8 | 2021-01-21 22:25:21 -0500 | [diff] [blame] | 437 | fLayerManager, fnextDrawImageRectLayerId, fFrame, src, dst, sampling, |
| 438 | paint, constraint)); |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 439 | } else { |
Mike Reed | 18aeb57 | 2021-01-19 17:58:25 -0500 | [diff] [blame] | 440 | this->addDrawCommand(new DrawImageRectCommand(image, src, dst, sampling, paint, constraint)); |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 441 | } |
| 442 | // Reset expectation so next drawImageRect is not special. |
| 443 | fnextDrawImageRectLayerId = -1; |
| 444 | } |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 445 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 446 | void DebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 447 | this->addDrawCommand(new DrawOvalCommand(oval, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | void DebugCanvas::onDrawArc(const SkRect& oval, |
| 451 | SkScalar startAngle, |
| 452 | SkScalar sweepAngle, |
| 453 | bool useCenter, |
| 454 | const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 455 | this->addDrawCommand(new DrawArcCommand(oval, startAngle, sweepAngle, useCenter, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | void DebugCanvas::onDrawPaint(const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 459 | this->addDrawCommand(new DrawPaintCommand(paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 460 | } |
| 461 | |
Mike Reed | d567408 | 2019-04-19 15:00:47 -0400 | [diff] [blame] | 462 | void DebugCanvas::onDrawBehind(const SkPaint& paint) { |
| 463 | this->addDrawCommand(new DrawBehindCommand(paint)); |
| 464 | } |
| 465 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 466 | void DebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 467 | this->addDrawCommand(new DrawPathCommand(path, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void DebugCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 471 | this->addDrawCommand(new DrawRegionCommand(region, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void DebugCanvas::onDrawPicture(const SkPicture* picture, |
| 475 | const SkMatrix* matrix, |
| 476 | const SkPaint* paint) { |
Nathaniel Nifong | 20b177a | 2019-12-12 11:05:10 -0500 | [diff] [blame] | 477 | if (fnextDrawPictureLayerId != -1 && fLayerManager) { |
| 478 | fLayerManager->storeSkPicture(fnextDrawPictureLayerId, fFrame, sk_ref_sp(picture), |
| 479 | fnextDrawPictureDirtyRect); |
| 480 | } else { |
| 481 | this->addDrawCommand(new BeginDrawPictureCommand(picture, matrix, paint)); |
| 482 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 483 | picture->playback(this); |
| 484 | this->addDrawCommand(new EndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint))); |
| 485 | } |
| 486 | fnextDrawPictureLayerId = -1; |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | void DebugCanvas::onDrawPoints(PointMode mode, |
| 490 | size_t count, |
| 491 | const SkPoint pts[], |
| 492 | const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 493 | this->addDrawCommand(new DrawPointsCommand(mode, count, pts, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | void DebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
| 497 | // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 498 | addDrawCommand(new DrawRectCommand(rect, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | void DebugCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 502 | this->addDrawCommand(new DrawRRectCommand(rrect, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | void DebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 506 | this->addDrawCommand(new DrawDRRectCommand(outer, inner, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | void DebugCanvas::onDrawTextBlob(const SkTextBlob* blob, |
| 510 | SkScalar x, |
| 511 | SkScalar y, |
| 512 | const SkPaint& paint) { |
| 513 | this->addDrawCommand( |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 514 | new DrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)), x, y, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | void DebugCanvas::onDrawPatch(const SkPoint cubics[12], |
| 518 | const SkColor colors[4], |
| 519 | const SkPoint texCoords[4], |
| 520 | SkBlendMode bmode, |
| 521 | const SkPaint& paint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 522 | this->addDrawCommand(new DrawPatchCommand(cubics, colors, texCoords, bmode, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Mike Reed | a2cf8ae | 2020-03-02 17:08:01 -0500 | [diff] [blame] | 525 | void DebugCanvas::onDrawVerticesObject(const SkVertices* vertices, |
| 526 | SkBlendMode bmode, |
| 527 | const SkPaint& paint) { |
| 528 | this->addDrawCommand( |
| 529 | new DrawVerticesCommand(sk_ref_sp(const_cast<SkVertices*>(vertices)), bmode, paint)); |
| 530 | } |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 531 | |
Mike Reed | 4f23dec | 2020-12-30 14:22:42 +0000 | [diff] [blame] | 532 | void DebugCanvas::onDrawAtlas2(const SkImage* image, |
| 533 | const SkRSXform xform[], |
| 534 | const SkRect tex[], |
| 535 | const SkColor colors[], |
| 536 | int count, |
| 537 | SkBlendMode bmode, |
| 538 | const SkSamplingOptions& sampling, |
| 539 | const SkRect* cull, |
| 540 | const SkPaint* paint) { |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 541 | this->addDrawCommand( |
Mike Reed | 9911630 | 2021-01-25 11:37:10 -0500 | [diff] [blame] | 542 | new DrawAtlasCommand(image, xform, tex, colors, count, bmode, sampling, cull, paint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | void DebugCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 546 | this->addDrawCommand(new DrawShadowCommand(path, rec)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | void DebugCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 550 | this->addDrawCommand(new DrawDrawableCommand(drawable, matrix)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Michael Ludwig | a595f86 | 2019-08-27 15:25:49 -0400 | [diff] [blame] | 553 | void DebugCanvas::onDrawEdgeAAQuad(const SkRect& rect, |
| 554 | const SkPoint clip[4], |
| 555 | QuadAAFlags aa, |
| 556 | const SkColor4f& color, |
| 557 | SkBlendMode mode) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 558 | this->addDrawCommand(new DrawEdgeAAQuadCommand(rect, clip, aa, color, mode)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 559 | } |
| 560 | |
Mike Reed | 4f50934 | 2021-01-05 12:03:47 -0500 | [diff] [blame] | 561 | void DebugCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[], |
| 562 | int count, |
| 563 | const SkPoint dstClips[], |
| 564 | const SkMatrix preViewMatrices[], |
| 565 | const SkSamplingOptions& sampling, |
| 566 | const SkPaint* paint, |
| 567 | SrcRectConstraint constraint) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 568 | this->addDrawCommand(new DrawEdgeAAImageSetCommand( |
Mike Reed | 4f50934 | 2021-01-05 12:03:47 -0500 | [diff] [blame] | 569 | set, count, dstClips, preViewMatrices, sampling, paint, constraint)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | void DebugCanvas::willRestore() { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 573 | this->addDrawCommand(new RestoreCommand()); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 574 | this->INHERITED::willRestore(); |
| 575 | } |
| 576 | |
| 577 | void DebugCanvas::willSave() { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 578 | this->addDrawCommand(new SaveCommand()); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 579 | this->INHERITED::willSave(); |
| 580 | } |
| 581 | |
| 582 | SkCanvas::SaveLayerStrategy DebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { |
Mike Klein | 1742813 | 2019-03-20 13:02:32 -0500 | [diff] [blame] | 583 | this->addDrawCommand(new SaveLayerCommand(rec)); |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 584 | (void)this->INHERITED::getSaveLayerStrategy(rec); |
| 585 | // No need for a full layer. |
| 586 | return kNoLayer_SaveLayerStrategy; |
| 587 | } |
| 588 | |
| 589 | bool DebugCanvas::onDoSaveBehind(const SkRect* subset) { |
| 590 | // TODO |
| 591 | return false; |
| 592 | } |
| 593 | |
Mike Reed | 420a9ba | 2020-11-25 13:37:30 -0500 | [diff] [blame] | 594 | void DebugCanvas::didSetM44(const SkM44& matrix) { |
| 595 | this->addDrawCommand(new SetM44Command(matrix)); |
| 596 | this->INHERITED::didSetM44(matrix); |
| 597 | } |
| 598 | |
Mike Klein | 8f4e224 | 2019-03-20 11:59:00 -0500 | [diff] [blame] | 599 | void DebugCanvas::toggleCommand(int index, bool toggle) { |
| 600 | SkASSERT(index < fCommandVector.count()); |
| 601 | fCommandVector[index]->setVisible(toggle); |
| 602 | } |
Nathaniel Nifong | 0b448da | 2020-09-16 10:35:22 -0400 | [diff] [blame] | 603 | |
| 604 | std::map<int, std::vector<int>> DebugCanvas::getImageIdToCommandMap(UrlDataManager& udm) const { |
| 605 | // map from image ids to list of commands that reference them. |
| 606 | std::map<int, std::vector<int>> m; |
| 607 | |
| 608 | for (int i = 0; i < this->getSize(); i++) { |
| 609 | const DrawCommand* command = this->getDrawCommandAt(i); |
| 610 | int imageIndex = -1; |
| 611 | // this is not an exaustive list of where images can be used, they show up in paints too. |
| 612 | switch (command->getOpType()) { |
| 613 | case DrawCommand::OpType::kDrawImage_OpType: { |
| 614 | imageIndex = static_cast<const DrawImageCommand*>(command)->imageId(udm); |
| 615 | break; |
| 616 | } |
| 617 | case DrawCommand::OpType::kDrawImageRect_OpType: { |
| 618 | imageIndex = static_cast<const DrawImageRectCommand*>(command)->imageId(udm); |
| 619 | break; |
| 620 | } |
Nathaniel Nifong | 0b448da | 2020-09-16 10:35:22 -0400 | [diff] [blame] | 621 | case DrawCommand::OpType::kDrawImageLattice_OpType: { |
| 622 | imageIndex = static_cast<const DrawImageLatticeCommand*>(command)->imageId(udm); |
| 623 | break; |
| 624 | } |
| 625 | default: break; |
| 626 | } |
| 627 | if (imageIndex >= 0) { |
| 628 | m[imageIndex].push_back(i); |
| 629 | } |
| 630 | } |
| 631 | return m; |
| 632 | } |