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