blob: 08047976922526632108d0cba0ccfe8c4336fd4b [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"
robertphillips3a092042015-02-12 13:29:15 -080012
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
robertphillips3a092042015-02-12 13:29:15 -080017const char* SkDrawCommand::kDrawRectString = "Draw Rect";
18const char* SkDrawCommand::kClipRectString = "Clip Rect";
robertphillips72942b82015-02-12 06:37:12 -080019
robertphillips3a092042015-02-12 13:29:15 -080020const SkDrawCommand::OpType SkDrawCommand::kSave_OpType = SAVE;
21const SkDrawCommand::OpType SkDrawCommand::kClipRect_OpType = CLIP_RECT;
22const SkDrawCommand::OpType SkDrawCommand::kDrawRect_OpType = DRAW_RECT;
23const SkDrawCommand::OpType SkDrawCommand::kRestore_OpType = RESTORE;
24const SkDrawCommand::OpType SkDrawCommand::kSetMatrix_OpType = SET_MATRIX;
25
26SkDrawCommand::SkDrawCommand(DrawType type)
27 : fDrawType(type)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000028 , fOffset(0)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000029 , fVisible(true) {
30}
31
chudy@google.com902ebe52012-06-29 14:21:22 +000032SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000033 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000034}
35
robertphillips3a092042015-02-12 13:29:15 -080036const char* SkDrawCommand::GetCommandString(DrawType type) {
chudy@google.com902ebe52012-06-29 14:21:22 +000037 switch (type) {
robertphillips3a092042015-02-12 13:29:15 -080038 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
39 case DRAW_CLEAR: return "Clear";
40 case CLIP_PATH: return "Clip Path";
41 case CLIP_REGION: return "Clip Region";
42 case CLIP_RECT: return "Clip Rect";
43 case CLIP_RRECT: return "Clip RRect";
44 case CONCAT: return "Concat";
45 case DRAW_BITMAP: return "Draw Bitmap";
46 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
47 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
48 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
49 case DRAW_DATA: return "Draw Data";
50 case DRAW_OVAL: return "Draw Oval";
51 case DRAW_PAINT: return "Draw Paint";
52 case DRAW_PATH: return "Draw Path";
53 case DRAW_PICTURE: return "Draw Picture";
54 case DRAW_POINTS: return "Draw Points";
55 case DRAW_POS_TEXT: return "Draw Pos Text";
56 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
57 case DRAW_RECT: return "Draw Rect";
58 case DRAW_RRECT: return "Draw RRect";
59 case DRAW_SPRITE: return "Draw Sprite";
60 case DRAW_TEXT: return "Draw Text";
61 case DRAW_TEXT_BLOB: return "Draw Text Blob";
62 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
63 case DRAW_VERTICES: return "Draw Vertices";
64 case RESTORE: return "Restore";
65 case ROTATE: return "Rotate";
66 case SAVE: return "Save";
67 case SAVE_LAYER: return "Save Layer";
68 case SCALE: return "Scale";
69 case SET_MATRIX: return "SetMatrix";
70 case SKEW: return "Skew";
71 case TRANSLATE: return "Translate";
72 case NOOP: return "NoOp";
73 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
74 case COMMENT: return "Comment";
75 case END_COMMENT_GROUP: return "EndCommentGroup";
76 case DRAW_DRRECT: return "Draw DRRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000077 default:
robertphillips3a092042015-02-12 13:29:15 -080078 SkDebugf("DrawType error 0x%08x\n", type);
chudy@google.com902ebe52012-06-29 14:21:22 +000079 SkASSERT(0);
80 break;
81 }
82 SkDEBUGFAIL("DrawType UNUSED\n");
83 return NULL;
84}
85
fmalita8c89c522014-11-08 16:18:56 -080086SkString SkDrawCommand::toString() const {
robertphillips3a092042015-02-12 13:29:15 -080087 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000088}
89
robertphillips3a092042015-02-12 13:29:15 -080090SkClearCommand::SkClearCommand(SkColor color) : INHERITED(DRAW_CLEAR) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000091 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000092 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000093}
94
fmalita8c89c522014-11-08 16:18:56 -080095void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000096 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000097}
98
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000099namespace {
100
101void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
102 const SkISize& size = canvas->getDeviceSize();
103
104 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
105
106 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
107 if (bounds.width() > bounds.height()) {
108 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
109 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
110 } else {
111 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
112 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
113 }
114 canvas->translate(-bounds.centerX(), -bounds.centerY());
115}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000116
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000117
118void render_path(SkCanvas* canvas, const SkPath& path) {
119 canvas->clear(0xFFFFFFFF);
120 canvas->save();
121
122 const SkRect& bounds = path.getBounds();
123
124 xlate_and_scale_to_bounds(canvas, bounds);
125
126 SkPaint p;
127 p.setColor(SK_ColorBLACK);
128 p.setStyle(SkPaint::kStroke_Style);
129
130 canvas->drawPath(path, p);
131 canvas->restore();
132}
133
134void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
135 const SkISize& size = canvas->getDeviceSize();
136
137 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
138 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
139
140 if (input.width() > input.height()) {
141 yScale *= input.height() / (float) input.width();
142 } else {
143 xScale *= input.width() / (float) input.height();
144 }
145
146 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
147 xScale * input.width(),
148 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000149
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000150 canvas->clear(0xFFFFFFFF);
151 canvas->drawBitmapRect(input, NULL, dst);
152
bsalomon49f085d2014-09-05 13:34:00 -0700153 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000154 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
155 srcRect->fTop * yScale + SK_Scalar1,
156 srcRect->fRight * xScale + SK_Scalar1,
157 srcRect->fBottom * yScale + SK_Scalar1);
158 SkPaint p;
159 p.setColor(SK_ColorRED);
160 p.setStyle(SkPaint::kStroke_Style);
161
162 canvas->drawRect(r, p);
163 }
164}
165
166void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
167 canvas->clear(0xFFFFFFFF);
168 canvas->save();
169
170 const SkRect& bounds = rrect.getBounds();
171
172 xlate_and_scale_to_bounds(canvas, bounds);
173
174 SkPaint p;
175 p.setColor(SK_ColorBLACK);
176 p.setStyle(SkPaint::kStroke_Style);
177
178 canvas->drawRRect(rrect, p);
179 canvas->restore();
180}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000181
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000182void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
183 canvas->clear(0xFFFFFFFF);
184 canvas->save();
185
186 const SkRect& bounds = outer.getBounds();
187
188 xlate_and_scale_to_bounds(canvas, bounds);
189
190 SkPaint p;
191 p.setColor(SK_ColorBLACK);
192 p.setStyle(SkPaint::kStroke_Style);
193
194 canvas->drawDRRect(outer, inner, p);
195 canvas->restore();
196}
197
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000198};
199
200
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000201SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips3a092042015-02-12 13:29:15 -0800202 : INHERITED(CLIP_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000203 fPath = path;
204 fOp = op;
205 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000206
robertphillips@google.com91217d02013-03-17 18:33:46 +0000207 fInfo.push(SkObjectParser::PathToString(path));
208 fInfo.push(SkObjectParser::RegionOpToString(op));
209 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000210}
211
fmalita8c89c522014-11-08 16:18:56 -0800212void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000213 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000214}
215
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000216bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000217 render_path(canvas, fPath);
218 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000219}
220
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000221SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips3a092042015-02-12 13:29:15 -0800222 : INHERITED(CLIP_REGION) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000223 fRegion = region;
224 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000225
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000226 fInfo.push(SkObjectParser::RegionToString(region));
227 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000228}
229
fmalita8c89c522014-11-08 16:18:56 -0800230void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000231 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000232}
233
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000234SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips3a092042015-02-12 13:29:15 -0800235 : INHERITED(CLIP_RECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000236 fRect = rect;
237 fOp = op;
238 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000239
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000240 fInfo.push(SkObjectParser::RectToString(rect));
241 fInfo.push(SkObjectParser::RegionOpToString(op));
242 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000243}
244
fmalita8c89c522014-11-08 16:18:56 -0800245void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000246 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000247}
248
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000249SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips3a092042015-02-12 13:29:15 -0800250 : INHERITED(CLIP_RRECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000251 fRRect = rrect;
252 fOp = op;
253 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000254
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000255 fInfo.push(SkObjectParser::RRectToString(rrect));
256 fInfo.push(SkObjectParser::RegionOpToString(op));
257 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000258}
259
fmalita8c89c522014-11-08 16:18:56 -0800260void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000261 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000262}
263
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000264bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000265 render_rrect(canvas, fRRect);
266 return true;
267}
268
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000269SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips3a092042015-02-12 13:29:15 -0800270 : INHERITED(CONCAT) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000271 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000272
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000273 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000274}
275
fmalita8c89c522014-11-08 16:18:56 -0800276void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000277 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000278}
279
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000280SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700281 const SkPaint* paint)
robertphillips3a092042015-02-12 13:29:15 -0800282 : INHERITED(DRAW_BITMAP) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000283 fBitmap = bitmap;
284 fLeft = left;
285 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700286 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000287 fPaint = *paint;
288 fPaintPtr = &fPaint;
289 } else {
290 fPaintPtr = NULL;
291 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000292
293 fInfo.push(SkObjectParser::BitmapToString(bitmap));
294 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
295 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700296 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000297 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000298 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000299}
300
fmalita8c89c522014-11-08 16:18:56 -0800301void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000302 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000303}
304
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000305bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000306 render_bitmap(canvas, fBitmap);
307 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000308}
309
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000310SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000311 const SkRect& dst, const SkPaint* paint)
robertphillips3a092042015-02-12 13:29:15 -0800312 : INHERITED(DRAW_BITMAP_NINE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000313 fBitmap = bitmap;
314 fCenter = center;
315 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700316 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000317 fPaint = *paint;
318 fPaintPtr = &fPaint;
319 } else {
320 fPaintPtr = NULL;
321 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000322
323 fInfo.push(SkObjectParser::BitmapToString(bitmap));
324 fInfo.push(SkObjectParser::IRectToString(center));
325 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700326 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000327 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000328 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000329}
330
fmalita8c89c522014-11-08 16:18:56 -0800331void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000332 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000333}
334
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000335bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000336 render_bitmap(canvas, fBitmap);
337 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000338}
339
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000340SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000341 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000342 SkCanvas::DrawBitmapRectFlags flags)
robertphillips3a092042015-02-12 13:29:15 -0800343 : INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000344 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700345 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000346 fSrc = *src;
347 } else {
348 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000349 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000350 fDst = dst;
351
bsalomon49f085d2014-09-05 13:34:00 -0700352 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000353 fPaint = *paint;
354 fPaintPtr = &fPaint;
355 } else {
356 fPaintPtr = NULL;
357 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000358 fFlags = flags;
359
robertphillips@google.com91217d02013-03-17 18:33:46 +0000360 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700361 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000362 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
363 }
364 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700365 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000366 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000367 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000368 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000369}
370
fmalita8c89c522014-11-08 16:18:56 -0800371void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000372 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000373}
374
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000375bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000376 render_bitmap(canvas, fBitmap, this->srcRect());
377 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000378}
379
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000380SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips3a092042015-02-12 13:29:15 -0800381 : INHERITED(BEGIN_COMMENT_GROUP)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000382 , fDescription(description) {
383 SkString* temp = new SkString;
384 temp->appendf("Description: %s", description);
385 fInfo.push(temp);
386}
387
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000388SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips3a092042015-02-12 13:29:15 -0800389 : INHERITED(COMMENT)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000390 , fKywd(kywd)
391 , fValue(value) {
392 SkString* temp = new SkString;
393 temp->appendf("%s: %s", kywd, value);
394 fInfo.push(temp);
395}
396
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000397SkEndCommentGroupCommand::SkEndCommentGroupCommand()
robertphillips3a092042015-02-12 13:29:15 -0800398 : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000399}
400
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000401SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800402 : INHERITED(DRAW_OVAL) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000403 fOval = oval;
404 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000405
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000406 fInfo.push(SkObjectParser::RectToString(oval));
407 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000408}
409
fmalita8c89c522014-11-08 16:18:56 -0800410void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000411 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000412}
413
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000414bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000415 canvas->clear(0xFFFFFFFF);
416 canvas->save();
417
418 xlate_and_scale_to_bounds(canvas, fOval);
419
420 SkPaint p;
421 p.setColor(SK_ColorBLACK);
422 p.setStyle(SkPaint::kStroke_Style);
423
424 canvas->drawOval(fOval, p);
425 canvas->restore();
426
427 return true;
428}
429
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000430SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800431 : INHERITED(DRAW_PAINT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000432 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000433
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000434 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000435}
436
fmalita8c89c522014-11-08 16:18:56 -0800437void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000438 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000439}
440
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000441bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000442 canvas->clear(0xFFFFFFFF);
443 canvas->drawPaint(fPaint);
444 return true;
445}
446
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000447SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800448 : INHERITED(DRAW_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000449 fPath = path;
450 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000451
robertphillips@google.com91217d02013-03-17 18:33:46 +0000452 fInfo.push(SkObjectParser::PathToString(path));
453 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000454}
455
fmalita8c89c522014-11-08 16:18:56 -0800456void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000457 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000458}
459
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000460bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000461 render_path(canvas, fPath);
462 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000463}
464
robertphillipsb3f319f2014-08-13 10:46:23 -0700465SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
466 const SkMatrix* matrix,
467 const SkPaint* paint)
robertphillips3a092042015-02-12 13:29:15 -0800468 : INHERITED(DRAW_PICTURE)
robertphillipsb3f319f2014-08-13 10:46:23 -0700469 , fPicture(SkRef(picture))
470 , fMatrixPtr(NULL)
471 , fPaintPtr(NULL) {
472
bsalomon49f085d2014-09-05 13:34:00 -0700473 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700474 fMatrix = *matrix;
475 fMatrixPtr = &fMatrix;
476 }
bsalomon49f085d2014-09-05 13:34:00 -0700477 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700478 fPaint = *paint;
479 fPaintPtr = &fPaint;
480 }
481
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000482 SkString* temp = new SkString;
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700483 temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
484 picture->cullRect().fLeft, picture->cullRect().fTop,
485 picture->cullRect().fRight, picture->cullRect().fBottom);
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000486 fInfo.push(temp);
bsalomon49f085d2014-09-05 13:34:00 -0700487 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700488 fInfo.push(SkObjectParser::MatrixToString(*matrix));
489 }
bsalomon49f085d2014-09-05 13:34:00 -0700490 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700491 fInfo.push(SkObjectParser::PaintToString(*paint));
492 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000493}
494
fmalita8c89c522014-11-08 16:18:56 -0800495void SkDrawPictureCommand::execute(SkCanvas* canvas) const {
robertphillipsb3f319f2014-08-13 10:46:23 -0700496 canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000497}
498
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000499bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
500 canvas->clear(0xFFFFFFFF);
501 canvas->save();
502
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700503 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000504
robertphillips9b14f262014-06-04 05:40:44 -0700505 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000506
507 canvas->restore();
508
509 return true;
510}
511
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000512SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000513 const SkPoint pts[], const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800514 : INHERITED(DRAW_POINTS) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000515 fMode = mode;
516 fCount = count;
517 fPts = new SkPoint[count];
518 memcpy(fPts, pts, count * sizeof(SkPoint));
519 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000520
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000521 fInfo.push(SkObjectParser::PointsToString(pts, count));
522 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
523 "Points: "));
524 fInfo.push(SkObjectParser::PointModeToString(mode));
525 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000526}
527
fmalita8c89c522014-11-08 16:18:56 -0800528void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000529 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000530}
531
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000532bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000533 canvas->clear(0xFFFFFFFF);
534 canvas->save();
535
536 SkRect bounds;
537
538 bounds.setEmpty();
539 for (unsigned int i = 0; i < fCount; ++i) {
540 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
541 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000542
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000543 xlate_and_scale_to_bounds(canvas, bounds);
544
545 SkPaint p;
546 p.setColor(SK_ColorBLACK);
547 p.setStyle(SkPaint::kStroke_Style);
548
549 canvas->drawPoints(fMode, fCount, fPts, p);
550 canvas->restore();
551
552 return true;
553}
554
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000555SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000556 const SkPoint pos[], const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800557 : INHERITED(DRAW_POS_TEXT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000558 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000559
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000560 fText = new char[byteLength];
561 memcpy(fText, text, byteLength);
562 fByteLength = byteLength;
563
564 fPos = new SkPoint[numPts];
565 memcpy(fPos, pos, numPts * sizeof(SkPoint));
566
567 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000568
569 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000570 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000571 fInfo.push(SkObjectParser::PointsToString(pos, 1));
572 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000573}
574
fmalita8c89c522014-11-08 16:18:56 -0800575void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000576 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000577}
578
579
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000580SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
581 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000582 const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800583 : INHERITED(DRAW_POS_TEXT_H) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000584 size_t numPts = paint.countText(text, byteLength);
585
586 fText = new char[byteLength];
587 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000588 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000589
590 fXpos = new SkScalar[numPts];
591 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
592
robertphillips@google.com91217d02013-03-17 18:33:46 +0000593 fConstY = constY;
594 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000595
robertphillips@google.com91217d02013-03-17 18:33:46 +0000596 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
597 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
598 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
599 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000600}
601
fmalita8c89c522014-11-08 16:18:56 -0800602void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000603 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000604}
605
fmalitab7425172014-08-26 07:56:44 -0700606SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
607 const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800608 : INHERITED(DRAW_TEXT_BLOB)
fmalitab7425172014-08-26 07:56:44 -0700609 , fBlob(blob)
610 , fXPos(x)
611 , fYPos(y)
612 , fPaint(paint) {
613
614 blob->ref();
615
616 // FIXME: push blob info
617 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800618 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
619 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700620 fInfo.push(SkObjectParser::PaintToString(paint));
621}
622
fmalita8c89c522014-11-08 16:18:56 -0800623void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700624 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
625}
626
fmalita55773872014-08-29 15:08:20 -0700627bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
628 canvas->clear(SK_ColorWHITE);
629 canvas->save();
630
631 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
632 xlate_and_scale_to_bounds(canvas, bounds);
633
634 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
635
636 canvas->restore();
637
638 return true;
639}
640
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000641SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800642 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000643 fRect = rect;
644 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000645
robertphillips@google.com91217d02013-03-17 18:33:46 +0000646 fInfo.push(SkObjectParser::RectToString(rect));
647 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000648}
649
fmalita8c89c522014-11-08 16:18:56 -0800650void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000651 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000652}
653
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000654SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800655 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000656 fRRect = rrect;
657 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000658
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000659 fInfo.push(SkObjectParser::RRectToString(rrect));
660 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000661}
662
fmalita8c89c522014-11-08 16:18:56 -0800663void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000664 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000665}
666
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000667bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000668 render_rrect(canvas, fRRect);
669 return true;
670}
671
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000672SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000673 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000674 const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800675 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000676 fOuter = outer;
677 fInner = inner;
678 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000679
680 fInfo.push(SkObjectParser::RRectToString(outer));
681 fInfo.push(SkObjectParser::RRectToString(inner));
682 fInfo.push(SkObjectParser::PaintToString(paint));
683}
684
fmalita8c89c522014-11-08 16:18:56 -0800685void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000686 canvas->drawDRRect(fOuter, fInner, fPaint);
687}
688
689bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
690 render_drrect(canvas, fOuter, fInner);
691 return true;
692}
693
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000694SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000695 const SkPaint* paint)
robertphillips3a092042015-02-12 13:29:15 -0800696 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000697 fBitmap = bitmap;
698 fLeft = left;
699 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700700 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000701 fPaint = *paint;
702 fPaintPtr = &fPaint;
703 } else {
704 fPaintPtr = NULL;
705 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000706
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000707 fInfo.push(SkObjectParser::BitmapToString(bitmap));
708 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
709 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700710 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000711 fInfo.push(SkObjectParser::PaintToString(*paint));
712 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000713}
714
fmalita8c89c522014-11-08 16:18:56 -0800715void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000716 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000717}
718
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000719bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000720 render_bitmap(canvas, fBitmap);
721 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000722}
723
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000724SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000725 const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800726 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000727 fText = new char[byteLength];
728 memcpy(fText, text, byteLength);
729 fByteLength = byteLength;
730 fX = x;
731 fY = y;
732 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000733
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000734 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
735 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
736 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
737 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000738}
739
fmalita8c89c522014-11-08 16:18:56 -0800740void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000741 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000742}
743
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000744SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
745 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000746 const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800747 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000748 fText = new char[byteLength];
749 memcpy(fText, text, byteLength);
750 fByteLength = byteLength;
751 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700752 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000753 fMatrix = *matrix;
754 } else {
755 fMatrix.setIdentity();
756 }
757 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000758
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000759 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
760 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700761 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000762 fInfo.push(SkObjectParser::MatrixToString(*matrix));
763 }
764 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000765}
766
fmalita8c89c522014-11-08 16:18:56 -0800767void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000768 canvas->drawTextOnPath(fText, fByteLength, fPath,
769 fMatrix.isIdentity() ? NULL : &fMatrix,
770 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000771}
772
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000773SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
774 const SkPoint vertices[], const SkPoint texs[],
775 const SkColor colors[], SkXfermode* xfermode,
776 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000777 const SkPaint& paint)
robertphillips3a092042015-02-12 13:29:15 -0800778 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000779 fVmode = vmode;
780
781 fVertexCount = vertexCount;
782
783 fVertices = new SkPoint[vertexCount];
784 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
785
bsalomon49f085d2014-09-05 13:34:00 -0700786 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000787 fTexs = new SkPoint[vertexCount];
788 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
789 } else {
790 fTexs = NULL;
791 }
792
bsalomon49f085d2014-09-05 13:34:00 -0700793 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000794 fColors = new SkColor[vertexCount];
795 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
796 } else {
797 fColors = NULL;
798 }
799
800 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700801 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000802 fXfermode->ref();
803 }
804
805 if (indexCount > 0) {
806 fIndices = new uint16_t[indexCount];
807 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
808 } else {
809 fIndices = NULL;
810 }
811
812 fIndexCount = indexCount;
813 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000814
chudy@google.com902ebe52012-06-29 14:21:22 +0000815 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000816 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
817 fInfo.push(SkObjectParser::PaintToString(paint));
818}
819
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000820SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000821 delete [] fVertices;
822 delete [] fTexs;
823 delete [] fColors;
824 SkSafeUnref(fXfermode);
825 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000826}
827
fmalita8c89c522014-11-08 16:18:56 -0800828void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000829 canvas->drawVertices(fVmode, fVertexCount, fVertices,
830 fTexs, fColors, fXfermode, fIndices,
831 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000832}
833
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000834SkRestoreCommand::SkRestoreCommand()
robertphillips3a092042015-02-12 13:29:15 -0800835 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000836 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000837}
838
fmalita8c89c522014-11-08 16:18:56 -0800839void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000840 canvas->restore();
841}
842
robertphillips3a092042015-02-12 13:29:15 -0800843SkRotateCommand::SkRotateCommand(SkScalar degrees)
844 : INHERITED(ROTATE) {
845 fDegrees = degrees;
846
847 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
848}
849
850void SkRotateCommand::execute(SkCanvas* canvas) const {
851 canvas->rotate(fDegrees);
852}
853
Florin Malita5f6102d2014-06-30 10:13:28 -0400854SkSaveCommand::SkSaveCommand()
robertphillips3a092042015-02-12 13:29:15 -0800855 : INHERITED(SAVE) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000856}
857
fmalita8c89c522014-11-08 16:18:56 -0800858void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400859 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000860}
861
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000862SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000863 SkCanvas::SaveFlags flags)
robertphillips3a092042015-02-12 13:29:15 -0800864 : INHERITED(SAVE_LAYER) {
bsalomon49f085d2014-09-05 13:34:00 -0700865 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000866 fBounds = *bounds;
867 } else {
868 fBounds.setEmpty();
869 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000870
bsalomon49f085d2014-09-05 13:34:00 -0700871 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000872 fPaint = *paint;
873 fPaintPtr = &fPaint;
874 } else {
875 fPaintPtr = NULL;
876 }
877 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000878
bsalomon49f085d2014-09-05 13:34:00 -0700879 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000880 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
881 }
bsalomon49f085d2014-09-05 13:34:00 -0700882 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000883 fInfo.push(SkObjectParser::PaintToString(*paint));
884 }
885 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000886}
887
fmalita8c89c522014-11-08 16:18:56 -0800888void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000889 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000890 fPaintPtr,
891 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000892}
893
fmalita8c89c522014-11-08 16:18:56 -0800894void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000895 canvas->save();
896}
897
robertphillips3a092042015-02-12 13:29:15 -0800898SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
899 : INHERITED(SCALE) {
900 fSx = sx;
901 fSy = sy;
902
903 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
904 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
905}
906
907void SkScaleCommand::execute(SkCanvas* canvas) const {
908 canvas->scale(fSx, fSy);
909}
910
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000911SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips3a092042015-02-12 13:29:15 -0800912 : INHERITED(SET_MATRIX) {
robertphillips70171682014-10-16 14:28:28 -0700913 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000914 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000915
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000916 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000917}
918
robertphillips70171682014-10-16 14:28:28 -0700919void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
920 fUserMatrix = userMatrix;
921}
922
fmalita8c89c522014-11-08 16:18:56 -0800923void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700924 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
925 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000926}
927
robertphillips3a092042015-02-12 13:29:15 -0800928SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
929 : INHERITED(SKEW) {
930 fSx = sx;
931 fSy = sy;
932
933 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
934 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
935}
936
937void SkSkewCommand::execute(SkCanvas* canvas) const {
938 canvas->skew(fSx, fSy);
939}
940
941SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
942 : INHERITED(TRANSLATE) {
943 fDx = dx;
944 fDy = dy;
945
946 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
947 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
948}
949
950void SkTranslateCommand::execute(SkCanvas* canvas) const {
951 canvas->translate(fDx, fDy);
952}
953