blob: a24b8918505dab373ee3024135affd396a052095 [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";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000058 case NOOP: return "NoOp";
chudy@google.com902ebe52012-06-29 14:21:22 +000059 default:
60 SkDebugf("DrawType error 0x%08x\n", type);
61 SkASSERT(0);
62 break;
63 }
64 SkDEBUGFAIL("DrawType UNUSED\n");
65 return NULL;
66}
67
chudy@google.com97cee972012-08-07 20:41:37 +000068SkString SkDrawCommand::toString() {
69 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000070}
71
72Clear::Clear(SkColor color) {
73 this->fColor = color;
74 this->fDrawType = DRAW_CLEAR;
chudy@google.com97cee972012-08-07 20:41:37 +000075 this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000076}
77
78void Clear::execute(SkCanvas* canvas) {
79 canvas->clear(this->fColor);
80}
81
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000082ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap) {
robertphillips@google.com91217d02013-03-17 18:33:46 +000083 fPath = path;
84 fOp = op;
85 fDoAA = doAA;
86 fDrawType = CLIP_PATH;
87 fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +000088
robertphillips@google.com91217d02013-03-17 18:33:46 +000089 fInfo.push(SkObjectParser::PathToString(path));
90 fInfo.push(SkObjectParser::RegionOpToString(op));
91 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +000092}
93
94void ClipPath::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +000095 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +000096}
97
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000098const SkBitmap* ClipPath::getBitmap() const {
99 return &fBitmap;
100}
101
chudy@google.com902ebe52012-06-29 14:21:22 +0000102ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) {
103 this->fRegion = &region;
104 this->fOp = op;
105 this->fDrawType = CLIP_REGION;
106
chudy@google.com97cee972012-08-07 20:41:37 +0000107 this->fInfo.push(SkObjectParser::RegionToString(region));
108 this->fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000109}
110
111void ClipRegion::execute(SkCanvas* canvas) {
112 canvas->clipRegion(*this->fRegion, this->fOp);
113}
114
115ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
116 this->fRect = ▭
117 this->fOp = op;
118 this->fDoAA = doAA;
119 this->fDrawType = CLIP_RECT;
120
chudy@google.com97cee972012-08-07 20:41:37 +0000121 this->fInfo.push(SkObjectParser::RectToString(rect));
122 this->fInfo.push(SkObjectParser::RegionOpToString(op));
123 this->fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000124}
125
126void ClipRect::execute(SkCanvas* canvas) {
127 canvas->clipRect(*this->fRect, this->fOp, this->fDoAA);
128}
129
robertphillips@google.com67baba42013-01-02 20:20:31 +0000130ClipRRect::ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
robertphillips@google.com2da95b22013-01-17 16:07:04 +0000131 this->fRRect = rrect;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000132 this->fOp = op;
133 this->fDoAA = doAA;
134 this->fDrawType = CLIP_RRECT;
135
136 this->fInfo.push(SkObjectParser::RRectToString(rrect));
137 this->fInfo.push(SkObjectParser::RegionOpToString(op));
138 this->fInfo.push(SkObjectParser::BoolToString(doAA));
139}
140
141void ClipRRect::execute(SkCanvas* canvas) {
robertphillips@google.com2da95b22013-01-17 16:07:04 +0000142 canvas->clipRRect(this->fRRect, this->fOp, this->fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000143}
144
chudy@google.com902ebe52012-06-29 14:21:22 +0000145Concat::Concat(const SkMatrix& matrix) {
146 this->fMatrix = &matrix;
147 this->fDrawType = CONCAT;
148
chudy@google.com97cee972012-08-07 20:41:37 +0000149 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000150}
151
152void Concat::execute(SkCanvas* canvas) {
153 canvas->concat(*this->fMatrix);
154}
155
156DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000157 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000158 this->fBitmap = &bitmap;
159 this->fLeft = left;
160 this->fTop = top;
161 this->fPaint = paint;
162 this->fDrawType = DRAW_BITMAP;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000163 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000164
chudy@google.com97cee972012-08-07 20:41:37 +0000165 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
166 this->fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
167 this->fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000168 if (NULL != paint) {
169 this->fInfo.push(SkObjectParser::PaintToString(*paint));
170 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000171}
172
173void DrawBitmap::execute(SkCanvas* canvas) {
174 canvas->drawBitmap(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
175}
176
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000177const SkBitmap* DrawBitmap::getBitmap() const {
178 return &fResizedBitmap;
179}
180
chudy@google.com902ebe52012-06-29 14:21:22 +0000181DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000182 const SkMatrix& matrix, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000183 this->fBitmap = &bitmap;
184 this->fMatrix = &matrix;
185 this->fPaint = paint;
186 this->fDrawType = DRAW_BITMAP_MATRIX;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000187 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000188
chudy@google.com97cee972012-08-07 20:41:37 +0000189 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
190 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000191 if (NULL != paint) {
192 this->fInfo.push(SkObjectParser::PaintToString(*paint));
193 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000194}
195
196void DrawBitmapMatrix::execute(SkCanvas* canvas) {
197 canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint);
198}
199
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000200const SkBitmap* DrawBitmapMatrix::getBitmap() const {
201 return &fResizedBitmap;
202}
203
chudy@google.com902ebe52012-06-29 14:21:22 +0000204DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000205 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000206 this->fBitmap = &bitmap;
207 this->fCenter = &center;
208 this->fDst = &dst;
209 this->fPaint = paint;
210 this->fDrawType = DRAW_BITMAP_NINE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000211 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000212
chudy@google.com97cee972012-08-07 20:41:37 +0000213 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
214 this->fInfo.push(SkObjectParser::IRectToString(center));
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000215 this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000216 if (NULL != paint) {
217 this->fInfo.push(SkObjectParser::PaintToString(*paint));
218 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000219}
220
221void DrawBitmapNine::execute(SkCanvas* canvas) {
222 canvas->drawBitmapNine(*this->fBitmap, *this->fCenter, *this->fDst, this->fPaint);
223}
224
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000225const SkBitmap* DrawBitmapNine::getBitmap() const {
226 return &fResizedBitmap;
227}
228
reed@google.com71121732012-09-18 15:14:33 +0000229DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000230 const SkRect& dst, const SkPaint* paint,
231 SkBitmap& resizedBitmap) {
232 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000233 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000234 fSrc = *src;
235 } else {
236 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000237 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000238 fDst = dst;
239
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000240 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000241 fPaint = *paint;
242 fPaintPtr = &fPaint;
243 } else {
244 fPaintPtr = NULL;
245 }
246 fDrawType = DRAW_BITMAP_RECT_TO_RECT;
247 fResizedBitmap = resizedBitmap;
248
249 fInfo.push(SkObjectParser::BitmapToString(bitmap));
250 if (NULL != src) {
251 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
252 }
253 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
254 if (NULL != paint) {
255 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000256 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000257}
258
259void DrawBitmapRect::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000260 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000261}
262
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000263const SkBitmap* DrawBitmapRect::getBitmap() const {
264 return &fResizedBitmap;
265}
266
chudy@google.com902ebe52012-06-29 14:21:22 +0000267DrawData::DrawData(const void* data, size_t length) {
268 this->fData = data;
269 this->fLength = length;
270 this->fDrawType = DRAW_DATA;
271 // TODO(chudy): See if we can't display data and length.
272}
273
274void DrawData::execute(SkCanvas* canvas) {
275 canvas->drawData(this->fData, this->fLength);
276}
277
robertphillips@google.com67baba42013-01-02 20:20:31 +0000278DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
279 this->fOval = &oval;
280 this->fPaint = &paint;
281 this->fDrawType = DRAW_OVAL;
282
283 this->fInfo.push(SkObjectParser::RectToString(oval));
284 this->fInfo.push(SkObjectParser::PaintToString(paint));
285}
286
287void DrawOval::execute(SkCanvas* canvas) {
288 canvas->drawOval(*this->fOval, *this->fPaint);
289}
290
chudy@google.com902ebe52012-06-29 14:21:22 +0000291DrawPaint::DrawPaint(const SkPaint& paint) {
292 this->fPaint = &paint;
293 this->fDrawType = DRAW_PAINT;
294
chudy@google.com97cee972012-08-07 20:41:37 +0000295 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000296}
297
298void DrawPaint::execute(SkCanvas* canvas) {
299 canvas->drawPaint(*this->fPaint);
300}
301
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000302DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000303 fPath = path;
304 fPaint = paint;
305 fBitmap = bitmap;
306 fDrawType = DRAW_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000307
robertphillips@google.com91217d02013-03-17 18:33:46 +0000308 fInfo.push(SkObjectParser::PathToString(path));
309 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000310}
311
312void DrawPath::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000313 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000314}
315
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000316const SkBitmap* DrawPath::getBitmap() const {
317 return &fBitmap;
318}
319
chudy@google.com902ebe52012-06-29 14:21:22 +0000320DrawPicture::DrawPicture(SkPicture& picture) {
321 this->fPicture = &picture;
322 this->fDrawType = DRAW_PICTURE;
chudy@google.com97cee972012-08-07 20:41:37 +0000323 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000324}
325
326void DrawPicture::execute(SkCanvas* canvas) {
327 canvas->drawPicture(*this->fPicture);
328}
329
330DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
331 const SkPoint pts[], const SkPaint& paint) {
332 this->fMode = mode;
333 this->fCount = count;
334 this->fPts = pts;
335 this->fPaint = &paint;
336 this->fDrawType = DRAW_POINTS;
337
chudy@google.com97cee972012-08-07 20:41:37 +0000338 this->fInfo.push(SkObjectParser::PointsToString(pts, count));
robertphillips@google.comcb9b4a52013-01-31 16:52:43 +0000339 this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
robertphillips@google.com94acc702012-09-06 18:43:21 +0000340 "Points: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000341 this->fInfo.push(SkObjectParser::PointModeToString(mode));
robertphillips@google.com5c4d5582013-01-15 12:53:31 +0000342 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000343}
344
345void DrawPoints::execute(SkCanvas* canvas) {
346 canvas->drawPoints(this->fMode, this->fCount, this->fPts, *this->fPaint);
347}
348
349DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
350 const SkPaint& paint) {
351 this->fText = text;
352 this->fByteLength = byteLength;
353 this->fPos = pos;
354 this->fPaint = &paint;
355 this->fDrawType = DRAW_POS_TEXT;
356
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000357 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000358 // TODO(chudy): Test that this works.
chudy@google.com97cee972012-08-07 20:41:37 +0000359 this->fInfo.push(SkObjectParser::PointsToString(pos, 1));
360 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000361}
362
363void DrawPosText::execute(SkCanvas* canvas) {
364 canvas->drawPosText(this->fText, this->fByteLength, this->fPos, *this->fPaint);
365}
366
367
368DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000369 const SkScalar xpos[], SkScalar constY,
370 const SkPaint& paint) {
371 fText = text;
372 fByteLength = byteLength;
373 fXpos = xpos;
374 fConstY = constY;
375 fPaint = paint;
376 fDrawType = DRAW_POS_TEXT_H;
chudy@google.com902ebe52012-06-29 14:21:22 +0000377
robertphillips@google.com91217d02013-03-17 18:33:46 +0000378 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
379 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
380 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
381 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000382}
383
384void DrawPosTextH::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000385 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000386}
387
388DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000389 fRect = rect;
390 fPaint = paint;
391 fDrawType = DRAW_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000392
robertphillips@google.com91217d02013-03-17 18:33:46 +0000393 fInfo.push(SkObjectParser::RectToString(rect));
394 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
397void DrawRectC::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000398 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000399}
400
robertphillips@google.com67baba42013-01-02 20:20:31 +0000401DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
402 this->fRRect = rrect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000403 this->fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000404 this->fDrawType = DRAW_RRECT;
405
406 this->fInfo.push(SkObjectParser::RRectToString(rrect));
407 this->fInfo.push(SkObjectParser::PaintToString(paint));
408}
409
410void DrawRRect::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000411 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000412}
413
chudy@google.com902ebe52012-06-29 14:21:22 +0000414DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000415 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000416 this->fBitmap = &bitmap;
417 this->fLeft = left;
418 this->fTop = top;
419 this->fPaint = paint;
420 this->fDrawType = DRAW_SPRITE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000421 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000422
chudy@google.com97cee972012-08-07 20:41:37 +0000423 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
424 this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
425 this->fInfo.push(SkObjectParser::IntToString(top, "Top: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000426}
427
428void DrawSprite::execute(SkCanvas* canvas) {
429 canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
430}
431
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000432const SkBitmap* DrawSprite::getBitmap() const {
433 return &fResizedBitmap;
434}
435
chudy@google.com902ebe52012-06-29 14:21:22 +0000436DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
437 const SkPaint& paint) {
438 this->fText = text;
439 this->fByteLength = byteLength;
440 this->fX = x;
441 this->fY = y;
442 this->fPaint = &paint;
443 this->fDrawType = DRAW_TEXT;
444
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000445 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000446 this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
447 this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
448 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000449}
450
451void DrawTextC::execute(SkCanvas* canvas) {
452 canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint);
453}
454
455DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
456 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
457 this->fText = text;
458 this->fByteLength = byteLength;
459 this->fPath = &path;
460 this->fMatrix = matrix;
461 this->fPaint = &paint;
462 this->fDrawType = DRAW_TEXT_ON_PATH;
463
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000464 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000465 this->fInfo.push(SkObjectParser::PathToString(path));
466 if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
467 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000468}
469
470void DrawTextOnPath::execute(SkCanvas* canvas) {
471 canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath,
472 this->fMatrix, *this->fPaint);
473}
474
475DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
476 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
477 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
478 const SkPaint& paint) {
479 this->fVmode = vmode;
480 this->fVertexCount = vertexCount;
481 this->fTexs = texs;
482 this->fColors = colors;
483 this->fXfermode = xfermode;
484 this->fIndices = indices;
485 this->fIndexCount = indexCount;
486 this->fPaint = &paint;
487 this->fDrawType = DRAW_VERTICES;
488 // TODO(chudy)
chudy@google.com97cee972012-08-07 20:41:37 +0000489 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000490}
491
492void DrawVertices::execute(SkCanvas* canvas) {
493 canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices,
494 this->fTexs, this->fColors, this->fXfermode, this->fIndices,
495 this->fIndexCount, *this->fPaint);
496}
497
498Restore::Restore() {
499 this->fDrawType = RESTORE;
chudy@google.com97cee972012-08-07 20:41:37 +0000500 this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000501}
502
503void Restore::execute(SkCanvas* canvas) {
504 canvas->restore();
505}
506
tomhudson@google.com0699e022012-11-27 16:09:42 +0000507void Restore::trackSaveState(int* state) {
508 (*state)--;
509}
510
chudy@google.com902ebe52012-06-29 14:21:22 +0000511Rotate::Rotate(SkScalar degrees) {
512 this->fDegrees = degrees;
513 this->fDrawType = ROTATE;
514
chudy@google.com97cee972012-08-07 20:41:37 +0000515 this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000516}
517
518void Rotate::execute(SkCanvas* canvas) {
519 canvas->rotate(this->fDegrees);
520}
521
522Save::Save(SkCanvas::SaveFlags flags) {
523 this->fFlags = flags;
524 this->fDrawType = SAVE;
chudy@google.com97cee972012-08-07 20:41:37 +0000525 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000526}
527
528void Save::execute(SkCanvas* canvas) {
529 canvas->save(this->fFlags);
530}
531
tomhudson@google.com0699e022012-11-27 16:09:42 +0000532void Save::trackSaveState(int* state) {
533 (*state)++;
534}
535
chudy@google.com902ebe52012-06-29 14:21:22 +0000536SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
537 SkCanvas::SaveFlags flags) {
538 this->fBounds = bounds;
539 this->fPaint = paint;
540 this->fFlags = flags;
541 this->fDrawType = SAVE_LAYER;
542
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000543 if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000544 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
545 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000546}
547
548void SaveLayer::execute(SkCanvas* canvas) {
549 canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags);
550}
551
tomhudson@google.com0699e022012-11-27 16:09:42 +0000552void SaveLayer::trackSaveState(int* state) {
553 (*state)++;
554}
555
chudy@google.com902ebe52012-06-29 14:21:22 +0000556Scale::Scale(SkScalar sx, SkScalar sy) {
557 this->fSx = sx;
558 this->fSy = sy;
559 this->fDrawType = SCALE;
560
chudy@google.com97cee972012-08-07 20:41:37 +0000561 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
562 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000563}
564
565void Scale::execute(SkCanvas* canvas) {
566 canvas->scale(this->fSx, this->fSy);
567}
568
569SetMatrix::SetMatrix(const SkMatrix& matrix) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000570 this->fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000571 this->fDrawType = SET_MATRIX;
572
chudy@google.com97cee972012-08-07 20:41:37 +0000573 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000574}
575
576void SetMatrix::execute(SkCanvas* canvas) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000577 canvas->setMatrix(this->fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000578}
579
580Skew::Skew(SkScalar sx, SkScalar sy) {
581 this->fSx = sx;
582 this->fSy = sy;
583 this->fDrawType = SKEW;
584
chudy@google.com97cee972012-08-07 20:41:37 +0000585 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
586 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000587}
588
589void Skew::execute(SkCanvas* canvas) {
590 canvas->skew(this->fSx, this->fSy);
591}
592
593Translate::Translate(SkScalar dx, SkScalar dy) {
594 this->fDx = dx;
595 this->fDy = dy;
596 this->fDrawType = TRANSLATE;
597
chudy@google.com97cee972012-08-07 20:41:37 +0000598 this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
599 this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000600}
601
602void Translate::execute(SkCanvas* canvas) {
603 canvas->translate(this->fDx, this->fDy);
604}