blob: b1855955308a5cded3e91b737503d475d88c7830 [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) {
robertphillips@google.com2da95b22013-01-17 16:07:04 +0000130 this->fRRect = rrect;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000131 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) {
robertphillips@google.com2da95b22013-01-17 16:07:04 +0000141 canvas->clipRRect(this->fRRect, this->fOp, this->fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000142}
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: "));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000167 if (NULL != paint) {
168 this->fInfo.push(SkObjectParser::PaintToString(*paint));
169 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000170}
171
172void DrawBitmap::execute(SkCanvas* canvas) {
173 canvas->drawBitmap(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
174}
175
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000176const SkBitmap* DrawBitmap::getBitmap() const {
177 return &fResizedBitmap;
178}
179
chudy@google.com902ebe52012-06-29 14:21:22 +0000180DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000181 const SkMatrix& matrix, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000182 this->fBitmap = &bitmap;
183 this->fMatrix = &matrix;
184 this->fPaint = paint;
185 this->fDrawType = DRAW_BITMAP_MATRIX;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000186 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000187
chudy@google.com97cee972012-08-07 20:41:37 +0000188 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
189 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000190 if (NULL != paint) {
191 this->fInfo.push(SkObjectParser::PaintToString(*paint));
192 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000193}
194
195void DrawBitmapMatrix::execute(SkCanvas* canvas) {
196 canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint);
197}
198
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000199const SkBitmap* DrawBitmapMatrix::getBitmap() const {
200 return &fResizedBitmap;
201}
202
chudy@google.com902ebe52012-06-29 14:21:22 +0000203DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000204 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000205 this->fBitmap = &bitmap;
206 this->fCenter = &center;
207 this->fDst = &dst;
208 this->fPaint = paint;
209 this->fDrawType = DRAW_BITMAP_NINE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000210 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000211
chudy@google.com97cee972012-08-07 20:41:37 +0000212 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
213 this->fInfo.push(SkObjectParser::IRectToString(center));
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000214 this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000215 if (NULL != paint) {
216 this->fInfo.push(SkObjectParser::PaintToString(*paint));
217 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000218}
219
220void DrawBitmapNine::execute(SkCanvas* canvas) {
221 canvas->drawBitmapNine(*this->fBitmap, *this->fCenter, *this->fDst, this->fPaint);
222}
223
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000224const SkBitmap* DrawBitmapNine::getBitmap() const {
225 return &fResizedBitmap;
226}
227
reed@google.com71121732012-09-18 15:14:33 +0000228DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000229 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000230 this->fBitmap = &bitmap;
231 this->fSrc = src;
232 this->fDst = &dst;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000233 if (NULL != paint) {
234 this->fPaint = *paint;
235 this->fPaintPtr = &this->fPaint;
236 } else {
237 this->fPaintPtr = NULL;
238 }
robertphillips@google.com84d320e2012-09-20 19:09:17 +0000239 this->fDrawType = DRAW_BITMAP_RECT_TO_RECT;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000240 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000241
chudy@google.com97cee972012-08-07 20:41:37 +0000242 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000243 if (NULL != src) {
244 this->fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
245 }
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000246 this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000247 if (NULL != paint) {
248 this->fInfo.push(SkObjectParser::PaintToString(*paint));
249 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000250}
251
252void DrawBitmapRect::execute(SkCanvas* canvas) {
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000253 canvas->drawBitmapRectToRect(*this->fBitmap, this->fSrc, *this->fDst, this->fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000254}
255
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000256const SkBitmap* DrawBitmapRect::getBitmap() const {
257 return &fResizedBitmap;
258}
259
chudy@google.com902ebe52012-06-29 14:21:22 +0000260DrawData::DrawData(const void* data, size_t length) {
261 this->fData = data;
262 this->fLength = length;
263 this->fDrawType = DRAW_DATA;
264 // TODO(chudy): See if we can't display data and length.
265}
266
267void DrawData::execute(SkCanvas* canvas) {
268 canvas->drawData(this->fData, this->fLength);
269}
270
robertphillips@google.com67baba42013-01-02 20:20:31 +0000271DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
272 this->fOval = &oval;
273 this->fPaint = &paint;
274 this->fDrawType = DRAW_OVAL;
275
276 this->fInfo.push(SkObjectParser::RectToString(oval));
277 this->fInfo.push(SkObjectParser::PaintToString(paint));
278}
279
280void DrawOval::execute(SkCanvas* canvas) {
281 canvas->drawOval(*this->fOval, *this->fPaint);
282}
283
chudy@google.com902ebe52012-06-29 14:21:22 +0000284DrawPaint::DrawPaint(const SkPaint& paint) {
285 this->fPaint = &paint;
286 this->fDrawType = DRAW_PAINT;
287
chudy@google.com97cee972012-08-07 20:41:37 +0000288 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000289}
290
291void DrawPaint::execute(SkCanvas* canvas) {
292 canvas->drawPaint(*this->fPaint);
293}
294
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000295DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000296 this->fPath = &path;
297 this->fPaint = &paint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000298 this->fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000299 this->fDrawType = DRAW_PATH;
300
chudy@google.com97cee972012-08-07 20:41:37 +0000301 this->fInfo.push(SkObjectParser::PathToString(path));
302 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000303}
304
305void DrawPath::execute(SkCanvas* canvas) {
306 canvas->drawPath(*this->fPath, *this->fPaint);
307}
308
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000309const SkBitmap* DrawPath::getBitmap() const {
310 return &fBitmap;
311}
312
chudy@google.com902ebe52012-06-29 14:21:22 +0000313DrawPicture::DrawPicture(SkPicture& picture) {
314 this->fPicture = &picture;
315 this->fDrawType = DRAW_PICTURE;
chudy@google.com97cee972012-08-07 20:41:37 +0000316 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000317}
318
319void DrawPicture::execute(SkCanvas* canvas) {
320 canvas->drawPicture(*this->fPicture);
321}
322
323DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
324 const SkPoint pts[], const SkPaint& paint) {
325 this->fMode = mode;
326 this->fCount = count;
327 this->fPts = pts;
328 this->fPaint = &paint;
329 this->fDrawType = DRAW_POINTS;
330
chudy@google.com97cee972012-08-07 20:41:37 +0000331 this->fInfo.push(SkObjectParser::PointsToString(pts, count));
robertphillips@google.comcb9b4a52013-01-31 16:52:43 +0000332 this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
robertphillips@google.com94acc702012-09-06 18:43:21 +0000333 "Points: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000334 this->fInfo.push(SkObjectParser::PointModeToString(mode));
robertphillips@google.com5c4d5582013-01-15 12:53:31 +0000335 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000336}
337
338void DrawPoints::execute(SkCanvas* canvas) {
339 canvas->drawPoints(this->fMode, this->fCount, this->fPts, *this->fPaint);
340}
341
342DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
343 const SkPaint& paint) {
344 this->fText = text;
345 this->fByteLength = byteLength;
346 this->fPos = pos;
347 this->fPaint = &paint;
348 this->fDrawType = DRAW_POS_TEXT;
349
chudy@google.com97cee972012-08-07 20:41:37 +0000350 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
chudy@google.com902ebe52012-06-29 14:21:22 +0000351 // TODO(chudy): Test that this works.
chudy@google.com97cee972012-08-07 20:41:37 +0000352 this->fInfo.push(SkObjectParser::PointsToString(pos, 1));
353 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000354}
355
356void DrawPosText::execute(SkCanvas* canvas) {
357 canvas->drawPosText(this->fText, this->fByteLength, this->fPos, *this->fPaint);
358}
359
360
361DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
362 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
363 this->fText = text;
364 this->fByteLength = byteLength;
365 this->fXpos = xpos;
366 this->fConstY = constY;
367 this->fPaint = &paint;
368 this->fDrawType = DRAW_POS_TEXT_H;
369
chudy@google.com97cee972012-08-07 20:41:37 +0000370 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
371 this->fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
372 this->fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
373 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000374}
375
376void DrawPosTextH::execute(SkCanvas* canvas) {
377 canvas->drawPosTextH(this->fText, this->fByteLength, this->fXpos, this->fConstY,
378 *this->fPaint);
379}
380
381DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
382 this->fRect = ▭
383 this->fPaint = &paint;
384 this->fDrawType = DRAW_RECT;
385
chudy@google.com97cee972012-08-07 20:41:37 +0000386 this->fInfo.push(SkObjectParser::RectToString(rect));
387 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000388}
389
390void DrawRectC::execute(SkCanvas* canvas) {
391 canvas->drawRect(*this->fRect, *this->fPaint);
392}
393
robertphillips@google.com67baba42013-01-02 20:20:31 +0000394DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
395 this->fRRect = rrect;
396 this->fPaint = &paint;
397 this->fDrawType = DRAW_RRECT;
398
399 this->fInfo.push(SkObjectParser::RRectToString(rrect));
400 this->fInfo.push(SkObjectParser::PaintToString(paint));
401}
402
403void DrawRRect::execute(SkCanvas* canvas) {
404 canvas->drawRRect(this->fRRect, *this->fPaint);
405}
406
chudy@google.com902ebe52012-06-29 14:21:22 +0000407DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000408 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000409 this->fBitmap = &bitmap;
410 this->fLeft = left;
411 this->fTop = top;
412 this->fPaint = paint;
413 this->fDrawType = DRAW_SPRITE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000414 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000415
chudy@google.com97cee972012-08-07 20:41:37 +0000416 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
417 this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
418 this->fInfo.push(SkObjectParser::IntToString(top, "Top: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000419}
420
421void DrawSprite::execute(SkCanvas* canvas) {
422 canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
423}
424
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000425const SkBitmap* DrawSprite::getBitmap() const {
426 return &fResizedBitmap;
427}
428
chudy@google.com902ebe52012-06-29 14:21:22 +0000429DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
430 const SkPaint& paint) {
431 this->fText = text;
432 this->fByteLength = byteLength;
433 this->fX = x;
434 this->fY = y;
435 this->fPaint = &paint;
436 this->fDrawType = DRAW_TEXT;
437
chudy@google.com97cee972012-08-07 20:41:37 +0000438 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
439 this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
440 this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
441 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000442}
443
444void DrawTextC::execute(SkCanvas* canvas) {
445 canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint);
446}
447
448DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
449 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
450 this->fText = text;
451 this->fByteLength = byteLength;
452 this->fPath = &path;
453 this->fMatrix = matrix;
454 this->fPaint = &paint;
455 this->fDrawType = DRAW_TEXT_ON_PATH;
456
chudy@google.com97cee972012-08-07 20:41:37 +0000457 this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
458 this->fInfo.push(SkObjectParser::PathToString(path));
459 if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
460 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000461}
462
463void DrawTextOnPath::execute(SkCanvas* canvas) {
464 canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath,
465 this->fMatrix, *this->fPaint);
466}
467
468DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
469 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
470 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
471 const SkPaint& paint) {
472 this->fVmode = vmode;
473 this->fVertexCount = vertexCount;
474 this->fTexs = texs;
475 this->fColors = colors;
476 this->fXfermode = xfermode;
477 this->fIndices = indices;
478 this->fIndexCount = indexCount;
479 this->fPaint = &paint;
480 this->fDrawType = DRAW_VERTICES;
481 // TODO(chudy)
chudy@google.com97cee972012-08-07 20:41:37 +0000482 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000483}
484
485void DrawVertices::execute(SkCanvas* canvas) {
486 canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices,
487 this->fTexs, this->fColors, this->fXfermode, this->fIndices,
488 this->fIndexCount, *this->fPaint);
489}
490
491Restore::Restore() {
492 this->fDrawType = RESTORE;
chudy@google.com97cee972012-08-07 20:41:37 +0000493 this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000494}
495
496void Restore::execute(SkCanvas* canvas) {
497 canvas->restore();
498}
499
tomhudson@google.com0699e022012-11-27 16:09:42 +0000500void Restore::trackSaveState(int* state) {
501 (*state)--;
502}
503
chudy@google.com902ebe52012-06-29 14:21:22 +0000504Rotate::Rotate(SkScalar degrees) {
505 this->fDegrees = degrees;
506 this->fDrawType = ROTATE;
507
chudy@google.com97cee972012-08-07 20:41:37 +0000508 this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000509}
510
511void Rotate::execute(SkCanvas* canvas) {
512 canvas->rotate(this->fDegrees);
513}
514
515Save::Save(SkCanvas::SaveFlags flags) {
516 this->fFlags = flags;
517 this->fDrawType = SAVE;
chudy@google.com97cee972012-08-07 20:41:37 +0000518 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000519}
520
521void Save::execute(SkCanvas* canvas) {
522 canvas->save(this->fFlags);
523}
524
tomhudson@google.com0699e022012-11-27 16:09:42 +0000525void Save::trackSaveState(int* state) {
526 (*state)++;
527}
528
chudy@google.com902ebe52012-06-29 14:21:22 +0000529SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
530 SkCanvas::SaveFlags flags) {
531 this->fBounds = bounds;
532 this->fPaint = paint;
533 this->fFlags = flags;
534 this->fDrawType = SAVE_LAYER;
535
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000536 if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000537 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
538 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000539}
540
541void SaveLayer::execute(SkCanvas* canvas) {
542 canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags);
543}
544
tomhudson@google.com0699e022012-11-27 16:09:42 +0000545void SaveLayer::trackSaveState(int* state) {
546 (*state)++;
547}
548
chudy@google.com902ebe52012-06-29 14:21:22 +0000549Scale::Scale(SkScalar sx, SkScalar sy) {
550 this->fSx = sx;
551 this->fSy = sy;
552 this->fDrawType = SCALE;
553
chudy@google.com97cee972012-08-07 20:41:37 +0000554 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
555 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000556}
557
558void Scale::execute(SkCanvas* canvas) {
559 canvas->scale(this->fSx, this->fSy);
560}
561
562SetMatrix::SetMatrix(const SkMatrix& matrix) {
563 this->fMatrix = &matrix;
564 this->fDrawType = SET_MATRIX;
565
chudy@google.com97cee972012-08-07 20:41:37 +0000566 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000567}
568
569void SetMatrix::execute(SkCanvas* canvas) {
570 canvas->setMatrix(*this->fMatrix);
571}
572
573Skew::Skew(SkScalar sx, SkScalar sy) {
574 this->fSx = sx;
575 this->fSy = sy;
576 this->fDrawType = SKEW;
577
chudy@google.com97cee972012-08-07 20:41:37 +0000578 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
579 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000580}
581
582void Skew::execute(SkCanvas* canvas) {
583 canvas->skew(this->fSx, this->fSy);
584}
585
586Translate::Translate(SkScalar dx, SkScalar dy) {
587 this->fDx = dx;
588 this->fDy = dy;
589 this->fDrawType = TRANSLATE;
590
chudy@google.com97cee972012-08-07 20:41:37 +0000591 this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
592 this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000593}
594
595void Translate::execute(SkCanvas* canvas) {
596 canvas->translate(this->fDx, this->fDy);
597}