blob: 079961ae701b30eb1b41c4ff72cc8d6437e31c92 [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,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000276 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
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000505SkDrawPictureCommand::SkDrawPictureCommand(SkPicture& picture)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000506 : INHERITED(DRAW_PICTURE)
507 , fPicture(picture) {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000508 SkString* temp = new SkString;
509 temp->appendf("SkPicture: W: %d H: %d", picture.width(), picture.height());
510 fInfo.push(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000511}
512
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000513void SkDrawPictureCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000514 canvas->drawPicture(fPicture);
chudy@google.com902ebe52012-06-29 14:21:22 +0000515}
516
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000517bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
518 canvas->clear(0xFFFFFFFF);
519 canvas->save();
520
fmalita@google.com517dbe82013-11-21 17:50:15 +0000521 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture.width()),
522 SkIntToScalar(fPicture.height()));
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000523 xlate_and_scale_to_bounds(canvas, bounds);
524
525 canvas->drawPicture(const_cast<SkPicture&>(fPicture));
526
527 canvas->restore();
528
529 return true;
530}
531
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000532SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000533 const SkPoint pts[], const SkPaint& paint)
534 : INHERITED(DRAW_POINTS) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000535 fMode = mode;
536 fCount = count;
537 fPts = new SkPoint[count];
538 memcpy(fPts, pts, count * sizeof(SkPoint));
539 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000540
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000541 fInfo.push(SkObjectParser::PointsToString(pts, count));
542 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
543 "Points: "));
544 fInfo.push(SkObjectParser::PointModeToString(mode));
545 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000546}
547
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000548void SkDrawPointsCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000549 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000550}
551
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000552bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000553 canvas->clear(0xFFFFFFFF);
554 canvas->save();
555
556 SkRect bounds;
557
558 bounds.setEmpty();
559 for (unsigned int i = 0; i < fCount; ++i) {
560 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
561 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000562
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000563 xlate_and_scale_to_bounds(canvas, bounds);
564
565 SkPaint p;
566 p.setColor(SK_ColorBLACK);
567 p.setStyle(SkPaint::kStroke_Style);
568
569 canvas->drawPoints(fMode, fCount, fPts, p);
570 canvas->restore();
571
572 return true;
573}
574
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000575SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000576 const SkPoint pos[], const SkPaint& paint)
577 : INHERITED(DRAW_POS_TEXT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000578 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000579
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000580 fText = new char[byteLength];
581 memcpy(fText, text, byteLength);
582 fByteLength = byteLength;
583
584 fPos = new SkPoint[numPts];
585 memcpy(fPos, pos, numPts * sizeof(SkPoint));
586
587 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000588
589 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000590 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000591 fInfo.push(SkObjectParser::PointsToString(pos, 1));
592 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000593}
594
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000595void SkDrawPosTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000596 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000597}
598
599
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000600SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
601 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000602 const SkPaint& paint)
603 : INHERITED(DRAW_POS_TEXT_H) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000604 size_t numPts = paint.countText(text, byteLength);
605
606 fText = new char[byteLength];
607 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000608 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000609
610 fXpos = new SkScalar[numPts];
611 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
612
robertphillips@google.com91217d02013-03-17 18:33:46 +0000613 fConstY = constY;
614 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000615
robertphillips@google.com91217d02013-03-17 18:33:46 +0000616 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
617 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
618 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
619 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000620}
621
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000622void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000623 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000624}
625
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000626SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
627 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000628 fRect = rect;
629 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000630
robertphillips@google.com91217d02013-03-17 18:33:46 +0000631 fInfo.push(SkObjectParser::RectToString(rect));
632 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000633}
634
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000635void SkDrawRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000636 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000637}
638
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000639SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
640 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000641 fRRect = rrect;
642 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000643
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000644 fInfo.push(SkObjectParser::RRectToString(rrect));
645 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000646}
647
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000648void SkDrawRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000649 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000650}
651
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000652bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000653 render_rrect(canvas, fRRect);
654 return true;
655}
656
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000657SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000658 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000659 const SkPaint& paint)
660 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000661 fOuter = outer;
662 fInner = inner;
663 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000664
665 fInfo.push(SkObjectParser::RRectToString(outer));
666 fInfo.push(SkObjectParser::RRectToString(inner));
667 fInfo.push(SkObjectParser::PaintToString(paint));
668}
669
670void SkDrawDRRectCommand::execute(SkCanvas* canvas) {
671 canvas->drawDRRect(fOuter, fInner, fPaint);
672}
673
674bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
675 render_drrect(canvas, fOuter, fInner);
676 return true;
677}
678
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000679SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000680 const SkPaint* paint)
681 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000682 fBitmap = bitmap;
683 fLeft = left;
684 fTop = top;
685 if (NULL != paint) {
686 fPaint = *paint;
687 fPaintPtr = &fPaint;
688 } else {
689 fPaintPtr = NULL;
690 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000691
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000692 fInfo.push(SkObjectParser::BitmapToString(bitmap));
693 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
694 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
695 if (NULL != paint) {
696 fInfo.push(SkObjectParser::PaintToString(*paint));
697 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000698}
699
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000700void SkDrawSpriteCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000701 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000702}
703
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000704bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000705 render_bitmap(canvas, fBitmap);
706 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000707}
708
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000709SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000710 const SkPaint& paint)
711 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000712 fText = new char[byteLength];
713 memcpy(fText, text, byteLength);
714 fByteLength = byteLength;
715 fX = x;
716 fY = y;
717 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000718
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000719 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
720 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
721 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
722 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000723}
724
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000725void SkDrawTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000726 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000727}
728
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000729SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
730 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000731 const SkPaint& paint)
732 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000733 fText = new char[byteLength];
734 memcpy(fText, text, byteLength);
735 fByteLength = byteLength;
736 fPath = path;
737 if (NULL != matrix) {
738 fMatrix = *matrix;
739 } else {
740 fMatrix.setIdentity();
741 }
742 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000743
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000744 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
745 fInfo.push(SkObjectParser::PathToString(path));
746 if (NULL != matrix) {
747 fInfo.push(SkObjectParser::MatrixToString(*matrix));
748 }
749 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000750}
751
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000752void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000753 canvas->drawTextOnPath(fText, fByteLength, fPath,
754 fMatrix.isIdentity() ? NULL : &fMatrix,
755 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000756}
757
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000758SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
759 const SkPoint vertices[], const SkPoint texs[],
760 const SkColor colors[], SkXfermode* xfermode,
761 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000762 const SkPaint& paint)
763 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000764 fVmode = vmode;
765
766 fVertexCount = vertexCount;
767
768 fVertices = new SkPoint[vertexCount];
769 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
770
771 if (NULL != texs) {
772 fTexs = new SkPoint[vertexCount];
773 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
774 } else {
775 fTexs = NULL;
776 }
777
778 if (NULL != colors) {
779 fColors = new SkColor[vertexCount];
780 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
781 } else {
782 fColors = NULL;
783 }
784
785 fXfermode = xfermode;
786 if (NULL != fXfermode) {
787 fXfermode->ref();
788 }
789
790 if (indexCount > 0) {
791 fIndices = new uint16_t[indexCount];
792 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
793 } else {
794 fIndices = NULL;
795 }
796
797 fIndexCount = indexCount;
798 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000799
chudy@google.com902ebe52012-06-29 14:21:22 +0000800 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000801 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
802 fInfo.push(SkObjectParser::PaintToString(paint));
803}
804
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000805SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000806 delete [] fVertices;
807 delete [] fTexs;
808 delete [] fColors;
809 SkSafeUnref(fXfermode);
810 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000811}
812
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000813void SkDrawVerticesCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000814 canvas->drawVertices(fVmode, fVertexCount, fVertices,
815 fTexs, fColors, fXfermode, fIndices,
816 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000817}
818
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000819SkRestoreCommand::SkRestoreCommand()
820 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000821 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000822}
823
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000824void SkRestoreCommand::execute(SkCanvas* canvas) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000825 canvas->restore();
826}
827
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000828void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000829 (*state)--;
830}
831
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000832SkRotateCommand::SkRotateCommand(SkScalar degrees)
833 : INHERITED(ROTATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000834 fDegrees = degrees;
chudy@google.com902ebe52012-06-29 14:21:22 +0000835
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000836 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000837}
838
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000839void SkRotateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000840 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000841}
842
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000843SkSaveCommand::SkSaveCommand(SkCanvas::SaveFlags flags)
844 : INHERITED(SAVE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000845 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000846 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000847}
848
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000849void SkSaveCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000850 canvas->save(fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000851}
852
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000853void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000854 (*state)++;
855}
856
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000857SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000858 SkCanvas::SaveFlags flags)
859 : INHERITED(SAVE_LAYER) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000860 if (NULL != bounds) {
861 fBounds = *bounds;
862 } else {
863 fBounds.setEmpty();
864 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000865
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000866 if (NULL != paint) {
867 fPaint = *paint;
868 fPaintPtr = &fPaint;
869 } else {
870 fPaintPtr = NULL;
871 }
872 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000873
874 if (NULL != bounds) {
875 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
876 }
877 if (NULL != paint) {
878 fInfo.push(SkObjectParser::PaintToString(*paint));
879 }
880 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000881}
882
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000883void SkSaveLayerCommand::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000884 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000885 fPaintPtr,
886 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000887}
888
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000889void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) {
890 canvas->save();
891}
892
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000893void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000894 (*state)++;
895}
896
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000897SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
898 : INHERITED(SCALE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000899 fSx = sx;
900 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000901
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000902 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
903 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000904}
905
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000906void SkScaleCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000907 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000908}
909
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000910SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
911 : INHERITED(SET_MATRIX) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000912 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000913
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000914 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000915}
916
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000917void SkSetMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000918 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000919}
920
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000921SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
922 : INHERITED(SKEW) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000923 fSx = sx;
924 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000925
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000926 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
927 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000928}
929
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000930void SkSkewCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000931 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000932}
933
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000934SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
935 : INHERITED(TRANSLATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000936 fDx = dx;
937 fDy = dy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000938
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000939 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
940 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000941}
942
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000943void SkTranslateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000944 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000945}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000946
947SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000948 : INHERITED(PUSH_CULL)
949 , fCullRect(cullRect) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000950 fInfo.push(SkObjectParser::RectToString(cullRect));
951}
952
953void SkPushCullCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000954 canvas->pushCull(fCullRect);
955}
956
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000957void SkPushCullCommand::vizExecute(SkCanvas* canvas) {
958 canvas->pushCull(fCullRect);
959
960 SkPaint p;
961 p.setColor(SK_ColorCYAN);
962 p.setStyle(SkPaint::kStroke_Style);
963 canvas->drawRect(fCullRect, p);
964}
965
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000966SkPopCullCommand::SkPopCullCommand() : INHERITED(POP_CULL) { }
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000967
968void SkPopCullCommand::execute(SkCanvas* canvas) {
969 canvas->popCull();
970}