blob: c85d8c98a13c0703c38fa2027adb020f221e77fd [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) {
chudy@google.com902ebe52012-06-29 14:21:22 +000083 this->fPath = &path;
84 this->fOp = op;
85 this->fDoAA = doAA;
86 this->fDrawType = CLIP_PATH;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000087 this->fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +000088
chudy@google.com97cee972012-08-07 20:41:37 +000089 this->fInfo.push(SkObjectParser::PathToString(path));
90 this->fInfo.push(SkObjectParser::RegionOpToString(op));
91 this->fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +000092}
93
94void ClipPath::execute(SkCanvas* canvas) {
95 canvas->clipPath(*this->fPath, this->fOp, this->fDoAA);
96}
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.com53ec73d2012-11-26 13:09:17 +0000230 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000231 this->fBitmap = &bitmap;
232 this->fSrc = src;
233 this->fDst = &dst;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000234 if (NULL != paint) {
235 this->fPaint = *paint;
236 this->fPaintPtr = &this->fPaint;
237 } else {
238 this->fPaintPtr = NULL;
239 }
robertphillips@google.com84d320e2012-09-20 19:09:17 +0000240 this->fDrawType = DRAW_BITMAP_RECT_TO_RECT;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000241 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000242
chudy@google.com97cee972012-08-07 20:41:37 +0000243 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000244 if (NULL != src) {
245 this->fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
246 }
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000247 this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000248 if (NULL != paint) {
249 this->fInfo.push(SkObjectParser::PaintToString(*paint));
250 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000251}
252
253void DrawBitmapRect::execute(SkCanvas* canvas) {
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000254 canvas->drawBitmapRectToRect(*this->fBitmap, this->fSrc, *this->fDst, this->fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000255}
256
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000257const SkBitmap* DrawBitmapRect::getBitmap() const {
258 return &fResizedBitmap;
259}
260
chudy@google.com902ebe52012-06-29 14:21:22 +0000261DrawData::DrawData(const void* data, size_t length) {
262 this->fData = data;
263 this->fLength = length;
264 this->fDrawType = DRAW_DATA;
265 // TODO(chudy): See if we can't display data and length.
266}
267
268void DrawData::execute(SkCanvas* canvas) {
269 canvas->drawData(this->fData, this->fLength);
270}
271
robertphillips@google.com67baba42013-01-02 20:20:31 +0000272DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
273 this->fOval = &oval;
274 this->fPaint = &paint;
275 this->fDrawType = DRAW_OVAL;
276
277 this->fInfo.push(SkObjectParser::RectToString(oval));
278 this->fInfo.push(SkObjectParser::PaintToString(paint));
279}
280
281void DrawOval::execute(SkCanvas* canvas) {
282 canvas->drawOval(*this->fOval, *this->fPaint);
283}
284
chudy@google.com902ebe52012-06-29 14:21:22 +0000285DrawPaint::DrawPaint(const SkPaint& paint) {
286 this->fPaint = &paint;
287 this->fDrawType = DRAW_PAINT;
288
chudy@google.com97cee972012-08-07 20:41:37 +0000289 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000290}
291
292void DrawPaint::execute(SkCanvas* canvas) {
293 canvas->drawPaint(*this->fPaint);
294}
295
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000296DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000297 this->fPath = &path;
298 this->fPaint = &paint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000299 this->fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000300 this->fDrawType = DRAW_PATH;
301
chudy@google.com97cee972012-08-07 20:41:37 +0000302 this->fInfo.push(SkObjectParser::PathToString(path));
303 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000304}
305
306void DrawPath::execute(SkCanvas* canvas) {
307 canvas->drawPath(*this->fPath, *this->fPaint);
308}
309
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000310const SkBitmap* DrawPath::getBitmap() const {
311 return &fBitmap;
312}
313
chudy@google.com902ebe52012-06-29 14:21:22 +0000314DrawPicture::DrawPicture(SkPicture& picture) {
315 this->fPicture = &picture;
316 this->fDrawType = DRAW_PICTURE;
chudy@google.com97cee972012-08-07 20:41:37 +0000317 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000318}
319
320void DrawPicture::execute(SkCanvas* canvas) {
321 canvas->drawPicture(*this->fPicture);
322}
323
324DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
325 const SkPoint pts[], const SkPaint& paint) {
326 this->fMode = mode;
327 this->fCount = count;
328 this->fPts = pts;
329 this->fPaint = &paint;
330 this->fDrawType = DRAW_POINTS;
331
chudy@google.com97cee972012-08-07 20:41:37 +0000332 this->fInfo.push(SkObjectParser::PointsToString(pts, count));
robertphillips@google.comcb9b4a52013-01-31 16:52:43 +0000333 this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
robertphillips@google.com94acc702012-09-06 18:43:21 +0000334 "Points: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000335 this->fInfo.push(SkObjectParser::PointModeToString(mode));
robertphillips@google.com5c4d5582013-01-15 12:53:31 +0000336 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000337}
338
339void DrawPoints::execute(SkCanvas* canvas) {
340 canvas->drawPoints(this->fMode, this->fCount, this->fPts, *this->fPaint);
341}
342
343DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
344 const SkPaint& paint) {
345 this->fText = text;
346 this->fByteLength = byteLength;
347 this->fPos = pos;
348 this->fPaint = &paint;
349 this->fDrawType = DRAW_POS_TEXT;
350
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000351 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000352 // TODO(chudy): Test that this works.
chudy@google.com97cee972012-08-07 20:41:37 +0000353 this->fInfo.push(SkObjectParser::PointsToString(pos, 1));
354 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000355}
356
357void DrawPosText::execute(SkCanvas* canvas) {
358 canvas->drawPosText(this->fText, this->fByteLength, this->fPos, *this->fPaint);
359}
360
361
362DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
363 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
364 this->fText = text;
365 this->fByteLength = byteLength;
366 this->fXpos = xpos;
367 this->fConstY = constY;
368 this->fPaint = &paint;
369 this->fDrawType = DRAW_POS_TEXT_H;
370
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000371 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000372 this->fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
373 this->fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
374 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000375}
376
377void DrawPosTextH::execute(SkCanvas* canvas) {
378 canvas->drawPosTextH(this->fText, this->fByteLength, this->fXpos, this->fConstY,
379 *this->fPaint);
380}
381
382DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
383 this->fRect = ▭
384 this->fPaint = &paint;
385 this->fDrawType = DRAW_RECT;
386
chudy@google.com97cee972012-08-07 20:41:37 +0000387 this->fInfo.push(SkObjectParser::RectToString(rect));
388 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000389}
390
391void DrawRectC::execute(SkCanvas* canvas) {
392 canvas->drawRect(*this->fRect, *this->fPaint);
393}
394
robertphillips@google.com67baba42013-01-02 20:20:31 +0000395DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
396 this->fRRect = rrect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000397 this->fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000398 this->fDrawType = DRAW_RRECT;
399
400 this->fInfo.push(SkObjectParser::RRectToString(rrect));
401 this->fInfo.push(SkObjectParser::PaintToString(paint));
402}
403
404void DrawRRect::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000405 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000406}
407
chudy@google.com902ebe52012-06-29 14:21:22 +0000408DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000409 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000410 this->fBitmap = &bitmap;
411 this->fLeft = left;
412 this->fTop = top;
413 this->fPaint = paint;
414 this->fDrawType = DRAW_SPRITE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000415 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000416
chudy@google.com97cee972012-08-07 20:41:37 +0000417 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
418 this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
419 this->fInfo.push(SkObjectParser::IntToString(top, "Top: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000420}
421
422void DrawSprite::execute(SkCanvas* canvas) {
423 canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
424}
425
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000426const SkBitmap* DrawSprite::getBitmap() const {
427 return &fResizedBitmap;
428}
429
chudy@google.com902ebe52012-06-29 14:21:22 +0000430DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
431 const SkPaint& paint) {
432 this->fText = text;
433 this->fByteLength = byteLength;
434 this->fX = x;
435 this->fY = y;
436 this->fPaint = &paint;
437 this->fDrawType = DRAW_TEXT;
438
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000439 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000440 this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
441 this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
442 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000443}
444
445void DrawTextC::execute(SkCanvas* canvas) {
446 canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint);
447}
448
449DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
450 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
451 this->fText = text;
452 this->fByteLength = byteLength;
453 this->fPath = &path;
454 this->fMatrix = matrix;
455 this->fPaint = &paint;
456 this->fDrawType = DRAW_TEXT_ON_PATH;
457
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000458 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000459 this->fInfo.push(SkObjectParser::PathToString(path));
460 if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
461 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000462}
463
464void DrawTextOnPath::execute(SkCanvas* canvas) {
465 canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath,
466 this->fMatrix, *this->fPaint);
467}
468
469DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
470 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
471 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
472 const SkPaint& paint) {
473 this->fVmode = vmode;
474 this->fVertexCount = vertexCount;
475 this->fTexs = texs;
476 this->fColors = colors;
477 this->fXfermode = xfermode;
478 this->fIndices = indices;
479 this->fIndexCount = indexCount;
480 this->fPaint = &paint;
481 this->fDrawType = DRAW_VERTICES;
482 // TODO(chudy)
chudy@google.com97cee972012-08-07 20:41:37 +0000483 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000484}
485
486void DrawVertices::execute(SkCanvas* canvas) {
487 canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices,
488 this->fTexs, this->fColors, this->fXfermode, this->fIndices,
489 this->fIndexCount, *this->fPaint);
490}
491
492Restore::Restore() {
493 this->fDrawType = RESTORE;
chudy@google.com97cee972012-08-07 20:41:37 +0000494 this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000495}
496
497void Restore::execute(SkCanvas* canvas) {
498 canvas->restore();
499}
500
tomhudson@google.com0699e022012-11-27 16:09:42 +0000501void Restore::trackSaveState(int* state) {
502 (*state)--;
503}
504
chudy@google.com902ebe52012-06-29 14:21:22 +0000505Rotate::Rotate(SkScalar degrees) {
506 this->fDegrees = degrees;
507 this->fDrawType = ROTATE;
508
chudy@google.com97cee972012-08-07 20:41:37 +0000509 this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000510}
511
512void Rotate::execute(SkCanvas* canvas) {
513 canvas->rotate(this->fDegrees);
514}
515
516Save::Save(SkCanvas::SaveFlags flags) {
517 this->fFlags = flags;
518 this->fDrawType = SAVE;
chudy@google.com97cee972012-08-07 20:41:37 +0000519 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000520}
521
522void Save::execute(SkCanvas* canvas) {
523 canvas->save(this->fFlags);
524}
525
tomhudson@google.com0699e022012-11-27 16:09:42 +0000526void Save::trackSaveState(int* state) {
527 (*state)++;
528}
529
chudy@google.com902ebe52012-06-29 14:21:22 +0000530SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
531 SkCanvas::SaveFlags flags) {
532 this->fBounds = bounds;
533 this->fPaint = paint;
534 this->fFlags = flags;
535 this->fDrawType = SAVE_LAYER;
536
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000537 if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000538 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
539 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000540}
541
542void SaveLayer::execute(SkCanvas* canvas) {
543 canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags);
544}
545
tomhudson@google.com0699e022012-11-27 16:09:42 +0000546void SaveLayer::trackSaveState(int* state) {
547 (*state)++;
548}
549
chudy@google.com902ebe52012-06-29 14:21:22 +0000550Scale::Scale(SkScalar sx, SkScalar sy) {
551 this->fSx = sx;
552 this->fSy = sy;
553 this->fDrawType = SCALE;
554
chudy@google.com97cee972012-08-07 20:41:37 +0000555 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
556 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000557}
558
559void Scale::execute(SkCanvas* canvas) {
560 canvas->scale(this->fSx, this->fSy);
561}
562
563SetMatrix::SetMatrix(const SkMatrix& matrix) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000564 this->fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000565 this->fDrawType = SET_MATRIX;
566
chudy@google.com97cee972012-08-07 20:41:37 +0000567 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000568}
569
570void SetMatrix::execute(SkCanvas* canvas) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000571 canvas->setMatrix(this->fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000572}
573
574Skew::Skew(SkScalar sx, SkScalar sy) {
575 this->fSx = sx;
576 this->fSy = sy;
577 this->fDrawType = SKEW;
578
chudy@google.com97cee972012-08-07 20:41:37 +0000579 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
580 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000581}
582
583void Skew::execute(SkCanvas* canvas) {
584 canvas->skew(this->fSx, this->fSy);
585}
586
587Translate::Translate(SkScalar dx, SkScalar dy) {
588 this->fDx = dx;
589 this->fDy = dy;
590 this->fDrawType = TRANSLATE;
591
chudy@google.com97cee972012-08-07 20:41:37 +0000592 this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
593 this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000594}
595
596void Translate::execute(SkCanvas* canvas) {
597 canvas->translate(this->fDx, this->fDy);
598}