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