blob: 26d2a85a8a1baac10be3b27e26579e0a12268988 [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)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000017 , fOffset(0)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000018 , fVisible(true) {
19}
20
chudy@google.com902ebe52012-06-29 14:21:22 +000021SkDrawCommand::SkDrawCommand() {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000022 fOffset = 0;
chudy@google.com902ebe52012-06-29 14:21:22 +000023 fVisible = true;
24}
25
26SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000027 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000028}
29
30const char* SkDrawCommand::GetCommandString(DrawType type) {
31 switch (type) {
32 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
33 case DRAW_CLEAR: return "Clear";
34 case CLIP_PATH: return "Clip Path";
35 case CLIP_REGION: return "Clip Region";
36 case CLIP_RECT: return "Clip Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000037 case CLIP_RRECT: return "Clip RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000038 case CONCAT: return "Concat";
39 case DRAW_BITMAP: return "Draw Bitmap";
40 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
41 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
robertphillips@google.com84d320e2012-09-20 19:09:17 +000042 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
chudy@google.com902ebe52012-06-29 14:21:22 +000043 case DRAW_DATA: return "Draw Data";
robertphillips@google.com67baba42013-01-02 20:20:31 +000044 case DRAW_OVAL: return "Draw Oval";
chudy@google.com902ebe52012-06-29 14:21:22 +000045 case DRAW_PAINT: return "Draw Paint";
46 case DRAW_PATH: return "Draw Path";
47 case DRAW_PICTURE: return "Draw Picture";
48 case DRAW_POINTS: return "Draw Points";
49 case DRAW_POS_TEXT: return "Draw Pos Text";
50 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
51 case DRAW_RECT: return "Draw Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000052 case DRAW_RRECT: return "Draw RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000053 case DRAW_SPRITE: return "Draw Sprite";
54 case DRAW_TEXT: return "Draw Text";
55 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
56 case DRAW_VERTICES: return "Draw Vertices";
57 case RESTORE: return "Restore";
58 case ROTATE: return "Rotate";
59 case SAVE: return "Save";
60 case SAVE_LAYER: return "Save Layer";
61 case SCALE: return "Scale";
62 case SET_MATRIX: return "Set Matrix";
63 case SKEW: return "Skew";
64 case TRANSLATE: return "Translate";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000065 case NOOP: return "NoOp";
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000066 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
67 case COMMENT: return "Comment";
68 case END_COMMENT_GROUP: return "EndCommentGroup";
commit-bot@chromium.org3d305202014-02-24 17:28:55 +000069 case DRAW_DRRECT: return "Draw DRRect";
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +000070 case PUSH_CULL: return "PushCull";
71 case POP_CULL: return "PopCull";
chudy@google.com902ebe52012-06-29 14:21:22 +000072 default:
73 SkDebugf("DrawType error 0x%08x\n", type);
74 SkASSERT(0);
75 break;
76 }
77 SkDEBUGFAIL("DrawType UNUSED\n");
78 return NULL;
79}
80
chudy@google.com97cee972012-08-07 20:41:37 +000081SkString SkDrawCommand::toString() {
82 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000083}
84
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000085SkClearCommand::SkClearCommand(SkColor color) : INHERITED(DRAW_CLEAR) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000086 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000087 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000088}
89
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000090void SkClearCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000091 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000092}
93
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000094namespace {
95
96void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
97 const SkISize& size = canvas->getDeviceSize();
98
99 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
100
101 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
102 if (bounds.width() > bounds.height()) {
103 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
104 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
105 } else {
106 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
107 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
108 }
109 canvas->translate(-bounds.centerX(), -bounds.centerY());
110}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000111
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000112
113void render_path(SkCanvas* canvas, const SkPath& path) {
114 canvas->clear(0xFFFFFFFF);
115 canvas->save();
116
117 const SkRect& bounds = path.getBounds();
118
119 xlate_and_scale_to_bounds(canvas, bounds);
120
121 SkPaint p;
122 p.setColor(SK_ColorBLACK);
123 p.setStyle(SkPaint::kStroke_Style);
124
125 canvas->drawPath(path, p);
126 canvas->restore();
127}
128
129void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
130 const SkISize& size = canvas->getDeviceSize();
131
132 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
133 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
134
135 if (input.width() > input.height()) {
136 yScale *= input.height() / (float) input.width();
137 } else {
138 xScale *= input.width() / (float) input.height();
139 }
140
141 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
142 xScale * input.width(),
143 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000144
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000145 canvas->clear(0xFFFFFFFF);
146 canvas->drawBitmapRect(input, NULL, dst);
147
148 if (NULL != srcRect) {
149 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
150 srcRect->fTop * yScale + SK_Scalar1,
151 srcRect->fRight * xScale + SK_Scalar1,
152 srcRect->fBottom * yScale + SK_Scalar1);
153 SkPaint p;
154 p.setColor(SK_ColorRED);
155 p.setStyle(SkPaint::kStroke_Style);
156
157 canvas->drawRect(r, p);
158 }
159}
160
161void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
162 canvas->clear(0xFFFFFFFF);
163 canvas->save();
164
165 const SkRect& bounds = rrect.getBounds();
166
167 xlate_and_scale_to_bounds(canvas, bounds);
168
169 SkPaint p;
170 p.setColor(SK_ColorBLACK);
171 p.setStyle(SkPaint::kStroke_Style);
172
173 canvas->drawRRect(rrect, p);
174 canvas->restore();
175}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000176
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000177void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
178 canvas->clear(0xFFFFFFFF);
179 canvas->save();
180
181 const SkRect& bounds = outer.getBounds();
182
183 xlate_and_scale_to_bounds(canvas, bounds);
184
185 SkPaint p;
186 p.setColor(SK_ColorBLACK);
187 p.setStyle(SkPaint::kStroke_Style);
188
189 canvas->drawDRRect(outer, inner, p);
190 canvas->restore();
191}
192
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000193};
194
195
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000196SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
197 : INHERITED(CLIP_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000198 fPath = path;
199 fOp = op;
200 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000201
robertphillips@google.com91217d02013-03-17 18:33:46 +0000202 fInfo.push(SkObjectParser::PathToString(path));
203 fInfo.push(SkObjectParser::RegionOpToString(op));
204 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000205}
206
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000207void SkClipPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000208 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000209}
210
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000211bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000212 render_path(canvas, fPath);
213 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000214}
215
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000216SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000217 : INHERITED(CLIP_REGION) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000218 fRegion = region;
219 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000220
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000221 fInfo.push(SkObjectParser::RegionToString(region));
222 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000223}
224
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000225void SkClipRegionCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000226 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000227}
228
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000229SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
230 : INHERITED(CLIP_RECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000231 fRect = rect;
232 fOp = op;
233 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000234
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000235 fInfo.push(SkObjectParser::RectToString(rect));
236 fInfo.push(SkObjectParser::RegionOpToString(op));
237 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000238}
239
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000240void SkClipRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000241 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000242}
243
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000244SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000245 : INHERITED(CLIP_RRECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000246 fRRect = rrect;
247 fOp = op;
248 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000249
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000250 fInfo.push(SkObjectParser::RRectToString(rrect));
251 fInfo.push(SkObjectParser::RegionOpToString(op));
252 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000253}
254
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000255void SkClipRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000256 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000257}
258
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000259bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000260 render_rrect(canvas, fRRect);
261 return true;
262}
263
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000264SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
265 : INHERITED(CONCAT) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000266 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000267
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000268 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000269}
270
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000271void SkConcatCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000272 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000273}
274
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000275SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700276 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000277 : INHERITED(DRAW_BITMAP) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000278 fBitmap = bitmap;
279 fLeft = left;
280 fTop = top;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000281 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000282 fPaint = *paint;
283 fPaintPtr = &fPaint;
284 } else {
285 fPaintPtr = NULL;
286 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000287
288 fInfo.push(SkObjectParser::BitmapToString(bitmap));
289 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
290 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
291 if (NULL != paint) {
292 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000293 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000294}
295
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000296void SkDrawBitmapCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000297 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000298}
299
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000300bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000301 render_bitmap(canvas, fBitmap);
302 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000303}
304
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000305SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
306 const SkMatrix& matrix,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000307 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000308 : INHERITED(DRAW_BITMAP_MATRIX) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000309 fBitmap = bitmap;
310 fMatrix = matrix;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000311 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000312 fPaint = *paint;
313 fPaintPtr = &fPaint;
314 } else {
315 fPaintPtr = NULL;
316 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000317
318 fInfo.push(SkObjectParser::BitmapToString(bitmap));
319 fInfo.push(SkObjectParser::MatrixToString(matrix));
320 if (NULL != paint) {
321 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000322 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000323}
324
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000325void SkDrawBitmapMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000326 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000327}
328
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000329bool SkDrawBitmapMatrixCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000330 render_bitmap(canvas, fBitmap);
331 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000332}
333
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000334SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000335 const SkRect& dst, const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000336 : INHERITED(DRAW_BITMAP_NINE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000337 fBitmap = bitmap;
338 fCenter = center;
339 fDst = dst;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000340 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000341 fPaint = *paint;
342 fPaintPtr = &fPaint;
343 } else {
344 fPaintPtr = NULL;
345 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000346
347 fInfo.push(SkObjectParser::BitmapToString(bitmap));
348 fInfo.push(SkObjectParser::IRectToString(center));
349 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
350 if (NULL != paint) {
351 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000352 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000353}
354
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000355void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000356 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000357}
358
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000359bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000360 render_bitmap(canvas, fBitmap);
361 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000362}
363
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000364SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000365 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000366 SkCanvas::DrawBitmapRectFlags flags)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000367 : INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000368 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000369 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000370 fSrc = *src;
371 } else {
372 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000373 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000374 fDst = dst;
375
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000376 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000377 fPaint = *paint;
378 fPaintPtr = &fPaint;
379 } else {
380 fPaintPtr = NULL;
381 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000382 fFlags = flags;
383
robertphillips@google.com91217d02013-03-17 18:33:46 +0000384 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
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000404SkDrawDataCommand::SkDrawDataCommand(const void* data, size_t length)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000405 : INHERITED(DRAW_DATA) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000406 fData = new char[length];
407 memcpy(fData, data, length);
408 fLength = length;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000409
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
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000437SkEndCommentGroupCommand::SkEndCommentGroupCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000438 : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000439}
440
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000441SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
442 : INHERITED(DRAW_OVAL) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000443 fOval = oval;
444 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000445
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000446 fInfo.push(SkObjectParser::RectToString(oval));
447 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000448}
449
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000450void SkDrawOvalCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000451 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000452}
453
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000454bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000455 canvas->clear(0xFFFFFFFF);
456 canvas->save();
457
458 xlate_and_scale_to_bounds(canvas, fOval);
459
460 SkPaint p;
461 p.setColor(SK_ColorBLACK);
462 p.setStyle(SkPaint::kStroke_Style);
463
464 canvas->drawOval(fOval, p);
465 canvas->restore();
466
467 return true;
468}
469
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000470SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
471 : INHERITED(DRAW_PAINT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000472 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000473
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000474 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000475}
476
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000477void SkDrawPaintCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000478 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000479}
480
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000481bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000482 canvas->clear(0xFFFFFFFF);
483 canvas->drawPaint(fPaint);
484 return true;
485}
486
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000487SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
488 : INHERITED(DRAW_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000489 fPath = path;
490 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000491
robertphillips@google.com91217d02013-03-17 18:33:46 +0000492 fInfo.push(SkObjectParser::PathToString(path));
493 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000494}
495
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000496void SkDrawPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000497 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000498}
499
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000500bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000501 render_path(canvas, fPath);
502 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000503}
504
robertphillipsb3f319f2014-08-13 10:46:23 -0700505SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
506 const SkMatrix* matrix,
507 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000508 : INHERITED(DRAW_PICTURE)
robertphillipsb3f319f2014-08-13 10:46:23 -0700509 , fPicture(SkRef(picture))
510 , fMatrixPtr(NULL)
511 , fPaintPtr(NULL) {
512
513 if (NULL != matrix) {
514 fMatrix = *matrix;
515 fMatrixPtr = &fMatrix;
516 }
517 if (NULL != paint) {
518 fPaint = *paint;
519 fPaintPtr = &fPaint;
520 }
521
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000522 SkString* temp = new SkString;
robertphillips9b14f262014-06-04 05:40:44 -0700523 temp->appendf("SkPicture: W: %d H: %d", picture->width(), picture->height());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000524 fInfo.push(temp);
robertphillipsb3f319f2014-08-13 10:46:23 -0700525 if (NULL != matrix) {
526 fInfo.push(SkObjectParser::MatrixToString(*matrix));
527 }
528 if (NULL != paint) {
529 fInfo.push(SkObjectParser::PaintToString(*paint));
530 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000531}
532
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000533void SkDrawPictureCommand::execute(SkCanvas* canvas) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700534 canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000535}
536
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000537bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
538 canvas->clear(0xFFFFFFFF);
539 canvas->save();
540
robertphillips9b14f262014-06-04 05:40:44 -0700541 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()),
542 SkIntToScalar(fPicture->height()));
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000543 xlate_and_scale_to_bounds(canvas, bounds);
544
robertphillips9b14f262014-06-04 05:40:44 -0700545 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000546
547 canvas->restore();
548
549 return true;
550}
551
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000552SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000553 const SkPoint pts[], const SkPaint& paint)
554 : INHERITED(DRAW_POINTS) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000555 fMode = mode;
556 fCount = count;
557 fPts = new SkPoint[count];
558 memcpy(fPts, pts, count * sizeof(SkPoint));
559 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000560
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000561 fInfo.push(SkObjectParser::PointsToString(pts, count));
562 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
563 "Points: "));
564 fInfo.push(SkObjectParser::PointModeToString(mode));
565 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000566}
567
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000568void SkDrawPointsCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000569 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000570}
571
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000572bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000573 canvas->clear(0xFFFFFFFF);
574 canvas->save();
575
576 SkRect bounds;
577
578 bounds.setEmpty();
579 for (unsigned int i = 0; i < fCount; ++i) {
580 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
581 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000582
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000583 xlate_and_scale_to_bounds(canvas, bounds);
584
585 SkPaint p;
586 p.setColor(SK_ColorBLACK);
587 p.setStyle(SkPaint::kStroke_Style);
588
589 canvas->drawPoints(fMode, fCount, fPts, p);
590 canvas->restore();
591
592 return true;
593}
594
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000595SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000596 const SkPoint pos[], const SkPaint& paint)
597 : INHERITED(DRAW_POS_TEXT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000598 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000599
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000600 fText = new char[byteLength];
601 memcpy(fText, text, byteLength);
602 fByteLength = byteLength;
603
604 fPos = new SkPoint[numPts];
605 memcpy(fPos, pos, numPts * sizeof(SkPoint));
606
607 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000608
609 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000610 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000611 fInfo.push(SkObjectParser::PointsToString(pos, 1));
612 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000613}
614
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000615void SkDrawPosTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000616 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000617}
618
619
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000620SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
621 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000622 const SkPaint& paint)
623 : INHERITED(DRAW_POS_TEXT_H) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000624 size_t numPts = paint.countText(text, byteLength);
625
626 fText = new char[byteLength];
627 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000628 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000629
630 fXpos = new SkScalar[numPts];
631 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
632
robertphillips@google.com91217d02013-03-17 18:33:46 +0000633 fConstY = constY;
634 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000635
robertphillips@google.com91217d02013-03-17 18:33:46 +0000636 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
637 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
638 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
639 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000640}
641
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000642void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000643 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000644}
645
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000646SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
647 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000648 fRect = rect;
649 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000650
robertphillips@google.com91217d02013-03-17 18:33:46 +0000651 fInfo.push(SkObjectParser::RectToString(rect));
652 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000653}
654
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000655void SkDrawRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000656 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000657}
658
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000659SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
660 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000661 fRRect = rrect;
662 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000663
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000664 fInfo.push(SkObjectParser::RRectToString(rrect));
665 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000666}
667
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000668void SkDrawRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000669 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000670}
671
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000672bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000673 render_rrect(canvas, fRRect);
674 return true;
675}
676
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000677SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000678 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000679 const SkPaint& paint)
680 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000681 fOuter = outer;
682 fInner = inner;
683 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000684
685 fInfo.push(SkObjectParser::RRectToString(outer));
686 fInfo.push(SkObjectParser::RRectToString(inner));
687 fInfo.push(SkObjectParser::PaintToString(paint));
688}
689
690void SkDrawDRRectCommand::execute(SkCanvas* canvas) {
691 canvas->drawDRRect(fOuter, fInner, fPaint);
692}
693
694bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
695 render_drrect(canvas, fOuter, fInner);
696 return true;
697}
698
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000699SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000700 const SkPaint* paint)
701 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000702 fBitmap = bitmap;
703 fLeft = left;
704 fTop = top;
705 if (NULL != paint) {
706 fPaint = *paint;
707 fPaintPtr = &fPaint;
708 } else {
709 fPaintPtr = NULL;
710 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000711
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000712 fInfo.push(SkObjectParser::BitmapToString(bitmap));
713 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
714 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
715 if (NULL != paint) {
716 fInfo.push(SkObjectParser::PaintToString(*paint));
717 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000718}
719
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000720void SkDrawSpriteCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000721 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000722}
723
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000724bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000725 render_bitmap(canvas, fBitmap);
726 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000727}
728
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000729SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000730 const SkPaint& paint)
731 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000732 fText = new char[byteLength];
733 memcpy(fText, text, byteLength);
734 fByteLength = byteLength;
735 fX = x;
736 fY = y;
737 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000738
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000739 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
740 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
741 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
742 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000743}
744
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000745void SkDrawTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000746 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000747}
748
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000749SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
750 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000751 const SkPaint& paint)
752 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000753 fText = new char[byteLength];
754 memcpy(fText, text, byteLength);
755 fByteLength = byteLength;
756 fPath = path;
757 if (NULL != matrix) {
758 fMatrix = *matrix;
759 } else {
760 fMatrix.setIdentity();
761 }
762 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000763
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000764 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
765 fInfo.push(SkObjectParser::PathToString(path));
766 if (NULL != matrix) {
767 fInfo.push(SkObjectParser::MatrixToString(*matrix));
768 }
769 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000770}
771
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000772void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000773 canvas->drawTextOnPath(fText, fByteLength, fPath,
774 fMatrix.isIdentity() ? NULL : &fMatrix,
775 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000776}
777
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000778SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
779 const SkPoint vertices[], const SkPoint texs[],
780 const SkColor colors[], SkXfermode* xfermode,
781 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000782 const SkPaint& paint)
783 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000784 fVmode = vmode;
785
786 fVertexCount = vertexCount;
787
788 fVertices = new SkPoint[vertexCount];
789 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
790
791 if (NULL != texs) {
792 fTexs = new SkPoint[vertexCount];
793 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
794 } else {
795 fTexs = NULL;
796 }
797
798 if (NULL != colors) {
799 fColors = new SkColor[vertexCount];
800 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
801 } else {
802 fColors = NULL;
803 }
804
805 fXfermode = xfermode;
806 if (NULL != fXfermode) {
807 fXfermode->ref();
808 }
809
810 if (indexCount > 0) {
811 fIndices = new uint16_t[indexCount];
812 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
813 } else {
814 fIndices = NULL;
815 }
816
817 fIndexCount = indexCount;
818 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000819
chudy@google.com902ebe52012-06-29 14:21:22 +0000820 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000821 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
822 fInfo.push(SkObjectParser::PaintToString(paint));
823}
824
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000825SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000826 delete [] fVertices;
827 delete [] fTexs;
828 delete [] fColors;
829 SkSafeUnref(fXfermode);
830 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000831}
832
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000833void SkDrawVerticesCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000834 canvas->drawVertices(fVmode, fVertexCount, fVertices,
835 fTexs, fColors, fXfermode, fIndices,
836 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000837}
838
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000839SkRestoreCommand::SkRestoreCommand()
840 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000841 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000842}
843
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000844void SkRestoreCommand::execute(SkCanvas* canvas) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000845 canvas->restore();
846}
847
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000848void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000849 (*state)--;
850}
851
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000852SkRotateCommand::SkRotateCommand(SkScalar degrees)
853 : INHERITED(ROTATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000854 fDegrees = degrees;
chudy@google.com902ebe52012-06-29 14:21:22 +0000855
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000856 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000857}
858
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000859void SkRotateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000860 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000861}
862
Florin Malita5f6102d2014-06-30 10:13:28 -0400863SkSaveCommand::SkSaveCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000864 : INHERITED(SAVE) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000865}
866
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000867void SkSaveCommand::execute(SkCanvas* canvas) {
Florin Malita5f6102d2014-06-30 10:13:28 -0400868 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000869}
870
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000871void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000872 (*state)++;
873}
874
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000875SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000876 SkCanvas::SaveFlags flags)
877 : INHERITED(SAVE_LAYER) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000878 if (NULL != bounds) {
879 fBounds = *bounds;
880 } else {
881 fBounds.setEmpty();
882 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000883
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000884 if (NULL != paint) {
885 fPaint = *paint;
886 fPaintPtr = &fPaint;
887 } else {
888 fPaintPtr = NULL;
889 }
890 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000891
892 if (NULL != bounds) {
893 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
894 }
895 if (NULL != paint) {
896 fInfo.push(SkObjectParser::PaintToString(*paint));
897 }
898 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000899}
900
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000901void SkSaveLayerCommand::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000902 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000903 fPaintPtr,
904 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000905}
906
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000907void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) {
908 canvas->save();
909}
910
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000911void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000912 (*state)++;
913}
914
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000915SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
916 : INHERITED(SCALE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000917 fSx = sx;
918 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000919
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000920 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
921 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000922}
923
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000924void SkScaleCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000925 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000926}
927
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000928SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
929 : INHERITED(SET_MATRIX) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000930 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000931
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000932 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000933}
934
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000935void SkSetMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000936 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000937}
938
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000939SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
940 : INHERITED(SKEW) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000941 fSx = sx;
942 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000943
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000944 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
945 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000946}
947
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000948void SkSkewCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000949 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000950}
951
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000952SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
953 : INHERITED(TRANSLATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000954 fDx = dx;
955 fDy = dy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000956
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000957 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
958 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000959}
960
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000961void SkTranslateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000962 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000963}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000964
965SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000966 : INHERITED(PUSH_CULL)
967 , fCullRect(cullRect) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000968 fInfo.push(SkObjectParser::RectToString(cullRect));
969}
970
971void SkPushCullCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000972 canvas->pushCull(fCullRect);
973}
974
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000975void SkPushCullCommand::vizExecute(SkCanvas* canvas) {
976 canvas->pushCull(fCullRect);
977
978 SkPaint p;
979 p.setColor(SK_ColorCYAN);
980 p.setStyle(SkPaint::kStroke_Style);
981 canvas->drawRect(fCullRect, p);
982}
983
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000984SkPopCullCommand::SkPopCullCommand() : INHERITED(POP_CULL) { }
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000985
986void SkPopCullCommand::execute(SkCanvas* canvas) {
987 canvas->popCull();
988}