blob: be7fdfc71674b02a232cbad3485bdbf9b2b42081 [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
fmalitab7425172014-08-26 07:56:44 -070013#include "SkTextBlob.h"
14
chudy@google.com902ebe52012-06-29 14:21:22 +000015// TODO(chudy): Refactor into non subclass model.
16
skia.committer@gmail.coma5d3e772013-05-30 07:01:29 +000017SkDrawCommand::SkDrawCommand(DrawType type)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000018 : fDrawType(type)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000019 , fOffset(0)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000020 , fVisible(true) {
21}
22
chudy@google.com902ebe52012-06-29 14:21:22 +000023SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000024 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000025}
26
27const char* SkDrawCommand::GetCommandString(DrawType type) {
28 switch (type) {
29 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
30 case DRAW_CLEAR: return "Clear";
31 case CLIP_PATH: return "Clip Path";
32 case CLIP_REGION: return "Clip Region";
33 case CLIP_RECT: return "Clip Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000034 case CLIP_RRECT: return "Clip RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000035 case CONCAT: return "Concat";
36 case DRAW_BITMAP: return "Draw Bitmap";
37 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
38 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
robertphillips@google.com84d320e2012-09-20 19:09:17 +000039 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
chudy@google.com902ebe52012-06-29 14:21:22 +000040 case DRAW_DATA: return "Draw Data";
robertphillips@google.com67baba42013-01-02 20:20:31 +000041 case DRAW_OVAL: return "Draw Oval";
chudy@google.com902ebe52012-06-29 14:21:22 +000042 case DRAW_PAINT: return "Draw Paint";
43 case DRAW_PATH: return "Draw Path";
44 case DRAW_PICTURE: return "Draw Picture";
45 case DRAW_POINTS: return "Draw Points";
46 case DRAW_POS_TEXT: return "Draw Pos Text";
47 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
48 case DRAW_RECT: return "Draw Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000049 case DRAW_RRECT: return "Draw RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000050 case DRAW_SPRITE: return "Draw Sprite";
51 case DRAW_TEXT: return "Draw Text";
fmalita30313502014-08-27 08:41:25 -070052 case DRAW_TEXT_BLOB: return "Draw Text Blob";
chudy@google.com902ebe52012-06-29 14:21:22 +000053 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
54 case DRAW_VERTICES: return "Draw Vertices";
55 case RESTORE: return "Restore";
56 case ROTATE: return "Rotate";
57 case SAVE: return "Save";
58 case SAVE_LAYER: return "Save Layer";
59 case SCALE: return "Scale";
60 case SET_MATRIX: return "Set Matrix";
61 case SKEW: return "Skew";
62 case TRANSLATE: return "Translate";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000063 case NOOP: return "NoOp";
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000064 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
65 case COMMENT: return "Comment";
66 case END_COMMENT_GROUP: return "EndCommentGroup";
commit-bot@chromium.org3d305202014-02-24 17:28:55 +000067 case DRAW_DRRECT: return "Draw DRRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000068 default:
69 SkDebugf("DrawType error 0x%08x\n", type);
70 SkASSERT(0);
71 break;
72 }
73 SkDEBUGFAIL("DrawType UNUSED\n");
74 return NULL;
75}
76
fmalita8c89c522014-11-08 16:18:56 -080077SkString SkDrawCommand::toString() const {
chudy@google.com97cee972012-08-07 20:41:37 +000078 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000079}
80
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000081SkClearCommand::SkClearCommand(SkColor color) : INHERITED(DRAW_CLEAR) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000082 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000083 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000084}
85
fmalita8c89c522014-11-08 16:18:56 -080086void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000087 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000088}
89
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000090namespace {
91
92void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
93 const SkISize& size = canvas->getDeviceSize();
94
95 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
96
97 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
98 if (bounds.width() > bounds.height()) {
99 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
100 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
101 } else {
102 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
103 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
104 }
105 canvas->translate(-bounds.centerX(), -bounds.centerY());
106}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000107
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000108
109void render_path(SkCanvas* canvas, const SkPath& path) {
110 canvas->clear(0xFFFFFFFF);
111 canvas->save();
112
113 const SkRect& bounds = path.getBounds();
114
115 xlate_and_scale_to_bounds(canvas, bounds);
116
117 SkPaint p;
118 p.setColor(SK_ColorBLACK);
119 p.setStyle(SkPaint::kStroke_Style);
120
121 canvas->drawPath(path, p);
122 canvas->restore();
123}
124
125void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
126 const SkISize& size = canvas->getDeviceSize();
127
128 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
129 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
130
131 if (input.width() > input.height()) {
132 yScale *= input.height() / (float) input.width();
133 } else {
134 xScale *= input.width() / (float) input.height();
135 }
136
137 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
138 xScale * input.width(),
139 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000140
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000141 canvas->clear(0xFFFFFFFF);
142 canvas->drawBitmapRect(input, NULL, dst);
143
bsalomon49f085d2014-09-05 13:34:00 -0700144 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000145 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
146 srcRect->fTop * yScale + SK_Scalar1,
147 srcRect->fRight * xScale + SK_Scalar1,
148 srcRect->fBottom * yScale + SK_Scalar1);
149 SkPaint p;
150 p.setColor(SK_ColorRED);
151 p.setStyle(SkPaint::kStroke_Style);
152
153 canvas->drawRect(r, p);
154 }
155}
156
157void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
158 canvas->clear(0xFFFFFFFF);
159 canvas->save();
160
161 const SkRect& bounds = rrect.getBounds();
162
163 xlate_and_scale_to_bounds(canvas, bounds);
164
165 SkPaint p;
166 p.setColor(SK_ColorBLACK);
167 p.setStyle(SkPaint::kStroke_Style);
168
169 canvas->drawRRect(rrect, p);
170 canvas->restore();
171}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000172
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000173void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
174 canvas->clear(0xFFFFFFFF);
175 canvas->save();
176
177 const SkRect& bounds = outer.getBounds();
178
179 xlate_and_scale_to_bounds(canvas, bounds);
180
181 SkPaint p;
182 p.setColor(SK_ColorBLACK);
183 p.setStyle(SkPaint::kStroke_Style);
184
185 canvas->drawDRRect(outer, inner, p);
186 canvas->restore();
187}
188
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000189};
190
191
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000192SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
193 : INHERITED(CLIP_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000194 fPath = path;
195 fOp = op;
196 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000197
robertphillips@google.com91217d02013-03-17 18:33:46 +0000198 fInfo.push(SkObjectParser::PathToString(path));
199 fInfo.push(SkObjectParser::RegionOpToString(op));
200 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000201}
202
fmalita8c89c522014-11-08 16:18:56 -0800203void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000204 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000205}
206
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000207bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000208 render_path(canvas, fPath);
209 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000210}
211
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000212SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000213 : INHERITED(CLIP_REGION) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000214 fRegion = region;
215 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000216
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000217 fInfo.push(SkObjectParser::RegionToString(region));
218 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000219}
220
fmalita8c89c522014-11-08 16:18:56 -0800221void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000222 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000223}
224
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000225SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
226 : INHERITED(CLIP_RECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000227 fRect = rect;
228 fOp = op;
229 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000230
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000231 fInfo.push(SkObjectParser::RectToString(rect));
232 fInfo.push(SkObjectParser::RegionOpToString(op));
233 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000234}
235
fmalita8c89c522014-11-08 16:18:56 -0800236void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000237 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000238}
239
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000240SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000241 : INHERITED(CLIP_RRECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000242 fRRect = rrect;
243 fOp = op;
244 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000245
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000246 fInfo.push(SkObjectParser::RRectToString(rrect));
247 fInfo.push(SkObjectParser::RegionOpToString(op));
248 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000249}
250
fmalita8c89c522014-11-08 16:18:56 -0800251void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000252 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000253}
254
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000255bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000256 render_rrect(canvas, fRRect);
257 return true;
258}
259
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000260SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
261 : INHERITED(CONCAT) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000262 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000263
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000264 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000265}
266
fmalita8c89c522014-11-08 16:18:56 -0800267void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000268 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000269}
270
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000271SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700272 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000273 : INHERITED(DRAW_BITMAP) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000274 fBitmap = bitmap;
275 fLeft = left;
276 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700277 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000278 fPaint = *paint;
279 fPaintPtr = &fPaint;
280 } else {
281 fPaintPtr = NULL;
282 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000283
284 fInfo.push(SkObjectParser::BitmapToString(bitmap));
285 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
286 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700287 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000288 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000289 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000290}
291
fmalita8c89c522014-11-08 16:18:56 -0800292void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000293 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000294}
295
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000296bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000297 render_bitmap(canvas, fBitmap);
298 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000299}
300
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000301SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000302 const SkRect& dst, const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000303 : INHERITED(DRAW_BITMAP_NINE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000304 fBitmap = bitmap;
305 fCenter = center;
306 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700307 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000308 fPaint = *paint;
309 fPaintPtr = &fPaint;
310 } else {
311 fPaintPtr = NULL;
312 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000313
314 fInfo.push(SkObjectParser::BitmapToString(bitmap));
315 fInfo.push(SkObjectParser::IRectToString(center));
316 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700317 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000318 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000319 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000320}
321
fmalita8c89c522014-11-08 16:18:56 -0800322void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000323 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000324}
325
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000326bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000327 render_bitmap(canvas, fBitmap);
328 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000329}
330
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000331SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000332 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000333 SkCanvas::DrawBitmapRectFlags flags)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000334 : INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000335 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700336 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000337 fSrc = *src;
338 } else {
339 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000340 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000341 fDst = dst;
342
bsalomon49f085d2014-09-05 13:34:00 -0700343 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000344 fPaint = *paint;
345 fPaintPtr = &fPaint;
346 } else {
347 fPaintPtr = NULL;
348 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000349 fFlags = flags;
350
robertphillips@google.com91217d02013-03-17 18:33:46 +0000351 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700352 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000353 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
354 }
355 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700356 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000357 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000358 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000359 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000360}
361
fmalita8c89c522014-11-08 16:18:56 -0800362void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000363 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000364}
365
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000366bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000367 render_bitmap(canvas, fBitmap, this->srcRect());
368 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000369}
370
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000371SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000372 : INHERITED(BEGIN_COMMENT_GROUP)
373 , fDescription(description) {
374 SkString* temp = new SkString;
375 temp->appendf("Description: %s", description);
376 fInfo.push(temp);
377}
378
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000379SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000380 : INHERITED(COMMENT)
381 , fKywd(kywd)
382 , fValue(value) {
383 SkString* temp = new SkString;
384 temp->appendf("%s: %s", kywd, value);
385 fInfo.push(temp);
386}
387
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000388SkEndCommentGroupCommand::SkEndCommentGroupCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000389 : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000390}
391
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000392SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
393 : INHERITED(DRAW_OVAL) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000394 fOval = oval;
395 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000396
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000397 fInfo.push(SkObjectParser::RectToString(oval));
398 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000399}
400
fmalita8c89c522014-11-08 16:18:56 -0800401void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000402 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000403}
404
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000405bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000406 canvas->clear(0xFFFFFFFF);
407 canvas->save();
408
409 xlate_and_scale_to_bounds(canvas, fOval);
410
411 SkPaint p;
412 p.setColor(SK_ColorBLACK);
413 p.setStyle(SkPaint::kStroke_Style);
414
415 canvas->drawOval(fOval, p);
416 canvas->restore();
417
418 return true;
419}
420
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000421SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
422 : INHERITED(DRAW_PAINT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000423 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000424
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000425 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000426}
427
fmalita8c89c522014-11-08 16:18:56 -0800428void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000429 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000430}
431
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000432bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000433 canvas->clear(0xFFFFFFFF);
434 canvas->drawPaint(fPaint);
435 return true;
436}
437
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000438SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
439 : INHERITED(DRAW_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000440 fPath = path;
441 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000442
robertphillips@google.com91217d02013-03-17 18:33:46 +0000443 fInfo.push(SkObjectParser::PathToString(path));
444 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000445}
446
fmalita8c89c522014-11-08 16:18:56 -0800447void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000448 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000449}
450
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000451bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000452 render_path(canvas, fPath);
453 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000454}
455
robertphillipsb3f319f2014-08-13 10:46:23 -0700456SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
457 const SkMatrix* matrix,
458 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000459 : INHERITED(DRAW_PICTURE)
robertphillipsb3f319f2014-08-13 10:46:23 -0700460 , fPicture(SkRef(picture))
461 , fMatrixPtr(NULL)
462 , fPaintPtr(NULL) {
463
bsalomon49f085d2014-09-05 13:34:00 -0700464 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700465 fMatrix = *matrix;
466 fMatrixPtr = &fMatrix;
467 }
bsalomon49f085d2014-09-05 13:34:00 -0700468 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700469 fPaint = *paint;
470 fPaintPtr = &fPaint;
471 }
472
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000473 SkString* temp = new SkString;
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700474 temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
475 picture->cullRect().fLeft, picture->cullRect().fTop,
476 picture->cullRect().fRight, picture->cullRect().fBottom);
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000477 fInfo.push(temp);
bsalomon49f085d2014-09-05 13:34:00 -0700478 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700479 fInfo.push(SkObjectParser::MatrixToString(*matrix));
480 }
bsalomon49f085d2014-09-05 13:34:00 -0700481 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700482 fInfo.push(SkObjectParser::PaintToString(*paint));
483 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000484}
485
fmalita8c89c522014-11-08 16:18:56 -0800486void SkDrawPictureCommand::execute(SkCanvas* canvas) const {
robertphillipsb3f319f2014-08-13 10:46:23 -0700487 canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000488}
489
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000490bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
491 canvas->clear(0xFFFFFFFF);
492 canvas->save();
493
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700494 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000495
robertphillips9b14f262014-06-04 05:40:44 -0700496 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000497
498 canvas->restore();
499
500 return true;
501}
502
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000503SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000504 const SkPoint pts[], const SkPaint& paint)
505 : INHERITED(DRAW_POINTS) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000506 fMode = mode;
507 fCount = count;
508 fPts = new SkPoint[count];
509 memcpy(fPts, pts, count * sizeof(SkPoint));
510 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000511
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000512 fInfo.push(SkObjectParser::PointsToString(pts, count));
513 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
514 "Points: "));
515 fInfo.push(SkObjectParser::PointModeToString(mode));
516 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000517}
518
fmalita8c89c522014-11-08 16:18:56 -0800519void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000520 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000521}
522
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000523bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000524 canvas->clear(0xFFFFFFFF);
525 canvas->save();
526
527 SkRect bounds;
528
529 bounds.setEmpty();
530 for (unsigned int i = 0; i < fCount; ++i) {
531 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
532 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000533
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000534 xlate_and_scale_to_bounds(canvas, bounds);
535
536 SkPaint p;
537 p.setColor(SK_ColorBLACK);
538 p.setStyle(SkPaint::kStroke_Style);
539
540 canvas->drawPoints(fMode, fCount, fPts, p);
541 canvas->restore();
542
543 return true;
544}
545
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000546SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000547 const SkPoint pos[], const SkPaint& paint)
548 : INHERITED(DRAW_POS_TEXT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000549 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000550
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000551 fText = new char[byteLength];
552 memcpy(fText, text, byteLength);
553 fByteLength = byteLength;
554
555 fPos = new SkPoint[numPts];
556 memcpy(fPos, pos, numPts * sizeof(SkPoint));
557
558 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000559
560 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000561 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000562 fInfo.push(SkObjectParser::PointsToString(pos, 1));
563 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000564}
565
fmalita8c89c522014-11-08 16:18:56 -0800566void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000567 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000568}
569
570
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000571SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
572 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000573 const SkPaint& paint)
574 : INHERITED(DRAW_POS_TEXT_H) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000575 size_t numPts = paint.countText(text, byteLength);
576
577 fText = new char[byteLength];
578 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000579 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000580
581 fXpos = new SkScalar[numPts];
582 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
583
robertphillips@google.com91217d02013-03-17 18:33:46 +0000584 fConstY = constY;
585 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000586
robertphillips@google.com91217d02013-03-17 18:33:46 +0000587 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
588 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
589 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
590 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000591}
592
fmalita8c89c522014-11-08 16:18:56 -0800593void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000594 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000595}
596
fmalitab7425172014-08-26 07:56:44 -0700597SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
598 const SkPaint& paint)
599 : INHERITED(DRAW_TEXT_BLOB)
600 , fBlob(blob)
601 , fXPos(x)
602 , fYPos(y)
603 , fPaint(paint) {
604
605 blob->ref();
606
607 // FIXME: push blob info
608 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800609 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
610 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700611 fInfo.push(SkObjectParser::PaintToString(paint));
612}
613
fmalita8c89c522014-11-08 16:18:56 -0800614void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700615 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
616}
617
fmalita55773872014-08-29 15:08:20 -0700618bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
619 canvas->clear(SK_ColorWHITE);
620 canvas->save();
621
622 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
623 xlate_and_scale_to_bounds(canvas, bounds);
624
625 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
626
627 canvas->restore();
628
629 return true;
630}
631
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000632SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
633 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000634 fRect = rect;
635 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000636
robertphillips@google.com91217d02013-03-17 18:33:46 +0000637 fInfo.push(SkObjectParser::RectToString(rect));
638 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000639}
640
fmalita8c89c522014-11-08 16:18:56 -0800641void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000642 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000643}
644
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000645SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
646 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000647 fRRect = rrect;
648 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000649
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000650 fInfo.push(SkObjectParser::RRectToString(rrect));
651 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000652}
653
fmalita8c89c522014-11-08 16:18:56 -0800654void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000655 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000656}
657
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000658bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000659 render_rrect(canvas, fRRect);
660 return true;
661}
662
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000663SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000664 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000665 const SkPaint& paint)
666 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000667 fOuter = outer;
668 fInner = inner;
669 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000670
671 fInfo.push(SkObjectParser::RRectToString(outer));
672 fInfo.push(SkObjectParser::RRectToString(inner));
673 fInfo.push(SkObjectParser::PaintToString(paint));
674}
675
fmalita8c89c522014-11-08 16:18:56 -0800676void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000677 canvas->drawDRRect(fOuter, fInner, fPaint);
678}
679
680bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
681 render_drrect(canvas, fOuter, fInner);
682 return true;
683}
684
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000685SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000686 const SkPaint* paint)
687 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000688 fBitmap = bitmap;
689 fLeft = left;
690 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700691 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000692 fPaint = *paint;
693 fPaintPtr = &fPaint;
694 } else {
695 fPaintPtr = NULL;
696 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000697
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000698 fInfo.push(SkObjectParser::BitmapToString(bitmap));
699 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
700 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700701 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000702 fInfo.push(SkObjectParser::PaintToString(*paint));
703 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000704}
705
fmalita8c89c522014-11-08 16:18:56 -0800706void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000707 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000708}
709
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000710bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000711 render_bitmap(canvas, fBitmap);
712 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000713}
714
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000715SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000716 const SkPaint& paint)
717 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000718 fText = new char[byteLength];
719 memcpy(fText, text, byteLength);
720 fByteLength = byteLength;
721 fX = x;
722 fY = y;
723 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000724
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000725 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
726 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
727 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
728 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000729}
730
fmalita8c89c522014-11-08 16:18:56 -0800731void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000732 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000733}
734
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000735SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
736 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000737 const SkPaint& paint)
738 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000739 fText = new char[byteLength];
740 memcpy(fText, text, byteLength);
741 fByteLength = byteLength;
742 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700743 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000744 fMatrix = *matrix;
745 } else {
746 fMatrix.setIdentity();
747 }
748 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000749
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000750 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
751 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700752 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000753 fInfo.push(SkObjectParser::MatrixToString(*matrix));
754 }
755 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000756}
757
fmalita8c89c522014-11-08 16:18:56 -0800758void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000759 canvas->drawTextOnPath(fText, fByteLength, fPath,
760 fMatrix.isIdentity() ? NULL : &fMatrix,
761 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000762}
763
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000764SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
765 const SkPoint vertices[], const SkPoint texs[],
766 const SkColor colors[], SkXfermode* xfermode,
767 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000768 const SkPaint& paint)
769 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000770 fVmode = vmode;
771
772 fVertexCount = vertexCount;
773
774 fVertices = new SkPoint[vertexCount];
775 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
776
bsalomon49f085d2014-09-05 13:34:00 -0700777 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000778 fTexs = new SkPoint[vertexCount];
779 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
780 } else {
781 fTexs = NULL;
782 }
783
bsalomon49f085d2014-09-05 13:34:00 -0700784 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000785 fColors = new SkColor[vertexCount];
786 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
787 } else {
788 fColors = NULL;
789 }
790
791 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700792 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000793 fXfermode->ref();
794 }
795
796 if (indexCount > 0) {
797 fIndices = new uint16_t[indexCount];
798 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
799 } else {
800 fIndices = NULL;
801 }
802
803 fIndexCount = indexCount;
804 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000805
chudy@google.com902ebe52012-06-29 14:21:22 +0000806 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000807 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
808 fInfo.push(SkObjectParser::PaintToString(paint));
809}
810
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000811SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000812 delete [] fVertices;
813 delete [] fTexs;
814 delete [] fColors;
815 SkSafeUnref(fXfermode);
816 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000817}
818
fmalita8c89c522014-11-08 16:18:56 -0800819void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000820 canvas->drawVertices(fVmode, fVertexCount, fVertices,
821 fTexs, fColors, fXfermode, fIndices,
822 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000823}
824
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000825SkRestoreCommand::SkRestoreCommand()
826 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000827 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000828}
829
fmalita8c89c522014-11-08 16:18:56 -0800830void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000831 canvas->restore();
832}
833
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000834void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000835 (*state)--;
836}
837
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000838SkRotateCommand::SkRotateCommand(SkScalar degrees)
839 : INHERITED(ROTATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000840 fDegrees = degrees;
chudy@google.com902ebe52012-06-29 14:21:22 +0000841
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000842 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000843}
844
fmalita8c89c522014-11-08 16:18:56 -0800845void SkRotateCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000846 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000847}
848
Florin Malita5f6102d2014-06-30 10:13:28 -0400849SkSaveCommand::SkSaveCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000850 : INHERITED(SAVE) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000851}
852
fmalita8c89c522014-11-08 16:18:56 -0800853void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400854 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000855}
856
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000857void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000858 (*state)++;
859}
860
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000861SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000862 SkCanvas::SaveFlags flags)
863 : INHERITED(SAVE_LAYER) {
bsalomon49f085d2014-09-05 13:34:00 -0700864 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000865 fBounds = *bounds;
866 } else {
867 fBounds.setEmpty();
868 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000869
bsalomon49f085d2014-09-05 13:34:00 -0700870 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000871 fPaint = *paint;
872 fPaintPtr = &fPaint;
873 } else {
874 fPaintPtr = NULL;
875 }
876 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000877
bsalomon49f085d2014-09-05 13:34:00 -0700878 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000879 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
880 }
bsalomon49f085d2014-09-05 13:34:00 -0700881 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000882 fInfo.push(SkObjectParser::PaintToString(*paint));
883 }
884 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000885}
886
fmalita8c89c522014-11-08 16:18:56 -0800887void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000888 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000889 fPaintPtr,
890 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000891}
892
fmalita8c89c522014-11-08 16:18:56 -0800893void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000894 canvas->save();
895}
896
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000897void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000898 (*state)++;
899}
900
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000901SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
902 : INHERITED(SCALE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000903 fSx = sx;
904 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000905
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000906 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
907 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000908}
909
fmalita8c89c522014-11-08 16:18:56 -0800910void SkScaleCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000911 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000912}
913
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000914SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
915 : INHERITED(SET_MATRIX) {
robertphillips70171682014-10-16 14:28:28 -0700916 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000917 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000918
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000919 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000920}
921
robertphillips70171682014-10-16 14:28:28 -0700922void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
923 fUserMatrix = userMatrix;
924}
925
fmalita8c89c522014-11-08 16:18:56 -0800926void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700927 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
928 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000929}
930
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000931SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
932 : INHERITED(SKEW) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000933 fSx = sx;
934 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000935
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000936 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
937 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000938}
939
fmalita8c89c522014-11-08 16:18:56 -0800940void SkSkewCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000941 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000942}
943
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000944SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
945 : INHERITED(TRANSLATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000946 fDx = dx;
947 fDy = dy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000948
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000949 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
950 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000951}
952
fmalita8c89c522014-11-08 16:18:56 -0800953void SkTranslateCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000954 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000955}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000956