blob: 08a97188c1b60e43f3726187b6a9af1463bae0ae [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: "));
fmalitaff3106c2014-12-09 05:28:20 -0800656 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
657 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700658 fInfo.push(SkObjectParser::PaintToString(paint));
659}
660
fmalita8c89c522014-11-08 16:18:56 -0800661void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700662 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
663}
664
fmalita55773872014-08-29 15:08:20 -0700665bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
666 canvas->clear(SK_ColorWHITE);
667 canvas->save();
668
669 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
670 xlate_and_scale_to_bounds(canvas, bounds);
671
672 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
673
674 canvas->restore();
675
676 return true;
677}
678
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000679SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
680 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000681 fRect = rect;
682 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000683
robertphillips@google.com91217d02013-03-17 18:33:46 +0000684 fInfo.push(SkObjectParser::RectToString(rect));
685 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000686}
687
fmalita8c89c522014-11-08 16:18:56 -0800688void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000689 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000690}
691
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000692SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
693 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000694 fRRect = rrect;
695 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000696
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000697 fInfo.push(SkObjectParser::RRectToString(rrect));
698 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000699}
700
fmalita8c89c522014-11-08 16:18:56 -0800701void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000702 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000703}
704
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000705bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000706 render_rrect(canvas, fRRect);
707 return true;
708}
709
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000710SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000711 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000712 const SkPaint& paint)
713 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000714 fOuter = outer;
715 fInner = inner;
716 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000717
718 fInfo.push(SkObjectParser::RRectToString(outer));
719 fInfo.push(SkObjectParser::RRectToString(inner));
720 fInfo.push(SkObjectParser::PaintToString(paint));
721}
722
fmalita8c89c522014-11-08 16:18:56 -0800723void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000724 canvas->drawDRRect(fOuter, fInner, fPaint);
725}
726
727bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
728 render_drrect(canvas, fOuter, fInner);
729 return true;
730}
731
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000732SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000733 const SkPaint* paint)
734 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000735 fBitmap = bitmap;
736 fLeft = left;
737 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700738 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000739 fPaint = *paint;
740 fPaintPtr = &fPaint;
741 } else {
742 fPaintPtr = NULL;
743 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000744
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000745 fInfo.push(SkObjectParser::BitmapToString(bitmap));
746 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
747 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700748 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000749 fInfo.push(SkObjectParser::PaintToString(*paint));
750 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000751}
752
fmalita8c89c522014-11-08 16:18:56 -0800753void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000754 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000755}
756
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000757bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000758 render_bitmap(canvas, fBitmap);
759 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000760}
761
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000762SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000763 const SkPaint& paint)
764 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000765 fText = new char[byteLength];
766 memcpy(fText, text, byteLength);
767 fByteLength = byteLength;
768 fX = x;
769 fY = y;
770 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000771
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000772 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
773 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
774 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
775 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000776}
777
fmalita8c89c522014-11-08 16:18:56 -0800778void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000779 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000780}
781
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000782SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
783 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000784 const SkPaint& paint)
785 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000786 fText = new char[byteLength];
787 memcpy(fText, text, byteLength);
788 fByteLength = byteLength;
789 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700790 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000791 fMatrix = *matrix;
792 } else {
793 fMatrix.setIdentity();
794 }
795 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000796
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000797 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
798 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700799 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000800 fInfo.push(SkObjectParser::MatrixToString(*matrix));
801 }
802 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000803}
804
fmalita8c89c522014-11-08 16:18:56 -0800805void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000806 canvas->drawTextOnPath(fText, fByteLength, fPath,
807 fMatrix.isIdentity() ? NULL : &fMatrix,
808 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000809}
810
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000811SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
812 const SkPoint vertices[], const SkPoint texs[],
813 const SkColor colors[], SkXfermode* xfermode,
814 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000815 const SkPaint& paint)
816 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000817 fVmode = vmode;
818
819 fVertexCount = vertexCount;
820
821 fVertices = new SkPoint[vertexCount];
822 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
823
bsalomon49f085d2014-09-05 13:34:00 -0700824 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000825 fTexs = new SkPoint[vertexCount];
826 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
827 } else {
828 fTexs = NULL;
829 }
830
bsalomon49f085d2014-09-05 13:34:00 -0700831 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000832 fColors = new SkColor[vertexCount];
833 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
834 } else {
835 fColors = NULL;
836 }
837
838 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700839 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000840 fXfermode->ref();
841 }
842
843 if (indexCount > 0) {
844 fIndices = new uint16_t[indexCount];
845 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
846 } else {
847 fIndices = NULL;
848 }
849
850 fIndexCount = indexCount;
851 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000852
chudy@google.com902ebe52012-06-29 14:21:22 +0000853 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000854 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
855 fInfo.push(SkObjectParser::PaintToString(paint));
856}
857
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000858SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000859 delete [] fVertices;
860 delete [] fTexs;
861 delete [] fColors;
862 SkSafeUnref(fXfermode);
863 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000864}
865
fmalita8c89c522014-11-08 16:18:56 -0800866void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000867 canvas->drawVertices(fVmode, fVertexCount, fVertices,
868 fTexs, fColors, fXfermode, fIndices,
869 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000870}
871
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000872SkRestoreCommand::SkRestoreCommand()
873 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000874 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000875}
876
fmalita8c89c522014-11-08 16:18:56 -0800877void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000878 canvas->restore();
879}
880
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000881void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000882 (*state)--;
883}
884
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000885SkRotateCommand::SkRotateCommand(SkScalar degrees)
886 : INHERITED(ROTATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000887 fDegrees = degrees;
chudy@google.com902ebe52012-06-29 14:21:22 +0000888
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000889 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000890}
891
fmalita8c89c522014-11-08 16:18:56 -0800892void SkRotateCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000893 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000894}
895
Florin Malita5f6102d2014-06-30 10:13:28 -0400896SkSaveCommand::SkSaveCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000897 : INHERITED(SAVE) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000898}
899
fmalita8c89c522014-11-08 16:18:56 -0800900void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400901 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000902}
903
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000904void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000905 (*state)++;
906}
907
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000908SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000909 SkCanvas::SaveFlags flags)
910 : INHERITED(SAVE_LAYER) {
bsalomon49f085d2014-09-05 13:34:00 -0700911 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000912 fBounds = *bounds;
913 } else {
914 fBounds.setEmpty();
915 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000916
bsalomon49f085d2014-09-05 13:34:00 -0700917 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000918 fPaint = *paint;
919 fPaintPtr = &fPaint;
920 } else {
921 fPaintPtr = NULL;
922 }
923 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000924
bsalomon49f085d2014-09-05 13:34:00 -0700925 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000926 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
927 }
bsalomon49f085d2014-09-05 13:34:00 -0700928 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000929 fInfo.push(SkObjectParser::PaintToString(*paint));
930 }
931 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000932}
933
fmalita8c89c522014-11-08 16:18:56 -0800934void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000935 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000936 fPaintPtr,
937 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000938}
939
fmalita8c89c522014-11-08 16:18:56 -0800940void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000941 canvas->save();
942}
943
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000944void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000945 (*state)++;
946}
947
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000948SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
949 : INHERITED(SCALE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000950 fSx = sx;
951 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000952
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000953 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
954 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000955}
956
fmalita8c89c522014-11-08 16:18:56 -0800957void SkScaleCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000958 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000959}
960
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000961SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
962 : INHERITED(SET_MATRIX) {
robertphillips70171682014-10-16 14:28:28 -0700963 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000964 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000965
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000966 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000967}
968
robertphillips70171682014-10-16 14:28:28 -0700969void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
970 fUserMatrix = userMatrix;
971}
972
fmalita8c89c522014-11-08 16:18:56 -0800973void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700974 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
975 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000976}
977
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000978SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
979 : INHERITED(SKEW) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000980 fSx = sx;
981 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000982
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000983 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
984 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000985}
986
fmalita8c89c522014-11-08 16:18:56 -0800987void SkSkewCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000988 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000989}
990
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000991SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
992 : INHERITED(TRANSLATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000993 fDx = dx;
994 fDy = dy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000995
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000996 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
997 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000998}
999
fmalita8c89c522014-11-08 16:18:56 -08001000void SkTranslateCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +00001001 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +00001002}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001003
1004SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001005 : INHERITED(PUSH_CULL)
1006 , fCullRect(cullRect) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001007 fInfo.push(SkObjectParser::RectToString(cullRect));
1008}
1009
fmalita8c89c522014-11-08 16:18:56 -08001010void SkPushCullCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001011 canvas->pushCull(fCullRect);
1012}
1013
fmalita8c89c522014-11-08 16:18:56 -08001014void SkPushCullCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +00001015 canvas->pushCull(fCullRect);
1016
1017 SkPaint p;
1018 p.setColor(SK_ColorCYAN);
1019 p.setStyle(SkPaint::kStroke_Style);
1020 canvas->drawRect(fCullRect, p);
1021}
1022
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001023SkPopCullCommand::SkPopCullCommand() : INHERITED(POP_CULL) { }
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001024
fmalita8c89c522014-11-08 16:18:56 -08001025void SkPopCullCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001026 canvas->popCull();
1027}