blob: 142c4a44b1f818a00821e63535b210acc3b7ef65 [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";
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +000068 case PUSH_CULL: return "PushCull";
69 case POP_CULL: return "PopCull";
chudy@google.com902ebe52012-06-29 14:21:22 +000070 default:
71 SkDebugf("DrawType error 0x%08x\n", type);
72 SkASSERT(0);
73 break;
74 }
75 SkDEBUGFAIL("DrawType UNUSED\n");
76 return NULL;
77}
78
fmalita8c89c522014-11-08 16:18:56 -080079SkString SkDrawCommand::toString() const {
chudy@google.com97cee972012-08-07 20:41:37 +000080 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000081}
82
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000083SkClearCommand::SkClearCommand(SkColor color) : INHERITED(DRAW_CLEAR) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000084 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000085 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000086}
87
fmalita8c89c522014-11-08 16:18:56 -080088void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000089 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000090}
91
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000092namespace {
93
94void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
95 const SkISize& size = canvas->getDeviceSize();
96
97 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
98
99 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
100 if (bounds.width() > bounds.height()) {
101 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
102 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
103 } else {
104 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
105 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
106 }
107 canvas->translate(-bounds.centerX(), -bounds.centerY());
108}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000109
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000110
111void render_path(SkCanvas* canvas, const SkPath& path) {
112 canvas->clear(0xFFFFFFFF);
113 canvas->save();
114
115 const SkRect& bounds = path.getBounds();
116
117 xlate_and_scale_to_bounds(canvas, bounds);
118
119 SkPaint p;
120 p.setColor(SK_ColorBLACK);
121 p.setStyle(SkPaint::kStroke_Style);
122
123 canvas->drawPath(path, p);
124 canvas->restore();
125}
126
127void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
128 const SkISize& size = canvas->getDeviceSize();
129
130 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
131 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
132
133 if (input.width() > input.height()) {
134 yScale *= input.height() / (float) input.width();
135 } else {
136 xScale *= input.width() / (float) input.height();
137 }
138
139 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
140 xScale * input.width(),
141 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000142
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000143 canvas->clear(0xFFFFFFFF);
144 canvas->drawBitmapRect(input, NULL, dst);
145
bsalomon49f085d2014-09-05 13:34:00 -0700146 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000147 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
148 srcRect->fTop * yScale + SK_Scalar1,
149 srcRect->fRight * xScale + SK_Scalar1,
150 srcRect->fBottom * yScale + SK_Scalar1);
151 SkPaint p;
152 p.setColor(SK_ColorRED);
153 p.setStyle(SkPaint::kStroke_Style);
154
155 canvas->drawRect(r, p);
156 }
157}
158
159void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
160 canvas->clear(0xFFFFFFFF);
161 canvas->save();
162
163 const SkRect& bounds = rrect.getBounds();
164
165 xlate_and_scale_to_bounds(canvas, bounds);
166
167 SkPaint p;
168 p.setColor(SK_ColorBLACK);
169 p.setStyle(SkPaint::kStroke_Style);
170
171 canvas->drawRRect(rrect, p);
172 canvas->restore();
173}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000174
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000175void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
176 canvas->clear(0xFFFFFFFF);
177 canvas->save();
178
179 const SkRect& bounds = outer.getBounds();
180
181 xlate_and_scale_to_bounds(canvas, bounds);
182
183 SkPaint p;
184 p.setColor(SK_ColorBLACK);
185 p.setStyle(SkPaint::kStroke_Style);
186
187 canvas->drawDRRect(outer, inner, p);
188 canvas->restore();
189}
190
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000191};
192
193
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000194SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
195 : INHERITED(CLIP_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000196 fPath = path;
197 fOp = op;
198 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000199
robertphillips@google.com91217d02013-03-17 18:33:46 +0000200 fInfo.push(SkObjectParser::PathToString(path));
201 fInfo.push(SkObjectParser::RegionOpToString(op));
202 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000203}
204
fmalita8c89c522014-11-08 16:18:56 -0800205void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000206 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000207}
208
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000209bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000210 render_path(canvas, fPath);
211 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000212}
213
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000214SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000215 : INHERITED(CLIP_REGION) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000216 fRegion = region;
217 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000218
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000219 fInfo.push(SkObjectParser::RegionToString(region));
220 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000221}
222
fmalita8c89c522014-11-08 16:18:56 -0800223void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000224 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000225}
226
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000227SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
228 : INHERITED(CLIP_RECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000229 fRect = rect;
230 fOp = op;
231 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000232
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000233 fInfo.push(SkObjectParser::RectToString(rect));
234 fInfo.push(SkObjectParser::RegionOpToString(op));
235 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000236}
237
fmalita8c89c522014-11-08 16:18:56 -0800238void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000239 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000240}
241
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000242SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000243 : INHERITED(CLIP_RRECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000244 fRRect = rrect;
245 fOp = op;
246 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000247
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000248 fInfo.push(SkObjectParser::RRectToString(rrect));
249 fInfo.push(SkObjectParser::RegionOpToString(op));
250 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000251}
252
fmalita8c89c522014-11-08 16:18:56 -0800253void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000254 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000255}
256
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000257bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000258 render_rrect(canvas, fRRect);
259 return true;
260}
261
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000262SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
263 : INHERITED(CONCAT) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000264 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000265
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000266 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000267}
268
fmalita8c89c522014-11-08 16:18:56 -0800269void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000270 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000271}
272
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000273SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700274 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000275 : INHERITED(DRAW_BITMAP) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000276 fBitmap = bitmap;
277 fLeft = left;
278 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700279 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000280 fPaint = *paint;
281 fPaintPtr = &fPaint;
282 } else {
283 fPaintPtr = NULL;
284 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000285
286 fInfo.push(SkObjectParser::BitmapToString(bitmap));
287 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
288 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700289 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000290 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000291 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000292}
293
fmalita8c89c522014-11-08 16:18:56 -0800294void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000295 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000296}
297
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000298bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000299 render_bitmap(canvas, fBitmap);
300 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000301}
302
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000303SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
304 const SkMatrix& matrix,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000305 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000306 : INHERITED(DRAW_BITMAP_MATRIX) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000307 fBitmap = bitmap;
308 fMatrix = matrix;
bsalomon49f085d2014-09-05 13:34:00 -0700309 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000310 fPaint = *paint;
311 fPaintPtr = &fPaint;
312 } else {
313 fPaintPtr = NULL;
314 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000315
316 fInfo.push(SkObjectParser::BitmapToString(bitmap));
317 fInfo.push(SkObjectParser::MatrixToString(matrix));
bsalomon49f085d2014-09-05 13:34:00 -0700318 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000319 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000320 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000321}
322
fmalita8c89c522014-11-08 16:18:56 -0800323void SkDrawBitmapMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000324 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000325}
326
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000327bool SkDrawBitmapMatrixCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000328 render_bitmap(canvas, fBitmap);
329 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000330}
331
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000332SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000333 const SkRect& dst, const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000334 : INHERITED(DRAW_BITMAP_NINE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000335 fBitmap = bitmap;
336 fCenter = center;
337 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700338 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000339 fPaint = *paint;
340 fPaintPtr = &fPaint;
341 } else {
342 fPaintPtr = NULL;
343 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000344
345 fInfo.push(SkObjectParser::BitmapToString(bitmap));
346 fInfo.push(SkObjectParser::IRectToString(center));
347 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700348 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000349 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000350 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000351}
352
fmalita8c89c522014-11-08 16:18:56 -0800353void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000354 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000355}
356
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000357bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000358 render_bitmap(canvas, fBitmap);
359 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000360}
361
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000362SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000363 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000364 SkCanvas::DrawBitmapRectFlags flags)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000365 : INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000366 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700367 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000368 fSrc = *src;
369 } else {
370 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000371 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000372 fDst = dst;
373
bsalomon49f085d2014-09-05 13:34:00 -0700374 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000375 fPaint = *paint;
376 fPaintPtr = &fPaint;
377 } else {
378 fPaintPtr = NULL;
379 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000380 fFlags = flags;
381
robertphillips@google.com91217d02013-03-17 18:33:46 +0000382 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700383 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000384 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
385 }
386 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700387 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000388 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000389 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000390 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000391}
392
fmalita8c89c522014-11-08 16:18:56 -0800393void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000394 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000397bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000398 render_bitmap(canvas, fBitmap, this->srcRect());
399 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000400}
401
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000402SkDrawDataCommand::SkDrawDataCommand(const void* data, size_t length)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000403 : INHERITED(DRAW_DATA) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000404 fData = new char[length];
405 memcpy(fData, data, length);
406 fLength = length;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000407
408 // TODO: add display of actual data?
409 SkString* str = new SkString;
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000410 str->appendf("length: %d", (int) length);
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000411 fInfo.push(str);
chudy@google.com902ebe52012-06-29 14:21:22 +0000412}
413
fmalita8c89c522014-11-08 16:18:56 -0800414void SkDrawDataCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000415 canvas->drawData(fData, fLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000416}
417
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000418SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000419 : INHERITED(BEGIN_COMMENT_GROUP)
420 , fDescription(description) {
421 SkString* temp = new SkString;
422 temp->appendf("Description: %s", description);
423 fInfo.push(temp);
424}
425
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000426SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000427 : INHERITED(COMMENT)
428 , fKywd(kywd)
429 , fValue(value) {
430 SkString* temp = new SkString;
431 temp->appendf("%s: %s", kywd, value);
432 fInfo.push(temp);
433}
434
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000435SkEndCommentGroupCommand::SkEndCommentGroupCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000436 : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000437}
438
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000439SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
440 : INHERITED(DRAW_OVAL) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000441 fOval = oval;
442 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000443
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000444 fInfo.push(SkObjectParser::RectToString(oval));
445 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000446}
447
fmalita8c89c522014-11-08 16:18:56 -0800448void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000449 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000450}
451
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000452bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000453 canvas->clear(0xFFFFFFFF);
454 canvas->save();
455
456 xlate_and_scale_to_bounds(canvas, fOval);
457
458 SkPaint p;
459 p.setColor(SK_ColorBLACK);
460 p.setStyle(SkPaint::kStroke_Style);
461
462 canvas->drawOval(fOval, p);
463 canvas->restore();
464
465 return true;
466}
467
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000468SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
469 : INHERITED(DRAW_PAINT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000470 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000471
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000472 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000473}
474
fmalita8c89c522014-11-08 16:18:56 -0800475void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000476 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000477}
478
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000479bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000480 canvas->clear(0xFFFFFFFF);
481 canvas->drawPaint(fPaint);
482 return true;
483}
484
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000485SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
486 : INHERITED(DRAW_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000487 fPath = path;
488 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000489
robertphillips@google.com91217d02013-03-17 18:33:46 +0000490 fInfo.push(SkObjectParser::PathToString(path));
491 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000492}
493
fmalita8c89c522014-11-08 16:18:56 -0800494void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000495 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000496}
497
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000498bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000499 render_path(canvas, fPath);
500 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000501}
502
robertphillipsb3f319f2014-08-13 10:46:23 -0700503SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
504 const SkMatrix* matrix,
505 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000506 : INHERITED(DRAW_PICTURE)
robertphillipsb3f319f2014-08-13 10:46:23 -0700507 , fPicture(SkRef(picture))
508 , fMatrixPtr(NULL)
509 , fPaintPtr(NULL) {
510
bsalomon49f085d2014-09-05 13:34:00 -0700511 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700512 fMatrix = *matrix;
513 fMatrixPtr = &fMatrix;
514 }
bsalomon49f085d2014-09-05 13:34:00 -0700515 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700516 fPaint = *paint;
517 fPaintPtr = &fPaint;
518 }
519
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000520 SkString* temp = new SkString;
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700521 temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
522 picture->cullRect().fLeft, picture->cullRect().fTop,
523 picture->cullRect().fRight, picture->cullRect().fBottom);
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000524 fInfo.push(temp);
bsalomon49f085d2014-09-05 13:34:00 -0700525 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700526 fInfo.push(SkObjectParser::MatrixToString(*matrix));
527 }
bsalomon49f085d2014-09-05 13:34:00 -0700528 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700529 fInfo.push(SkObjectParser::PaintToString(*paint));
530 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000531}
532
fmalita8c89c522014-11-08 16:18:56 -0800533void SkDrawPictureCommand::execute(SkCanvas* canvas) const {
robertphillipsb3f319f2014-08-13 10:46:23 -0700534 canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000535}
536
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000537bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
538 canvas->clear(0xFFFFFFFF);
539 canvas->save();
540
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700541 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000542
robertphillips9b14f262014-06-04 05:40:44 -0700543 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000544
545 canvas->restore();
546
547 return true;
548}
549
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000550SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000551 const SkPoint pts[], const SkPaint& paint)
552 : INHERITED(DRAW_POINTS) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000553 fMode = mode;
554 fCount = count;
555 fPts = new SkPoint[count];
556 memcpy(fPts, pts, count * sizeof(SkPoint));
557 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000558
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000559 fInfo.push(SkObjectParser::PointsToString(pts, count));
560 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
561 "Points: "));
562 fInfo.push(SkObjectParser::PointModeToString(mode));
563 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000564}
565
fmalita8c89c522014-11-08 16:18:56 -0800566void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000567 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000568}
569
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000570bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000571 canvas->clear(0xFFFFFFFF);
572 canvas->save();
573
574 SkRect bounds;
575
576 bounds.setEmpty();
577 for (unsigned int i = 0; i < fCount; ++i) {
578 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
579 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000580
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000581 xlate_and_scale_to_bounds(canvas, bounds);
582
583 SkPaint p;
584 p.setColor(SK_ColorBLACK);
585 p.setStyle(SkPaint::kStroke_Style);
586
587 canvas->drawPoints(fMode, fCount, fPts, p);
588 canvas->restore();
589
590 return true;
591}
592
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000593SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000594 const SkPoint pos[], const SkPaint& paint)
595 : INHERITED(DRAW_POS_TEXT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000596 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000597
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000598 fText = new char[byteLength];
599 memcpy(fText, text, byteLength);
600 fByteLength = byteLength;
601
602 fPos = new SkPoint[numPts];
603 memcpy(fPos, pos, numPts * sizeof(SkPoint));
604
605 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000606
607 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000608 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000609 fInfo.push(SkObjectParser::PointsToString(pos, 1));
610 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000611}
612
fmalita8c89c522014-11-08 16:18:56 -0800613void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000614 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000615}
616
617
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000618SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
619 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000620 const SkPaint& paint)
621 : INHERITED(DRAW_POS_TEXT_H) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000622 size_t numPts = paint.countText(text, byteLength);
623
624 fText = new char[byteLength];
625 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000626 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000627
628 fXpos = new SkScalar[numPts];
629 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
630
robertphillips@google.com91217d02013-03-17 18:33:46 +0000631 fConstY = constY;
632 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000633
robertphillips@google.com91217d02013-03-17 18:33:46 +0000634 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
635 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
636 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
637 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000638}
639
fmalita8c89c522014-11-08 16:18:56 -0800640void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000641 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000642}
643
fmalitab7425172014-08-26 07:56:44 -0700644SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
645 const SkPaint& paint)
646 : INHERITED(DRAW_TEXT_BLOB)
647 , fBlob(blob)
648 , fXPos(x)
649 , fYPos(y)
650 , fPaint(paint) {
651
652 blob->ref();
653
654 // FIXME: push blob info
655 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
656 fInfo.push(SkObjectParser::ScalarToString(x, "YPOS: "));
657 fInfo.push(SkObjectParser::PaintToString(paint));
658}
659
fmalita8c89c522014-11-08 16:18:56 -0800660void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700661 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
662}
663
fmalita55773872014-08-29 15:08:20 -0700664bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
665 canvas->clear(SK_ColorWHITE);
666 canvas->save();
667
668 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
669 xlate_and_scale_to_bounds(canvas, bounds);
670
671 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
672
673 canvas->restore();
674
675 return true;
676}
677
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000678SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
679 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000680 fRect = rect;
681 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000682
robertphillips@google.com91217d02013-03-17 18:33:46 +0000683 fInfo.push(SkObjectParser::RectToString(rect));
684 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000685}
686
fmalita8c89c522014-11-08 16:18:56 -0800687void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000688 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000689}
690
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000691SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
692 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000693 fRRect = rrect;
694 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000695
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000696 fInfo.push(SkObjectParser::RRectToString(rrect));
697 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000698}
699
fmalita8c89c522014-11-08 16:18:56 -0800700void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000701 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000702}
703
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000704bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000705 render_rrect(canvas, fRRect);
706 return true;
707}
708
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000709SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000710 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000711 const SkPaint& paint)
712 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000713 fOuter = outer;
714 fInner = inner;
715 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000716
717 fInfo.push(SkObjectParser::RRectToString(outer));
718 fInfo.push(SkObjectParser::RRectToString(inner));
719 fInfo.push(SkObjectParser::PaintToString(paint));
720}
721
fmalita8c89c522014-11-08 16:18:56 -0800722void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000723 canvas->drawDRRect(fOuter, fInner, fPaint);
724}
725
726bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
727 render_drrect(canvas, fOuter, fInner);
728 return true;
729}
730
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000731SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000732 const SkPaint* paint)
733 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000734 fBitmap = bitmap;
735 fLeft = left;
736 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700737 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000738 fPaint = *paint;
739 fPaintPtr = &fPaint;
740 } else {
741 fPaintPtr = NULL;
742 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000743
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000744 fInfo.push(SkObjectParser::BitmapToString(bitmap));
745 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
746 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700747 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000748 fInfo.push(SkObjectParser::PaintToString(*paint));
749 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000750}
751
fmalita8c89c522014-11-08 16:18:56 -0800752void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000753 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000754}
755
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000756bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000757 render_bitmap(canvas, fBitmap);
758 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000759}
760
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000761SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000762 const SkPaint& paint)
763 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000764 fText = new char[byteLength];
765 memcpy(fText, text, byteLength);
766 fByteLength = byteLength;
767 fX = x;
768 fY = y;
769 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000770
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000771 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
772 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
773 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
774 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000775}
776
fmalita8c89c522014-11-08 16:18:56 -0800777void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000778 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000779}
780
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000781SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
782 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000783 const SkPaint& paint)
784 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000785 fText = new char[byteLength];
786 memcpy(fText, text, byteLength);
787 fByteLength = byteLength;
788 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700789 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000790 fMatrix = *matrix;
791 } else {
792 fMatrix.setIdentity();
793 }
794 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000795
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000796 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
797 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700798 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000799 fInfo.push(SkObjectParser::MatrixToString(*matrix));
800 }
801 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000802}
803
fmalita8c89c522014-11-08 16:18:56 -0800804void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000805 canvas->drawTextOnPath(fText, fByteLength, fPath,
806 fMatrix.isIdentity() ? NULL : &fMatrix,
807 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000808}
809
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000810SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
811 const SkPoint vertices[], const SkPoint texs[],
812 const SkColor colors[], SkXfermode* xfermode,
813 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000814 const SkPaint& paint)
815 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000816 fVmode = vmode;
817
818 fVertexCount = vertexCount;
819
820 fVertices = new SkPoint[vertexCount];
821 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
822
bsalomon49f085d2014-09-05 13:34:00 -0700823 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000824 fTexs = new SkPoint[vertexCount];
825 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
826 } else {
827 fTexs = NULL;
828 }
829
bsalomon49f085d2014-09-05 13:34:00 -0700830 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000831 fColors = new SkColor[vertexCount];
832 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
833 } else {
834 fColors = NULL;
835 }
836
837 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700838 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000839 fXfermode->ref();
840 }
841
842 if (indexCount > 0) {
843 fIndices = new uint16_t[indexCount];
844 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
845 } else {
846 fIndices = NULL;
847 }
848
849 fIndexCount = indexCount;
850 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000851
chudy@google.com902ebe52012-06-29 14:21:22 +0000852 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000853 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
854 fInfo.push(SkObjectParser::PaintToString(paint));
855}
856
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000857SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000858 delete [] fVertices;
859 delete [] fTexs;
860 delete [] fColors;
861 SkSafeUnref(fXfermode);
862 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000863}
864
fmalita8c89c522014-11-08 16:18:56 -0800865void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000866 canvas->drawVertices(fVmode, fVertexCount, fVertices,
867 fTexs, fColors, fXfermode, fIndices,
868 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000869}
870
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000871SkRestoreCommand::SkRestoreCommand()
872 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000873 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000874}
875
fmalita8c89c522014-11-08 16:18:56 -0800876void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000877 canvas->restore();
878}
879
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000880void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000881 (*state)--;
882}
883
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000884SkRotateCommand::SkRotateCommand(SkScalar degrees)
885 : INHERITED(ROTATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000886 fDegrees = degrees;
chudy@google.com902ebe52012-06-29 14:21:22 +0000887
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000888 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000889}
890
fmalita8c89c522014-11-08 16:18:56 -0800891void SkRotateCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000892 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000893}
894
Florin Malita5f6102d2014-06-30 10:13:28 -0400895SkSaveCommand::SkSaveCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000896 : INHERITED(SAVE) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000897}
898
fmalita8c89c522014-11-08 16:18:56 -0800899void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400900 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000901}
902
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000903void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000904 (*state)++;
905}
906
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000907SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000908 SkCanvas::SaveFlags flags)
909 : INHERITED(SAVE_LAYER) {
bsalomon49f085d2014-09-05 13:34:00 -0700910 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000911 fBounds = *bounds;
912 } else {
913 fBounds.setEmpty();
914 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000915
bsalomon49f085d2014-09-05 13:34:00 -0700916 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000917 fPaint = *paint;
918 fPaintPtr = &fPaint;
919 } else {
920 fPaintPtr = NULL;
921 }
922 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000923
bsalomon49f085d2014-09-05 13:34:00 -0700924 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000925 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
926 }
bsalomon49f085d2014-09-05 13:34:00 -0700927 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000928 fInfo.push(SkObjectParser::PaintToString(*paint));
929 }
930 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000931}
932
fmalita8c89c522014-11-08 16:18:56 -0800933void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000934 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000935 fPaintPtr,
936 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000937}
938
fmalita8c89c522014-11-08 16:18:56 -0800939void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000940 canvas->save();
941}
942
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000943void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000944 (*state)++;
945}
946
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000947SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
948 : INHERITED(SCALE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000949 fSx = sx;
950 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000951
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000952 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
953 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000954}
955
fmalita8c89c522014-11-08 16:18:56 -0800956void SkScaleCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000957 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000958}
959
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000960SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
961 : INHERITED(SET_MATRIX) {
robertphillips70171682014-10-16 14:28:28 -0700962 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000963 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000964
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000965 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000966}
967
robertphillips70171682014-10-16 14:28:28 -0700968void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
969 fUserMatrix = userMatrix;
970}
971
fmalita8c89c522014-11-08 16:18:56 -0800972void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700973 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
974 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000975}
976
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000977SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
978 : INHERITED(SKEW) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000979 fSx = sx;
980 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000981
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000982 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
983 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000984}
985
fmalita8c89c522014-11-08 16:18:56 -0800986void SkSkewCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000987 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000988}
989
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000990SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
991 : INHERITED(TRANSLATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000992 fDx = dx;
993 fDy = dy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000994
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000995 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
996 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000997}
998
fmalita8c89c522014-11-08 16:18:56 -0800999void SkTranslateCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +00001000 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +00001001}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001002
1003SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001004 : INHERITED(PUSH_CULL)
1005 , fCullRect(cullRect) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001006 fInfo.push(SkObjectParser::RectToString(cullRect));
1007}
1008
fmalita8c89c522014-11-08 16:18:56 -08001009void SkPushCullCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001010 canvas->pushCull(fCullRect);
1011}
1012
fmalita8c89c522014-11-08 16:18:56 -08001013void SkPushCullCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +00001014 canvas->pushCull(fCullRect);
1015
1016 SkPaint p;
1017 p.setColor(SK_ColorCYAN);
1018 p.setStyle(SkPaint::kStroke_Style);
1019 canvas->drawRect(fCullRect, p);
1020}
1021
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001022SkPopCullCommand::SkPopCullCommand() : INHERITED(POP_CULL) { }
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001023
fmalita8c89c522014-11-08 16:18:56 -08001024void SkPopCullCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001025 canvas->popCull();
1026}