blob: 4e410d1cfe2b3e8a12b74c2afcb7dc72b23e7f86 [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
skia.committer@gmail.coma5d3e772013-05-30 07:01:29 +000015SkDrawCommand::SkDrawCommand(DrawType type)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000016 : fDrawType(type)
17 , fVisible(true) {
18}
19
chudy@google.com902ebe52012-06-29 14:21:22 +000020SkDrawCommand::SkDrawCommand() {
21 fVisible = true;
22}
23
24SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000025 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000026}
27
28const char* SkDrawCommand::GetCommandString(DrawType type) {
29 switch (type) {
30 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
31 case DRAW_CLEAR: return "Clear";
32 case CLIP_PATH: return "Clip Path";
33 case CLIP_REGION: return "Clip Region";
34 case CLIP_RECT: return "Clip Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000035 case CLIP_RRECT: return "Clip RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000036 case CONCAT: return "Concat";
37 case DRAW_BITMAP: return "Draw Bitmap";
38 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
39 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
robertphillips@google.com84d320e2012-09-20 19:09:17 +000040 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
chudy@google.com902ebe52012-06-29 14:21:22 +000041 case DRAW_DATA: return "Draw Data";
robertphillips@google.com67baba42013-01-02 20:20:31 +000042 case DRAW_OVAL: return "Draw Oval";
chudy@google.com902ebe52012-06-29 14:21:22 +000043 case DRAW_PAINT: return "Draw Paint";
44 case DRAW_PATH: return "Draw Path";
45 case DRAW_PICTURE: return "Draw Picture";
46 case DRAW_POINTS: return "Draw Points";
47 case DRAW_POS_TEXT: return "Draw Pos Text";
48 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
49 case DRAW_RECT: return "Draw Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000050 case DRAW_RRECT: return "Draw RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000051 case DRAW_SPRITE: return "Draw Sprite";
52 case DRAW_TEXT: return "Draw Text";
53 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
54 case DRAW_VERTICES: return "Draw Vertices";
55 case RESTORE: return "Restore";
56 case ROTATE: return "Rotate";
57 case SAVE: return "Save";
58 case SAVE_LAYER: return "Save Layer";
59 case SCALE: return "Scale";
60 case SET_MATRIX: return "Set Matrix";
61 case SKEW: return "Skew";
62 case TRANSLATE: return "Translate";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000063 case NOOP: return "NoOp";
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000064 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
65 case COMMENT: return "Comment";
66 case END_COMMENT_GROUP: return "EndCommentGroup";
commit-bot@chromium.org3d305202014-02-24 17:28:55 +000067 case DRAW_DRRECT: return "Draw DRRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000068 default:
69 SkDebugf("DrawType error 0x%08x\n", type);
70 SkASSERT(0);
71 break;
72 }
73 SkDEBUGFAIL("DrawType UNUSED\n");
74 return NULL;
75}
76
chudy@google.com97cee972012-08-07 20:41:37 +000077SkString SkDrawCommand::toString() {
78 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000079}
80
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000081SkClearCommand::SkClearCommand(SkColor color) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000082 fColor = color;
83 fDrawType = DRAW_CLEAR;
84 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000085}
86
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000087void SkClearCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000088 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000089}
90
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000091namespace {
92
93void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
94 const SkISize& size = canvas->getDeviceSize();
95
96 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
97
98 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
99 if (bounds.width() > bounds.height()) {
100 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
101 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
102 } else {
103 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
104 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
105 }
106 canvas->translate(-bounds.centerX(), -bounds.centerY());
107}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000108
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000109
110void render_path(SkCanvas* canvas, const SkPath& path) {
111 canvas->clear(0xFFFFFFFF);
112 canvas->save();
113
114 const SkRect& bounds = path.getBounds();
115
116 xlate_and_scale_to_bounds(canvas, bounds);
117
118 SkPaint p;
119 p.setColor(SK_ColorBLACK);
120 p.setStyle(SkPaint::kStroke_Style);
121
122 canvas->drawPath(path, p);
123 canvas->restore();
124}
125
126void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
127 const SkISize& size = canvas->getDeviceSize();
128
129 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
130 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
131
132 if (input.width() > input.height()) {
133 yScale *= input.height() / (float) input.width();
134 } else {
135 xScale *= input.width() / (float) input.height();
136 }
137
138 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
139 xScale * input.width(),
140 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000141
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000142 canvas->clear(0xFFFFFFFF);
143 canvas->drawBitmapRect(input, NULL, dst);
144
145 if (NULL != srcRect) {
146 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
147 srcRect->fTop * yScale + SK_Scalar1,
148 srcRect->fRight * xScale + SK_Scalar1,
149 srcRect->fBottom * yScale + SK_Scalar1);
150 SkPaint p;
151 p.setColor(SK_ColorRED);
152 p.setStyle(SkPaint::kStroke_Style);
153
154 canvas->drawRect(r, p);
155 }
156}
157
158void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
159 canvas->clear(0xFFFFFFFF);
160 canvas->save();
161
162 const SkRect& bounds = rrect.getBounds();
163
164 xlate_and_scale_to_bounds(canvas, bounds);
165
166 SkPaint p;
167 p.setColor(SK_ColorBLACK);
168 p.setStyle(SkPaint::kStroke_Style);
169
170 canvas->drawRRect(rrect, p);
171 canvas->restore();
172}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000173
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000174void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
175 canvas->clear(0xFFFFFFFF);
176 canvas->save();
177
178 const SkRect& bounds = outer.getBounds();
179
180 xlate_and_scale_to_bounds(canvas, bounds);
181
182 SkPaint p;
183 p.setColor(SK_ColorBLACK);
184 p.setStyle(SkPaint::kStroke_Style);
185
186 canvas->drawDRRect(outer, inner, p);
187 canvas->restore();
188}
189
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000190};
191
192
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000193SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000194 fPath = path;
195 fOp = op;
196 fDoAA = doAA;
197 fDrawType = CLIP_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000198
robertphillips@google.com91217d02013-03-17 18:33:46 +0000199 fInfo.push(SkObjectParser::PathToString(path));
200 fInfo.push(SkObjectParser::RegionOpToString(op));
201 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000202}
203
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000204void SkClipPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000205 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000206}
207
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000208bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000209 render_path(canvas, fPath);
210 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000211}
212
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000213SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000214 fRegion = region;
215 fOp = op;
216 fDrawType = CLIP_REGION;
chudy@google.com902ebe52012-06-29 14:21:22 +0000217
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000218 fInfo.push(SkObjectParser::RegionToString(region));
219 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000220}
221
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000222void SkClipRegionCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000223 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000224}
225
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000226SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000227 fRect = rect;
228 fOp = op;
229 fDoAA = doAA;
230 fDrawType = CLIP_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000231
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000232 fInfo.push(SkObjectParser::RectToString(rect));
233 fInfo.push(SkObjectParser::RegionOpToString(op));
234 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000235}
236
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000237void SkClipRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000238 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000239}
240
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000241SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000242 fRRect = rrect;
243 fOp = op;
244 fDoAA = doAA;
245 fDrawType = CLIP_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000246
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000247 fInfo.push(SkObjectParser::RRectToString(rrect));
248 fInfo.push(SkObjectParser::RegionOpToString(op));
249 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000250}
251
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000252void SkClipRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000253 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000254}
255
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000256bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000257 render_rrect(canvas, fRRect);
258 return true;
259}
260
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000261SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000262 fMatrix = matrix;
263 fDrawType = CONCAT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000264
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000265 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000266}
267
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000268void SkConcatCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000269 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000270}
271
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000272SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000273 const SkPaint* paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000274 fBitmap = bitmap;
275 fLeft = left;
276 fTop = top;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000277 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000278 fPaint = *paint;
279 fPaintPtr = &fPaint;
280 } else {
281 fPaintPtr = NULL;
282 }
283 fDrawType = DRAW_BITMAP;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000284
285 fInfo.push(SkObjectParser::BitmapToString(bitmap));
286 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
287 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
288 if (NULL != paint) {
289 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000290 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000291}
292
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000293void SkDrawBitmapCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000294 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000295}
296
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000297bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000298 render_bitmap(canvas, fBitmap);
299 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000300}
301
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000302SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
303 const SkMatrix& matrix,
304 const SkPaint* paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000305 fBitmap = bitmap;
306 fMatrix = matrix;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000307 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000308 fPaint = *paint;
309 fPaintPtr = &fPaint;
310 } else {
311 fPaintPtr = NULL;
312 }
313 fDrawType = DRAW_BITMAP_MATRIX;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000314
315 fInfo.push(SkObjectParser::BitmapToString(bitmap));
316 fInfo.push(SkObjectParser::MatrixToString(matrix));
317 if (NULL != paint) {
318 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000319 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000320}
321
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000322void SkDrawBitmapMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000323 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000324}
325
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000326bool SkDrawBitmapMatrixCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000327 render_bitmap(canvas, fBitmap);
328 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000329}
330
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000331SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
332 const SkRect& dst, const SkPaint* paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000333 fBitmap = bitmap;
334 fCenter = center;
335 fDst = dst;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000336 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000337 fPaint = *paint;
338 fPaintPtr = &fPaint;
339 } else {
340 fPaintPtr = NULL;
341 }
342 fDrawType = DRAW_BITMAP_NINE;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000343
344 fInfo.push(SkObjectParser::BitmapToString(bitmap));
345 fInfo.push(SkObjectParser::IRectToString(center));
346 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
347 if (NULL != paint) {
348 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000349 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000350}
351
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000352void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000353 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000354}
355
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000356bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000357 render_bitmap(canvas, fBitmap);
358 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000359}
360
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000361SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000362 const SkRect& dst, const SkPaint* paint,
363 SkCanvas::DrawBitmapRectFlags flags) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000364 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000365 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000366 fSrc = *src;
367 } else {
368 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000369 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000370 fDst = dst;
371
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000372 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000373 fPaint = *paint;
374 fPaintPtr = &fPaint;
375 } else {
376 fPaintPtr = NULL;
377 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000378 fFlags = flags;
379
robertphillips@google.com91217d02013-03-17 18:33:46 +0000380 fDrawType = DRAW_BITMAP_RECT_TO_RECT;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000381
382 fInfo.push(SkObjectParser::BitmapToString(bitmap));
383 if (NULL != src) {
384 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
385 }
386 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
387 if (NULL != paint) {
388 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000389 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000390 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000391}
392
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000393void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000394 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000397bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000398 render_bitmap(canvas, fBitmap, this->srcRect());
399 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000400}
401
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000402SkDrawDataCommand::SkDrawDataCommand(const void* data, size_t length) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000403 fData = new char[length];
404 memcpy(fData, data, length);
405 fLength = length;
406 fDrawType = DRAW_DATA;
407
408 // TODO: add display of actual data?
409 SkString* str = new SkString;
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000410 str->appendf("length: %d", (int) length);
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000411 fInfo.push(str);
chudy@google.com902ebe52012-06-29 14:21:22 +0000412}
413
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000414void SkDrawDataCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000415 canvas->drawData(fData, fLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000416}
417
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000418SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000419 : INHERITED(BEGIN_COMMENT_GROUP)
420 , fDescription(description) {
421 SkString* temp = new SkString;
422 temp->appendf("Description: %s", description);
423 fInfo.push(temp);
424}
425
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000426SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000427 : INHERITED(COMMENT)
428 , fKywd(kywd)
429 , fValue(value) {
430 SkString* temp = new SkString;
431 temp->appendf("%s: %s", kywd, value);
432 fInfo.push(temp);
433}
434
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000435SkEndCommentGroupCommand::SkEndCommentGroupCommand() : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000436}
437
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000438SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000439 fOval = oval;
440 fPaint = paint;
441 fDrawType = DRAW_OVAL;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000442
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000443 fInfo.push(SkObjectParser::RectToString(oval));
444 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000445}
446
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000447void SkDrawOvalCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000448 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000449}
450
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000451bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000452 canvas->clear(0xFFFFFFFF);
453 canvas->save();
454
455 xlate_and_scale_to_bounds(canvas, fOval);
456
457 SkPaint p;
458 p.setColor(SK_ColorBLACK);
459 p.setStyle(SkPaint::kStroke_Style);
460
461 canvas->drawOval(fOval, p);
462 canvas->restore();
463
464 return true;
465}
466
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000467SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000468 fPaint = paint;
469 fDrawType = DRAW_PAINT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000470
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000471 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000472}
473
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000474void SkDrawPaintCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000475 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000476}
477
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000478bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000479 canvas->clear(0xFFFFFFFF);
480 canvas->drawPaint(fPaint);
481 return true;
482}
483
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000484SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000485 fPath = path;
486 fPaint = paint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000487 fDrawType = DRAW_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000488
robertphillips@google.com91217d02013-03-17 18:33:46 +0000489 fInfo.push(SkObjectParser::PathToString(path));
490 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000491}
492
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000493void SkDrawPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000494 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495}
496
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000497bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000498 render_path(canvas, fPath);
499 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000500}
501
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000502SkDrawPictureCommand::SkDrawPictureCommand(SkPicture& picture) :
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000503 fPicture(picture) {
504 fDrawType = DRAW_PICTURE;
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000505 SkString* temp = new SkString;
506 temp->appendf("SkPicture: W: %d H: %d", picture.width(), picture.height());
507 fInfo.push(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000508}
509
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000510void SkDrawPictureCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000511 canvas->drawPicture(fPicture);
chudy@google.com902ebe52012-06-29 14:21:22 +0000512}
513
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000514bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
515 canvas->clear(0xFFFFFFFF);
516 canvas->save();
517
fmalita@google.com517dbe82013-11-21 17:50:15 +0000518 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture.width()),
519 SkIntToScalar(fPicture.height()));
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000520 xlate_and_scale_to_bounds(canvas, bounds);
521
522 canvas->drawPicture(const_cast<SkPicture&>(fPicture));
523
524 canvas->restore();
525
526 return true;
527}
528
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000529SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
530 const SkPoint pts[], const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000531 fMode = mode;
532 fCount = count;
533 fPts = new SkPoint[count];
534 memcpy(fPts, pts, count * sizeof(SkPoint));
535 fPaint = paint;
536 fDrawType = DRAW_POINTS;
chudy@google.com902ebe52012-06-29 14:21:22 +0000537
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000538 fInfo.push(SkObjectParser::PointsToString(pts, count));
539 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
540 "Points: "));
541 fInfo.push(SkObjectParser::PointModeToString(mode));
542 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000543}
544
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000545void SkDrawPointsCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000546 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000547}
548
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000549bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000550 canvas->clear(0xFFFFFFFF);
551 canvas->save();
552
553 SkRect bounds;
554
555 bounds.setEmpty();
556 for (unsigned int i = 0; i < fCount; ++i) {
557 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
558 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000559
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000560 xlate_and_scale_to_bounds(canvas, bounds);
561
562 SkPaint p;
563 p.setColor(SK_ColorBLACK);
564 p.setStyle(SkPaint::kStroke_Style);
565
566 canvas->drawPoints(fMode, fCount, fPts, p);
567 canvas->restore();
568
569 return true;
570}
571
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000572SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
573 const SkPoint pos[], const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000574 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000575
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000576 fText = new char[byteLength];
577 memcpy(fText, text, byteLength);
578 fByteLength = byteLength;
579
580 fPos = new SkPoint[numPts];
581 memcpy(fPos, pos, numPts * sizeof(SkPoint));
582
583 fPaint = paint;
584 fDrawType = DRAW_POS_TEXT;
585
586 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000587 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000588 fInfo.push(SkObjectParser::PointsToString(pos, 1));
589 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000590}
591
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000592void SkDrawPosTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000593 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000594}
595
596
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000597SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
598 const SkScalar xpos[], SkScalar constY,
599 const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000600 size_t numPts = paint.countText(text, byteLength);
601
602 fText = new char[byteLength];
603 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000604 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000605
606 fXpos = new SkScalar[numPts];
607 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
608
robertphillips@google.com91217d02013-03-17 18:33:46 +0000609 fConstY = constY;
610 fPaint = paint;
611 fDrawType = DRAW_POS_TEXT_H;
chudy@google.com902ebe52012-06-29 14:21:22 +0000612
robertphillips@google.com91217d02013-03-17 18:33:46 +0000613 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
614 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
615 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
616 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000617}
618
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000619void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000620 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000621}
622
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000623SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000624 fRect = rect;
625 fPaint = paint;
626 fDrawType = DRAW_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000627
robertphillips@google.com91217d02013-03-17 18:33:46 +0000628 fInfo.push(SkObjectParser::RectToString(rect));
629 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000630}
631
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000632void SkDrawRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000633 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000634}
635
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000636SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000637 fRRect = rrect;
638 fPaint = paint;
639 fDrawType = DRAW_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000640
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000641 fInfo.push(SkObjectParser::RRectToString(rrect));
642 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000643}
644
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000645void SkDrawRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000646 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000647}
648
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000649bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000650 render_rrect(canvas, fRRect);
651 return true;
652}
653
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000654SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000655 const SkRRect& inner,
656 const SkPaint& paint) {
657 fOuter = outer;
658 fInner = inner;
659 fPaint = paint;
660 fDrawType = DRAW_DRRECT;
661
662 fInfo.push(SkObjectParser::RRectToString(outer));
663 fInfo.push(SkObjectParser::RRectToString(inner));
664 fInfo.push(SkObjectParser::PaintToString(paint));
665}
666
667void SkDrawDRRectCommand::execute(SkCanvas* canvas) {
668 canvas->drawDRRect(fOuter, fInner, fPaint);
669}
670
671bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
672 render_drrect(canvas, fOuter, fInner);
673 return true;
674}
675
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000676SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
677 const SkPaint* paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000678 fBitmap = bitmap;
679 fLeft = left;
680 fTop = top;
681 if (NULL != paint) {
682 fPaint = *paint;
683 fPaintPtr = &fPaint;
684 } else {
685 fPaintPtr = NULL;
686 }
687 fDrawType = DRAW_SPRITE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000688
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000689 fInfo.push(SkObjectParser::BitmapToString(bitmap));
690 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
691 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
692 if (NULL != paint) {
693 fInfo.push(SkObjectParser::PaintToString(*paint));
694 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000695}
696
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000697void SkDrawSpriteCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000698 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000699}
700
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000701bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000702 render_bitmap(canvas, fBitmap);
703 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000704}
705
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000706SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
707 const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000708 fText = new char[byteLength];
709 memcpy(fText, text, byteLength);
710 fByteLength = byteLength;
711 fX = x;
712 fY = y;
713 fPaint = paint;
714 fDrawType = DRAW_TEXT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000715
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000716 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
717 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
718 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
719 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000720}
721
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000722void SkDrawTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000723 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000724}
725
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000726SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
727 const SkPath& path, const SkMatrix* matrix,
728 const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000729 fText = new char[byteLength];
730 memcpy(fText, text, byteLength);
731 fByteLength = byteLength;
732 fPath = path;
733 if (NULL != matrix) {
734 fMatrix = *matrix;
735 } else {
736 fMatrix.setIdentity();
737 }
738 fPaint = paint;
739 fDrawType = DRAW_TEXT_ON_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000740
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000741 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
742 fInfo.push(SkObjectParser::PathToString(path));
743 if (NULL != matrix) {
744 fInfo.push(SkObjectParser::MatrixToString(*matrix));
745 }
746 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000747}
748
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000749void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000750 canvas->drawTextOnPath(fText, fByteLength, fPath,
751 fMatrix.isIdentity() ? NULL : &fMatrix,
752 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000753}
754
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000755SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
756 const SkPoint vertices[], const SkPoint texs[],
757 const SkColor colors[], SkXfermode* xfermode,
758 const uint16_t indices[], int indexCount,
759 const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000760 fVmode = vmode;
761
762 fVertexCount = vertexCount;
763
764 fVertices = new SkPoint[vertexCount];
765 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
766
767 if (NULL != texs) {
768 fTexs = new SkPoint[vertexCount];
769 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
770 } else {
771 fTexs = NULL;
772 }
773
774 if (NULL != colors) {
775 fColors = new SkColor[vertexCount];
776 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
777 } else {
778 fColors = NULL;
779 }
780
781 fXfermode = xfermode;
782 if (NULL != fXfermode) {
783 fXfermode->ref();
784 }
785
786 if (indexCount > 0) {
787 fIndices = new uint16_t[indexCount];
788 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
789 } else {
790 fIndices = NULL;
791 }
792
793 fIndexCount = indexCount;
794 fPaint = paint;
795 fDrawType = DRAW_VERTICES;
796
chudy@google.com902ebe52012-06-29 14:21:22 +0000797 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000798 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
799 fInfo.push(SkObjectParser::PaintToString(paint));
800}
801
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000802SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000803 delete [] fVertices;
804 delete [] fTexs;
805 delete [] fColors;
806 SkSafeUnref(fXfermode);
807 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000808}
809
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000810void SkDrawVerticesCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000811 canvas->drawVertices(fVmode, fVertexCount, fVertices,
812 fTexs, fColors, fXfermode, fIndices,
813 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000814}
815
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000816SkRestoreCommand::SkRestoreCommand() {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000817 fDrawType = RESTORE;
818 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000819}
820
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000821void SkRestoreCommand::execute(SkCanvas* canvas) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000822 canvas->restore();
823}
824
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000825void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000826 (*state)--;
827}
828
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000829SkRotateCommand::SkRotateCommand(SkScalar degrees) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000830 fDegrees = degrees;
831 fDrawType = ROTATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000832
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000833 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000834}
835
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000836void SkRotateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000837 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000838}
839
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000840SkSaveCommand::SkSaveCommand(SkCanvas::SaveFlags flags) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000841 fFlags = flags;
842 fDrawType = SAVE;
843 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000844}
845
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000846void SkSaveCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000847 canvas->save(fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000848}
849
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000850void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000851 (*state)++;
852}
853
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000854SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
855 SkCanvas::SaveFlags flags) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000856 if (NULL != bounds) {
857 fBounds = *bounds;
858 } else {
859 fBounds.setEmpty();
860 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000861
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000862 if (NULL != paint) {
863 fPaint = *paint;
864 fPaintPtr = &fPaint;
865 } else {
866 fPaintPtr = NULL;
867 }
868 fFlags = flags;
869 fDrawType = SAVE_LAYER;
870
871 if (NULL != bounds) {
872 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
873 }
874 if (NULL != paint) {
875 fInfo.push(SkObjectParser::PaintToString(*paint));
876 }
877 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000878}
879
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000880void SkSaveLayerCommand::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000881 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000882 fPaintPtr,
883 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000884}
885
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000886void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000887 (*state)++;
888}
889
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000890SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000891 fSx = sx;
892 fSy = sy;
893 fDrawType = SCALE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000894
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000895 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
896 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000897}
898
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000899void SkScaleCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000900 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000901}
902
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000903SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000904 fMatrix = matrix;
905 fDrawType = SET_MATRIX;
chudy@google.com902ebe52012-06-29 14:21:22 +0000906
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000907 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000908}
909
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000910void SkSetMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000911 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000912}
913
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000914SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000915 fSx = sx;
916 fSy = sy;
917 fDrawType = SKEW;
chudy@google.com902ebe52012-06-29 14:21:22 +0000918
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000919 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
920 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000921}
922
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000923void SkSkewCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000924 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000925}
926
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000927SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000928 fDx = dx;
929 fDy = dy;
930 fDrawType = TRANSLATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000931
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000932 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
933 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000934}
935
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000936void SkTranslateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000937 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000938}