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