chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 10 | #include "SkColorPriv.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 11 | #include "SkDebugCanvas.h" |
| 12 | #include "SkDrawCommand.h" |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 13 | #include "SkDrawFilter.h" |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 14 | #include "SkDevice.h" |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 15 | #include "SkXfermode.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 16 | |
reed@google.com | 6ae24e0 | 2012-09-26 13:44:13 +0000 | [diff] [blame] | 17 | SkDebugCanvas::SkDebugCanvas(int width, int height) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 18 | : INHERITED(width, height) |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 19 | , fWidth(width) |
| 20 | , fHeight(height) |
| 21 | , fFilter(false) |
| 22 | , fIndex(0) |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 23 | , fOverdrawViz(false) |
scroggo@google.com | 06d6ac6 | 2013-02-08 21:16:19 +0000 | [diff] [blame] | 24 | , fOverdrawFilter(NULL) |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 25 | , fOverrideTexFiltering(false) |
| 26 | , fTexOverrideFilter(NULL) |
scroggo@google.com | 06d6ac6 | 2013-02-08 21:16:19 +0000 | [diff] [blame] | 27 | , fOutstandingSaveCount(0) { |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 28 | fUserMatrix.reset(); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 29 | |
| 30 | // SkPicturePlayback uses the base-class' quickReject calls to cull clipped |
| 31 | // operations. This can lead to problems in the debugger which expects all |
| 32 | // the operations in the captured skp to appear in the debug canvas. To |
| 33 | // circumvent this we create a wide open clip here (an empty clip rect |
| 34 | // is not sufficient). |
| 35 | // Internally, the SkRect passed to clipRect is converted to an SkIRect and |
| 36 | // rounded out. The following code creates a nearly maximal rect that will |
| 37 | // not get collapsed by the coming conversions (Due to precision loss the |
| 38 | // inset has to be surprisingly large). |
| 39 | SkIRect largeIRect = SkIRect::MakeLargest(); |
| 40 | largeIRect.inset(1024, 1024); |
robertphillips@google.com | 6c1e49a | 2013-11-10 15:08:45 +0000 | [diff] [blame] | 41 | SkRect large = SkRect::Make(largeIRect); |
robertphillips@google.com | 8b15717 | 2013-11-07 22:20:31 +0000 | [diff] [blame] | 42 | #ifdef SK_DEBUG |
| 43 | large.roundOut(&largeIRect); |
| 44 | SkASSERT(!largeIRect.isEmpty()); |
| 45 | #endif |
robertphillips@google.com | 392c9be | 2014-02-28 14:35:45 +0000 | [diff] [blame] | 46 | // call the base class' version to avoid adding a draw command |
| 47 | this->INHERITED::onClipRect(large, SkRegion::kReplace_Op, kHard_ClipEdgeStyle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 48 | } |
| 49 | |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 50 | SkDebugCanvas::~SkDebugCanvas() { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 51 | fCommandVector.deleteAll(); |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 52 | SkSafeUnref(fOverdrawFilter); |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 53 | SkSafeUnref(fTexOverrideFilter); |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 54 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 55 | |
| 56 | void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 57 | fCommandVector.push(command); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void SkDebugCanvas::draw(SkCanvas* canvas) { |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 61 | if (!fCommandVector.isEmpty()) { |
| 62 | drawTo(canvas, fCommandVector.count() - 1); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 66 | void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 67 | canvas->concat(fUserMatrix); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 71 | SkBitmap bitmap; |
reed@google.com | 9ebcac5 | 2014-01-24 18:53:42 +0000 | [diff] [blame] | 72 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 73 | |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 74 | SkCanvas canvas(bitmap); |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 75 | canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y)); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 76 | applyUserTransform(&canvas); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 77 | |
| 78 | int layer = 0; |
chudy@google.com | 751961d | 2012-07-31 20:07:42 +0000 | [diff] [blame] | 79 | SkColor prev = bitmap.getColor(0,0); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 80 | for (int i = 0; i < index; i++) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 81 | if (fCommandVector[i]->isVisible()) { |
| 82 | fCommandVector[i]->execute(&canvas); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 83 | } |
| 84 | if (prev != bitmap.getColor(0,0)) { |
| 85 | layer = i; |
| 86 | } |
| 87 | prev = bitmap.getColor(0,0); |
| 88 | } |
| 89 | return layer; |
| 90 | } |
| 91 | |
bsalomon@google.com | 383e234 | 2013-02-06 21:44:21 +0000 | [diff] [blame] | 92 | static SkPMColor OverdrawXferModeProc(SkPMColor src, SkPMColor dst) { |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 93 | // This table encodes the color progression of the overdraw visualization |
| 94 | static const SkPMColor gTable[] = { |
| 95 | SkPackARGB32(0x00, 0x00, 0x00, 0x00), |
| 96 | SkPackARGB32(0xFF, 128, 158, 255), |
| 97 | SkPackARGB32(0xFF, 170, 185, 212), |
| 98 | SkPackARGB32(0xFF, 213, 195, 170), |
| 99 | SkPackARGB32(0xFF, 255, 192, 127), |
| 100 | SkPackARGB32(0xFF, 255, 185, 85), |
| 101 | SkPackARGB32(0xFF, 255, 165, 42), |
| 102 | SkPackARGB32(0xFF, 255, 135, 0), |
| 103 | SkPackARGB32(0xFF, 255, 95, 0), |
| 104 | SkPackARGB32(0xFF, 255, 50, 0), |
| 105 | SkPackARGB32(0xFF, 255, 0, 0) |
| 106 | }; |
| 107 | |
robertphillips@google.com | 0b256e1 | 2013-02-06 20:42:14 +0000 | [diff] [blame] | 108 | for (size_t i = 0; i < SK_ARRAY_COUNT(gTable)-1; ++i) { |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 109 | if (gTable[i] == dst) { |
| 110 | return gTable[i+1]; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return gTable[SK_ARRAY_COUNT(gTable)-1]; |
| 115 | } |
| 116 | |
| 117 | // The OverdrawFilter modifies every paint to use an SkProcXfermode which |
| 118 | // in turn invokes OverdrawXferModeProc |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 119 | class SkOverdrawFilter : public SkDrawFilter { |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 120 | public: |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 121 | SkOverdrawFilter() { |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 122 | fXferMode = SkProcXfermode::Create(OverdrawXferModeProc); |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 123 | } |
| 124 | |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 125 | virtual ~SkOverdrawFilter() { |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 126 | delete fXferMode; |
| 127 | } |
| 128 | |
| 129 | virtual bool filter(SkPaint* p, Type) SK_OVERRIDE { |
| 130 | p->setXfermode(fXferMode); |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | protected: |
| 135 | SkXfermode* fXferMode; |
| 136 | |
| 137 | private: |
| 138 | typedef SkDrawFilter INHERITED; |
| 139 | }; |
| 140 | |
skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 141 | // SkTexOverrideFilter modifies every paint to use the specified |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 142 | // texture filtering mode |
| 143 | class SkTexOverrideFilter : public SkDrawFilter { |
| 144 | public: |
| 145 | SkTexOverrideFilter() : fFilterLevel(SkPaint::kNone_FilterLevel) { |
| 146 | } |
| 147 | |
| 148 | void setFilterLevel(SkPaint::FilterLevel filterLevel) { |
| 149 | fFilterLevel = filterLevel; |
| 150 | } |
| 151 | |
| 152 | virtual bool filter(SkPaint* p, Type) SK_OVERRIDE { |
| 153 | p->setFilterLevel(fFilterLevel); |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | protected: |
| 158 | SkPaint::FilterLevel fFilterLevel; |
| 159 | |
| 160 | private: |
| 161 | typedef SkDrawFilter INHERITED; |
| 162 | }; |
| 163 | |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 164 | void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 165 | SkASSERT(!fCommandVector.isEmpty()); |
| 166 | SkASSERT(index < fCommandVector.count()); |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 167 | int i = 0; |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 168 | |
| 169 | // This only works assuming the canvas and device are the same ones that |
| 170 | // were previously drawn into because they need to preserve all saves |
| 171 | // and restores. |
commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 172 | // The visibility filter also requires a full re-draw - otherwise we can |
| 173 | // end up drawing the filter repeatedly. |
| 174 | if (fIndex < index && !fFilter) { |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 175 | i = fIndex + 1; |
| 176 | } else { |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 177 | for (int j = 0; j < fOutstandingSaveCount; j++) { |
| 178 | canvas->restore(); |
| 179 | } |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 180 | canvas->clear(SK_ColorTRANSPARENT); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 181 | canvas->resetMatrix(); |
skia.committer@gmail.com | 04ba448 | 2012-09-07 02:01:30 +0000 | [diff] [blame] | 182 | SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 183 | SkIntToScalar(fHeight)); |
chudy@google.com | 4c7962e | 2012-08-14 19:38:31 +0000 | [diff] [blame] | 184 | canvas->clipRect(rect, SkRegion::kReplace_Op ); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 185 | applyUserTransform(canvas); |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 186 | fOutstandingSaveCount = 0; |
commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 187 | } |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 188 | |
commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 189 | // The setting of the draw filter has to go here (rather than in |
| 190 | // SkRasterWidget) due to the canvas restores this class performs. |
| 191 | // Since the draw filter is stored in the layer stack if we |
| 192 | // call setDrawFilter on anything but the root layer odd things happen. |
| 193 | if (fOverdrawViz) { |
| 194 | if (NULL == fOverdrawFilter) { |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 195 | fOverdrawFilter = new SkOverdrawFilter; |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 196 | } |
commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 197 | |
| 198 | if (fOverdrawFilter != canvas->getDrawFilter()) { |
| 199 | canvas->setDrawFilter(fOverdrawFilter); |
| 200 | } |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 201 | } else if (fOverrideTexFiltering) { |
| 202 | if (NULL == fTexOverrideFilter) { |
| 203 | fTexOverrideFilter = new SkTexOverrideFilter; |
| 204 | } |
| 205 | |
| 206 | if (fTexOverrideFilter != canvas->getDrawFilter()) { |
| 207 | canvas->setDrawFilter(fTexOverrideFilter); |
| 208 | } |
commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 209 | } else { |
| 210 | canvas->setDrawFilter(NULL); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | for (; i <= index; i++) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 214 | if (i == index && fFilter) { |
| 215 | SkPaint p; |
| 216 | p.setColor(0xAAFFFFFF); |
| 217 | canvas->save(); |
| 218 | canvas->resetMatrix(); |
| 219 | SkRect mask; |
| 220 | mask.set(SkIntToScalar(0), SkIntToScalar(0), |
| 221 | SkIntToScalar(fWidth), SkIntToScalar(fHeight)); |
| 222 | canvas->clipRect(mask, SkRegion::kReplace_Op, false); |
| 223 | canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
| 224 | SkIntToScalar(fWidth), SkIntToScalar(fHeight), p); |
| 225 | canvas->restore(); |
| 226 | } |
| 227 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 228 | if (fCommandVector[i]->isVisible()) { |
| 229 | fCommandVector[i]->execute(canvas); |
| 230 | fCommandVector[i]->trackSaveState(&fOutstandingSaveCount); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 231 | } |
| 232 | } |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 233 | fMatrix = canvas->getTotalMatrix(); |
| 234 | fClip = canvas->getTotalClip().getBounds(); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 235 | fIndex = index; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 236 | } |
| 237 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 238 | void SkDebugCanvas::deleteDrawCommandAt(int index) { |
| 239 | SkASSERT(index < fCommandVector.count()); |
| 240 | delete fCommandVector[index]; |
| 241 | fCommandVector.remove(index); |
| 242 | } |
| 243 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 244 | SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 245 | SkASSERT(index < fCommandVector.count()); |
| 246 | return fCommandVector[index]; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 247 | } |
| 248 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 249 | void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) { |
| 250 | SkASSERT(index < fCommandVector.count()); |
| 251 | delete fCommandVector[index]; |
| 252 | fCommandVector[index] = command; |
| 253 | } |
| 254 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 255 | SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 256 | SkASSERT(index < fCommandVector.count()); |
| 257 | return fCommandVector[index]->Info(); |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 258 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 259 | |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 260 | bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 261 | SkASSERT(index < fCommandVector.count()); |
| 262 | return fCommandVector[index]->isVisible(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 263 | } |
| 264 | |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 265 | const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 266 | return fCommandVector; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 267 | } |
| 268 | |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 269 | SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { |
| 270 | return fCommandVector; |
| 271 | } |
| 272 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 273 | // TODO(chudy): Free command string memory. |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 274 | SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 275 | SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count()); |
| 276 | if (!fCommandVector.isEmpty()) { |
| 277 | for (int i = 0; i < fCommandVector.count(); i ++) { |
| 278 | commandString->push_back() = fCommandVector[i]->toString(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | return commandString; |
| 282 | } |
| 283 | |
| 284 | void SkDebugCanvas::toggleFilter(bool toggle) { |
| 285 | fFilter = toggle; |
| 286 | } |
| 287 | |
skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 288 | void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level) { |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 289 | if (NULL == fTexOverrideFilter) { |
| 290 | fTexOverrideFilter = new SkTexOverrideFilter; |
| 291 | } |
| 292 | |
skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 293 | fOverrideTexFiltering = overrideTexFiltering; |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 294 | fTexOverrideFilter->setFilterLevel(level); |
| 295 | } |
| 296 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 297 | void SkDebugCanvas::clear(SkColor color) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 298 | addDrawCommand(new SkClearCommand(color)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 299 | } |
| 300 | |
robertphillips@google.com | 392c9be | 2014-02-28 14:35:45 +0000 | [diff] [blame] | 301 | void SkDebugCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
| 302 | this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 303 | } |
| 304 | |
robertphillips@google.com | 392c9be | 2014-02-28 14:35:45 +0000 | [diff] [blame] | 305 | void SkDebugCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
| 306 | this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 307 | } |
| 308 | |
robertphillips@google.com | 392c9be | 2014-02-28 14:35:45 +0000 | [diff] [blame] | 309 | void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
| 310 | this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 311 | } |
| 312 | |
robertphillips@google.com | 392c9be | 2014-02-28 14:35:45 +0000 | [diff] [blame] | 313 | void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) { |
| 314 | this->addDrawCommand(new SkClipRegionCommand(region, op)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | bool SkDebugCanvas::concat(const SkMatrix& matrix) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 318 | addDrawCommand(new SkConcatCommand(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 319 | return true; |
| 320 | } |
| 321 | |
| 322 | void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 323 | SkScalar top, const SkPaint* paint = NULL) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 324 | addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 325 | } |
| 326 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 327 | void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 328 | const SkRect* src, const SkRect& dst, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 329 | const SkPaint* paint, |
| 330 | SkCanvas::DrawBitmapRectFlags flags) { |
| 331 | addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 335 | const SkMatrix& matrix, const SkPaint* paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 336 | addDrawCommand(new SkDrawBitmapMatrixCommand(bitmap, matrix, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap, |
| 340 | const SkIRect& center, const SkRect& dst, const SkPaint* paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 341 | addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | void SkDebugCanvas::drawData(const void* data, size_t length) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 345 | addDrawCommand(new SkDrawDataCommand(data, length)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 346 | } |
| 347 | |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 348 | void SkDebugCanvas::beginCommentGroup(const char* description) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 349 | addDrawCommand(new SkBeginCommentGroupCommand(description)); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | void SkDebugCanvas::addComment(const char* kywd, const char* value) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 353 | addDrawCommand(new SkCommentCommand(kywd, value)); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void SkDebugCanvas::endCommentGroup() { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 357 | addDrawCommand(new SkEndCommentGroupCommand()); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 358 | } |
| 359 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 360 | void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 361 | addDrawCommand(new SkDrawOvalCommand(oval, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 362 | } |
| 363 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 364 | void SkDebugCanvas::drawPaint(const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 365 | addDrawCommand(new SkDrawPaintCommand(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 366 | } |
| 367 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 368 | void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 369 | addDrawCommand(new SkDrawPathCommand(path, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void SkDebugCanvas::drawPicture(SkPicture& picture) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 373 | addDrawCommand(new SkDrawPictureCommand(picture)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void SkDebugCanvas::drawPoints(PointMode mode, size_t count, |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 377 | const SkPoint pts[], const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 378 | addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void SkDebugCanvas::drawPosText(const void* text, size_t byteLength, |
| 382 | const SkPoint pos[], const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 383 | addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 387 | const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 388 | addDrawCommand( |
| 389 | new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 390 | } |
| 391 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 392 | void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 393 | // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 394 | addDrawCommand(new SkDrawRectCommand(rect, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 395 | } |
| 396 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 397 | void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 398 | addDrawCommand(new SkDrawRRectCommand(rrect, paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 399 | } |
| 400 | |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 401 | void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 402 | const SkPaint& paint) { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 403 | this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint)); |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 404 | } |
| 405 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 406 | void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 407 | const SkPaint* paint = NULL) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 408 | addDrawCommand(new SkDrawSpriteCommand(bitmap, left, top, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 412 | SkScalar y, const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 413 | addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 417 | const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 418 | addDrawCommand( |
| 419 | new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 423 | const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], |
| 424 | SkXfermode*, const uint16_t indices[], int indexCount, |
| 425 | const SkPaint& paint) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 426 | addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices, |
| 427 | texs, colors, NULL, indices, indexCount, paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 428 | } |
| 429 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 430 | void SkDebugCanvas::onPushCull(const SkRect& cullRect) { |
| 431 | this->addDrawCommand(new SkPushCullCommand(cullRect)); |
| 432 | } |
| 433 | |
| 434 | void SkDebugCanvas::onPopCull() { |
| 435 | this->addDrawCommand(new SkPopCullCommand()); |
| 436 | } |
| 437 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 438 | void SkDebugCanvas::restore() { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 439 | addDrawCommand(new SkRestoreCommand()); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | bool SkDebugCanvas::rotate(SkScalar degrees) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 443 | addDrawCommand(new SkRotateCommand(degrees)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | |
| 447 | int SkDebugCanvas::save(SaveFlags flags) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 448 | addDrawCommand(new SkSaveCommand(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 449 | return true; |
| 450 | } |
| 451 | |
| 452 | int SkDebugCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 453 | SaveFlags flags) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 454 | addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 455 | return true; |
| 456 | } |
| 457 | |
| 458 | bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 459 | addDrawCommand(new SkScaleCommand(sx, sy)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 460 | return true; |
| 461 | } |
| 462 | |
| 463 | void SkDebugCanvas::setMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 464 | addDrawCommand(new SkSetMatrixCommand(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | bool SkDebugCanvas::skew(SkScalar sx, SkScalar sy) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 468 | addDrawCommand(new SkSkewCommand(sx, sy)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 469 | return true; |
| 470 | } |
| 471 | |
| 472 | bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 473 | addDrawCommand(new SkTranslateCommand(dx, dy)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 474 | return true; |
| 475 | } |
| 476 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 477 | void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 478 | SkASSERT(index < fCommandVector.count()); |
| 479 | fCommandVector[index]->setVisible(toggle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 480 | } |