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