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