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