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