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