blob: cf3c09872da1c16419b38e6dad5f6f6c0a8fe3bf [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) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000116 fRect = rect;
117 fOp = op;
118 fDoAA = doAA;
119 fDrawType = CLIP_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000120
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000121 fInfo.push(SkObjectParser::RectToString(rect));
122 fInfo.push(SkObjectParser::RegionOpToString(op));
123 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000124}
125
126void ClipRect::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000127 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000128}
129
robertphillips@google.com67baba42013-01-02 20:20:31 +0000130ClipRRect::ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000131 fRRect = rrect;
132 fOp = op;
133 fDoAA = doAA;
134 fDrawType = CLIP_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000135
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000136 fInfo.push(SkObjectParser::RRectToString(rrect));
137 fInfo.push(SkObjectParser::RegionOpToString(op));
138 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000139}
140
141void ClipRRect::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000142 canvas->clipRRect(fRRect, fOp, 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,
skia.committer@gmail.comc76bb232013-03-18 07:01:03 +0000230 const SkRect& dst, const SkPaint* paint,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000231 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) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000279 fOval = oval;
280 fPaint = paint;
281 fDrawType = DRAW_OVAL;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000282
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000283 fInfo.push(SkObjectParser::RectToString(oval));
284 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000285}
286
287void DrawOval::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000288 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000289}
290
chudy@google.com902ebe52012-06-29 14:21:22 +0000291DrawPaint::DrawPaint(const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000292 fPaint = paint;
293 fDrawType = DRAW_PAINT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000294
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000295 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000296}
297
298void DrawPaint::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000299 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000300}
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,
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000331 const SkPoint pts[], const SkPaint& paint) {
332 fMode = mode;
333 fCount = count;
334 fPts = new SkPoint[count];
335 memcpy(fPts, pts, count * sizeof(SkPoint));
336 fPaint = paint;
337 fDrawType = DRAW_POINTS;
chudy@google.com902ebe52012-06-29 14:21:22 +0000338
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000339 fInfo.push(SkObjectParser::PointsToString(pts, count));
340 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
341 "Points: "));
342 fInfo.push(SkObjectParser::PointModeToString(mode));
343 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000344}
345
346void DrawPoints::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000347 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000348}
349
350DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000351 const SkPaint& paint) {
352 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000353
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000354 fText = new char[byteLength];
355 memcpy(fText, text, byteLength);
356 fByteLength = byteLength;
357
358 fPos = new SkPoint[numPts];
359 memcpy(fPos, pos, numPts * sizeof(SkPoint));
360
361 fPaint = paint;
362 fDrawType = DRAW_POS_TEXT;
363
364 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000365 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000366 fInfo.push(SkObjectParser::PointsToString(pos, 1));
367 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000368}
369
370void DrawPosText::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000371 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000372}
373
374
375DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
skia.committer@gmail.comc76bb232013-03-18 07:01:03 +0000376 const SkScalar xpos[], SkScalar constY,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000377 const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000378 size_t numPts = paint.countText(text, byteLength);
379
380 fText = new char[byteLength];
381 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000382 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000383
384 fXpos = new SkScalar[numPts];
385 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
386
robertphillips@google.com91217d02013-03-17 18:33:46 +0000387 fConstY = constY;
388 fPaint = paint;
389 fDrawType = DRAW_POS_TEXT_H;
chudy@google.com902ebe52012-06-29 14:21:22 +0000390
robertphillips@google.com91217d02013-03-17 18:33:46 +0000391 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
392 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
393 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
394 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
397void DrawPosTextH::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000398 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000399}
400
401DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000402 fRect = rect;
403 fPaint = paint;
404 fDrawType = DRAW_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000405
robertphillips@google.com91217d02013-03-17 18:33:46 +0000406 fInfo.push(SkObjectParser::RectToString(rect));
407 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000408}
409
410void DrawRectC::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000411 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000412}
413
robertphillips@google.com67baba42013-01-02 20:20:31 +0000414DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
415 this->fRRect = rrect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000416 this->fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000417 this->fDrawType = DRAW_RRECT;
418
419 this->fInfo.push(SkObjectParser::RRectToString(rrect));
420 this->fInfo.push(SkObjectParser::PaintToString(paint));
421}
422
423void DrawRRect::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000424 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000425}
426
chudy@google.com902ebe52012-06-29 14:21:22 +0000427DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000428 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000429 this->fBitmap = &bitmap;
430 this->fLeft = left;
431 this->fTop = top;
432 this->fPaint = paint;
433 this->fDrawType = DRAW_SPRITE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000434 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000435
chudy@google.com97cee972012-08-07 20:41:37 +0000436 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
437 this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
438 this->fInfo.push(SkObjectParser::IntToString(top, "Top: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000439}
440
441void DrawSprite::execute(SkCanvas* canvas) {
442 canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
443}
444
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000445const SkBitmap* DrawSprite::getBitmap() const {
446 return &fResizedBitmap;
447}
448
chudy@google.com902ebe52012-06-29 14:21:22 +0000449DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
450 const SkPaint& paint) {
451 this->fText = text;
452 this->fByteLength = byteLength;
453 this->fX = x;
454 this->fY = y;
455 this->fPaint = &paint;
456 this->fDrawType = DRAW_TEXT;
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::ScalarToString(x, "SkScalar x: "));
460 this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
461 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000462}
463
464void DrawTextC::execute(SkCanvas* canvas) {
465 canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint);
466}
467
468DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
469 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
470 this->fText = text;
471 this->fByteLength = byteLength;
472 this->fPath = &path;
473 this->fMatrix = matrix;
474 this->fPaint = &paint;
475 this->fDrawType = DRAW_TEXT_ON_PATH;
476
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000477 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000478 this->fInfo.push(SkObjectParser::PathToString(path));
479 if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
480 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000481}
482
483void DrawTextOnPath::execute(SkCanvas* canvas) {
484 canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath,
485 this->fMatrix, *this->fPaint);
486}
487
488DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
489 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
490 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
491 const SkPaint& paint) {
492 this->fVmode = vmode;
493 this->fVertexCount = vertexCount;
494 this->fTexs = texs;
495 this->fColors = colors;
496 this->fXfermode = xfermode;
497 this->fIndices = indices;
498 this->fIndexCount = indexCount;
499 this->fPaint = &paint;
500 this->fDrawType = DRAW_VERTICES;
501 // TODO(chudy)
chudy@google.com97cee972012-08-07 20:41:37 +0000502 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000503}
504
505void DrawVertices::execute(SkCanvas* canvas) {
506 canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices,
507 this->fTexs, this->fColors, this->fXfermode, this->fIndices,
508 this->fIndexCount, *this->fPaint);
509}
510
511Restore::Restore() {
512 this->fDrawType = RESTORE;
chudy@google.com97cee972012-08-07 20:41:37 +0000513 this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000514}
515
516void Restore::execute(SkCanvas* canvas) {
517 canvas->restore();
518}
519
tomhudson@google.com0699e022012-11-27 16:09:42 +0000520void Restore::trackSaveState(int* state) {
521 (*state)--;
522}
523
chudy@google.com902ebe52012-06-29 14:21:22 +0000524Rotate::Rotate(SkScalar degrees) {
525 this->fDegrees = degrees;
526 this->fDrawType = ROTATE;
527
chudy@google.com97cee972012-08-07 20:41:37 +0000528 this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000529}
530
531void Rotate::execute(SkCanvas* canvas) {
532 canvas->rotate(this->fDegrees);
533}
534
535Save::Save(SkCanvas::SaveFlags flags) {
536 this->fFlags = flags;
537 this->fDrawType = SAVE;
chudy@google.com97cee972012-08-07 20:41:37 +0000538 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000539}
540
541void Save::execute(SkCanvas* canvas) {
542 canvas->save(this->fFlags);
543}
544
tomhudson@google.com0699e022012-11-27 16:09:42 +0000545void Save::trackSaveState(int* state) {
546 (*state)++;
547}
548
chudy@google.com902ebe52012-06-29 14:21:22 +0000549SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
550 SkCanvas::SaveFlags flags) {
551 this->fBounds = bounds;
552 this->fPaint = paint;
553 this->fFlags = flags;
554 this->fDrawType = SAVE_LAYER;
555
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000556 if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
chudy@google.com97cee972012-08-07 20:41:37 +0000557 if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
558 this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000559}
560
561void SaveLayer::execute(SkCanvas* canvas) {
562 canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags);
563}
564
tomhudson@google.com0699e022012-11-27 16:09:42 +0000565void SaveLayer::trackSaveState(int* state) {
566 (*state)++;
567}
568
chudy@google.com902ebe52012-06-29 14:21:22 +0000569Scale::Scale(SkScalar sx, SkScalar sy) {
570 this->fSx = sx;
571 this->fSy = sy;
572 this->fDrawType = SCALE;
573
chudy@google.com97cee972012-08-07 20:41:37 +0000574 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
575 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000576}
577
578void Scale::execute(SkCanvas* canvas) {
579 canvas->scale(this->fSx, this->fSy);
580}
581
582SetMatrix::SetMatrix(const SkMatrix& matrix) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000583 this->fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000584 this->fDrawType = SET_MATRIX;
585
chudy@google.com97cee972012-08-07 20:41:37 +0000586 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000587}
588
589void SetMatrix::execute(SkCanvas* canvas) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000590 canvas->setMatrix(this->fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000591}
592
593Skew::Skew(SkScalar sx, SkScalar sy) {
594 this->fSx = sx;
595 this->fSy = sy;
596 this->fDrawType = SKEW;
597
chudy@google.com97cee972012-08-07 20:41:37 +0000598 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
599 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000600}
601
602void Skew::execute(SkCanvas* canvas) {
603 canvas->skew(this->fSx, this->fSy);
604}
605
606Translate::Translate(SkScalar dx, SkScalar dy) {
607 this->fDx = dx;
608 this->fDy = dy;
609 this->fDrawType = TRANSLATE;
610
chudy@google.com97cee972012-08-07 20:41:37 +0000611 this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
612 this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000613}
614
615void Translate::execute(SkCanvas* canvas) {
616 canvas->translate(this->fDx, this->fDy);
617}