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