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) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 83 | fPath = path; |
| 84 | fOp = op; |
| 85 | fDoAA = doAA; |
| 86 | fDrawType = CLIP_PATH; |
| 87 | fBitmap = bitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 88 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 89 | fInfo.push(SkObjectParser::PathToString(path)); |
| 90 | fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 91 | 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) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 95 | canvas->clipPath(fPath, fOp, fDoAA); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 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, |
skia.committer@gmail.com | c76bb23 | 2013-03-18 07:01:03 +0000 | [diff] [blame] | 230 | const SkRect& dst, const SkPaint* paint, |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 231 | SkBitmap& resizedBitmap) { |
| 232 | fBitmap = bitmap; |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 233 | if (NULL != src) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 234 | fSrc = *src; |
| 235 | } else { |
| 236 | fSrc.setEmpty(); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 237 | } |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 238 | fDst = dst; |
| 239 | |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 240 | if (NULL != paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 241 | fPaint = *paint; |
| 242 | fPaintPtr = &fPaint; |
| 243 | } else { |
| 244 | fPaintPtr = NULL; |
| 245 | } |
| 246 | fDrawType = DRAW_BITMAP_RECT_TO_RECT; |
| 247 | fResizedBitmap = resizedBitmap; |
| 248 | |
| 249 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 250 | if (NULL != src) { |
| 251 | fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); |
| 252 | } |
| 253 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
| 254 | if (NULL != paint) { |
| 255 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 256 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void DrawBitmapRect::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 260 | canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 261 | } |
| 262 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 263 | const SkBitmap* DrawBitmapRect::getBitmap() const { |
| 264 | return &fResizedBitmap; |
| 265 | } |
| 266 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 267 | DrawData::DrawData(const void* data, size_t length) { |
| 268 | this->fData = data; |
| 269 | this->fLength = length; |
| 270 | this->fDrawType = DRAW_DATA; |
| 271 | // TODO(chudy): See if we can't display data and length. |
| 272 | } |
| 273 | |
| 274 | void DrawData::execute(SkCanvas* canvas) { |
| 275 | canvas->drawData(this->fData, this->fLength); |
| 276 | } |
| 277 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 278 | DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) { |
| 279 | this->fOval = &oval; |
| 280 | this->fPaint = &paint; |
| 281 | this->fDrawType = DRAW_OVAL; |
| 282 | |
| 283 | this->fInfo.push(SkObjectParser::RectToString(oval)); |
| 284 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
| 285 | } |
| 286 | |
| 287 | void DrawOval::execute(SkCanvas* canvas) { |
| 288 | canvas->drawOval(*this->fOval, *this->fPaint); |
| 289 | } |
| 290 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 291 | DrawPaint::DrawPaint(const SkPaint& paint) { |
| 292 | this->fPaint = &paint; |
| 293 | this->fDrawType = DRAW_PAINT; |
| 294 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 295 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | void DrawPaint::execute(SkCanvas* canvas) { |
| 299 | canvas->drawPaint(*this->fPaint); |
| 300 | } |
| 301 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 302 | DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 303 | fPath = path; |
| 304 | fPaint = paint; |
| 305 | fBitmap = bitmap; |
| 306 | fDrawType = DRAW_PATH; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 307 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 308 | fInfo.push(SkObjectParser::PathToString(path)); |
| 309 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void DrawPath::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 313 | canvas->drawPath(fPath, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 314 | } |
| 315 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 316 | const SkBitmap* DrawPath::getBitmap() const { |
| 317 | return &fBitmap; |
| 318 | } |
| 319 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 320 | DrawPicture::DrawPicture(SkPicture& picture) { |
| 321 | this->fPicture = &picture; |
| 322 | this->fDrawType = DRAW_PICTURE; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 323 | this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void DrawPicture::execute(SkCanvas* canvas) { |
| 327 | canvas->drawPicture(*this->fPicture); |
| 328 | } |
| 329 | |
| 330 | DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count, |
| 331 | const SkPoint pts[], const SkPaint& paint) { |
| 332 | this->fMode = mode; |
| 333 | this->fCount = count; |
| 334 | this->fPts = pts; |
| 335 | this->fPaint = &paint; |
| 336 | this->fDrawType = DRAW_POINTS; |
| 337 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 338 | this->fInfo.push(SkObjectParser::PointsToString(pts, count)); |
robertphillips@google.com | cb9b4a5 | 2013-01-31 16:52:43 +0000 | [diff] [blame] | 339 | this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count), |
robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 340 | "Points: ")); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 341 | this->fInfo.push(SkObjectParser::PointModeToString(mode)); |
robertphillips@google.com | 5c4d558 | 2013-01-15 12:53:31 +0000 | [diff] [blame] | 342 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | void DrawPoints::execute(SkCanvas* canvas) { |
| 346 | canvas->drawPoints(this->fMode, this->fCount, this->fPts, *this->fPaint); |
| 347 | } |
| 348 | |
| 349 | DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 350 | const SkPaint& paint) { |
| 351 | this->fText = text; |
| 352 | this->fByteLength = byteLength; |
| 353 | this->fPos = pos; |
| 354 | this->fPaint = &paint; |
| 355 | this->fDrawType = DRAW_POS_TEXT; |
| 356 | |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 357 | this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 358 | // TODO(chudy): Test that this works. |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 359 | this->fInfo.push(SkObjectParser::PointsToString(pos, 1)); |
| 360 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | void DrawPosText::execute(SkCanvas* canvas) { |
| 364 | canvas->drawPosText(this->fText, this->fByteLength, this->fPos, *this->fPaint); |
| 365 | } |
| 366 | |
| 367 | |
| 368 | DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength, |
skia.committer@gmail.com | c76bb23 | 2013-03-18 07:01:03 +0000 | [diff] [blame] | 369 | const SkScalar xpos[], SkScalar constY, |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 370 | const SkPaint& paint) { |
| 371 | fText = text; |
| 372 | fByteLength = byteLength; |
| 373 | fXpos = xpos; |
| 374 | fConstY = constY; |
| 375 | fPaint = paint; |
| 376 | fDrawType = DRAW_POS_TEXT_H; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 377 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 378 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 379 | fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: ")); |
| 380 | fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: ")); |
| 381 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void DrawPosTextH::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 385 | canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 389 | fRect = rect; |
| 390 | fPaint = paint; |
| 391 | fDrawType = DRAW_RECT; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 392 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 393 | fInfo.push(SkObjectParser::RectToString(rect)); |
| 394 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void DrawRectC::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 398 | canvas->drawRect(fRect, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 399 | } |
| 400 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 401 | DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 402 | this->fRRect = rrect; |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 403 | this->fPaint = paint; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 404 | this->fDrawType = DRAW_RRECT; |
| 405 | |
| 406 | this->fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 407 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
| 408 | } |
| 409 | |
| 410 | void DrawRRect::execute(SkCanvas* canvas) { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 411 | canvas->drawRRect(fRRect, fPaint); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 412 | } |
| 413 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 414 | DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top, |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 415 | const SkPaint* paint, SkBitmap& resizedBitmap) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 416 | this->fBitmap = &bitmap; |
| 417 | this->fLeft = left; |
| 418 | this->fTop = top; |
| 419 | this->fPaint = paint; |
| 420 | this->fDrawType = DRAW_SPRITE; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 421 | this->fResizedBitmap = resizedBitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 422 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 423 | this->fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 424 | this->fInfo.push(SkObjectParser::IntToString(left, "Left: ")); |
| 425 | this->fInfo.push(SkObjectParser::IntToString(top, "Top: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | void DrawSprite::execute(SkCanvas* canvas) { |
| 429 | canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint); |
| 430 | } |
| 431 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 432 | const SkBitmap* DrawSprite::getBitmap() const { |
| 433 | return &fResizedBitmap; |
| 434 | } |
| 435 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 436 | DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 437 | const SkPaint& paint) { |
| 438 | this->fText = text; |
| 439 | this->fByteLength = byteLength; |
| 440 | this->fX = x; |
| 441 | this->fY = y; |
| 442 | this->fPaint = &paint; |
| 443 | this->fDrawType = DRAW_TEXT; |
| 444 | |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 445 | this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 446 | this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); |
| 447 | this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); |
| 448 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | void DrawTextC::execute(SkCanvas* canvas) { |
| 452 | canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint); |
| 453 | } |
| 454 | |
| 455 | DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength, |
| 456 | const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { |
| 457 | this->fText = text; |
| 458 | this->fByteLength = byteLength; |
| 459 | this->fPath = &path; |
| 460 | this->fMatrix = matrix; |
| 461 | this->fPaint = &paint; |
| 462 | this->fDrawType = DRAW_TEXT_ON_PATH; |
| 463 | |
bungeman@google.com | 428fc4a | 2013-03-07 20:30:32 +0000 | [diff] [blame] | 464 | this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 465 | this->fInfo.push(SkObjectParser::PathToString(path)); |
| 466 | if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 467 | this->fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void DrawTextOnPath::execute(SkCanvas* canvas) { |
| 471 | canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath, |
| 472 | this->fMatrix, *this->fPaint); |
| 473 | } |
| 474 | |
| 475 | DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount, |
| 476 | const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], |
| 477 | SkXfermode* xfermode, const uint16_t indices[], int indexCount, |
| 478 | const SkPaint& paint) { |
| 479 | this->fVmode = vmode; |
| 480 | this->fVertexCount = vertexCount; |
| 481 | this->fTexs = texs; |
| 482 | this->fColors = colors; |
| 483 | this->fXfermode = xfermode; |
| 484 | this->fIndices = indices; |
| 485 | this->fIndexCount = indexCount; |
| 486 | this->fPaint = &paint; |
| 487 | this->fDrawType = DRAW_VERTICES; |
| 488 | // TODO(chudy) |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 489 | this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void DrawVertices::execute(SkCanvas* canvas) { |
| 493 | canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices, |
| 494 | this->fTexs, this->fColors, this->fXfermode, this->fIndices, |
| 495 | this->fIndexCount, *this->fPaint); |
| 496 | } |
| 497 | |
| 498 | Restore::Restore() { |
| 499 | this->fDrawType = RESTORE; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 500 | this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | void Restore::execute(SkCanvas* canvas) { |
| 504 | canvas->restore(); |
| 505 | } |
| 506 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 507 | void Restore::trackSaveState(int* state) { |
| 508 | (*state)--; |
| 509 | } |
| 510 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 511 | Rotate::Rotate(SkScalar degrees) { |
| 512 | this->fDegrees = degrees; |
| 513 | this->fDrawType = ROTATE; |
| 514 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 515 | this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void Rotate::execute(SkCanvas* canvas) { |
| 519 | canvas->rotate(this->fDegrees); |
| 520 | } |
| 521 | |
| 522 | Save::Save(SkCanvas::SaveFlags flags) { |
| 523 | this->fFlags = flags; |
| 524 | this->fDrawType = SAVE; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 525 | this->fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | void Save::execute(SkCanvas* canvas) { |
| 529 | canvas->save(this->fFlags); |
| 530 | } |
| 531 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 532 | void Save::trackSaveState(int* state) { |
| 533 | (*state)++; |
| 534 | } |
| 535 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 536 | SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint, |
| 537 | SkCanvas::SaveFlags flags) { |
| 538 | this->fBounds = bounds; |
| 539 | this->fPaint = paint; |
| 540 | this->fFlags = flags; |
| 541 | this->fDrawType = SAVE_LAYER; |
| 542 | |
robertphillips@google.com | 30d35f2 | 2012-11-06 16:45:36 +0000 | [diff] [blame] | 543 | if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: ")); |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 544 | if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 545 | this->fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void SaveLayer::execute(SkCanvas* canvas) { |
| 549 | canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags); |
| 550 | } |
| 551 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 552 | void SaveLayer::trackSaveState(int* state) { |
| 553 | (*state)++; |
| 554 | } |
| 555 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 556 | Scale::Scale(SkScalar sx, SkScalar sy) { |
| 557 | this->fSx = sx; |
| 558 | this->fSy = sy; |
| 559 | this->fDrawType = SCALE; |
| 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 Scale::execute(SkCanvas* canvas) { |
| 566 | canvas->scale(this->fSx, this->fSy); |
| 567 | } |
| 568 | |
| 569 | SetMatrix::SetMatrix(const SkMatrix& matrix) { |
robertphillips@google.com | b94b1e7 | 2013-02-19 21:00:26 +0000 | [diff] [blame] | 570 | this->fMatrix = matrix; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 571 | this->fDrawType = SET_MATRIX; |
| 572 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 573 | this->fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | void SetMatrix::execute(SkCanvas* canvas) { |
robertphillips@google.com | b94b1e7 | 2013-02-19 21:00:26 +0000 | [diff] [blame] | 577 | canvas->setMatrix(this->fMatrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | Skew::Skew(SkScalar sx, SkScalar sy) { |
| 581 | this->fSx = sx; |
| 582 | this->fSy = sy; |
| 583 | this->fDrawType = SKEW; |
| 584 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 585 | this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); |
| 586 | this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | void Skew::execute(SkCanvas* canvas) { |
| 590 | canvas->skew(this->fSx, this->fSy); |
| 591 | } |
| 592 | |
| 593 | Translate::Translate(SkScalar dx, SkScalar dy) { |
| 594 | this->fDx = dx; |
| 595 | this->fDy = dy; |
| 596 | this->fDrawType = TRANSLATE; |
| 597 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 598 | this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: ")); |
| 599 | this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void Translate::execute(SkCanvas* canvas) { |
| 603 | canvas->translate(this->fDx, this->fDy); |
| 604 | } |