blob: 5f33eb1f39bcef96698624bd0feeb32921193547 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
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.com902ebe52012-06-29 14:21:22 +000010#include "SkDrawCommand.h"
11#include "SkObjectParser.h"
12
13// TODO(chudy): Refactor into non subclass model.
14
15SkDrawCommand::SkDrawCommand() {
16 fVisible = true;
17}
18
19SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000020 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000021}
22
23const 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.com67baba42013-01-02 20:20:31 +000030 case CLIP_RRECT: return "Clip RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000031 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.com84d320e2012-09-20 19:09:17 +000035 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
chudy@google.com902ebe52012-06-29 14:21:22 +000036 case DRAW_DATA: return "Draw Data";
robertphillips@google.com67baba42013-01-02 20:20:31 +000037 case DRAW_OVAL: return "Draw Oval";
chudy@google.com902ebe52012-06-29 14:21:22 +000038 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.com67baba42013-01-02 20:20:31 +000045 case DRAW_RRECT: return "Draw RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000046 case DRAW_SPRITE: return "Draw Sprite";
47 case DRAW_TEXT: return "Draw Text";
48 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
49 case DRAW_VERTICES: return "Draw Vertices";
50 case RESTORE: return "Restore";
51 case ROTATE: return "Rotate";
52 case SAVE: return "Save";
53 case SAVE_LAYER: return "Save Layer";
54 case SCALE: return "Scale";
55 case SET_MATRIX: return "Set Matrix";
56 case SKEW: return "Skew";
57 case TRANSLATE: return "Translate";
58 default:
59 SkDebugf("DrawType error 0x%08x\n", type);
60 SkASSERT(0);
61 break;
62 }
63 SkDEBUGFAIL("DrawType UNUSED\n");
64 return NULL;
65}
66
chudy@google.com97cee972012-08-07 20:41:37 +000067SkString SkDrawCommand::toString() {
68 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000069}
70
71Clear::Clear(SkColor color) {
72 this->fColor = color;
73 this->fDrawType = DRAW_CLEAR;
chudy@google.com97cee972012-08-07 20:41:37 +000074 this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000075}
76
77void Clear::execute(SkCanvas* canvas) {
78 canvas->clear(this->fColor);
79}
80
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000081ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +000082 this->fPath = &path;
83 this->fOp = op;
84 this->fDoAA = doAA;
85 this->fDrawType = CLIP_PATH;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000086 this->fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +000087
chudy@google.com97cee972012-08-07 20:41:37 +000088 this->fInfo.push(SkObjectParser::PathToString(path));
89 this->fInfo.push(SkObjectParser::RegionOpToString(op));
90 this->fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +000091}
92
93void ClipPath::execute(SkCanvas* canvas) {
94 canvas->clipPath(*this->fPath, this->fOp, this->fDoAA);
95}
96
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000097const SkBitmap* ClipPath::getBitmap() const {
98 return &fBitmap;
99}
100
chudy@google.com902ebe52012-06-29 14:21:22 +0000101ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) {
102 this->fRegion = &region;
103 this->fOp = op;
104 this->fDrawType = CLIP_REGION;
105
chudy@google.com97cee972012-08-07 20:41:37 +0000106 this->fInfo.push(SkObjectParser::RegionToString(region));
107 this->fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000108}
109
110void ClipRegion::execute(SkCanvas* canvas) {
111 canvas->clipRegion(*this->fRegion, this->fOp);
112}
113
114ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
115 this->fRect = ▭
116 this->fOp = op;
117 this->fDoAA = doAA;
118 this->fDrawType = CLIP_RECT;
119
chudy@google.com97cee972012-08-07 20:41:37 +0000120 this->fInfo.push(SkObjectParser::RectToString(rect));
121 this->fInfo.push(SkObjectParser::RegionOpToString(op));
122 this->fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000123}
124
125void ClipRect::execute(SkCanvas* canvas) {
126 canvas->clipRect(*this->fRect, this->fOp, this->fDoAA);
127}
128
robertphillips@google.com67baba42013-01-02 20:20:31 +0000129ClipRRect::ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
130 this->fRRect = &rrect;
131 this->fOp = op;
132 this->fDoAA = doAA;
133 this->fDrawType = CLIP_RRECT;
134
135 this->fInfo.push(SkObjectParser::RRectToString(rrect));
136 this->fInfo.push(SkObjectParser::RegionOpToString(op));
137 this->fInfo.push(SkObjectParser::BoolToString(doAA));
138}
139
140void ClipRRect::execute(SkCanvas* canvas) {
141 canvas->clipRRect(*this->fRRect, this->fOp, this->fDoAA);
142}
143
chudy@google.com902ebe52012-06-29 14:21:22 +0000144Concat::Concat(const SkMatrix& matrix) {
145 this->fMatrix = &matrix;
146 this->fDrawType = CONCAT;
147
chudy@google.com97cee972012-08-07 20:41:37 +0000148 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000149}
150
151void Concat::execute(SkCanvas* canvas) {
152 canvas->concat(*this->fMatrix);
153}
154
155DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000156 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000157 this->fBitmap = &bitmap;
158 this->fLeft = left;
159 this->fTop = top;
160 this->fPaint = paint;
161 this->fDrawType = DRAW_BITMAP;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000162 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000163
chudy@google.com97cee972012-08-07 20:41:37 +0000164 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
165 this->fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
166 this->fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000167}
168
169void DrawBitmap::execute(SkCanvas* canvas) {
170 canvas->drawBitmap(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
171}
172
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000173const SkBitmap* DrawBitmap::getBitmap() const {
174 return &fResizedBitmap;
175}
176
chudy@google.com902ebe52012-06-29 14:21:22 +0000177DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000178 const SkMatrix& matrix, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000179 this->fBitmap = &bitmap;
180 this->fMatrix = &matrix;
181 this->fPaint = paint;
182 this->fDrawType = DRAW_BITMAP_MATRIX;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000183 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000184
chudy@google.com97cee972012-08-07 20:41:37 +0000185 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
186 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
187 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000188}
189
190void DrawBitmapMatrix::execute(SkCanvas* canvas) {
191 canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint);
192}
193
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000194const SkBitmap* DrawBitmapMatrix::getBitmap() const {
195 return &fResizedBitmap;
196}
197
chudy@google.com902ebe52012-06-29 14:21:22 +0000198DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000199 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000200 this->fBitmap = &bitmap;
201 this->fCenter = &center;
202 this->fDst = &dst;
203 this->fPaint = paint;
204 this->fDrawType = DRAW_BITMAP_NINE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000205 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000206
chudy@google.com97cee972012-08-07 20:41:37 +0000207 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
208 this->fInfo.push(SkObjectParser::IRectToString(center));
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000209 this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000210 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000211}
212
213void DrawBitmapNine::execute(SkCanvas* canvas) {
214 canvas->drawBitmapNine(*this->fBitmap, *this->fCenter, *this->fDst, this->fPaint);
215}
216
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000217const SkBitmap* DrawBitmapNine::getBitmap() const {
218 return &fResizedBitmap;
219}
220
reed@google.com71121732012-09-18 15:14:33 +0000221DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000222 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000223 this->fBitmap = &bitmap;
224 this->fSrc = src;
225 this->fDst = &dst;
226 this->fPaint = paint;
robertphillips@google.com84d320e2012-09-20 19:09:17 +0000227 this->fDrawType = DRAW_BITMAP_RECT_TO_RECT;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000228 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000229
chudy@google.com97cee972012-08-07 20:41:37 +0000230 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000231 if (src) this->fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
232 this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000233 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000234}
235
236void DrawBitmapRect::execute(SkCanvas* canvas) {
robertphillips@google.com84d320e2012-09-20 19:09:17 +0000237 canvas->drawBitmapRectToRect(*this->fBitmap, this->fSrc, *this->fDst, this->fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000238}
239
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000240const SkBitmap* DrawBitmapRect::getBitmap() const {
241 return &fResizedBitmap;
242}
243
chudy@google.com902ebe52012-06-29 14:21:22 +0000244DrawData::DrawData(const void* data, size_t length) {
245 this->fData = data;
246 this->fLength = length;
247 this->fDrawType = DRAW_DATA;
248 // TODO(chudy): See if we can't display data and length.
249}
250
251void DrawData::execute(SkCanvas* canvas) {
252 canvas->drawData(this->fData, this->fLength);
253}
254
robertphillips@google.com67baba42013-01-02 20:20:31 +0000255DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
256 this->fOval = &oval;
257 this->fPaint = &paint;
258 this->fDrawType = DRAW_OVAL;
259
260 this->fInfo.push(SkObjectParser::RectToString(oval));
261 this->fInfo.push(SkObjectParser::PaintToString(paint));
262}
263
264void DrawOval::execute(SkCanvas* canvas) {
265 canvas->drawOval(*this->fOval, *this->fPaint);
266}
267
chudy@google.com902ebe52012-06-29 14:21:22 +0000268DrawPaint::DrawPaint(const SkPaint& paint) {
269 this->fPaint = &paint;
270 this->fDrawType = DRAW_PAINT;
271
chudy@google.com97cee972012-08-07 20:41:37 +0000272 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000273}
274
275void DrawPaint::execute(SkCanvas* canvas) {
276 canvas->drawPaint(*this->fPaint);
277}
278
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000279DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000280 this->fPath = &path;
281 this->fPaint = &paint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000282 this->fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000283 this->fDrawType = DRAW_PATH;
284
chudy@google.com97cee972012-08-07 20:41:37 +0000285 this->fInfo.push(SkObjectParser::PathToString(path));
286 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000287}
288
289void DrawPath::execute(SkCanvas* canvas) {
290 canvas->drawPath(*this->fPath, *this->fPaint);
291}
292
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000293const SkBitmap* DrawPath::getBitmap() const {
294 return &fBitmap;
295}
296
chudy@google.com902ebe52012-06-29 14:21:22 +0000297DrawPicture::DrawPicture(SkPicture& picture) {
298 this->fPicture = &picture;
299 this->fDrawType = DRAW_PICTURE;
chudy@google.com97cee972012-08-07 20:41:37 +0000300 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000301}
302
303void DrawPicture::execute(SkCanvas* canvas) {
304 canvas->drawPicture(*this->fPicture);
305}
306
307DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
308 const SkPoint pts[], const SkPaint& paint) {
309 this->fMode = mode;
310 this->fCount = count;
311 this->fPts = pts;
312 this->fPaint = &paint;
313 this->fDrawType = DRAW_POINTS;
314
chudy@google.com97cee972012-08-07 20:41:37 +0000315 this->fInfo.push(SkObjectParser::PointsToString(pts, count));
skia.committer@gmail.com04ba4482012-09-07 02:01:30 +0000316 this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar(count),
robertphillips@google.com94acc702012-09-06 18:43:21 +0000317 "Points: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000318 this->fInfo.push(SkObjectParser::PointModeToString(mode));
robertphillips@google.com5c4d5582013-01-15 12:53:31 +0000319 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000320}
321
322void DrawPoints::execute(SkCanvas* canvas) {
323 canvas->drawPoints(this->fMode, this->fCount, this->fPts, *this->fPaint);
324}
325
326DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
327 const SkPaint& paint) {
328 this->fText = text;
329 this->fByteLength = byteLength;
330 this->fPos = pos;
331 this->fPaint = &paint;
332 this->fDrawType = DRAW_POS_TEXT;
333
chudy@google.com97cee972012-08-07 20:41:37 +0000334 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
chudy@google.com902ebe52012-06-29 14:21:22 +0000335 // TODO(chudy): Test that this works.
chudy@google.com97cee972012-08-07 20:41:37 +0000336 this->fInfo.push(SkObjectParser::PointsToString(pos, 1));
337 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000338}
339
340void DrawPosText::execute(SkCanvas* canvas) {
341 canvas->drawPosText(this->fText, this->fByteLength, this->fPos, *this->fPaint);
342}
343
344
345DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
346 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
347 this->fText = text;
348 this->fByteLength = byteLength;
349 this->fXpos = xpos;
350 this->fConstY = constY;
351 this->fPaint = &paint;
352 this->fDrawType = DRAW_POS_TEXT_H;
353
chudy@google.com97cee972012-08-07 20:41:37 +0000354 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
355 this->fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
356 this->fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
357 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000358}
359
360void DrawPosTextH::execute(SkCanvas* canvas) {
361 canvas->drawPosTextH(this->fText, this->fByteLength, this->fXpos, this->fConstY,
362 *this->fPaint);
363}
364
365DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
366 this->fRect = ▭
367 this->fPaint = &paint;
368 this->fDrawType = DRAW_RECT;
369
chudy@google.com97cee972012-08-07 20:41:37 +0000370 this->fInfo.push(SkObjectParser::RectToString(rect));
371 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000372}
373
374void DrawRectC::execute(SkCanvas* canvas) {
375 canvas->drawRect(*this->fRect, *this->fPaint);
376}
377
robertphillips@google.com67baba42013-01-02 20:20:31 +0000378DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
379 this->fRRect = rrect;
380 this->fPaint = &paint;
381 this->fDrawType = DRAW_RRECT;
382
383 this->fInfo.push(SkObjectParser::RRectToString(rrect));
384 this->fInfo.push(SkObjectParser::PaintToString(paint));
385}
386
387void DrawRRect::execute(SkCanvas* canvas) {
388 canvas->drawRRect(this->fRRect, *this->fPaint);
389}
390
chudy@google.com902ebe52012-06-29 14:21:22 +0000391DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000392 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000393 this->fBitmap = &bitmap;
394 this->fLeft = left;
395 this->fTop = top;
396 this->fPaint = paint;
397 this->fDrawType = DRAW_SPRITE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000398 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000399
chudy@google.com97cee972012-08-07 20:41:37 +0000400 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
401 this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
402 this->fInfo.push(SkObjectParser::IntToString(top, "Top: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000403}
404
405void DrawSprite::execute(SkCanvas* canvas) {
406 canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
407}
408
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000409const SkBitmap* DrawSprite::getBitmap() const {
410 return &fResizedBitmap;
411}
412
chudy@google.com902ebe52012-06-29 14:21:22 +0000413DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
414 const SkPaint& paint) {
415 this->fText = text;
416 this->fByteLength = byteLength;
417 this->fX = x;
418 this->fY = y;
419 this->fPaint = &paint;
420 this->fDrawType = DRAW_TEXT;
421
chudy@google.com97cee972012-08-07 20:41:37 +0000422 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
423 this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
424 this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
425 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000426}
427
428void DrawTextC::execute(SkCanvas* canvas) {
429 canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint);
430}
431
432DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
433 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
434 this->fText = text;
435 this->fByteLength = byteLength;
436 this->fPath = &path;
437 this->fMatrix = matrix;
438 this->fPaint = &paint;
439 this->fDrawType = DRAW_TEXT_ON_PATH;
440
chudy@google.com97cee972012-08-07 20:41:37 +0000441 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
442 this->fInfo.push(SkObjectParser::PathToString(path));
443 if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
444 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000445}
446
447void DrawTextOnPath::execute(SkCanvas* canvas) {
448 canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath,
449 this->fMatrix, *this->fPaint);
450}
451
452DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
453 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
454 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
455 const SkPaint& paint) {
456 this->fVmode = vmode;
457 this->fVertexCount = vertexCount;
458 this->fTexs = texs;
459 this->fColors = colors;
460 this->fXfermode = xfermode;
461 this->fIndices = indices;
462 this->fIndexCount = indexCount;
463 this->fPaint = &paint;
464 this->fDrawType = DRAW_VERTICES;
465 // TODO(chudy)
chudy@google.com97cee972012-08-07 20:41:37 +0000466 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000467}
468
469void DrawVertices::execute(SkCanvas* canvas) {
470 canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices,
471 this->fTexs, this->fColors, this->fXfermode, this->fIndices,
472 this->fIndexCount, *this->fPaint);
473}
474
475Restore::Restore() {
476 this->fDrawType = RESTORE;
chudy@google.com97cee972012-08-07 20:41:37 +0000477 this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000478}
479
480void Restore::execute(SkCanvas* canvas) {
481 canvas->restore();
482}
483
tomhudson@google.com0699e022012-11-27 16:09:42 +0000484void Restore::trackSaveState(int* state) {
485 (*state)--;
486}
487
chudy@google.com902ebe52012-06-29 14:21:22 +0000488Rotate::Rotate(SkScalar degrees) {
489 this->fDegrees = degrees;
490 this->fDrawType = ROTATE;
491
chudy@google.com97cee972012-08-07 20:41:37 +0000492 this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000493}
494
495void Rotate::execute(SkCanvas* canvas) {
496 canvas->rotate(this->fDegrees);
497}
498
499Save::Save(SkCanvas::SaveFlags flags) {
500 this->fFlags = flags;
501 this->fDrawType = SAVE;
chudy@google.com97cee972012-08-07 20:41:37 +0000502 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000503}
504
505void Save::execute(SkCanvas* canvas) {
506 canvas->save(this->fFlags);
507}
508
tomhudson@google.com0699e022012-11-27 16:09:42 +0000509void Save::trackSaveState(int* state) {
510 (*state)++;
511}
512
chudy@google.com902ebe52012-06-29 14:21:22 +0000513SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
514 SkCanvas::SaveFlags flags) {
515 this->fBounds = bounds;
516 this->fPaint = paint;
517 this->fFlags = flags;
518 this->fDrawType = SAVE_LAYER;
519
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000520 if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000521 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
522 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000523}
524
525void SaveLayer::execute(SkCanvas* canvas) {
526 canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags);
527}
528
tomhudson@google.com0699e022012-11-27 16:09:42 +0000529void SaveLayer::trackSaveState(int* state) {
530 (*state)++;
531}
532
chudy@google.com902ebe52012-06-29 14:21:22 +0000533Scale::Scale(SkScalar sx, SkScalar sy) {
534 this->fSx = sx;
535 this->fSy = sy;
536 this->fDrawType = SCALE;
537
chudy@google.com97cee972012-08-07 20:41:37 +0000538 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
539 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000540}
541
542void Scale::execute(SkCanvas* canvas) {
543 canvas->scale(this->fSx, this->fSy);
544}
545
546SetMatrix::SetMatrix(const SkMatrix& matrix) {
547 this->fMatrix = &matrix;
548 this->fDrawType = SET_MATRIX;
549
chudy@google.com97cee972012-08-07 20:41:37 +0000550 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000551}
552
553void SetMatrix::execute(SkCanvas* canvas) {
554 canvas->setMatrix(*this->fMatrix);
555}
556
557Skew::Skew(SkScalar sx, SkScalar sy) {
558 this->fSx = sx;
559 this->fSy = sy;
560 this->fDrawType = SKEW;
561
chudy@google.com97cee972012-08-07 20:41:37 +0000562 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
563 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000564}
565
566void Skew::execute(SkCanvas* canvas) {
567 canvas->skew(this->fSx, this->fSy);
568}
569
570Translate::Translate(SkScalar dx, SkScalar dy) {
571 this->fDx = dx;
572 this->fDy = dy;
573 this->fDrawType = TRANSLATE;
574
chudy@google.com97cee972012-08-07 20:41:37 +0000575 this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
576 this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000577}
578
579void Translate::execute(SkCanvas* canvas) {
580 canvas->translate(this->fDx, this->fDy);
581}