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