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