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 | |
| 10 | #include <iostream> |
| 11 | #include "SkDebugCanvas.h" |
| 12 | #include "SkDrawCommand.h" |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 13 | #include "SkDevice.h" |
| 14 | #include "SkImageWidget.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 15 | |
reed@google.com | 6ae24e0 | 2012-09-26 13:44:13 +0000 | [diff] [blame] | 16 | static SkBitmap make_noconfig_bm(int width, int height) { |
| 17 | SkBitmap bm; |
| 18 | bm.setConfig(SkBitmap::kNo_Config, width, height); |
| 19 | return bm; |
| 20 | } |
| 21 | |
| 22 | SkDebugCanvas::SkDebugCanvas(int width, int height) |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 23 | : INHERITED(make_noconfig_bm(width, height)) |
| 24 | , fOutstandingSaveCount(0) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 25 | // TODO(chudy): Free up memory from all draw commands in destructor. |
chudy@google.com | 80a4a60 | 2012-07-30 18:54:07 +0000 | [diff] [blame] | 26 | fWidth = width; |
| 27 | fHeight = height; |
reed@google.com | 6ae24e0 | 2012-09-26 13:44:13 +0000 | [diff] [blame] | 28 | // do we need fBm anywhere? |
chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 29 | fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 30 | fFilter = false; |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 31 | fIndex = 0; |
| 32 | fUserOffset.set(0,0); |
| 33 | fUserScale = 1.0; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 34 | } |
| 35 | |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 36 | SkDebugCanvas::~SkDebugCanvas() { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 37 | commandVector.deleteAll(); |
chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 38 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 39 | |
| 40 | void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 41 | commandVector.push(command); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void SkDebugCanvas::draw(SkCanvas* canvas) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 45 | if(!commandVector.isEmpty()) { |
| 46 | for (int i = 0; i < commandVector.count(); i++) { |
| 47 | if (commandVector[i]->isVisible()) { |
| 48 | commandVector[i]->execute(canvas); |
chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 49 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 52 | fIndex = commandVector.count() - 1; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 53 | } |
| 54 | |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 55 | void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { |
skia.committer@gmail.com | 04ba448 | 2012-09-07 02:01:30 +0000 | [diff] [blame] | 56 | canvas->translate(SkIntToScalar(fUserOffset.fX), |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 57 | SkIntToScalar(fUserOffset.fY)); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 58 | if (fUserScale < 0) { |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 59 | canvas->scale((1.0f / -fUserScale), (1.0f / -fUserScale)); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 60 | } else if (fUserScale > 0) { |
| 61 | canvas->scale(fUserScale, fUserScale); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 66 | SkBitmap bitmap; |
| 67 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| 68 | bitmap.allocPixels(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 69 | |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 70 | SkCanvas canvas(bitmap); |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 71 | canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y)); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 72 | applyUserTransform(&canvas); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 73 | |
| 74 | int layer = 0; |
chudy@google.com | 751961d | 2012-07-31 20:07:42 +0000 | [diff] [blame] | 75 | SkColor prev = bitmap.getColor(0,0); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 76 | for (int i = 0; i < index; i++) { |
| 77 | if (commandVector[i]->isVisible()) { |
| 78 | commandVector[i]->execute(&canvas); |
| 79 | } |
| 80 | if (prev != bitmap.getColor(0,0)) { |
| 81 | layer = i; |
| 82 | } |
| 83 | prev = bitmap.getColor(0,0); |
| 84 | } |
| 85 | return layer; |
| 86 | } |
| 87 | |
| 88 | void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { |
| 89 | int counter = 0; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 90 | SkASSERT(!commandVector.isEmpty()); |
| 91 | SkASSERT(index < commandVector.count()); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 92 | int i; |
| 93 | |
| 94 | // This only works assuming the canvas and device are the same ones that |
| 95 | // were previously drawn into because they need to preserve all saves |
| 96 | // and restores. |
| 97 | if (fIndex < index) { |
| 98 | i = fIndex + 1; |
| 99 | } else { |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 100 | for (int j = 0; j < fOutstandingSaveCount; j++) { |
| 101 | canvas->restore(); |
| 102 | } |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 103 | i = 0; |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 104 | canvas->clear(SK_ColorTRANSPARENT); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 105 | canvas->resetMatrix(); |
skia.committer@gmail.com | 04ba448 | 2012-09-07 02:01:30 +0000 | [diff] [blame] | 106 | SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 107 | SkIntToScalar(fHeight)); |
chudy@google.com | 4c7962e | 2012-08-14 19:38:31 +0000 | [diff] [blame] | 108 | canvas->clipRect(rect, SkRegion::kReplace_Op ); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 109 | applyUserTransform(canvas); |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 110 | fOutstandingSaveCount = 0; |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | for (; i <= index; i++) { |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 114 | if (i == index && fFilter) { |
| 115 | SkPaint p; |
| 116 | p.setColor(0xAAFFFFFF); |
| 117 | canvas->save(); |
| 118 | canvas->resetMatrix(); |
| 119 | SkRect mask; |
| 120 | mask.set(SkIntToScalar(0), SkIntToScalar(0), |
| 121 | SkIntToScalar(fWidth), SkIntToScalar(fHeight)); |
| 122 | canvas->clipRect(mask, SkRegion::kReplace_Op, false); |
| 123 | canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
| 124 | SkIntToScalar(fWidth), SkIntToScalar(fHeight), p); |
| 125 | canvas->restore(); |
| 126 | } |
| 127 | |
| 128 | if (commandVector[i]->isVisible()) { |
| 129 | commandVector[i]->execute(canvas); |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 130 | commandVector[i]->trackSaveState(&fOutstandingSaveCount); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 131 | } |
| 132 | } |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 133 | fMatrix = canvas->getTotalMatrix(); |
| 134 | fClip = canvas->getTotalClip().getBounds(); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 135 | fIndex = index; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 139 | SkASSERT(index < commandVector.count()); |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 140 | return commandVector[index]; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 141 | } |
| 142 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 143 | SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) { |
| 144 | SkASSERT(index < commandVector.count()); |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 145 | return commandVector[index]->Info(); |
| 146 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 147 | |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 148 | bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 149 | SkASSERT(index < commandVector.count()); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 150 | return commandVector[index]->isVisible(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 151 | } |
| 152 | |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 153 | const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 154 | return commandVector; |
| 155 | } |
| 156 | |
| 157 | // TODO(chudy): Free command string memory. |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 158 | SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const { |
| 159 | SkTArray<SkString>* commandString = new SkTArray<SkString>(commandVector.count()); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 160 | if (!commandVector.isEmpty()) { |
| 161 | for (int i = 0; i < commandVector.count(); i ++) { |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 162 | commandString->push_back() = commandVector[i]->toString(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | return commandString; |
| 166 | } |
| 167 | |
| 168 | void SkDebugCanvas::toggleFilter(bool toggle) { |
| 169 | fFilter = toggle; |
| 170 | } |
| 171 | |
| 172 | void SkDebugCanvas::clear(SkColor color) { |
| 173 | addDrawCommand(new Clear(color)); |
| 174 | } |
| 175 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 176 | static SkBitmap createBitmap(const SkPath& path) { |
| 177 | SkBitmap bitmap; |
skia.committer@gmail.com | 1c9c0d3 | 2012-11-22 02:02:41 +0000 | [diff] [blame] | 178 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 179 | SkImageWidget::kImageWidgetWidth, |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 180 | SkImageWidget::kImageWidgetHeight); |
| 181 | bitmap.allocPixels(); |
| 182 | bitmap.eraseColor(SK_ColorWHITE); |
| 183 | SkDevice* device = new SkDevice(bitmap); |
| 184 | |
| 185 | SkCanvas canvas(device); |
| 186 | device->unref(); |
| 187 | |
| 188 | const SkRect& bounds = path.getBounds(); |
| 189 | |
| 190 | if (bounds.width() > bounds.height()) { |
skia.committer@gmail.com | 1c9c0d3 | 2012-11-22 02:02:41 +0000 | [diff] [blame] | 191 | canvas.scale(SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetWidth)/bounds.width()), |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 192 | SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetHeight)/bounds.width())); |
| 193 | } else { |
skia.committer@gmail.com | 1c9c0d3 | 2012-11-22 02:02:41 +0000 | [diff] [blame] | 194 | canvas.scale(SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetWidth)/bounds.height()), |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 195 | SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetHeight)/bounds.height())); |
| 196 | } |
| 197 | canvas.translate(-bounds.fLeft+2, -bounds.fTop+2); |
| 198 | |
| 199 | SkPaint p; |
| 200 | p.setColor(SK_ColorBLACK); |
| 201 | p.setStyle(SkPaint::kStroke_Style); |
| 202 | |
| 203 | canvas.drawPath(path, p); |
| 204 | |
| 205 | return bitmap; |
| 206 | } |
| 207 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 208 | static SkBitmap createBitmap(const SkBitmap& input, const SkRect* srcRect) { |
| 209 | SkBitmap bitmap; |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 210 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 211 | SkImageWidget::kImageWidgetWidth, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 212 | SkImageWidget::kImageWidgetHeight); |
| 213 | bitmap.allocPixels(); |
| 214 | bitmap.eraseColor(SK_ColorLTGRAY); |
| 215 | SkDevice* device = new SkDevice(bitmap); |
| 216 | |
| 217 | SkCanvas canvas(device); |
| 218 | device->unref(); |
| 219 | |
| 220 | SkScalar xScale = (SkImageWidget::kImageWidgetWidth-2.0) / input.width(); |
| 221 | SkScalar yScale = (SkImageWidget::kImageWidgetHeight-2.0) / input.height(); |
| 222 | |
| 223 | if (input.width() > input.height()) { |
| 224 | yScale *= input.height() / (float) input.width(); |
| 225 | } else { |
| 226 | xScale *= input.width() / (float) input.height(); |
| 227 | } |
| 228 | |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 229 | SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 230 | xScale * input.width(), |
| 231 | yScale * input.height()); |
| 232 | |
| 233 | canvas.drawBitmapRect(input, NULL, dst); |
| 234 | |
| 235 | if (NULL != srcRect) { |
| 236 | SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1, |
| 237 | srcRect->fTop * yScale + SK_Scalar1, |
| 238 | srcRect->fRight * xScale + SK_Scalar1, |
| 239 | srcRect->fBottom * yScale + SK_Scalar1); |
| 240 | SkPaint p; |
| 241 | p.setColor(SK_ColorRED); |
| 242 | p.setStyle(SkPaint::kStroke_Style); |
| 243 | |
| 244 | canvas.drawRect(r, p); |
| 245 | } |
| 246 | |
| 247 | return bitmap; |
| 248 | } |
| 249 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 250 | bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
rmistry@google.com | 4473765 | 2012-11-21 18:37:58 +0000 | [diff] [blame] | 251 | SkBitmap bitmap = createBitmap(path); |
| 252 | addDrawCommand(new ClipPath(path, op, doAA, bitmap)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | |
| 256 | bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 257 | addDrawCommand(new ClipRect(rect, op, doAA)); |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) { |
| 262 | addDrawCommand(new ClipRegion(region, op)); |
| 263 | return true; |
| 264 | } |
| 265 | |
| 266 | bool SkDebugCanvas::concat(const SkMatrix& matrix) { |
| 267 | addDrawCommand(new Concat(matrix)); |
| 268 | return true; |
| 269 | } |
| 270 | |
| 271 | void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, |
| 272 | SkScalar top, const SkPaint* paint = NULL) { |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 273 | SkBitmap resizedBitmap = createBitmap(bitmap, NULL); |
| 274 | addDrawCommand(new DrawBitmap(bitmap, left, top, paint, resizedBitmap)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 275 | } |
| 276 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 277 | void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, |
| 278 | const SkRect* src, const SkRect& dst, const SkPaint* paint) { |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 279 | SkBitmap resizedBitmap = createBitmap(bitmap, src); |
| 280 | addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint, resizedBitmap)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap, |
| 284 | const SkMatrix& matrix, const SkPaint* paint) { |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 285 | SkBitmap resizedBitmap = createBitmap(bitmap, NULL); |
| 286 | addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint, resizedBitmap)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap, |
| 290 | const SkIRect& center, const SkRect& dst, const SkPaint* paint) { |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 291 | SkBitmap resizedBitmap = createBitmap(bitmap, NULL); |
| 292 | addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint, resizedBitmap)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | void SkDebugCanvas::drawData(const void* data, size_t length) { |
| 296 | addDrawCommand(new DrawData(data, length)); |
| 297 | } |
| 298 | |
| 299 | void SkDebugCanvas::drawPaint(const SkPaint& paint) { |
| 300 | addDrawCommand(new DrawPaint(paint)); |
| 301 | } |
| 302 | |
| 303 | void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
rmistry@google.com | 4473765 | 2012-11-21 18:37:58 +0000 | [diff] [blame] | 304 | SkBitmap bitmap = createBitmap(path); |
| 305 | addDrawCommand(new DrawPath(path, paint, bitmap)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void SkDebugCanvas::drawPicture(SkPicture& picture) { |
| 309 | addDrawCommand(new DrawPicture(picture)); |
| 310 | } |
| 311 | |
| 312 | void SkDebugCanvas::drawPoints(PointMode mode, size_t count, |
| 313 | const SkPoint pts[], const SkPaint& paint) { |
| 314 | addDrawCommand(new DrawPoints(mode, count, pts, paint)); |
| 315 | } |
| 316 | |
| 317 | void SkDebugCanvas::drawPosText(const void* text, size_t byteLength, |
| 318 | const SkPoint pos[], const SkPaint& paint) { |
| 319 | addDrawCommand(new DrawPosText(text, byteLength, pos, paint)); |
| 320 | } |
| 321 | |
| 322 | void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 323 | const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { |
| 324 | addDrawCommand(new DrawPosTextH(text, byteLength, xpos, constY, paint)); |
| 325 | } |
| 326 | |
| 327 | void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
| 328 | // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
| 329 | addDrawCommand(new DrawRectC(rect, paint)); |
| 330 | } |
| 331 | |
| 332 | void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, |
| 333 | const SkPaint* paint = NULL) { |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 334 | SkBitmap resizedBitmap = createBitmap(bitmap, NULL); |
| 335 | addDrawCommand(new DrawSprite(bitmap, left, top, paint, resizedBitmap)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 339 | SkScalar y, const SkPaint& paint) { |
| 340 | addDrawCommand(new DrawTextC(text, byteLength, x, y, paint)); |
| 341 | } |
| 342 | |
| 343 | void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 344 | const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { |
| 345 | addDrawCommand(new DrawTextOnPath(text, byteLength, path, matrix, paint)); |
| 346 | } |
| 347 | |
| 348 | void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 349 | const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], |
| 350 | SkXfermode*, const uint16_t indices[], int indexCount, |
| 351 | const SkPaint& paint) { |
| 352 | addDrawCommand(new DrawVertices(vmode, vertexCount, vertices, texs, colors, |
| 353 | NULL, indices, indexCount, paint)); |
| 354 | } |
| 355 | |
| 356 | void SkDebugCanvas::restore() { |
| 357 | addDrawCommand(new Restore()); |
| 358 | } |
| 359 | |
| 360 | bool SkDebugCanvas::rotate(SkScalar degrees) { |
| 361 | addDrawCommand(new Rotate(degrees)); |
| 362 | return true; |
| 363 | } |
| 364 | |
| 365 | int SkDebugCanvas::save(SaveFlags flags) { |
| 366 | addDrawCommand(new Save(flags)); |
| 367 | return true; |
| 368 | } |
| 369 | |
| 370 | int SkDebugCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 371 | SaveFlags flags) { |
| 372 | addDrawCommand(new SaveLayer(bounds, paint, flags)); |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) { |
| 377 | addDrawCommand(new Scale(sx, sy)); |
| 378 | return true; |
| 379 | } |
| 380 | |
| 381 | void SkDebugCanvas::setMatrix(const SkMatrix& matrix) { |
| 382 | addDrawCommand(new SetMatrix(matrix)); |
| 383 | } |
| 384 | |
| 385 | bool SkDebugCanvas::skew(SkScalar sx, SkScalar sy) { |
| 386 | addDrawCommand(new Skew(sx, sy)); |
| 387 | return true; |
| 388 | } |
| 389 | |
| 390 | bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { |
| 391 | addDrawCommand(new Translate(dx, dy)); |
| 392 | return true; |
| 393 | } |
| 394 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 395 | void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 396 | SkASSERT(index < commandVector.count()); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 397 | commandVector[index]->setVisible(toggle); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 398 | } |