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 "SkDrawCommand.h" |
| 11 | #include "SkObjectParser.h" |
| 12 | |
| 13 | // TODO(chudy): Refactor into non subclass model. |
| 14 | |
| 15 | SkDrawCommand::SkDrawCommand() { |
| 16 | fVisible = true; |
| 17 | } |
| 18 | |
| 19 | SkDrawCommand::~SkDrawCommand() { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 20 | fInfo.deleteAll(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | const char* SkDrawCommand::GetCommandString(DrawType type) { |
| 24 | switch (type) { |
| 25 | case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break; |
| 26 | case DRAW_CLEAR: return "Clear"; |
| 27 | case CLIP_PATH: return "Clip Path"; |
| 28 | case CLIP_REGION: return "Clip Region"; |
| 29 | case CLIP_RECT: return "Clip Rect"; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame^] | 30 | case CLIP_RRECT: return "Clip RRect"; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 31 | case CONCAT: return "Concat"; |
| 32 | case DRAW_BITMAP: return "Draw Bitmap"; |
| 33 | case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix"; |
| 34 | case DRAW_BITMAP_NINE: return "Draw Bitmap Nine"; |
robertphillips@google.com | 84d320e | 2012-09-20 19:09:17 +0000 | [diff] [blame] | 35 | case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect"; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 36 | case DRAW_DATA: return "Draw Data"; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame^] | 37 | case DRAW_OVAL: return "Draw Oval"; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 38 | case DRAW_PAINT: return "Draw Paint"; |
| 39 | case DRAW_PATH: return "Draw Path"; |
| 40 | case DRAW_PICTURE: return "Draw Picture"; |
| 41 | case DRAW_POINTS: return "Draw Points"; |
| 42 | case DRAW_POS_TEXT: return "Draw Pos Text"; |
| 43 | case DRAW_POS_TEXT_H: return "Draw Pos Text H"; |
| 44 | case DRAW_RECT: return "Draw Rect"; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame^] | 45 | case DRAW_RRECT: return "Draw RRect"; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 46 | case DRAW_SPRITE: return "Draw Sprite"; |
| 47 | case DRAW_TEXT: return "Draw Text"; |
| 48 | case DRAW_TEXT_ON_PATH: return "Draw Text On Path"; |
| 49 | case DRAW_VERTICES: return "Draw Vertices"; |
| 50 | case RESTORE: return "Restore"; |
| 51 | case ROTATE: return "Rotate"; |
| 52 | case SAVE: return "Save"; |
| 53 | case SAVE_LAYER: return "Save Layer"; |
| 54 | case SCALE: return "Scale"; |
| 55 | case SET_MATRIX: return "Set Matrix"; |
| 56 | case SKEW: return "Skew"; |
| 57 | case TRANSLATE: return "Translate"; |
| 58 | default: |
| 59 | SkDebugf("DrawType error 0x%08x\n", type); |
| 60 | SkASSERT(0); |
| 61 | break; |
| 62 | } |
| 63 | SkDEBUGFAIL("DrawType UNUSED\n"); |
| 64 | return NULL; |
| 65 | } |
| 66 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 67 | SkString SkDrawCommand::toString() { |
| 68 | return SkString(GetCommandString(fDrawType)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Clear::Clear(SkColor color) { |
| 72 | this->fColor = color; |
| 73 | this->fDrawType = DRAW_CLEAR; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 74 | this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void Clear::execute(SkCanvas* canvas) { |
| 78 | canvas->clear(this->fColor); |
| 79 | } |
| 80 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 81 | ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 82 | this->fPath = &path; |
| 83 | this->fOp = op; |
| 84 | this->fDoAA = doAA; |
| 85 | this->fDrawType = CLIP_PATH; |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 86 | this->fBitmap = bitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 87 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 88 | this->fInfo.push(SkObjectParser::PathToString(path)); |
| 89 | this->fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 90 | this->fInfo.push(SkObjectParser::BoolToString(doAA)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void ClipPath::execute(SkCanvas* canvas) { |
| 94 | canvas->clipPath(*this->fPath, this->fOp, this->fDoAA); |
| 95 | } |
| 96 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 97 | const SkBitmap* ClipPath::getBitmap() const { |
| 98 | return &fBitmap; |
| 99 | } |
| 100 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 101 | ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) { |
| 102 | this->fRegion = ®ion; |
| 103 | this->fOp = op; |
| 104 | this->fDrawType = CLIP_REGION; |
| 105 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 106 | this->fInfo.push(SkObjectParser::RegionToString(region)); |
| 107 | this->fInfo.push(SkObjectParser::RegionOpToString(op)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void ClipRegion::execute(SkCanvas* canvas) { |
| 111 | canvas->clipRegion(*this->fRegion, this->fOp); |
| 112 | } |
| 113 | |
| 114 | ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 115 | this->fRect = ▭ |
| 116 | this->fOp = op; |
| 117 | this->fDoAA = doAA; |
| 118 | this->fDrawType = CLIP_RECT; |
| 119 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 120 | this->fInfo.push(SkObjectParser::RectToString(rect)); |
| 121 | this->fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 122 | this->fInfo.push(SkObjectParser::BoolToString(doAA)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void ClipRect::execute(SkCanvas* canvas) { |
| 126 | canvas->clipRect(*this->fRect, this->fOp, this->fDoAA); |
| 127 | } |
| 128 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame^] | 129 | ClipRRect::ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| 130 | this->fRRect = &rrect; |
| 131 | this->fOp = op; |
| 132 | this->fDoAA = doAA; |
| 133 | this->fDrawType = CLIP_RRECT; |
| 134 | |
| 135 | this->fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 136 | this->fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 137 | this->fInfo.push(SkObjectParser::BoolToString(doAA)); |
| 138 | } |
| 139 | |
| 140 | void ClipRRect::execute(SkCanvas* canvas) { |
| 141 | canvas->clipRRect(*this->fRRect, this->fOp, this->fDoAA); |
| 142 | } |
| 143 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 144 | Concat::Concat(const SkMatrix& matrix) { |
| 145 | this->fMatrix = &matrix; |
| 146 | this->fDrawType = CONCAT; |
| 147 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 148 | this->fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void Concat::execute(SkCanvas* canvas) { |
| 152 | canvas->concat(*this->fMatrix); |
| 153 | } |
| 154 | |
| 155 | DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 156 | const SkPaint* paint, SkBitmap& resizedBitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 157 | this->fBitmap = &bitmap; |
| 158 | this->fLeft = left; |
| 159 | this->fTop = top; |
| 160 | this->fPaint = paint; |
| 161 | this->fDrawType = DRAW_BITMAP; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 162 | this->fResizedBitmap = resizedBitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 163 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 164 | this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 165 | this->fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: ")); |
| 166 | this->fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void DrawBitmap::execute(SkCanvas* canvas) { |
| 170 | canvas->drawBitmap(*this->fBitmap, this->fLeft, this->fTop, this->fPaint); |
| 171 | } |
| 172 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 173 | const SkBitmap* DrawBitmap::getBitmap() const { |
| 174 | return &fResizedBitmap; |
| 175 | } |
| 176 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 177 | DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 178 | const SkMatrix& matrix, const SkPaint* paint, SkBitmap& resizedBitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 179 | this->fBitmap = &bitmap; |
| 180 | this->fMatrix = &matrix; |
| 181 | this->fPaint = paint; |
| 182 | this->fDrawType = DRAW_BITMAP_MATRIX; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 183 | this->fResizedBitmap = resizedBitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 184 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 185 | this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 186 | this->fInfo.push(SkObjectParser::MatrixToString(matrix)); |
| 187 | if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void DrawBitmapMatrix::execute(SkCanvas* canvas) { |
| 191 | canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint); |
| 192 | } |
| 193 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 194 | const SkBitmap* DrawBitmapMatrix::getBitmap() const { |
| 195 | return &fResizedBitmap; |
| 196 | } |
| 197 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 198 | DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 199 | const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 200 | this->fBitmap = &bitmap; |
| 201 | this->fCenter = ¢er; |
| 202 | this->fDst = &dst; |
| 203 | this->fPaint = paint; |
| 204 | this->fDrawType = DRAW_BITMAP_NINE; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 205 | this->fResizedBitmap = resizedBitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 206 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 207 | this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 208 | this->fInfo.push(SkObjectParser::IRectToString(center)); |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 209 | this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 210 | if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void DrawBitmapNine::execute(SkCanvas* canvas) { |
| 214 | canvas->drawBitmapNine(*this->fBitmap, *this->fCenter, *this->fDst, this->fPaint); |
| 215 | } |
| 216 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 217 | const SkBitmap* DrawBitmapNine::getBitmap() const { |
| 218 | return &fResizedBitmap; |
| 219 | } |
| 220 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 221 | DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 222 | const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 223 | this->fBitmap = &bitmap; |
| 224 | this->fSrc = src; |
| 225 | this->fDst = &dst; |
| 226 | this->fPaint = paint; |
robertphillips@google.com | 84d320e | 2012-09-20 19:09:17 +0000 | [diff] [blame] | 227 | this->fDrawType = DRAW_BITMAP_RECT_TO_RECT; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 228 | this->fResizedBitmap = resizedBitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 229 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 230 | this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 231 | if (src) this->fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); |
| 232 | this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 233 | if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void DrawBitmapRect::execute(SkCanvas* canvas) { |
robertphillips@google.com | 84d320e | 2012-09-20 19:09:17 +0000 | [diff] [blame] | 237 | canvas->drawBitmapRectToRect(*this->fBitmap, this->fSrc, *this->fDst, this->fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 238 | } |
| 239 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 240 | const SkBitmap* DrawBitmapRect::getBitmap() const { |
| 241 | return &fResizedBitmap; |
| 242 | } |
| 243 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 244 | DrawData::DrawData(const void* data, size_t length) { |
| 245 | this->fData = data; |
| 246 | this->fLength = length; |
| 247 | this->fDrawType = DRAW_DATA; |
| 248 | // TODO(chudy): See if we can't display data and length. |
| 249 | } |
| 250 | |
| 251 | void DrawData::execute(SkCanvas* canvas) { |
| 252 | canvas->drawData(this->fData, this->fLength); |
| 253 | } |
| 254 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame^] | 255 | DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) { |
| 256 | this->fOval = &oval; |
| 257 | this->fPaint = &paint; |
| 258 | this->fDrawType = DRAW_OVAL; |
| 259 | |
| 260 | this->fInfo.push(SkObjectParser::RectToString(oval)); |
| 261 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
| 262 | } |
| 263 | |
| 264 | void DrawOval::execute(SkCanvas* canvas) { |
| 265 | canvas->drawOval(*this->fOval, *this->fPaint); |
| 266 | } |
| 267 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 268 | DrawPaint::DrawPaint(const SkPaint& paint) { |
| 269 | this->fPaint = &paint; |
| 270 | this->fDrawType = DRAW_PAINT; |
| 271 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 272 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void DrawPaint::execute(SkCanvas* canvas) { |
| 276 | canvas->drawPaint(*this->fPaint); |
| 277 | } |
| 278 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 279 | DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 280 | this->fPath = &path; |
| 281 | this->fPaint = &paint; |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 282 | this->fBitmap = bitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 283 | this->fDrawType = DRAW_PATH; |
| 284 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 285 | this->fInfo.push(SkObjectParser::PathToString(path)); |
| 286 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void DrawPath::execute(SkCanvas* canvas) { |
| 290 | canvas->drawPath(*this->fPath, *this->fPaint); |
| 291 | } |
| 292 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 293 | const SkBitmap* DrawPath::getBitmap() const { |
| 294 | return &fBitmap; |
| 295 | } |
| 296 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 297 | DrawPicture::DrawPicture(SkPicture& picture) { |
| 298 | this->fPicture = &picture; |
| 299 | this->fDrawType = DRAW_PICTURE; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 300 | this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void DrawPicture::execute(SkCanvas* canvas) { |
| 304 | canvas->drawPicture(*this->fPicture); |
| 305 | } |
| 306 | |
| 307 | DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count, |
| 308 | const SkPoint pts[], const SkPaint& paint) { |
| 309 | this->fMode = mode; |
| 310 | this->fCount = count; |
| 311 | this->fPts = pts; |
| 312 | this->fPaint = &paint; |
| 313 | this->fDrawType = DRAW_POINTS; |
| 314 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 315 | this->fInfo.push(SkObjectParser::PointsToString(pts, count)); |
skia.committer@gmail.com | 04ba448 | 2012-09-07 02:01:30 +0000 | [diff] [blame] | 316 | this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar(count), |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 317 | "Points: ")); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 318 | this->fInfo.push(SkObjectParser::PointModeToString(mode)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void DrawPoints::execute(SkCanvas* canvas) { |
| 322 | canvas->drawPoints(this->fMode, this->fCount, this->fPts, *this->fPaint); |
| 323 | } |
| 324 | |
| 325 | DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 326 | const SkPaint& paint) { |
| 327 | this->fText = text; |
| 328 | this->fByteLength = byteLength; |
| 329 | this->fPos = pos; |
| 330 | this->fPaint = &paint; |
| 331 | this->fDrawType = DRAW_POS_TEXT; |
| 332 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 333 | this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 334 | // TODO(chudy): Test that this works. |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 335 | this->fInfo.push(SkObjectParser::PointsToString(pos, 1)); |
| 336 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void DrawPosText::execute(SkCanvas* canvas) { |
| 340 | canvas->drawPosText(this->fText, this->fByteLength, this->fPos, *this->fPaint); |
| 341 | } |
| 342 | |
| 343 | |
| 344 | DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength, |
| 345 | const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { |
| 346 | this->fText = text; |
| 347 | this->fByteLength = byteLength; |
| 348 | this->fXpos = xpos; |
| 349 | this->fConstY = constY; |
| 350 | this->fPaint = &paint; |
| 351 | this->fDrawType = DRAW_POS_TEXT_H; |
| 352 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 353 | this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); |
| 354 | this->fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: ")); |
| 355 | this->fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: ")); |
| 356 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void DrawPosTextH::execute(SkCanvas* canvas) { |
| 360 | canvas->drawPosTextH(this->fText, this->fByteLength, this->fXpos, this->fConstY, |
| 361 | *this->fPaint); |
| 362 | } |
| 363 | |
| 364 | DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) { |
| 365 | this->fRect = ▭ |
| 366 | this->fPaint = &paint; |
| 367 | this->fDrawType = DRAW_RECT; |
| 368 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 369 | this->fInfo.push(SkObjectParser::RectToString(rect)); |
| 370 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | void DrawRectC::execute(SkCanvas* canvas) { |
| 374 | canvas->drawRect(*this->fRect, *this->fPaint); |
| 375 | } |
| 376 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame^] | 377 | DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 378 | this->fRRect = rrect; |
| 379 | this->fPaint = &paint; |
| 380 | this->fDrawType = DRAW_RRECT; |
| 381 | |
| 382 | this->fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 383 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
| 384 | } |
| 385 | |
| 386 | void DrawRRect::execute(SkCanvas* canvas) { |
| 387 | canvas->drawRRect(this->fRRect, *this->fPaint); |
| 388 | } |
| 389 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 390 | DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 391 | const SkPaint* paint, SkBitmap& resizedBitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 392 | this->fBitmap = &bitmap; |
| 393 | this->fLeft = left; |
| 394 | this->fTop = top; |
| 395 | this->fPaint = paint; |
| 396 | this->fDrawType = DRAW_SPRITE; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 397 | this->fResizedBitmap = resizedBitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 398 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 399 | this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 400 | this->fInfo.push(SkObjectParser::IntToString(left, "Left: ")); |
| 401 | this->fInfo.push(SkObjectParser::IntToString(top, "Top: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void DrawSprite::execute(SkCanvas* canvas) { |
| 405 | canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint); |
| 406 | } |
| 407 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 408 | const SkBitmap* DrawSprite::getBitmap() const { |
| 409 | return &fResizedBitmap; |
| 410 | } |
| 411 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 412 | DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 413 | const SkPaint& paint) { |
| 414 | this->fText = text; |
| 415 | this->fByteLength = byteLength; |
| 416 | this->fX = x; |
| 417 | this->fY = y; |
| 418 | this->fPaint = &paint; |
| 419 | this->fDrawType = DRAW_TEXT; |
| 420 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 421 | this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); |
| 422 | this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); |
| 423 | this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); |
| 424 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | void DrawTextC::execute(SkCanvas* canvas) { |
| 428 | canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint); |
| 429 | } |
| 430 | |
| 431 | DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength, |
| 432 | const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { |
| 433 | this->fText = text; |
| 434 | this->fByteLength = byteLength; |
| 435 | this->fPath = &path; |
| 436 | this->fMatrix = matrix; |
| 437 | this->fPaint = &paint; |
| 438 | this->fDrawType = DRAW_TEXT_ON_PATH; |
| 439 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 440 | this->fInfo.push(SkObjectParser::TextToString(text, byteLength)); |
| 441 | this->fInfo.push(SkObjectParser::PathToString(path)); |
| 442 | if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 443 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void DrawTextOnPath::execute(SkCanvas* canvas) { |
| 447 | canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath, |
| 448 | this->fMatrix, *this->fPaint); |
| 449 | } |
| 450 | |
| 451 | DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount, |
| 452 | const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], |
| 453 | SkXfermode* xfermode, const uint16_t indices[], int indexCount, |
| 454 | const SkPaint& paint) { |
| 455 | this->fVmode = vmode; |
| 456 | this->fVertexCount = vertexCount; |
| 457 | this->fTexs = texs; |
| 458 | this->fColors = colors; |
| 459 | this->fXfermode = xfermode; |
| 460 | this->fIndices = indices; |
| 461 | this->fIndexCount = indexCount; |
| 462 | this->fPaint = &paint; |
| 463 | this->fDrawType = DRAW_VERTICES; |
| 464 | // TODO(chudy) |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 465 | this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void DrawVertices::execute(SkCanvas* canvas) { |
| 469 | canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices, |
| 470 | this->fTexs, this->fColors, this->fXfermode, this->fIndices, |
| 471 | this->fIndexCount, *this->fPaint); |
| 472 | } |
| 473 | |
| 474 | Restore::Restore() { |
| 475 | this->fDrawType = RESTORE; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 476 | this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void Restore::execute(SkCanvas* canvas) { |
| 480 | canvas->restore(); |
| 481 | } |
| 482 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 483 | void Restore::trackSaveState(int* state) { |
| 484 | (*state)--; |
| 485 | } |
| 486 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 487 | Rotate::Rotate(SkScalar degrees) { |
| 488 | this->fDegrees = degrees; |
| 489 | this->fDrawType = ROTATE; |
| 490 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 491 | this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | void Rotate::execute(SkCanvas* canvas) { |
| 495 | canvas->rotate(this->fDegrees); |
| 496 | } |
| 497 | |
| 498 | Save::Save(SkCanvas::SaveFlags flags) { |
| 499 | this->fFlags = flags; |
| 500 | this->fDrawType = SAVE; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 501 | this->fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | void Save::execute(SkCanvas* canvas) { |
| 505 | canvas->save(this->fFlags); |
| 506 | } |
| 507 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 508 | void Save::trackSaveState(int* state) { |
| 509 | (*state)++; |
| 510 | } |
| 511 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 512 | SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint, |
| 513 | SkCanvas::SaveFlags flags) { |
| 514 | this->fBounds = bounds; |
| 515 | this->fPaint = paint; |
| 516 | this->fFlags = flags; |
| 517 | this->fDrawType = SAVE_LAYER; |
| 518 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 519 | if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: ")); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 520 | if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 521 | this->fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void SaveLayer::execute(SkCanvas* canvas) { |
| 525 | canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags); |
| 526 | } |
| 527 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 528 | void SaveLayer::trackSaveState(int* state) { |
| 529 | (*state)++; |
| 530 | } |
| 531 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 532 | Scale::Scale(SkScalar sx, SkScalar sy) { |
| 533 | this->fSx = sx; |
| 534 | this->fSy = sy; |
| 535 | this->fDrawType = SCALE; |
| 536 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 537 | this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); |
| 538 | this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | void Scale::execute(SkCanvas* canvas) { |
| 542 | canvas->scale(this->fSx, this->fSy); |
| 543 | } |
| 544 | |
| 545 | SetMatrix::SetMatrix(const SkMatrix& matrix) { |
| 546 | this->fMatrix = &matrix; |
| 547 | this->fDrawType = SET_MATRIX; |
| 548 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 549 | this->fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | void SetMatrix::execute(SkCanvas* canvas) { |
| 553 | canvas->setMatrix(*this->fMatrix); |
| 554 | } |
| 555 | |
| 556 | Skew::Skew(SkScalar sx, SkScalar sy) { |
| 557 | this->fSx = sx; |
| 558 | this->fSy = sy; |
| 559 | this->fDrawType = SKEW; |
| 560 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 561 | this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); |
| 562 | this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | void Skew::execute(SkCanvas* canvas) { |
| 566 | canvas->skew(this->fSx, this->fSy); |
| 567 | } |
| 568 | |
| 569 | Translate::Translate(SkScalar dx, SkScalar dy) { |
| 570 | this->fDx = dx; |
| 571 | this->fDy = dy; |
| 572 | this->fDrawType = TRANSLATE; |
| 573 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 574 | this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: ")); |
| 575 | this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | void Translate::execute(SkCanvas* canvas) { |
| 579 | canvas->translate(this->fDx, this->fDy); |
| 580 | } |