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