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