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) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 73 | fColor = color; |
| 74 | fDrawType = DRAW_CLEAR; |
| 75 | 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) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 79 | canvas->clear(fColor); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 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) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 103 | fRegion = region; |
| 104 | fOp = op; |
| 105 | fDrawType = CLIP_REGION; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 106 | |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 107 | fInfo.push(SkObjectParser::RegionToString(region)); |
| 108 | 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) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 112 | canvas->clipRegion(fRegion, fOp); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 116 | fRect = rect; |
| 117 | fOp = op; |
| 118 | fDoAA = doAA; |
| 119 | fDrawType = CLIP_RECT; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 120 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 121 | fInfo.push(SkObjectParser::RectToString(rect)); |
| 122 | fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 123 | 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) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 127 | canvas->clipRect(fRect, fOp, fDoAA); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 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 | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 131 | fRRect = rrect; |
| 132 | fOp = op; |
| 133 | fDoAA = doAA; |
| 134 | fDrawType = CLIP_RRECT; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 135 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 136 | fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 137 | fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 138 | fInfo.push(SkObjectParser::BoolToString(doAA)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void ClipRRect::execute(SkCanvas* canvas) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 142 | canvas->clipRRect(fRRect, fOp, 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) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 146 | fMatrix = matrix; |
| 147 | fDrawType = CONCAT; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 148 | |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 149 | 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) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 153 | canvas->concat(fMatrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 157 | const SkPaint* paint, SkBitmap& resizedBitmap) { |
| 158 | fBitmap = bitmap; |
| 159 | fLeft = left; |
| 160 | fTop = top; |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 161 | if (NULL != paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 162 | fPaint = *paint; |
| 163 | fPaintPtr = &fPaint; |
| 164 | } else { |
| 165 | fPaintPtr = NULL; |
| 166 | } |
| 167 | fDrawType = DRAW_BITMAP; |
| 168 | fResizedBitmap = resizedBitmap; |
| 169 | |
| 170 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 171 | fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: ")); |
| 172 | fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: ")); |
| 173 | if (NULL != paint) { |
| 174 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 175 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void DrawBitmap::execute(SkCanvas* canvas) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 179 | canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 180 | } |
| 181 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 182 | const SkBitmap* DrawBitmap::getBitmap() const { |
| 183 | return &fResizedBitmap; |
| 184 | } |
| 185 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 186 | DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap, |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 187 | const SkMatrix& matrix, |
| 188 | const SkPaint* paint, |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 189 | SkBitmap& resizedBitmap) { |
| 190 | fBitmap = bitmap; |
| 191 | fMatrix = matrix; |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 192 | if (NULL != paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 193 | fPaint = *paint; |
| 194 | fPaintPtr = &fPaint; |
| 195 | } else { |
| 196 | fPaintPtr = NULL; |
| 197 | } |
| 198 | fDrawType = DRAW_BITMAP_MATRIX; |
| 199 | fResizedBitmap = resizedBitmap; |
| 200 | |
| 201 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 202 | fInfo.push(SkObjectParser::MatrixToString(matrix)); |
| 203 | if (NULL != paint) { |
| 204 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 205 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void DrawBitmapMatrix::execute(SkCanvas* canvas) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 209 | canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 210 | } |
| 211 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 212 | const SkBitmap* DrawBitmapMatrix::getBitmap() const { |
| 213 | return &fResizedBitmap; |
| 214 | } |
| 215 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 216 | DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 217 | const SkRect& dst, const SkPaint* paint, |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 218 | SkBitmap& resizedBitmap) { |
| 219 | fBitmap = bitmap; |
| 220 | fCenter = center; |
| 221 | fDst = dst; |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 222 | if (NULL != paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 223 | fPaint = *paint; |
| 224 | fPaintPtr = &fPaint; |
| 225 | } else { |
| 226 | fPaintPtr = NULL; |
| 227 | } |
| 228 | fDrawType = DRAW_BITMAP_NINE; |
| 229 | fResizedBitmap = resizedBitmap; |
| 230 | |
| 231 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 232 | fInfo.push(SkObjectParser::IRectToString(center)); |
| 233 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
| 234 | if (NULL != paint) { |
| 235 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 236 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void DrawBitmapNine::execute(SkCanvas* canvas) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 240 | canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 241 | } |
| 242 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 243 | const SkBitmap* DrawBitmapNine::getBitmap() const { |
| 244 | return &fResizedBitmap; |
| 245 | } |
| 246 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 247 | DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
skia.committer@gmail.com | c76bb23 | 2013-03-18 07:01:03 +0000 | [diff] [blame] | 248 | const SkRect& dst, const SkPaint* paint, |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 249 | SkBitmap& resizedBitmap) { |
| 250 | fBitmap = bitmap; |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 251 | if (NULL != src) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 252 | fSrc = *src; |
| 253 | } else { |
| 254 | fSrc.setEmpty(); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 255 | } |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 256 | fDst = dst; |
| 257 | |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 258 | if (NULL != paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 259 | fPaint = *paint; |
| 260 | fPaintPtr = &fPaint; |
| 261 | } else { |
| 262 | fPaintPtr = NULL; |
| 263 | } |
| 264 | fDrawType = DRAW_BITMAP_RECT_TO_RECT; |
| 265 | fResizedBitmap = resizedBitmap; |
| 266 | |
| 267 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 268 | if (NULL != src) { |
| 269 | fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); |
| 270 | } |
| 271 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
| 272 | if (NULL != paint) { |
| 273 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 274 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void DrawBitmapRect::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 278 | canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 279 | } |
| 280 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 281 | const SkBitmap* DrawBitmapRect::getBitmap() const { |
| 282 | return &fResizedBitmap; |
| 283 | } |
| 284 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 285 | DrawData::DrawData(const void* data, size_t length) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 286 | fData = new char[length]; |
| 287 | memcpy(fData, data, length); |
| 288 | fLength = length; |
| 289 | fDrawType = DRAW_DATA; |
| 290 | |
| 291 | // TODO: add display of actual data? |
| 292 | SkString* str = new SkString; |
| 293 | str->appendf("length: %d", length); |
| 294 | fInfo.push(str); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void DrawData::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 298 | canvas->drawData(fData, fLength); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 299 | } |
| 300 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 301 | DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 302 | fOval = oval; |
| 303 | fPaint = paint; |
| 304 | fDrawType = DRAW_OVAL; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 305 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 306 | fInfo.push(SkObjectParser::RectToString(oval)); |
| 307 | fInfo.push(SkObjectParser::PaintToString(paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void DrawOval::execute(SkCanvas* canvas) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 311 | canvas->drawOval(fOval, fPaint); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 312 | } |
| 313 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 314 | DrawPaint::DrawPaint(const SkPaint& paint) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 315 | fPaint = paint; |
| 316 | fDrawType = DRAW_PAINT; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 317 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 318 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void DrawPaint::execute(SkCanvas* canvas) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 322 | canvas->drawPaint(fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 323 | } |
| 324 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 325 | DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 326 | fPath = path; |
| 327 | fPaint = paint; |
| 328 | fBitmap = bitmap; |
| 329 | fDrawType = DRAW_PATH; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 330 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 331 | fInfo.push(SkObjectParser::PathToString(path)); |
| 332 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void DrawPath::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 336 | canvas->drawPath(fPath, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 337 | } |
| 338 | |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 339 | const SkBitmap* DrawPath::getBitmap() const { |
| 340 | return &fBitmap; |
| 341 | } |
| 342 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 343 | DrawPicture::DrawPicture(SkPicture& picture) : |
| 344 | fPicture(picture) { |
| 345 | fDrawType = DRAW_PICTURE; |
| 346 | fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void DrawPicture::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 350 | canvas->drawPicture(fPicture); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count, |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 354 | const SkPoint pts[], const SkPaint& paint) { |
| 355 | fMode = mode; |
| 356 | fCount = count; |
| 357 | fPts = new SkPoint[count]; |
| 358 | memcpy(fPts, pts, count * sizeof(SkPoint)); |
| 359 | fPaint = paint; |
| 360 | fDrawType = DRAW_POINTS; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 361 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 362 | fInfo.push(SkObjectParser::PointsToString(pts, count)); |
| 363 | fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count), |
| 364 | "Points: ")); |
| 365 | fInfo.push(SkObjectParser::PointModeToString(mode)); |
| 366 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void DrawPoints::execute(SkCanvas* canvas) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 370 | canvas->drawPoints(fMode, fCount, fPts, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 374 | const SkPaint& paint) { |
| 375 | size_t numPts = paint.countText(text, byteLength); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 376 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 377 | fText = new char[byteLength]; |
| 378 | memcpy(fText, text, byteLength); |
| 379 | fByteLength = byteLength; |
| 380 | |
| 381 | fPos = new SkPoint[numPts]; |
| 382 | memcpy(fPos, pos, numPts * sizeof(SkPoint)); |
| 383 | |
| 384 | fPaint = paint; |
| 385 | fDrawType = DRAW_POS_TEXT; |
| 386 | |
| 387 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 388 | // TODO(chudy): Test that this works. |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 389 | fInfo.push(SkObjectParser::PointsToString(pos, 1)); |
| 390 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | void DrawPosText::execute(SkCanvas* canvas) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 394 | canvas->drawPosText(fText, fByteLength, fPos, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | |
| 398 | DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength, |
skia.committer@gmail.com | c76bb23 | 2013-03-18 07:01:03 +0000 | [diff] [blame] | 399 | const SkScalar xpos[], SkScalar constY, |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 400 | const SkPaint& paint) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 401 | size_t numPts = paint.countText(text, byteLength); |
| 402 | |
| 403 | fText = new char[byteLength]; |
| 404 | memcpy(fText, text, byteLength); |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 405 | fByteLength = byteLength; |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 406 | |
| 407 | fXpos = new SkScalar[numPts]; |
| 408 | memcpy(fXpos, xpos, numPts * sizeof(SkScalar)); |
| 409 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 410 | fConstY = constY; |
| 411 | fPaint = paint; |
| 412 | fDrawType = DRAW_POS_TEXT_H; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 413 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 414 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 415 | fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: ")); |
| 416 | fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: ")); |
| 417 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void DrawPosTextH::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 421 | canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 425 | fRect = rect; |
| 426 | fPaint = paint; |
| 427 | fDrawType = DRAW_RECT; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 428 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 429 | fInfo.push(SkObjectParser::RectToString(rect)); |
| 430 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void DrawRectC::execute(SkCanvas* canvas) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 434 | canvas->drawRect(fRect, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 435 | } |
| 436 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 437 | DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 438 | fRRect = rrect; |
| 439 | fPaint = paint; |
| 440 | fDrawType = DRAW_RRECT; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 441 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 442 | fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 443 | fInfo.push(SkObjectParser::PaintToString(paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void DrawRRect::execute(SkCanvas* canvas) { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 447 | canvas->drawRRect(fRRect, fPaint); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 448 | } |
| 449 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 450 | DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top, |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 451 | const SkPaint* paint, SkBitmap& resizedBitmap) { |
| 452 | fBitmap = bitmap; |
| 453 | fLeft = left; |
| 454 | fTop = top; |
| 455 | if (NULL != paint) { |
| 456 | fPaint = *paint; |
| 457 | fPaintPtr = &fPaint; |
| 458 | } else { |
| 459 | fPaintPtr = NULL; |
| 460 | } |
| 461 | fDrawType = DRAW_SPRITE; |
| 462 | fResizedBitmap = resizedBitmap; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 463 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 464 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 465 | fInfo.push(SkObjectParser::IntToString(left, "Left: ")); |
| 466 | fInfo.push(SkObjectParser::IntToString(top, "Top: ")); |
| 467 | if (NULL != paint) { |
| 468 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 469 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | void DrawSprite::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 473 | canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 474 | } |
| 475 | |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 476 | const SkBitmap* DrawSprite::getBitmap() const { |
| 477 | return &fResizedBitmap; |
| 478 | } |
| 479 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 480 | DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 481 | const SkPaint& paint) { |
| 482 | fText = new char[byteLength]; |
| 483 | memcpy(fText, text, byteLength); |
| 484 | fByteLength = byteLength; |
| 485 | fX = x; |
| 486 | fY = y; |
| 487 | fPaint = paint; |
| 488 | fDrawType = DRAW_TEXT; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 489 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 490 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 491 | fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); |
| 492 | fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); |
| 493 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | void DrawTextC::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 497 | canvas->drawText(fText, fByteLength, fX, fY, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength, |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 501 | const SkPath& path, const SkMatrix* matrix, |
| 502 | const SkPaint& paint) { |
| 503 | fText = new char[byteLength]; |
| 504 | memcpy(fText, text, byteLength); |
| 505 | fByteLength = byteLength; |
| 506 | fPath = path; |
| 507 | if (NULL != matrix) { |
| 508 | fMatrix = *matrix; |
| 509 | } else { |
| 510 | fMatrix.setIdentity(); |
| 511 | } |
| 512 | fPaint = paint; |
| 513 | fDrawType = DRAW_TEXT_ON_PATH; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 514 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 515 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 516 | fInfo.push(SkObjectParser::PathToString(path)); |
| 517 | if (NULL != matrix) { |
| 518 | fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 519 | } |
| 520 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | void DrawTextOnPath::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 524 | canvas->drawTextOnPath(fText, fByteLength, fPath, |
| 525 | fMatrix.isIdentity() ? NULL : &fMatrix, |
| 526 | fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount, |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 530 | const SkPoint vertices[], const SkPoint texs[], |
| 531 | const SkColor colors[], SkXfermode* xfermode, |
| 532 | const uint16_t indices[], int indexCount, |
| 533 | const SkPaint& paint) { |
| 534 | fVmode = vmode; |
| 535 | |
| 536 | fVertexCount = vertexCount; |
| 537 | |
| 538 | fVertices = new SkPoint[vertexCount]; |
| 539 | memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint)); |
| 540 | |
| 541 | if (NULL != texs) { |
| 542 | fTexs = new SkPoint[vertexCount]; |
| 543 | memcpy(fTexs, texs, vertexCount * sizeof(SkPoint)); |
| 544 | } else { |
| 545 | fTexs = NULL; |
| 546 | } |
| 547 | |
| 548 | if (NULL != colors) { |
| 549 | fColors = new SkColor[vertexCount]; |
| 550 | memcpy(fColors, colors, vertexCount * sizeof(SkColor)); |
| 551 | } else { |
| 552 | fColors = NULL; |
| 553 | } |
| 554 | |
| 555 | fXfermode = xfermode; |
| 556 | if (NULL != fXfermode) { |
| 557 | fXfermode->ref(); |
| 558 | } |
| 559 | |
| 560 | if (indexCount > 0) { |
| 561 | fIndices = new uint16_t[indexCount]; |
| 562 | memcpy(fIndices, indices, indexCount * sizeof(uint16_t)); |
| 563 | } else { |
| 564 | fIndices = NULL; |
| 565 | } |
| 566 | |
| 567 | fIndexCount = indexCount; |
| 568 | fPaint = paint; |
| 569 | fDrawType = DRAW_VERTICES; |
| 570 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 571 | // TODO(chudy) |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 572 | fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
| 573 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 574 | } |
| 575 | |
| 576 | DrawVertices::~DrawVertices() { |
| 577 | delete [] fVertices; |
| 578 | delete [] fTexs; |
| 579 | delete [] fColors; |
| 580 | SkSafeUnref(fXfermode); |
| 581 | delete [] fIndices; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | void DrawVertices::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 585 | canvas->drawVertices(fVmode, fVertexCount, fVertices, |
| 586 | fTexs, fColors, fXfermode, fIndices, |
| 587 | fIndexCount, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | Restore::Restore() { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 591 | fDrawType = RESTORE; |
| 592 | fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | void Restore::execute(SkCanvas* canvas) { |
| 596 | canvas->restore(); |
| 597 | } |
| 598 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 599 | void Restore::trackSaveState(int* state) { |
| 600 | (*state)--; |
| 601 | } |
| 602 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 603 | Rotate::Rotate(SkScalar degrees) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 604 | fDegrees = degrees; |
| 605 | fDrawType = ROTATE; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 606 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 607 | fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | void Rotate::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 611 | canvas->rotate(fDegrees); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | Save::Save(SkCanvas::SaveFlags flags) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 615 | fFlags = flags; |
| 616 | fDrawType = SAVE; |
| 617 | fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void Save::execute(SkCanvas* canvas) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 621 | canvas->save(fFlags); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 622 | } |
| 623 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 624 | void Save::trackSaveState(int* state) { |
| 625 | (*state)++; |
| 626 | } |
| 627 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 628 | SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint, |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 629 | SkCanvas::SaveFlags flags) { |
| 630 | if (NULL != bounds) { |
| 631 | fBounds = *bounds; |
| 632 | } else { |
| 633 | fBounds.setEmpty(); |
| 634 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 635 | |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 636 | if (NULL != paint) { |
| 637 | fPaint = *paint; |
| 638 | fPaintPtr = &fPaint; |
| 639 | } else { |
| 640 | fPaintPtr = NULL; |
| 641 | } |
| 642 | fFlags = flags; |
| 643 | fDrawType = SAVE_LAYER; |
| 644 | |
| 645 | if (NULL != bounds) { |
| 646 | fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: ")); |
| 647 | } |
| 648 | if (NULL != paint) { |
| 649 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 650 | } |
| 651 | fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void SaveLayer::execute(SkCanvas* canvas) { |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 655 | canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds, |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 656 | fPaintPtr, |
| 657 | fFlags); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 658 | } |
| 659 | |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 660 | void SaveLayer::trackSaveState(int* state) { |
| 661 | (*state)++; |
| 662 | } |
| 663 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 664 | Scale::Scale(SkScalar sx, SkScalar sy) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 665 | fSx = sx; |
| 666 | fSy = sy; |
| 667 | fDrawType = SCALE; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 668 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 669 | fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); |
| 670 | fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | void Scale::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 674 | canvas->scale(fSx, fSy); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | SetMatrix::SetMatrix(const SkMatrix& matrix) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 678 | fMatrix = matrix; |
| 679 | fDrawType = SET_MATRIX; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 680 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 681 | fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | void SetMatrix::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 685 | canvas->setMatrix(fMatrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | Skew::Skew(SkScalar sx, SkScalar sy) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 689 | fSx = sx; |
| 690 | fSy = sy; |
| 691 | fDrawType = SKEW; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 692 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 693 | fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: ")); |
| 694 | fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | void Skew::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 698 | canvas->skew(fSx, fSy); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | Translate::Translate(SkScalar dx, SkScalar dy) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 702 | fDx = dx; |
| 703 | fDy = dy; |
| 704 | fDrawType = TRANSLATE; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 705 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 706 | fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: ")); |
| 707 | fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void Translate::execute(SkCanvas* canvas) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame^] | 711 | canvas->translate(fDx, fDy); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 712 | } |