blob: 7e6b22b7c718317a0da6ed4620c6ac465b18121d [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";
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +000068 case PUSH_CULL: return "PushCull";
69 case POP_CULL: return "PopCull";
chudy@google.com902ebe52012-06-29 14:21:22 +000070 default:
71 SkDebugf("DrawType error 0x%08x\n", type);
72 SkASSERT(0);
73 break;
74 }
75 SkDEBUGFAIL("DrawType UNUSED\n");
76 return NULL;
77}
78
chudy@google.com97cee972012-08-07 20:41:37 +000079SkString SkDrawCommand::toString() {
80 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000081}
82
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000083SkClearCommand::SkClearCommand(SkColor color) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000084 fColor = color;
85 fDrawType = DRAW_CLEAR;
86 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000087}
88
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000089void SkClearCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000090 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000091}
92
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000093namespace {
94
95void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
96 const SkISize& size = canvas->getDeviceSize();
97
98 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
99
100 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
101 if (bounds.width() > bounds.height()) {
102 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
103 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
104 } else {
105 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
106 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
107 }
108 canvas->translate(-bounds.centerX(), -bounds.centerY());
109}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000110
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000111
112void render_path(SkCanvas* canvas, const SkPath& path) {
113 canvas->clear(0xFFFFFFFF);
114 canvas->save();
115
116 const SkRect& bounds = path.getBounds();
117
118 xlate_and_scale_to_bounds(canvas, bounds);
119
120 SkPaint p;
121 p.setColor(SK_ColorBLACK);
122 p.setStyle(SkPaint::kStroke_Style);
123
124 canvas->drawPath(path, p);
125 canvas->restore();
126}
127
128void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
129 const SkISize& size = canvas->getDeviceSize();
130
131 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
132 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
133
134 if (input.width() > input.height()) {
135 yScale *= input.height() / (float) input.width();
136 } else {
137 xScale *= input.width() / (float) input.height();
138 }
139
140 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
141 xScale * input.width(),
142 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000143
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000144 canvas->clear(0xFFFFFFFF);
145 canvas->drawBitmapRect(input, NULL, dst);
146
147 if (NULL != srcRect) {
148 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
149 srcRect->fTop * yScale + SK_Scalar1,
150 srcRect->fRight * xScale + SK_Scalar1,
151 srcRect->fBottom * yScale + SK_Scalar1);
152 SkPaint p;
153 p.setColor(SK_ColorRED);
154 p.setStyle(SkPaint::kStroke_Style);
155
156 canvas->drawRect(r, p);
157 }
158}
159
160void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
161 canvas->clear(0xFFFFFFFF);
162 canvas->save();
163
164 const SkRect& bounds = rrect.getBounds();
165
166 xlate_and_scale_to_bounds(canvas, bounds);
167
168 SkPaint p;
169 p.setColor(SK_ColorBLACK);
170 p.setStyle(SkPaint::kStroke_Style);
171
172 canvas->drawRRect(rrect, p);
173 canvas->restore();
174}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000175
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000176void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
177 canvas->clear(0xFFFFFFFF);
178 canvas->save();
179
180 const SkRect& bounds = outer.getBounds();
181
182 xlate_and_scale_to_bounds(canvas, bounds);
183
184 SkPaint p;
185 p.setColor(SK_ColorBLACK);
186 p.setStyle(SkPaint::kStroke_Style);
187
188 canvas->drawDRRect(outer, inner, p);
189 canvas->restore();
190}
191
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000192};
193
194
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000195SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000196 fPath = path;
197 fOp = op;
198 fDoAA = doAA;
199 fDrawType = CLIP_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000200
robertphillips@google.com91217d02013-03-17 18:33:46 +0000201 fInfo.push(SkObjectParser::PathToString(path));
202 fInfo.push(SkObjectParser::RegionOpToString(op));
203 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000204}
205
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000206void SkClipPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000207 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000208}
209
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000210bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000211 render_path(canvas, fPath);
212 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000213}
214
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000215SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000216 fRegion = region;
217 fOp = op;
218 fDrawType = CLIP_REGION;
chudy@google.com902ebe52012-06-29 14:21:22 +0000219
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000220 fInfo.push(SkObjectParser::RegionToString(region));
221 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000222}
223
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000224void SkClipRegionCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000225 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000226}
227
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000228SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000229 fRect = rect;
230 fOp = op;
231 fDoAA = doAA;
232 fDrawType = CLIP_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000233
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000234 fInfo.push(SkObjectParser::RectToString(rect));
235 fInfo.push(SkObjectParser::RegionOpToString(op));
236 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000237}
238
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000239void SkClipRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000240 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000241}
242
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000243SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000244 fRRect = rrect;
245 fOp = op;
246 fDoAA = doAA;
247 fDrawType = CLIP_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000248
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000249 fInfo.push(SkObjectParser::RRectToString(rrect));
250 fInfo.push(SkObjectParser::RegionOpToString(op));
251 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000252}
253
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000254void SkClipRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000255 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000256}
257
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000258bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000259 render_rrect(canvas, fRRect);
260 return true;
261}
262
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000263SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000264 fMatrix = matrix;
265 fDrawType = CONCAT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000266
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000267 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000268}
269
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000270void SkConcatCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000271 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000272}
273
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000274SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000275 const SkPaint* paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000276 fBitmap = bitmap;
277 fLeft = left;
278 fTop = top;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000279 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000280 fPaint = *paint;
281 fPaintPtr = &fPaint;
282 } else {
283 fPaintPtr = NULL;
284 }
285 fDrawType = DRAW_BITMAP;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000286
287 fInfo.push(SkObjectParser::BitmapToString(bitmap));
288 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
289 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
290 if (NULL != paint) {
291 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000292 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000293}
294
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000295void SkDrawBitmapCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000296 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000297}
298
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000299bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000300 render_bitmap(canvas, fBitmap);
301 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000302}
303
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000304SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
305 const SkMatrix& matrix,
306 const SkPaint* paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000307 fBitmap = bitmap;
308 fMatrix = matrix;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000309 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000310 fPaint = *paint;
311 fPaintPtr = &fPaint;
312 } else {
313 fPaintPtr = NULL;
314 }
315 fDrawType = DRAW_BITMAP_MATRIX;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000316
317 fInfo.push(SkObjectParser::BitmapToString(bitmap));
318 fInfo.push(SkObjectParser::MatrixToString(matrix));
319 if (NULL != paint) {
320 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000321 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000322}
323
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000324void SkDrawBitmapMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000325 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000326}
327
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000328bool SkDrawBitmapMatrixCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000329 render_bitmap(canvas, fBitmap);
330 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000331}
332
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000333SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
334 const SkRect& dst, const SkPaint* paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000335 fBitmap = bitmap;
336 fCenter = center;
337 fDst = dst;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000338 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000339 fPaint = *paint;
340 fPaintPtr = &fPaint;
341 } else {
342 fPaintPtr = NULL;
343 }
344 fDrawType = DRAW_BITMAP_NINE;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000345
346 fInfo.push(SkObjectParser::BitmapToString(bitmap));
347 fInfo.push(SkObjectParser::IRectToString(center));
348 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
349 if (NULL != paint) {
350 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000351 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000352}
353
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000354void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000355 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000356}
357
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000358bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000359 render_bitmap(canvas, fBitmap);
360 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000361}
362
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000363SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000364 const SkRect& dst, const SkPaint* paint,
365 SkCanvas::DrawBitmapRectFlags flags) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000366 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000367 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000368 fSrc = *src;
369 } else {
370 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000371 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000372 fDst = dst;
373
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000374 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000375 fPaint = *paint;
376 fPaintPtr = &fPaint;
377 } else {
378 fPaintPtr = NULL;
379 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000380 fFlags = flags;
381
robertphillips@google.com91217d02013-03-17 18:33:46 +0000382 fDrawType = DRAW_BITMAP_RECT_TO_RECT;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000383
384 fInfo.push(SkObjectParser::BitmapToString(bitmap));
385 if (NULL != src) {
386 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
387 }
388 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
389 if (NULL != paint) {
390 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000391 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000392 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000393}
394
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000395void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000396 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000397}
398
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000399bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000400 render_bitmap(canvas, fBitmap, this->srcRect());
401 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000402}
403
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000404SkDrawDataCommand::SkDrawDataCommand(const void* data, size_t length) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000405 fData = new char[length];
406 memcpy(fData, data, length);
407 fLength = length;
408 fDrawType = DRAW_DATA;
409
410 // TODO: add display of actual data?
411 SkString* str = new SkString;
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000412 str->appendf("length: %d", (int) length);
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000413 fInfo.push(str);
chudy@google.com902ebe52012-06-29 14:21:22 +0000414}
415
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000416void SkDrawDataCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000417 canvas->drawData(fData, fLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000418}
419
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000420SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000421 : INHERITED(BEGIN_COMMENT_GROUP)
422 , fDescription(description) {
423 SkString* temp = new SkString;
424 temp->appendf("Description: %s", description);
425 fInfo.push(temp);
426}
427
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000428SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000429 : INHERITED(COMMENT)
430 , fKywd(kywd)
431 , fValue(value) {
432 SkString* temp = new SkString;
433 temp->appendf("%s: %s", kywd, value);
434 fInfo.push(temp);
435}
436
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000437SkEndCommentGroupCommand::SkEndCommentGroupCommand() : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000438}
439
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000440SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000441 fOval = oval;
442 fPaint = paint;
443 fDrawType = DRAW_OVAL;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000444
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000445 fInfo.push(SkObjectParser::RectToString(oval));
446 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000447}
448
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000449void SkDrawOvalCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000450 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000451}
452
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000453bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000454 canvas->clear(0xFFFFFFFF);
455 canvas->save();
456
457 xlate_and_scale_to_bounds(canvas, fOval);
458
459 SkPaint p;
460 p.setColor(SK_ColorBLACK);
461 p.setStyle(SkPaint::kStroke_Style);
462
463 canvas->drawOval(fOval, p);
464 canvas->restore();
465
466 return true;
467}
468
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000469SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000470 fPaint = paint;
471 fDrawType = DRAW_PAINT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000472
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000473 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000474}
475
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000476void SkDrawPaintCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000477 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000478}
479
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000480bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000481 canvas->clear(0xFFFFFFFF);
482 canvas->drawPaint(fPaint);
483 return true;
484}
485
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000486SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000487 fPath = path;
488 fPaint = paint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000489 fDrawType = DRAW_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000490
robertphillips@google.com91217d02013-03-17 18:33:46 +0000491 fInfo.push(SkObjectParser::PathToString(path));
492 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000493}
494
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000495void SkDrawPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000496 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000497}
498
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000499bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000500 render_path(canvas, fPath);
501 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000502}
503
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000504SkDrawPictureCommand::SkDrawPictureCommand(SkPicture& picture) :
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000505 fPicture(picture) {
506 fDrawType = DRAW_PICTURE;
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000507 SkString* temp = new SkString;
508 temp->appendf("SkPicture: W: %d H: %d", picture.width(), picture.height());
509 fInfo.push(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000510}
511
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000512void SkDrawPictureCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000513 canvas->drawPicture(fPicture);
chudy@google.com902ebe52012-06-29 14:21:22 +0000514}
515
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000516bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
517 canvas->clear(0xFFFFFFFF);
518 canvas->save();
519
fmalita@google.com517dbe82013-11-21 17:50:15 +0000520 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture.width()),
521 SkIntToScalar(fPicture.height()));
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000522 xlate_and_scale_to_bounds(canvas, bounds);
523
524 canvas->drawPicture(const_cast<SkPicture&>(fPicture));
525
526 canvas->restore();
527
528 return true;
529}
530
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000531SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
532 const SkPoint pts[], const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000533 fMode = mode;
534 fCount = count;
535 fPts = new SkPoint[count];
536 memcpy(fPts, pts, count * sizeof(SkPoint));
537 fPaint = paint;
538 fDrawType = DRAW_POINTS;
chudy@google.com902ebe52012-06-29 14:21:22 +0000539
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000540 fInfo.push(SkObjectParser::PointsToString(pts, count));
541 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
542 "Points: "));
543 fInfo.push(SkObjectParser::PointModeToString(mode));
544 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000545}
546
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000547void SkDrawPointsCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000548 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000549}
550
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000551bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000552 canvas->clear(0xFFFFFFFF);
553 canvas->save();
554
555 SkRect bounds;
556
557 bounds.setEmpty();
558 for (unsigned int i = 0; i < fCount; ++i) {
559 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
560 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000561
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000562 xlate_and_scale_to_bounds(canvas, bounds);
563
564 SkPaint p;
565 p.setColor(SK_ColorBLACK);
566 p.setStyle(SkPaint::kStroke_Style);
567
568 canvas->drawPoints(fMode, fCount, fPts, p);
569 canvas->restore();
570
571 return true;
572}
573
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000574SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
575 const SkPoint pos[], const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000576 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000577
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000578 fText = new char[byteLength];
579 memcpy(fText, text, byteLength);
580 fByteLength = byteLength;
581
582 fPos = new SkPoint[numPts];
583 memcpy(fPos, pos, numPts * sizeof(SkPoint));
584
585 fPaint = paint;
586 fDrawType = DRAW_POS_TEXT;
587
588 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000589 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000590 fInfo.push(SkObjectParser::PointsToString(pos, 1));
591 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000592}
593
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000594void SkDrawPosTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000595 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000596}
597
598
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000599SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
600 const SkScalar xpos[], SkScalar constY,
601 const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000602 size_t numPts = paint.countText(text, byteLength);
603
604 fText = new char[byteLength];
605 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000606 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000607
608 fXpos = new SkScalar[numPts];
609 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
610
robertphillips@google.com91217d02013-03-17 18:33:46 +0000611 fConstY = constY;
612 fPaint = paint;
613 fDrawType = DRAW_POS_TEXT_H;
chudy@google.com902ebe52012-06-29 14:21:22 +0000614
robertphillips@google.com91217d02013-03-17 18:33:46 +0000615 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
616 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
617 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
618 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000619}
620
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000621void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000622 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000623}
624
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000625SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000626 fRect = rect;
627 fPaint = paint;
628 fDrawType = DRAW_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000629
robertphillips@google.com91217d02013-03-17 18:33:46 +0000630 fInfo.push(SkObjectParser::RectToString(rect));
631 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000632}
633
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000634void SkDrawRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000635 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000636}
637
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000638SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000639 fRRect = rrect;
640 fPaint = paint;
641 fDrawType = DRAW_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000642
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000643 fInfo.push(SkObjectParser::RRectToString(rrect));
644 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000645}
646
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000647void SkDrawRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000648 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000649}
650
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000651bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000652 render_rrect(canvas, fRRect);
653 return true;
654}
655
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000656SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000657 const SkRRect& inner,
658 const SkPaint& paint) {
659 fOuter = outer;
660 fInner = inner;
661 fPaint = paint;
662 fDrawType = DRAW_DRRECT;
663
664 fInfo.push(SkObjectParser::RRectToString(outer));
665 fInfo.push(SkObjectParser::RRectToString(inner));
666 fInfo.push(SkObjectParser::PaintToString(paint));
667}
668
669void SkDrawDRRectCommand::execute(SkCanvas* canvas) {
670 canvas->drawDRRect(fOuter, fInner, fPaint);
671}
672
673bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
674 render_drrect(canvas, fOuter, fInner);
675 return true;
676}
677
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000678SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
679 const SkPaint* paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000680 fBitmap = bitmap;
681 fLeft = left;
682 fTop = top;
683 if (NULL != paint) {
684 fPaint = *paint;
685 fPaintPtr = &fPaint;
686 } else {
687 fPaintPtr = NULL;
688 }
689 fDrawType = DRAW_SPRITE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000690
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000691 fInfo.push(SkObjectParser::BitmapToString(bitmap));
692 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
693 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
694 if (NULL != paint) {
695 fInfo.push(SkObjectParser::PaintToString(*paint));
696 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000697}
698
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000699void SkDrawSpriteCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000700 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000701}
702
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000703bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000704 render_bitmap(canvas, fBitmap);
705 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000706}
707
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000708SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
709 const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000710 fText = new char[byteLength];
711 memcpy(fText, text, byteLength);
712 fByteLength = byteLength;
713 fX = x;
714 fY = y;
715 fPaint = paint;
716 fDrawType = DRAW_TEXT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000717
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000718 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
719 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
720 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
721 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000722}
723
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000724void SkDrawTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000725 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000726}
727
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000728SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
729 const SkPath& path, const SkMatrix* matrix,
730 const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000731 fText = new char[byteLength];
732 memcpy(fText, text, byteLength);
733 fByteLength = byteLength;
734 fPath = path;
735 if (NULL != matrix) {
736 fMatrix = *matrix;
737 } else {
738 fMatrix.setIdentity();
739 }
740 fPaint = paint;
741 fDrawType = DRAW_TEXT_ON_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000742
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000743 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
744 fInfo.push(SkObjectParser::PathToString(path));
745 if (NULL != matrix) {
746 fInfo.push(SkObjectParser::MatrixToString(*matrix));
747 }
748 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000749}
750
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000751void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000752 canvas->drawTextOnPath(fText, fByteLength, fPath,
753 fMatrix.isIdentity() ? NULL : &fMatrix,
754 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000755}
756
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000757SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
758 const SkPoint vertices[], const SkPoint texs[],
759 const SkColor colors[], SkXfermode* xfermode,
760 const uint16_t indices[], int indexCount,
761 const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000762 fVmode = vmode;
763
764 fVertexCount = vertexCount;
765
766 fVertices = new SkPoint[vertexCount];
767 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
768
769 if (NULL != texs) {
770 fTexs = new SkPoint[vertexCount];
771 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
772 } else {
773 fTexs = NULL;
774 }
775
776 if (NULL != colors) {
777 fColors = new SkColor[vertexCount];
778 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
779 } else {
780 fColors = NULL;
781 }
782
783 fXfermode = xfermode;
784 if (NULL != fXfermode) {
785 fXfermode->ref();
786 }
787
788 if (indexCount > 0) {
789 fIndices = new uint16_t[indexCount];
790 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
791 } else {
792 fIndices = NULL;
793 }
794
795 fIndexCount = indexCount;
796 fPaint = paint;
797 fDrawType = DRAW_VERTICES;
798
chudy@google.com902ebe52012-06-29 14:21:22 +0000799 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000800 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
801 fInfo.push(SkObjectParser::PaintToString(paint));
802}
803
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000804SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000805 delete [] fVertices;
806 delete [] fTexs;
807 delete [] fColors;
808 SkSafeUnref(fXfermode);
809 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000810}
811
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000812void SkDrawVerticesCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000813 canvas->drawVertices(fVmode, fVertexCount, fVertices,
814 fTexs, fColors, fXfermode, fIndices,
815 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000816}
817
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000818SkRestoreCommand::SkRestoreCommand() {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000819 fDrawType = RESTORE;
820 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000821}
822
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000823void SkRestoreCommand::execute(SkCanvas* canvas) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000824 canvas->restore();
825}
826
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000827void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000828 (*state)--;
829}
830
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000831SkRotateCommand::SkRotateCommand(SkScalar degrees) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000832 fDegrees = degrees;
833 fDrawType = ROTATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000834
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000835 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000836}
837
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000838void SkRotateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000839 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000840}
841
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000842SkSaveCommand::SkSaveCommand(SkCanvas::SaveFlags flags) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000843 fFlags = flags;
844 fDrawType = SAVE;
845 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000846}
847
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000848void SkSaveCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000849 canvas->save(fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000850}
851
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000852void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000853 (*state)++;
854}
855
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000856SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
857 SkCanvas::SaveFlags flags) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000858 if (NULL != bounds) {
859 fBounds = *bounds;
860 } else {
861 fBounds.setEmpty();
862 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000863
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000864 if (NULL != paint) {
865 fPaint = *paint;
866 fPaintPtr = &fPaint;
867 } else {
868 fPaintPtr = NULL;
869 }
870 fFlags = flags;
871 fDrawType = SAVE_LAYER;
872
873 if (NULL != bounds) {
874 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
875 }
876 if (NULL != paint) {
877 fInfo.push(SkObjectParser::PaintToString(*paint));
878 }
879 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000880}
881
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000882void SkSaveLayerCommand::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000883 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000884 fPaintPtr,
885 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000886}
887
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000888void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) {
889 canvas->save();
890}
891
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000892void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000893 (*state)++;
894}
895
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000896SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000897 fSx = sx;
898 fSy = sy;
899 fDrawType = SCALE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000900
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000901 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
902 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000903}
904
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000905void SkScaleCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000906 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000907}
908
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000909SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000910 fMatrix = matrix;
911 fDrawType = SET_MATRIX;
chudy@google.com902ebe52012-06-29 14:21:22 +0000912
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000913 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000914}
915
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000916void SkSetMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000917 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000918}
919
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000920SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000921 fSx = sx;
922 fSy = sy;
923 fDrawType = SKEW;
chudy@google.com902ebe52012-06-29 14:21:22 +0000924
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000925 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
926 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000927}
928
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000929void SkSkewCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000930 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000931}
932
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000933SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000934 fDx = dx;
935 fDy = dy;
936 fDrawType = TRANSLATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000937
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000938 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
939 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000940}
941
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000942void SkTranslateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000943 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000944}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000945
946SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
947 : fCullRect(cullRect) {
948 fDrawType = PUSH_CULL;
949 fInfo.push(SkObjectParser::RectToString(cullRect));
950}
951
952void SkPushCullCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000953 canvas->pushCull(fCullRect);
954}
955
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000956void SkPushCullCommand::vizExecute(SkCanvas* canvas) {
957 canvas->pushCull(fCullRect);
958
959 SkPaint p;
960 p.setColor(SK_ColorCYAN);
961 p.setStyle(SkPaint::kStroke_Style);
962 canvas->drawRect(fCullRect, p);
963}
964
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000965SkPopCullCommand::SkPopCullCommand() {
966 fDrawType = POP_CULL;
967}
968
969void SkPopCullCommand::execute(SkCanvas* canvas) {
970 canvas->popCull();
971}