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" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 9 | #include "SkClipStack.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 10 | #include "SkDebugCanvas.h" |
| 11 | #include "SkDrawCommand.h" |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 12 | #include "SkPaintFilterCanvas.h" |
| 13 | #include "SkTextBlob.h" |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 14 | |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 15 | #if SK_SUPPORT_GPU |
| 16 | #include "GrAuditTrail.h" |
| 17 | #include "GrContext.h" |
| 18 | #include "GrRenderTarget.h" |
joshualitt | 1d7decf | 2016-03-01 07:15:52 -0800 | [diff] [blame] | 19 | #include "SkGpuDevice.h" |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 20 | #endif |
| 21 | |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 22 | #define SKDEBUGCANVAS_VERSION 1 |
| 23 | #define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version" |
| 24 | #define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands" |
| 25 | #define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail" |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 26 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 27 | class DebugPaintFilterCanvas : public SkPaintFilterCanvas { |
| 28 | public: |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame^] | 29 | DebugPaintFilterCanvas(SkCanvas* canvas, |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 30 | bool overdrawViz, |
| 31 | bool overrideFilterQuality, |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 32 | SkFilterQuality quality) |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame^] | 33 | : INHERITED(canvas) |
| 34 | , fOverdrawViz(overdrawViz) |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 35 | , fOverrideFilterQuality(overrideFilterQuality) |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 36 | , fFilterQuality(quality) {} |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 37 | |
| 38 | protected: |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 39 | bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override { |
| 40 | if (*paint) { |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame^] | 41 | if (fOverdrawViz) { |
| 42 | paint->writable()->setColor(SK_ColorRED); |
| 43 | paint->writable()->setAlpha(0x08); |
| 44 | paint->writable()->setBlendMode(SkBlendMode::kSrcOver); |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 45 | } |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 46 | |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 47 | if (fOverrideFilterQuality) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 48 | paint->writable()->setFilterQuality(fFilterQuality); |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 49 | } |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 50 | } |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 51 | return true; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 52 | } |
| 53 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 54 | void onDrawPicture(const SkPicture* picture, |
| 55 | const SkMatrix* matrix, |
| 56 | const SkPaint* paint) override { |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 57 | // We need to replay the picture onto this canvas in order to filter its internal paints. |
| 58 | this->SkCanvas::onDrawPicture(picture, matrix, paint); |
| 59 | } |
| 60 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 61 | void onDrawShadowedPicture(const SkPicture* picture, |
| 62 | const SkMatrix* matrix, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 63 | const SkPaint* paint, |
| 64 | const SkShadowParams& params) { |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 65 | #ifdef SK_EXPERIMENTAL_SHADOWING |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 66 | this->SkCanvas::onDrawShadowedPicture(picture, matrix, paint, params); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 67 | #else |
| 68 | this->SkCanvas::onDrawPicture(picture, matrix, paint); |
| 69 | #endif |
| 70 | } |
| 71 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 72 | private: |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame^] | 73 | bool fOverdrawViz; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 74 | bool fOverrideFilterQuality; |
| 75 | SkFilterQuality fFilterQuality; |
| 76 | |
| 77 | typedef SkPaintFilterCanvas INHERITED; |
| 78 | }; |
| 79 | |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 80 | SkDebugCanvas::SkDebugCanvas(int width, int height) |
| 81 | : INHERITED(width, height) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 82 | , fPicture(nullptr) |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 83 | , fFilter(false) |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 84 | , fMegaVizMode(false) |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 85 | , fOverdrawViz(false) |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 86 | , fOverrideFilterQuality(false) |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 87 | , fFilterQuality(kNone_SkFilterQuality) |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 88 | , fClipVizColor(SK_ColorTRANSPARENT) |
joshualitt | 5d5207a | 2016-02-29 12:46:04 -0800 | [diff] [blame] | 89 | , fDrawGpuBatchBounds(false) { |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 90 | fUserMatrix.reset(); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 91 | |
| 92 | // SkPicturePlayback uses the base-class' quickReject calls to cull clipped |
| 93 | // operations. This can lead to problems in the debugger which expects all |
| 94 | // the operations in the captured skp to appear in the debug canvas. To |
| 95 | // circumvent this we create a wide open clip here (an empty clip rect |
| 96 | // is not sufficient). |
| 97 | // Internally, the SkRect passed to clipRect is converted to an SkIRect and |
| 98 | // rounded out. The following code creates a nearly maximal rect that will |
| 99 | // not get collapsed by the coming conversions (Due to precision loss the |
| 100 | // inset has to be surprisingly large). |
| 101 | SkIRect largeIRect = SkIRect::MakeLargest(); |
| 102 | largeIRect.inset(1024, 1024); |
robertphillips@google.com | 6c1e49a | 2013-11-10 15:08:45 +0000 | [diff] [blame] | 103 | SkRect large = SkRect::Make(largeIRect); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 104 | #ifdef SK_DEBUG |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 105 | SkASSERT(!large.roundOut().isEmpty()); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 106 | #endif |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 107 | // call the base class' version to avoid adding a draw command |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 108 | this->INHERITED::onClipRect(large, kReplace_Op, kHard_ClipEdgeStyle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 109 | } |
| 110 | |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 111 | SkDebugCanvas::~SkDebugCanvas() { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 112 | fCommandVector.deleteAll(); |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 113 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 114 | |
| 115 | void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 116 | fCommandVector.push(command); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void SkDebugCanvas::draw(SkCanvas* canvas) { |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 120 | if (!fCommandVector.isEmpty()) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 121 | this->drawTo(canvas, fCommandVector.count() - 1); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 125 | void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 126 | canvas->concat(fUserMatrix); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 130 | SkBitmap bitmap; |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 131 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 132 | |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 133 | SkCanvas canvas(bitmap); |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 134 | canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y)); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 135 | this->applyUserTransform(&canvas); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 136 | |
| 137 | int layer = 0; |
chudy@google.com | 751961d | 2012-07-31 20:07:42 +0000 | [diff] [blame] | 138 | SkColor prev = bitmap.getColor(0,0); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 139 | for (int i = 0; i < index; i++) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 140 | if (fCommandVector[i]->isVisible()) { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 141 | fCommandVector[i]->setUserMatrix(fUserMatrix); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 142 | fCommandVector[i]->execute(&canvas); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 143 | } |
| 144 | if (prev != bitmap.getColor(0,0)) { |
| 145 | layer = i; |
| 146 | } |
| 147 | prev = bitmap.getColor(0,0); |
| 148 | } |
| 149 | return layer; |
| 150 | } |
| 151 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 152 | class SkDebugClipVisitor : public SkCanvas::ClipVisitor { |
| 153 | public: |
| 154 | SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {} |
| 155 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 156 | void clipRect(const SkRect& r, SkCanvas::ClipOp, bool doAA) override { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 157 | SkPaint p; |
| 158 | p.setColor(SK_ColorRED); |
| 159 | p.setStyle(SkPaint::kStroke_Style); |
| 160 | p.setAntiAlias(doAA); |
| 161 | fCanvas->drawRect(r, p); |
| 162 | } |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 163 | void clipRRect(const SkRRect& rr, SkCanvas::ClipOp, bool doAA) override { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 164 | SkPaint p; |
| 165 | p.setColor(SK_ColorGREEN); |
| 166 | p.setStyle(SkPaint::kStroke_Style); |
| 167 | p.setAntiAlias(doAA); |
| 168 | fCanvas->drawRRect(rr, p); |
| 169 | } |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 170 | void clipPath(const SkPath& path, SkCanvas::ClipOp, bool doAA) override { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 171 | SkPaint p; |
| 172 | p.setColor(SK_ColorBLUE); |
| 173 | p.setStyle(SkPaint::kStroke_Style); |
| 174 | p.setAntiAlias(doAA); |
| 175 | fCanvas->drawPath(path, p); |
| 176 | } |
| 177 | |
| 178 | protected: |
| 179 | SkCanvas* fCanvas; |
| 180 | |
| 181 | private: |
| 182 | typedef SkCanvas::ClipVisitor INHERITED; |
| 183 | }; |
| 184 | |
| 185 | // set up the saveLayer commands so that the active ones |
| 186 | // return true in their 'active' method |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 187 | void SkDebugCanvas::markActiveCommands(int index) { |
| 188 | fActiveLayers.rewind(); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 189 | |
| 190 | for (int i = 0; i < fCommandVector.count(); ++i) { |
| 191 | fCommandVector[i]->setActive(false); |
| 192 | } |
| 193 | |
| 194 | for (int i = 0; i < index; ++i) { |
| 195 | SkDrawCommand::Action result = fCommandVector[i]->action(); |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 196 | if (SkDrawCommand::kPushLayer_Action == result) { |
| 197 | fActiveLayers.push(fCommandVector[i]); |
| 198 | } else if (SkDrawCommand::kPopLayer_Action == result) { |
| 199 | fActiveLayers.pop(); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 203 | for (int i = 0; i < fActiveLayers.count(); ++i) { |
| 204 | fActiveLayers[i]->setActive(true); |
| 205 | } |
| 206 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 207 | } |
| 208 | |
joshualitt | 46b301d | 2016-03-02 08:32:37 -0800 | [diff] [blame] | 209 | void SkDebugCanvas::drawTo(SkCanvas* canvas, int index, int m) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 210 | SkASSERT(!fCommandVector.isEmpty()); |
| 211 | SkASSERT(index < fCommandVector.count()); |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 212 | |
| 213 | int saveCount = canvas->save(); |
| 214 | |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 215 | SkRect windowRect = SkRect::MakeWH(SkIntToScalar(canvas->getBaseLayerSize().width()), |
| 216 | SkIntToScalar(canvas->getBaseLayerSize().height())); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 217 | |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 218 | bool pathOpsMode = getAllowSimplifyClip(); |
| 219 | canvas->setAllowSimplifyClip(pathOpsMode); |
ethannicholas | cecbbe2 | 2016-02-17 11:49:43 -0800 | [diff] [blame] | 220 | canvas->clear(SK_ColorWHITE); |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 221 | canvas->resetMatrix(); |
| 222 | if (!windowRect.isEmpty()) { |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 223 | canvas->clipRect(windowRect, SkCanvas::kReplace_Op); |
commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 224 | } |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 225 | this->applyUserTransform(canvas); |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 226 | |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame^] | 227 | DebugPaintFilterCanvas fPaintFilterCanvas(canvas, fOverdrawViz, |
| 228 | fOverrideFilterQuality, fFilterQuality); |
| 229 | canvas = &fPaintFilterCanvas; |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 230 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 231 | if (fMegaVizMode) { |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 232 | this->markActiveCommands(index); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 233 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 234 | |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 235 | #if SK_SUPPORT_GPU |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 236 | // If we have a GPU backend we can also visualize the batching information |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 237 | GrAuditTrail* at = nullptr; |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 238 | if (fDrawGpuBatchBounds || m != -1) { |
| 239 | at = this->getAuditTrail(canvas); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 240 | } |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 241 | #endif |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 242 | |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 243 | for (int i = 0; i <= index; i++) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 244 | if (i == index && fFilter) { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 245 | canvas->clear(0xAAFFFFFF); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 246 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 247 | |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 248 | #if SK_SUPPORT_GPU |
brianosman | 1c9f922 | 2016-04-15 11:00:51 -0700 | [diff] [blame] | 249 | // We need to flush any pending operations, or they might batch with commands below. |
| 250 | // Previous operations were not registered with the audit trail when they were |
| 251 | // created, so if we allow them to combine, the audit trail will fail to find them. |
| 252 | canvas->flush(); |
| 253 | |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 254 | GrAuditTrail::AutoCollectBatches* acb = nullptr; |
| 255 | if (at) { |
| 256 | acb = new GrAuditTrail::AutoCollectBatches(at, i); |
| 257 | } |
| 258 | #endif |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 259 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 260 | if (fCommandVector[i]->isVisible()) { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 261 | if (fMegaVizMode && fCommandVector[i]->active()) { |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 262 | // "active" commands execute their visualization behaviors: |
| 263 | // All active saveLayers get replaced with saves so all draws go to the |
| 264 | // visible canvas. |
| 265 | // All active culls draw their cull box |
| 266 | fCommandVector[i]->vizExecute(canvas); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 267 | } else { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 268 | fCommandVector[i]->setUserMatrix(fUserMatrix); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 269 | fCommandVector[i]->execute(canvas); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 270 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 271 | } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 272 | #if SK_SUPPORT_GPU |
| 273 | if (at && acb) { |
| 274 | delete acb; |
| 275 | } |
| 276 | #endif |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 277 | } |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 278 | |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 279 | if (SkColorGetA(fClipVizColor) != 0) { |
| 280 | canvas->save(); |
| 281 | #define LARGE_COORD 1000000000 |
| 282 | canvas->clipRect(SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD), |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 283 | SkCanvas::kReverseDifference_Op); |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 284 | SkPaint clipPaint; |
| 285 | clipPaint.setColor(fClipVizColor); |
| 286 | canvas->drawPaint(clipPaint); |
| 287 | canvas->restore(); |
| 288 | } |
| 289 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 290 | if (fMegaVizMode) { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 291 | canvas->save(); |
| 292 | // nuke the CTM |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 293 | canvas->resetMatrix(); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 294 | // turn off clipping |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 295 | if (!windowRect.isEmpty()) { |
| 296 | SkRect r = windowRect; |
| 297 | r.outset(SK_Scalar1, SK_Scalar1); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 298 | canvas->clipRect(r, SkCanvas::kReplace_Op); |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 299 | } |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 300 | // visualize existing clips |
| 301 | SkDebugClipVisitor visitor(canvas); |
| 302 | |
| 303 | canvas->replayClips(&visitor); |
| 304 | |
| 305 | canvas->restore(); |
| 306 | } |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 307 | if (pathOpsMode) { |
| 308 | this->resetClipStackData(); |
| 309 | const SkClipStack* clipStack = canvas->getClipStack(); |
| 310 | SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart); |
| 311 | const SkClipStack::Element* element; |
| 312 | SkPath devPath; |
| 313 | while ((element = iter.next())) { |
| 314 | SkClipStack::Element::Type type = element->getType(); |
| 315 | SkPath operand; |
| 316 | if (type != SkClipStack::Element::kEmpty_Type) { |
| 317 | element->asPath(&operand); |
| 318 | } |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 319 | SkCanvas::ClipOp elementOp = element->getOp(); |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 320 | this->addClipStackData(devPath, operand, elementOp); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 321 | if (elementOp == SkCanvas::kReplace_Op) { |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 322 | devPath = operand; |
| 323 | } else { |
| 324 | Op(devPath, operand, (SkPathOp) elementOp, &devPath); |
| 325 | } |
| 326 | } |
| 327 | this->lastClipStackData(devPath); |
| 328 | } |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 329 | fMatrix = canvas->getTotalMatrix(); |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 330 | if (!canvas->getClipDeviceBounds(&fClip)) { |
| 331 | fClip.setEmpty(); |
| 332 | } |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 333 | |
| 334 | canvas->restoreToCount(saveCount); |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 335 | |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 336 | #if SK_SUPPORT_GPU |
| 337 | // draw any batches if required and issue a full reset onto GrAuditTrail |
| 338 | if (at) { |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 339 | // just in case there is global reordering, we flush the canvas before querying |
| 340 | // GrAuditTrail |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 341 | GrAuditTrail::AutoEnable ae(at); |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 342 | canvas->flush(); |
| 343 | |
joshualitt | bdc6b2b | 2016-03-01 14:22:02 -0800 | [diff] [blame] | 344 | // we pick three colorblind-safe colors, 75% alpha |
| 345 | static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A); |
| 346 | static const SkColor kOpBatchBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C); |
| 347 | static const SkColor kOtherBatchBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00); |
| 348 | |
joshualitt | 1d7decf | 2016-03-01 07:15:52 -0800 | [diff] [blame] | 349 | // get the render target of the top device so we can ignore batches drawn offscreen |
| 350 | SkBaseDevice* bd = canvas->getDevice_just_for_deprecated_compatibility_testing(); |
| 351 | SkGpuDevice* gbd = reinterpret_cast<SkGpuDevice*>(bd); |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 352 | uint32_t rtID = gbd->accessDrawContext()->accessRenderTarget()->uniqueID(); |
joshualitt | 1d7decf | 2016-03-01 07:15:52 -0800 | [diff] [blame] | 353 | |
| 354 | // get the bounding boxes to draw |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 355 | SkTArray<GrAuditTrail::BatchInfo> childrenBounds; |
joshualitt | 46b301d | 2016-03-02 08:32:37 -0800 | [diff] [blame] | 356 | if (m == -1) { |
| 357 | at->getBoundsByClientID(&childrenBounds, index); |
| 358 | } else { |
| 359 | // the client wants us to draw the mth batch |
| 360 | at->getBoundsByBatchListID(&childrenBounds.push_back(), m); |
| 361 | } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 362 | SkPaint paint; |
| 363 | paint.setStyle(SkPaint::kStroke_Style); |
| 364 | paint.setStrokeWidth(1); |
| 365 | for (int i = 0; i < childrenBounds.count(); i++) { |
joshualitt | 1d7decf | 2016-03-01 07:15:52 -0800 | [diff] [blame] | 366 | if (childrenBounds[i].fRenderTargetUniqueID != rtID) { |
| 367 | // offscreen draw, ignore for now |
| 368 | continue; |
| 369 | } |
joshualitt | bdc6b2b | 2016-03-01 14:22:02 -0800 | [diff] [blame] | 370 | paint.setColor(kTotalBounds); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 371 | canvas->drawRect(childrenBounds[i].fBounds, paint); |
| 372 | for (int j = 0; j < childrenBounds[i].fBatches.count(); j++) { |
| 373 | const GrAuditTrail::BatchInfo::Batch& batch = childrenBounds[i].fBatches[j]; |
| 374 | if (batch.fClientID != index) { |
joshualitt | bdc6b2b | 2016-03-01 14:22:02 -0800 | [diff] [blame] | 375 | paint.setColor(kOtherBatchBounds); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 376 | } else { |
joshualitt | bdc6b2b | 2016-03-01 14:22:02 -0800 | [diff] [blame] | 377 | paint.setColor(kOpBatchBounds); |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 378 | } |
| 379 | canvas->drawRect(batch.fBounds, paint); |
| 380 | } |
| 381 | } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 382 | } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 383 | #endif |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 384 | this->cleanupAuditTrail(canvas); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 385 | } |
| 386 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 387 | void SkDebugCanvas::deleteDrawCommandAt(int index) { |
| 388 | SkASSERT(index < fCommandVector.count()); |
| 389 | delete fCommandVector[index]; |
| 390 | fCommandVector.remove(index); |
| 391 | } |
| 392 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 393 | SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 394 | SkASSERT(index < fCommandVector.count()); |
| 395 | return fCommandVector[index]; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 396 | } |
| 397 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 398 | void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) { |
| 399 | SkASSERT(index < fCommandVector.count()); |
| 400 | delete fCommandVector[index]; |
| 401 | fCommandVector[index] = command; |
| 402 | } |
| 403 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 404 | const SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) const { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 405 | SkASSERT(index < fCommandVector.count()); |
| 406 | return fCommandVector[index]->Info(); |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 407 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 408 | |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 409 | bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 410 | SkASSERT(index < fCommandVector.count()); |
| 411 | return fCommandVector[index]->isVisible(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 412 | } |
| 413 | |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 414 | const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 415 | return fCommandVector; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 416 | } |
| 417 | |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 418 | SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { |
| 419 | return fCommandVector; |
| 420 | } |
| 421 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 422 | GrAuditTrail* SkDebugCanvas::getAuditTrail(SkCanvas* canvas) { |
| 423 | GrAuditTrail* at = nullptr; |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 424 | #if SK_SUPPORT_GPU |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 425 | GrContext* ctx = canvas->getGrContext(); |
| 426 | if (ctx) { |
| 427 | at = ctx->getAuditTrail(); |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 428 | } |
| 429 | #endif |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 430 | return at; |
| 431 | } |
| 432 | |
| 433 | void SkDebugCanvas::drawAndCollectBatches(int n, SkCanvas* canvas) { |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 434 | #if SK_SUPPORT_GPU |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 435 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 436 | if (at) { |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 437 | // loop over all of the commands and draw them, this is to collect reordering |
| 438 | // information |
| 439 | for (int i = 0; i < this->getSize() && i <= n; i++) { |
| 440 | GrAuditTrail::AutoCollectBatches enable(at, i); |
| 441 | fCommandVector[i]->execute(canvas); |
| 442 | } |
| 443 | |
| 444 | // in case there is some kind of global reordering |
| 445 | { |
| 446 | GrAuditTrail::AutoEnable ae(at); |
| 447 | canvas->flush(); |
| 448 | } |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 449 | } |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 450 | #endif |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void SkDebugCanvas::cleanupAuditTrail(SkCanvas* canvas) { |
| 454 | GrAuditTrail* at = this->getAuditTrail(canvas); |
| 455 | if (at) { |
| 456 | #if SK_SUPPORT_GPU |
| 457 | GrAuditTrail::AutoEnable ae(at); |
| 458 | at->fullReset(); |
| 459 | #endif |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) { |
| 464 | this->drawAndCollectBatches(n, canvas); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 465 | |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 466 | // now collect json |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 467 | #if SK_SUPPORT_GPU |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 468 | GrAuditTrail* at = this->getAuditTrail(canvas); |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 469 | #endif |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 470 | Json::Value result = Json::Value(Json::objectValue); |
| 471 | result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION); |
| 472 | Json::Value commands = Json::Value(Json::arrayValue); |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 473 | for (int i = 0; i < this->getSize() && i <= n; i++) { |
joshualitt | e43f7e6 | 2016-03-04 10:45:05 -0800 | [diff] [blame] | 474 | commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager); |
| 475 | #if SK_SUPPORT_GPU |
| 476 | if (at) { |
| 477 | // TODO if this is inefficient we could add a method to GrAuditTrail which takes |
| 478 | // a Json::Value and is only compiled in this file |
| 479 | Json::Value parsedFromString; |
| 480 | Json::Reader reader; |
| 481 | SkAssertResult(reader.parse(at->toJson(i).c_str(), parsedFromString)); |
| 482 | |
| 483 | commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString; |
| 484 | } |
| 485 | #endif |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 486 | } |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 487 | this->cleanupAuditTrail(canvas); |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 488 | result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; |
| 489 | return result; |
| 490 | } |
| 491 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 492 | Json::Value SkDebugCanvas::toJSONBatchList(int n, SkCanvas* canvas) { |
| 493 | this->drawAndCollectBatches(n, canvas); |
| 494 | |
| 495 | Json::Value parsedFromString; |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 496 | #if SK_SUPPORT_GPU |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 497 | GrAuditTrail* at = this->getAuditTrail(canvas); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 498 | if (at) { |
| 499 | GrAuditTrail::AutoManageBatchList enable(at); |
| 500 | Json::Reader reader; |
| 501 | SkAssertResult(reader.parse(at->toJson().c_str(), parsedFromString)); |
| 502 | } |
| 503 | #endif |
| 504 | this->cleanupAuditTrail(canvas); |
| 505 | return parsedFromString; |
| 506 | } |
| 507 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 508 | void SkDebugCanvas::setOverdrawViz(bool overdrawViz) { |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 509 | fOverdrawViz = overdrawViz; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkFilterQuality quality) { |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 513 | fOverrideFilterQuality = overrideTexFiltering; |
| 514 | fFilterQuality = quality; |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 515 | } |
| 516 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 517 | void SkDebugCanvas::onClipPath(const SkPath& path, ClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 518 | this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 519 | } |
| 520 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 521 | void SkDebugCanvas::onClipRect(const SkRect& rect, ClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 522 | this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 523 | } |
| 524 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 525 | void SkDebugCanvas::onClipRRect(const SkRRect& rrect, ClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 526 | this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 527 | } |
| 528 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 529 | void SkDebugCanvas::onClipRegion(const SkRegion& region, ClipOp op) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 530 | this->addDrawCommand(new SkClipRegionCommand(region, op)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 531 | } |
| 532 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 533 | void SkDebugCanvas::didConcat(const SkMatrix& matrix) { |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 534 | this->addDrawCommand(new SkConcatCommand(matrix)); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 535 | this->INHERITED::didConcat(matrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 536 | } |
| 537 | |
reed | 97660cc | 2016-06-28 18:54:19 -0700 | [diff] [blame] | 538 | void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
| 539 | this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value))); |
| 540 | } |
| 541 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 542 | void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, |
| 543 | SkScalar top, const SkPaint* paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 544 | this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 545 | } |
| 546 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 547 | void SkDebugCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 548 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 549 | this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, |
| 550 | (SrcRectConstraint)constraint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 551 | } |
| 552 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 553 | void SkDebugCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 554 | const SkRect& dst, const SkPaint* paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 555 | this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 556 | } |
| 557 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 558 | void SkDebugCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top, |
| 559 | const SkPaint* paint) { |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 560 | this->addDrawCommand(new SkDrawImageCommand(image, left, top, paint)); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | void SkDebugCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 564 | const SkPaint* paint, SrcRectConstraint constraint) { |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 565 | this->addDrawCommand(new SkDrawImageRectCommand(image, src, dst, paint, constraint)); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 566 | } |
| 567 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 568 | void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 569 | this->addDrawCommand(new SkDrawOvalCommand(oval, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 570 | } |
| 571 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 572 | void SkDebugCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 573 | bool useCenter, const SkPaint& paint) { |
| 574 | this->addDrawCommand(new SkDrawArcCommand(oval, startAngle, sweepAngle, useCenter, paint)); |
| 575 | } |
| 576 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 577 | void SkDebugCanvas::onDrawPaint(const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 578 | this->addDrawCommand(new SkDrawPaintCommand(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 579 | } |
| 580 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 581 | void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 582 | this->addDrawCommand(new SkDrawPathCommand(path, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 583 | } |
| 584 | |
mtklein | f0f1411 | 2014-12-12 08:46:25 -0800 | [diff] [blame] | 585 | void SkDebugCanvas::onDrawPicture(const SkPicture* picture, |
| 586 | const SkMatrix* matrix, |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 587 | const SkPaint* paint) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 588 | this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint)); |
ethannicholas | 891ad66 | 2016-02-12 07:15:45 -0800 | [diff] [blame] | 589 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 590 | picture->playback(this); |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 591 | this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint))); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 592 | } |
| 593 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 594 | void SkDebugCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| 595 | const SkMatrix* matrix, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 596 | const SkPaint* paint, |
| 597 | const SkShadowParams& params) { |
| 598 | this->addDrawCommand(new SkBeginDrawShadowedPictureCommand(picture, matrix, paint, params)); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 599 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 600 | picture->playback(this); |
| 601 | this->addDrawCommand(new SkEndDrawShadowedPictureCommand(SkToBool(matrix) || SkToBool(paint))); |
| 602 | } |
| 603 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 604 | void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count, |
| 605 | const SkPoint pts[], const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 606 | this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 607 | } |
| 608 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 609 | void SkDebugCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 610 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 611 | this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 612 | } |
| 613 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 614 | void SkDebugCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 615 | SkScalar constY, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 616 | this->addDrawCommand( |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 617 | new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 618 | } |
| 619 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 620 | void SkDebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 621 | // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 622 | addDrawCommand(new SkDrawRectCommand(rect, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 623 | } |
| 624 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 625 | void SkDebugCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 626 | this->addDrawCommand(new SkDrawRRectCommand(rrect, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 627 | } |
| 628 | |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 629 | void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 630 | const SkPaint& paint) { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 631 | this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint)); |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 632 | } |
| 633 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 634 | void SkDebugCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 635 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 636 | this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 637 | } |
| 638 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 639 | void SkDebugCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 640 | const SkMatrix* matrix, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 641 | this->addDrawCommand( |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 642 | new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 643 | } |
| 644 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 645 | void SkDebugCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 646 | const SkRect* cull, const SkPaint& paint) { |
| 647 | this->addDrawCommand(new SkDrawTextRSXformCommand(text, byteLength, xform, cull, paint)); |
| 648 | } |
| 649 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 650 | void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 651 | const SkPaint& paint) { |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 652 | this->addDrawCommand(new SkDrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)), |
| 653 | x, y, paint)); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 654 | } |
| 655 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 656 | void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 657 | const SkPoint texCoords[4], SkXfermode* xmode, |
| 658 | const SkPaint& paint) { |
| 659 | this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, xmode, paint)); |
| 660 | } |
| 661 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 662 | void SkDebugCanvas::onDrawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], |
| 663 | const SkPoint texs[], const SkColor colors[], |
| 664 | SkXfermode*, const uint16_t indices[], int indexCount, |
| 665 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 666 | this->addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 667 | texs, colors, nullptr, indices, indexCount, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 668 | } |
| 669 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 670 | void SkDebugCanvas::willRestore() { |
| 671 | this->addDrawCommand(new SkRestoreCommand()); |
| 672 | this->INHERITED::willRestore(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 675 | void SkDebugCanvas::willSave() { |
| 676 | this->addDrawCommand(new SkSaveCommand()); |
| 677 | this->INHERITED::willSave(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 678 | } |
| 679 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 680 | SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { |
| 681 | this->addDrawCommand(new SkSaveLayerCommand(rec)); |
| 682 | (void)this->INHERITED::getSaveLayerStrategy(rec); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 683 | // No need for a full layer. |
| 684 | return kNoLayer_SaveLayerStrategy; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 685 | } |
| 686 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 687 | void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 688 | this->addDrawCommand(new SkSetMatrixCommand(matrix)); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 689 | this->INHERITED::didSetMatrix(matrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 690 | } |
| 691 | |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 692 | void SkDebugCanvas::didTranslateZ(SkScalar z) { |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 693 | #ifdef SK_EXPERIMENTAL_SHADOWING |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 694 | this->addDrawCommand(new SkTranslateZCommand(z)); |
| 695 | this->INHERITED::didTranslateZ(z); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 696 | #endif |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 697 | } |
| 698 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 699 | void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 700 | SkASSERT(index < fCommandVector.count()); |
| 701 | fCommandVector[index]->setVisible(toggle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 702 | } |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 703 | |
| 704 | static const char* gFillTypeStrs[] = { |
| 705 | "kWinding_FillType", |
| 706 | "kEvenOdd_FillType", |
| 707 | "kInverseWinding_FillType", |
| 708 | "kInverseEvenOdd_FillType" |
| 709 | }; |
| 710 | |
| 711 | static const char* gOpStrs[] = { |
scroggo | 5965b73 | 2015-04-07 06:53:21 -0700 | [diff] [blame] | 712 | "kDifference_PathOp", |
| 713 | "kIntersect_PathOp", |
| 714 | "kUnion_PathOp", |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 715 | "kXor_PathOp", |
scroggo | 5965b73 | 2015-04-07 06:53:21 -0700 | [diff] [blame] | 716 | "kReverseDifference_PathOp", |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | static const char kHTML4SpaceIndent[] = " "; |
| 720 | |
| 721 | void SkDebugCanvas::outputScalar(SkScalar num) { |
| 722 | if (num == (int) num) { |
| 723 | fClipStackData.appendf("%d", (int) num); |
| 724 | } else { |
| 725 | SkString str; |
| 726 | str.printf("%1.9g", num); |
| 727 | int width = (int) str.size(); |
| 728 | const char* cStr = str.c_str(); |
| 729 | while (cStr[width - 1] == '0') { |
| 730 | --width; |
| 731 | } |
| 732 | str.resize(width); |
| 733 | fClipStackData.appendf("%sf", str.c_str()); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | void SkDebugCanvas::outputPointsCommon(const SkPoint* pts, int count) { |
| 738 | for (int index = 0; index < count; ++index) { |
| 739 | this->outputScalar(pts[index].fX); |
| 740 | fClipStackData.appendf(", "); |
| 741 | this->outputScalar(pts[index].fY); |
| 742 | if (index + 1 < count) { |
| 743 | fClipStackData.appendf(", "); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | void SkDebugCanvas::outputPoints(const SkPoint* pts, int count) { |
| 749 | this->outputPointsCommon(pts, count); |
| 750 | fClipStackData.appendf(");<br>"); |
| 751 | } |
| 752 | |
| 753 | void SkDebugCanvas::outputConicPoints(const SkPoint* pts, SkScalar weight) { |
| 754 | this->outputPointsCommon(pts, 2); |
| 755 | fClipStackData.appendf(", "); |
| 756 | this->outputScalar(weight); |
| 757 | fClipStackData.appendf(");<br>"); |
| 758 | } |
| 759 | |
| 760 | void SkDebugCanvas::addPathData(const SkPath& path, const char* pathName) { |
| 761 | SkPath::RawIter iter(path); |
| 762 | SkPath::FillType fillType = path.getFillType(); |
| 763 | fClipStackData.appendf("%sSkPath %s;<br>", kHTML4SpaceIndent, pathName); |
| 764 | fClipStackData.appendf("%s%s.setFillType(SkPath::%s);<br>", kHTML4SpaceIndent, pathName, |
| 765 | gFillTypeStrs[fillType]); |
| 766 | iter.setPath(path); |
| 767 | uint8_t verb; |
| 768 | SkPoint pts[4]; |
| 769 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 770 | switch (verb) { |
| 771 | case SkPath::kMove_Verb: |
| 772 | fClipStackData.appendf("%s%s.moveTo(", kHTML4SpaceIndent, pathName); |
| 773 | this->outputPoints(&pts[0], 1); |
| 774 | continue; |
| 775 | case SkPath::kLine_Verb: |
| 776 | fClipStackData.appendf("%s%s.lineTo(", kHTML4SpaceIndent, pathName); |
| 777 | this->outputPoints(&pts[1], 1); |
| 778 | break; |
| 779 | case SkPath::kQuad_Verb: |
| 780 | fClipStackData.appendf("%s%s.quadTo(", kHTML4SpaceIndent, pathName); |
| 781 | this->outputPoints(&pts[1], 2); |
| 782 | break; |
| 783 | case SkPath::kConic_Verb: |
| 784 | fClipStackData.appendf("%s%s.conicTo(", kHTML4SpaceIndent, pathName); |
| 785 | this->outputConicPoints(&pts[1], iter.conicWeight()); |
| 786 | break; |
| 787 | case SkPath::kCubic_Verb: |
| 788 | fClipStackData.appendf("%s%s.cubicTo(", kHTML4SpaceIndent, pathName); |
| 789 | this->outputPoints(&pts[1], 3); |
| 790 | break; |
| 791 | case SkPath::kClose_Verb: |
| 792 | fClipStackData.appendf("%s%s.close();<br>", kHTML4SpaceIndent, pathName); |
| 793 | break; |
| 794 | default: |
| 795 | SkDEBUGFAIL("bad verb"); |
| 796 | return; |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | void SkDebugCanvas::addClipStackData(const SkPath& devPath, const SkPath& operand, |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 802 | SkCanvas::ClipOp elementOp) { |
| 803 | if (elementOp == SkCanvas::kReplace_Op) { |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 804 | if (!lastClipStackData(devPath)) { |
| 805 | fSaveDevPath = operand; |
| 806 | } |
| 807 | fCalledAddStackData = false; |
| 808 | } else { |
| 809 | fClipStackData.appendf("<br>static void test(skiatest::Reporter* reporter," |
| 810 | " const char* filename) {<br>"); |
| 811 | addPathData(fCalledAddStackData ? devPath : fSaveDevPath, "path"); |
| 812 | addPathData(operand, "pathB"); |
| 813 | fClipStackData.appendf("%stestPathOp(reporter, path, pathB, %s, filename);<br>", |
| 814 | kHTML4SpaceIndent, gOpStrs[elementOp]); |
| 815 | fClipStackData.appendf("}<br>"); |
| 816 | fCalledAddStackData = true; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { |
| 821 | if (fCalledAddStackData) { |
| 822 | fClipStackData.appendf("<br>"); |
| 823 | addPathData(devPath, "pathOut"); |
| 824 | return true; |
| 825 | } |
| 826 | return false; |
| 827 | } |