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