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