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@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 12 | #include "SkDevice.h" |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 13 | #include "SkPaintFilterCanvas.h" |
robertphillips | f42fca4 | 2016-01-27 05:00:04 -0800 | [diff] [blame] | 14 | #include "SkOverdrawMode.h" |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 15 | |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 16 | #define SKDEBUGCANVAS_VERSION 1 |
| 17 | #define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version" |
| 18 | #define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands" |
| 19 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 20 | class DebugPaintFilterCanvas : public SkPaintFilterCanvas { |
| 21 | public: |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 22 | DebugPaintFilterCanvas(int width, |
| 23 | int height, |
| 24 | bool overdrawViz, |
| 25 | bool overrideFilterQuality, |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 26 | SkFilterQuality quality) |
| 27 | : INHERITED(width, height) |
robertphillips | f42fca4 | 2016-01-27 05:00:04 -0800 | [diff] [blame] | 28 | , fOverdrawXfermode(overdrawViz ? SkOverdrawMode::Create() : nullptr) |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 29 | , fOverrideFilterQuality(overrideFilterQuality) |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 30 | , fFilterQuality(quality) {} |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 31 | |
| 32 | protected: |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 33 | bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override { |
| 34 | if (*paint) { |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 35 | if (nullptr != fOverdrawXfermode.get()) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 36 | paint->writable()->setAntiAlias(false); |
| 37 | paint->writable()->setXfermode(fOverdrawXfermode.get()); |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 38 | } |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 39 | |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 40 | if (fOverrideFilterQuality) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 41 | paint->writable()->setFilterQuality(fFilterQuality); |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 42 | } |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 43 | } |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 44 | return true; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 45 | } |
| 46 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 47 | void onDrawPicture(const SkPicture* picture, |
| 48 | const SkMatrix* matrix, |
| 49 | const SkPaint* paint) override { |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 50 | // We need to replay the picture onto this canvas in order to filter its internal paints. |
| 51 | this->SkCanvas::onDrawPicture(picture, matrix, paint); |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | SkAutoTUnref<SkXfermode> fOverdrawXfermode; |
| 56 | |
| 57 | bool fOverrideFilterQuality; |
| 58 | SkFilterQuality fFilterQuality; |
| 59 | |
| 60 | typedef SkPaintFilterCanvas INHERITED; |
| 61 | }; |
| 62 | |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 63 | SkDebugCanvas::SkDebugCanvas(int width, int height) |
| 64 | : INHERITED(width, height) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 65 | , fPicture(nullptr) |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 66 | , fFilter(false) |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 67 | , fMegaVizMode(false) |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 68 | , fOverdrawViz(false) |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 69 | , fOverrideFilterQuality(false) |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 70 | , fFilterQuality(kNone_SkFilterQuality) |
| 71 | , fClipVizColor(SK_ColorTRANSPARENT) { |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 72 | fUserMatrix.reset(); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 73 | |
| 74 | // SkPicturePlayback uses the base-class' quickReject calls to cull clipped |
| 75 | // operations. This can lead to problems in the debugger which expects all |
| 76 | // the operations in the captured skp to appear in the debug canvas. To |
| 77 | // circumvent this we create a wide open clip here (an empty clip rect |
| 78 | // is not sufficient). |
| 79 | // Internally, the SkRect passed to clipRect is converted to an SkIRect and |
| 80 | // rounded out. The following code creates a nearly maximal rect that will |
| 81 | // not get collapsed by the coming conversions (Due to precision loss the |
| 82 | // inset has to be surprisingly large). |
| 83 | SkIRect largeIRect = SkIRect::MakeLargest(); |
| 84 | largeIRect.inset(1024, 1024); |
robertphillips@google.com | 6c1e49a | 2013-11-10 15:08:45 +0000 | [diff] [blame] | 85 | SkRect large = SkRect::Make(largeIRect); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 86 | #ifdef SK_DEBUG |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 87 | SkASSERT(!large.roundOut().isEmpty()); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 88 | #endif |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 89 | // call the base class' version to avoid adding a draw command |
| 90 | this->INHERITED::onClipRect(large, SkRegion::kReplace_Op, kHard_ClipEdgeStyle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 91 | } |
| 92 | |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 93 | SkDebugCanvas::~SkDebugCanvas() { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 94 | fCommandVector.deleteAll(); |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 95 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 96 | |
| 97 | void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 98 | fCommandVector.push(command); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void SkDebugCanvas::draw(SkCanvas* canvas) { |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 102 | if (!fCommandVector.isEmpty()) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 103 | this->drawTo(canvas, fCommandVector.count() - 1); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 107 | void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 108 | canvas->concat(fUserMatrix); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 112 | SkBitmap bitmap; |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 113 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 114 | |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 115 | SkCanvas canvas(bitmap); |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 116 | canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y)); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 117 | this->applyUserTransform(&canvas); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 118 | |
| 119 | int layer = 0; |
chudy@google.com | 751961d | 2012-07-31 20:07:42 +0000 | [diff] [blame] | 120 | SkColor prev = bitmap.getColor(0,0); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 121 | for (int i = 0; i < index; i++) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 122 | if (fCommandVector[i]->isVisible()) { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 123 | fCommandVector[i]->setUserMatrix(fUserMatrix); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 124 | fCommandVector[i]->execute(&canvas); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 125 | } |
| 126 | if (prev != bitmap.getColor(0,0)) { |
| 127 | layer = i; |
| 128 | } |
| 129 | prev = bitmap.getColor(0,0); |
| 130 | } |
| 131 | return layer; |
| 132 | } |
| 133 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 134 | class SkDebugClipVisitor : public SkCanvas::ClipVisitor { |
| 135 | public: |
| 136 | SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {} |
| 137 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 138 | void clipRect(const SkRect& r, SkRegion::Op, bool doAA) override { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 139 | SkPaint p; |
| 140 | p.setColor(SK_ColorRED); |
| 141 | p.setStyle(SkPaint::kStroke_Style); |
| 142 | p.setAntiAlias(doAA); |
| 143 | fCanvas->drawRect(r, p); |
| 144 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 145 | void clipRRect(const SkRRect& rr, SkRegion::Op, bool doAA) override { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 146 | SkPaint p; |
| 147 | p.setColor(SK_ColorGREEN); |
| 148 | p.setStyle(SkPaint::kStroke_Style); |
| 149 | p.setAntiAlias(doAA); |
| 150 | fCanvas->drawRRect(rr, p); |
| 151 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 152 | void clipPath(const SkPath& path, SkRegion::Op, bool doAA) override { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 153 | SkPaint p; |
| 154 | p.setColor(SK_ColorBLUE); |
| 155 | p.setStyle(SkPaint::kStroke_Style); |
| 156 | p.setAntiAlias(doAA); |
| 157 | fCanvas->drawPath(path, p); |
| 158 | } |
| 159 | |
| 160 | protected: |
| 161 | SkCanvas* fCanvas; |
| 162 | |
| 163 | private: |
| 164 | typedef SkCanvas::ClipVisitor INHERITED; |
| 165 | }; |
| 166 | |
| 167 | // set up the saveLayer commands so that the active ones |
| 168 | // return true in their 'active' method |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 169 | void SkDebugCanvas::markActiveCommands(int index) { |
| 170 | fActiveLayers.rewind(); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 171 | |
| 172 | for (int i = 0; i < fCommandVector.count(); ++i) { |
| 173 | fCommandVector[i]->setActive(false); |
| 174 | } |
| 175 | |
| 176 | for (int i = 0; i < index; ++i) { |
| 177 | SkDrawCommand::Action result = fCommandVector[i]->action(); |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 178 | if (SkDrawCommand::kPushLayer_Action == result) { |
| 179 | fActiveLayers.push(fCommandVector[i]); |
| 180 | } else if (SkDrawCommand::kPopLayer_Action == result) { |
| 181 | fActiveLayers.pop(); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 185 | for (int i = 0; i < fActiveLayers.count(); ++i) { |
| 186 | fActiveLayers[i]->setActive(true); |
| 187 | } |
| 188 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 189 | } |
| 190 | |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 191 | void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 192 | SkASSERT(!fCommandVector.isEmpty()); |
| 193 | SkASSERT(index < fCommandVector.count()); |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 194 | |
| 195 | int saveCount = canvas->save(); |
| 196 | |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 197 | SkRect windowRect = SkRect::MakeWH(SkIntToScalar(canvas->getBaseLayerSize().width()), |
| 198 | SkIntToScalar(canvas->getBaseLayerSize().height())); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 199 | |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 200 | bool pathOpsMode = getAllowSimplifyClip(); |
| 201 | canvas->setAllowSimplifyClip(pathOpsMode); |
ethannicholas | cecbbe2 | 2016-02-17 11:49:43 -0800 | [diff] [blame] | 202 | canvas->clear(SK_ColorWHITE); |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 203 | canvas->resetMatrix(); |
| 204 | if (!windowRect.isEmpty()) { |
| 205 | canvas->clipRect(windowRect, SkRegion::kReplace_Op); |
commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 206 | } |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 207 | this->applyUserTransform(canvas); |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 208 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 209 | if (fPaintFilterCanvas) { |
| 210 | fPaintFilterCanvas->addCanvas(canvas); |
| 211 | canvas = fPaintFilterCanvas.get(); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 212 | } |
| 213 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 214 | if (fMegaVizMode) { |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 215 | this->markActiveCommands(index); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 216 | } |
| 217 | |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 218 | for (int i = 0; i <= index; i++) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 219 | if (i == index && fFilter) { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 220 | canvas->clear(0xAAFFFFFF); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 221 | } |
| 222 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 223 | if (fCommandVector[i]->isVisible()) { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 224 | if (fMegaVizMode && fCommandVector[i]->active()) { |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 225 | // "active" commands execute their visualization behaviors: |
| 226 | // All active saveLayers get replaced with saves so all draws go to the |
| 227 | // visible canvas. |
| 228 | // All active culls draw their cull box |
| 229 | fCommandVector[i]->vizExecute(canvas); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 230 | } else { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 231 | fCommandVector[i]->setUserMatrix(fUserMatrix); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 232 | fCommandVector[i]->execute(canvas); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 233 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 234 | } |
| 235 | } |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 236 | |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 237 | if (SkColorGetA(fClipVizColor) != 0) { |
| 238 | canvas->save(); |
| 239 | #define LARGE_COORD 1000000000 |
| 240 | canvas->clipRect(SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD), |
| 241 | SkRegion::kReverseDifference_Op); |
| 242 | SkPaint clipPaint; |
| 243 | clipPaint.setColor(fClipVizColor); |
| 244 | canvas->drawPaint(clipPaint); |
| 245 | canvas->restore(); |
| 246 | } |
| 247 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 248 | if (fMegaVizMode) { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 249 | canvas->save(); |
| 250 | // nuke the CTM |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 251 | canvas->resetMatrix(); |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 252 | // turn off clipping |
kkinnunen | 26e5400 | 2015-01-05 12:58:56 -0800 | [diff] [blame] | 253 | if (!windowRect.isEmpty()) { |
| 254 | SkRect r = windowRect; |
| 255 | r.outset(SK_Scalar1, SK_Scalar1); |
| 256 | canvas->clipRect(r, SkRegion::kReplace_Op); |
| 257 | } |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 258 | // visualize existing clips |
| 259 | SkDebugClipVisitor visitor(canvas); |
| 260 | |
| 261 | canvas->replayClips(&visitor); |
| 262 | |
| 263 | canvas->restore(); |
| 264 | } |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 265 | if (pathOpsMode) { |
| 266 | this->resetClipStackData(); |
| 267 | const SkClipStack* clipStack = canvas->getClipStack(); |
| 268 | SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart); |
| 269 | const SkClipStack::Element* element; |
| 270 | SkPath devPath; |
| 271 | while ((element = iter.next())) { |
| 272 | SkClipStack::Element::Type type = element->getType(); |
| 273 | SkPath operand; |
| 274 | if (type != SkClipStack::Element::kEmpty_Type) { |
| 275 | element->asPath(&operand); |
| 276 | } |
| 277 | SkRegion::Op elementOp = element->getOp(); |
| 278 | this->addClipStackData(devPath, operand, elementOp); |
| 279 | if (elementOp == SkRegion::kReplace_Op) { |
| 280 | devPath = operand; |
| 281 | } else { |
| 282 | Op(devPath, operand, (SkPathOp) elementOp, &devPath); |
| 283 | } |
| 284 | } |
| 285 | this->lastClipStackData(devPath); |
| 286 | } |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 287 | fMatrix = canvas->getTotalMatrix(); |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 288 | if (!canvas->getClipDeviceBounds(&fClip)) { |
| 289 | fClip.setEmpty(); |
| 290 | } |
kkinnunen | 26a00de | 2015-01-13 23:09:19 -0800 | [diff] [blame] | 291 | |
| 292 | canvas->restoreToCount(saveCount); |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 293 | |
| 294 | if (fPaintFilterCanvas) { |
| 295 | fPaintFilterCanvas->removeAll(); |
| 296 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 297 | } |
| 298 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 299 | void SkDebugCanvas::deleteDrawCommandAt(int index) { |
| 300 | SkASSERT(index < fCommandVector.count()); |
| 301 | delete fCommandVector[index]; |
| 302 | fCommandVector.remove(index); |
| 303 | } |
| 304 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 305 | SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 306 | SkASSERT(index < fCommandVector.count()); |
| 307 | return fCommandVector[index]; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 308 | } |
| 309 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 310 | void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) { |
| 311 | SkASSERT(index < fCommandVector.count()); |
| 312 | delete fCommandVector[index]; |
| 313 | fCommandVector[index] = command; |
| 314 | } |
| 315 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 316 | const SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) const { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 317 | SkASSERT(index < fCommandVector.count()); |
| 318 | return fCommandVector[index]->Info(); |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 319 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 320 | |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 321 | bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 322 | SkASSERT(index < fCommandVector.count()); |
| 323 | return fCommandVector[index]->isVisible(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 324 | } |
| 325 | |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 326 | const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 327 | return fCommandVector; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 328 | } |
| 329 | |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 330 | SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { |
| 331 | return fCommandVector; |
| 332 | } |
| 333 | |
joshualitt | 6b3cf73 | 2016-02-17 11:20:26 -0800 | [diff] [blame] | 334 | Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) { |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 335 | Json::Value result = Json::Value(Json::objectValue); |
| 336 | result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION); |
| 337 | Json::Value commands = Json::Value(Json::arrayValue); |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 338 | for (int i = 0; i < this->getSize() && i <= n; i++) { |
joshualitt | 6b3cf73 | 2016-02-17 11:20:26 -0800 | [diff] [blame] | 339 | commands[i] = this->getDrawCommandAt(i)->drawToAndCollectJSON(canvas, urlDataManager); |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 340 | } |
| 341 | result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; |
| 342 | return result; |
| 343 | } |
| 344 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 345 | void SkDebugCanvas::updatePaintFilterCanvas() { |
| 346 | if (!fOverdrawViz && !fOverrideFilterQuality) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 347 | fPaintFilterCanvas.reset(nullptr); |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 348 | return; |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 349 | } |
| 350 | |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 351 | const SkImageInfo info = this->imageInfo(); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 352 | fPaintFilterCanvas.reset(new DebugPaintFilterCanvas(info.width(), info.height(), fOverdrawViz, |
| 353 | fOverrideFilterQuality, fFilterQuality)); |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void SkDebugCanvas::setOverdrawViz(bool overdrawViz) { |
| 357 | if (fOverdrawViz == overdrawViz) { |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | fOverdrawViz = overdrawViz; |
| 362 | this->updatePaintFilterCanvas(); |
| 363 | } |
| 364 | |
| 365 | void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkFilterQuality quality) { |
| 366 | if (fOverrideFilterQuality == overrideTexFiltering && fFilterQuality == quality) { |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | fOverrideFilterQuality = overrideTexFiltering; |
| 371 | fFilterQuality = quality; |
| 372 | this->updatePaintFilterCanvas(); |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 373 | } |
| 374 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 375 | void SkDebugCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
| 376 | this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 377 | } |
| 378 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 379 | void SkDebugCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
| 380 | this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 381 | } |
| 382 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 383 | void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
| 384 | this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 385 | } |
| 386 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 387 | void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) { |
| 388 | this->addDrawCommand(new SkClipRegionCommand(region, op)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 389 | } |
| 390 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 391 | void SkDebugCanvas::didConcat(const SkMatrix& matrix) { |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 392 | this->addDrawCommand(new SkConcatCommand(matrix)); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 393 | this->INHERITED::didConcat(matrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 394 | } |
| 395 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 396 | void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, |
| 397 | SkScalar top, const SkPaint* paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 398 | this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 399 | } |
| 400 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 401 | void SkDebugCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 402 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 403 | this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, |
| 404 | (SrcRectConstraint)constraint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 405 | } |
| 406 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 407 | void SkDebugCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 408 | const SkRect& dst, const SkPaint* paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 409 | this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 410 | } |
| 411 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 412 | void SkDebugCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top, |
| 413 | const SkPaint* paint) { |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 414 | this->addDrawCommand(new SkDrawImageCommand(image, left, top, paint)); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | void SkDebugCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 418 | const SkPaint* paint, SrcRectConstraint constraint) { |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 419 | this->addDrawCommand(new SkDrawImageRectCommand(image, src, dst, paint, constraint)); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 420 | } |
| 421 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 422 | void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 423 | this->addDrawCommand(new SkDrawOvalCommand(oval, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 424 | } |
| 425 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 426 | void SkDebugCanvas::onDrawPaint(const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 427 | this->addDrawCommand(new SkDrawPaintCommand(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 428 | } |
| 429 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 430 | void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 431 | this->addDrawCommand(new SkDrawPathCommand(path, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 432 | } |
| 433 | |
mtklein | f0f1411 | 2014-12-12 08:46:25 -0800 | [diff] [blame] | 434 | void SkDebugCanvas::onDrawPicture(const SkPicture* picture, |
| 435 | const SkMatrix* matrix, |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 436 | const SkPaint* paint) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 437 | this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint)); |
ethannicholas | 891ad66 | 2016-02-12 07:15:45 -0800 | [diff] [blame] | 438 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 439 | picture->playback(this); |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 440 | this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint))); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 441 | } |
| 442 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 443 | void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count, |
| 444 | const SkPoint pts[], const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 445 | this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 446 | } |
| 447 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 448 | void SkDebugCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 449 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 450 | this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 451 | } |
| 452 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 453 | void SkDebugCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 454 | SkScalar constY, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 455 | this->addDrawCommand( |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 456 | new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 457 | } |
| 458 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 459 | void SkDebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 460 | // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 461 | addDrawCommand(new SkDrawRectCommand(rect, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 462 | } |
| 463 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 464 | void SkDebugCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 465 | this->addDrawCommand(new SkDrawRRectCommand(rrect, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 466 | } |
| 467 | |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 468 | void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 469 | const SkPaint& paint) { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 470 | this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint)); |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 471 | } |
| 472 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 473 | void SkDebugCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 474 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 475 | this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 476 | } |
| 477 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 478 | void SkDebugCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 479 | const SkMatrix* matrix, const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 480 | this->addDrawCommand( |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 481 | new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 482 | } |
| 483 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 484 | void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 485 | const SkPaint& paint) { |
| 486 | this->addDrawCommand(new SkDrawTextBlobCommand(blob, x, y, paint)); |
| 487 | } |
| 488 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 489 | void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 490 | const SkPoint texCoords[4], SkXfermode* xmode, |
| 491 | const SkPaint& paint) { |
| 492 | this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, xmode, paint)); |
| 493 | } |
| 494 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 495 | void SkDebugCanvas::onDrawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], |
| 496 | const SkPoint texs[], const SkColor colors[], |
| 497 | SkXfermode*, const uint16_t indices[], int indexCount, |
| 498 | const SkPaint& paint) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 499 | this->addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 500 | texs, colors, nullptr, indices, indexCount, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 501 | } |
| 502 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 503 | void SkDebugCanvas::willRestore() { |
| 504 | this->addDrawCommand(new SkRestoreCommand()); |
| 505 | this->INHERITED::willRestore(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 508 | void SkDebugCanvas::willSave() { |
| 509 | this->addDrawCommand(new SkSaveCommand()); |
| 510 | this->INHERITED::willSave(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 511 | } |
| 512 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 513 | SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { |
| 514 | this->addDrawCommand(new SkSaveLayerCommand(rec)); |
| 515 | (void)this->INHERITED::getSaveLayerStrategy(rec); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 516 | // No need for a full layer. |
| 517 | return kNoLayer_SaveLayerStrategy; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 518 | } |
| 519 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 520 | void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 521 | this->addDrawCommand(new SkSetMatrixCommand(matrix)); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 522 | this->INHERITED::didSetMatrix(matrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 523 | } |
| 524 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 525 | void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 526 | SkASSERT(index < fCommandVector.count()); |
| 527 | fCommandVector[index]->setVisible(toggle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 528 | } |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 529 | |
| 530 | static const char* gFillTypeStrs[] = { |
| 531 | "kWinding_FillType", |
| 532 | "kEvenOdd_FillType", |
| 533 | "kInverseWinding_FillType", |
| 534 | "kInverseEvenOdd_FillType" |
| 535 | }; |
| 536 | |
| 537 | static const char* gOpStrs[] = { |
scroggo | 5965b73 | 2015-04-07 06:53:21 -0700 | [diff] [blame] | 538 | "kDifference_PathOp", |
| 539 | "kIntersect_PathOp", |
| 540 | "kUnion_PathOp", |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 541 | "kXor_PathOp", |
scroggo | 5965b73 | 2015-04-07 06:53:21 -0700 | [diff] [blame] | 542 | "kReverseDifference_PathOp", |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 543 | }; |
| 544 | |
| 545 | static const char kHTML4SpaceIndent[] = " "; |
| 546 | |
| 547 | void SkDebugCanvas::outputScalar(SkScalar num) { |
| 548 | if (num == (int) num) { |
| 549 | fClipStackData.appendf("%d", (int) num); |
| 550 | } else { |
| 551 | SkString str; |
| 552 | str.printf("%1.9g", num); |
| 553 | int width = (int) str.size(); |
| 554 | const char* cStr = str.c_str(); |
| 555 | while (cStr[width - 1] == '0') { |
| 556 | --width; |
| 557 | } |
| 558 | str.resize(width); |
| 559 | fClipStackData.appendf("%sf", str.c_str()); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | void SkDebugCanvas::outputPointsCommon(const SkPoint* pts, int count) { |
| 564 | for (int index = 0; index < count; ++index) { |
| 565 | this->outputScalar(pts[index].fX); |
| 566 | fClipStackData.appendf(", "); |
| 567 | this->outputScalar(pts[index].fY); |
| 568 | if (index + 1 < count) { |
| 569 | fClipStackData.appendf(", "); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | void SkDebugCanvas::outputPoints(const SkPoint* pts, int count) { |
| 575 | this->outputPointsCommon(pts, count); |
| 576 | fClipStackData.appendf(");<br>"); |
| 577 | } |
| 578 | |
| 579 | void SkDebugCanvas::outputConicPoints(const SkPoint* pts, SkScalar weight) { |
| 580 | this->outputPointsCommon(pts, 2); |
| 581 | fClipStackData.appendf(", "); |
| 582 | this->outputScalar(weight); |
| 583 | fClipStackData.appendf(");<br>"); |
| 584 | } |
| 585 | |
| 586 | void SkDebugCanvas::addPathData(const SkPath& path, const char* pathName) { |
| 587 | SkPath::RawIter iter(path); |
| 588 | SkPath::FillType fillType = path.getFillType(); |
| 589 | fClipStackData.appendf("%sSkPath %s;<br>", kHTML4SpaceIndent, pathName); |
| 590 | fClipStackData.appendf("%s%s.setFillType(SkPath::%s);<br>", kHTML4SpaceIndent, pathName, |
| 591 | gFillTypeStrs[fillType]); |
| 592 | iter.setPath(path); |
| 593 | uint8_t verb; |
| 594 | SkPoint pts[4]; |
| 595 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 596 | switch (verb) { |
| 597 | case SkPath::kMove_Verb: |
| 598 | fClipStackData.appendf("%s%s.moveTo(", kHTML4SpaceIndent, pathName); |
| 599 | this->outputPoints(&pts[0], 1); |
| 600 | continue; |
| 601 | case SkPath::kLine_Verb: |
| 602 | fClipStackData.appendf("%s%s.lineTo(", kHTML4SpaceIndent, pathName); |
| 603 | this->outputPoints(&pts[1], 1); |
| 604 | break; |
| 605 | case SkPath::kQuad_Verb: |
| 606 | fClipStackData.appendf("%s%s.quadTo(", kHTML4SpaceIndent, pathName); |
| 607 | this->outputPoints(&pts[1], 2); |
| 608 | break; |
| 609 | case SkPath::kConic_Verb: |
| 610 | fClipStackData.appendf("%s%s.conicTo(", kHTML4SpaceIndent, pathName); |
| 611 | this->outputConicPoints(&pts[1], iter.conicWeight()); |
| 612 | break; |
| 613 | case SkPath::kCubic_Verb: |
| 614 | fClipStackData.appendf("%s%s.cubicTo(", kHTML4SpaceIndent, pathName); |
| 615 | this->outputPoints(&pts[1], 3); |
| 616 | break; |
| 617 | case SkPath::kClose_Verb: |
| 618 | fClipStackData.appendf("%s%s.close();<br>", kHTML4SpaceIndent, pathName); |
| 619 | break; |
| 620 | default: |
| 621 | SkDEBUGFAIL("bad verb"); |
| 622 | return; |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | void SkDebugCanvas::addClipStackData(const SkPath& devPath, const SkPath& operand, |
| 628 | SkRegion::Op elementOp) { |
| 629 | if (elementOp == SkRegion::kReplace_Op) { |
| 630 | if (!lastClipStackData(devPath)) { |
| 631 | fSaveDevPath = operand; |
| 632 | } |
| 633 | fCalledAddStackData = false; |
| 634 | } else { |
| 635 | fClipStackData.appendf("<br>static void test(skiatest::Reporter* reporter," |
| 636 | " const char* filename) {<br>"); |
| 637 | addPathData(fCalledAddStackData ? devPath : fSaveDevPath, "path"); |
| 638 | addPathData(operand, "pathB"); |
| 639 | fClipStackData.appendf("%stestPathOp(reporter, path, pathB, %s, filename);<br>", |
| 640 | kHTML4SpaceIndent, gOpStrs[elementOp]); |
| 641 | fClipStackData.appendf("}<br>"); |
| 642 | fCalledAddStackData = true; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { |
| 647 | if (fCalledAddStackData) { |
| 648 | fClipStackData.appendf("<br>"); |
| 649 | addPathData(devPath, "pathOut"); |
| 650 | return true; |
| 651 | } |
| 652 | return false; |
| 653 | } |