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