blob: 3cebca2c64588fd44f2aa9278eaf8e91eba9d6a6 [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() {
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000024 fOffset = 0;
chudy@google.com902ebe52012-06-29 14:21:22 +000025 fVisible = true;
26}
27
28SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000029 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000030}
31
32const char* SkDrawCommand::GetCommandString(DrawType type) {
33 switch (type) {
34 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
35 case DRAW_CLEAR: return "Clear";
36 case CLIP_PATH: return "Clip Path";
37 case CLIP_REGION: return "Clip Region";
38 case CLIP_RECT: return "Clip Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000039 case CLIP_RRECT: return "Clip RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000040 case CONCAT: return "Concat";
41 case DRAW_BITMAP: return "Draw Bitmap";
42 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
43 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
robertphillips@google.com84d320e2012-09-20 19:09:17 +000044 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
chudy@google.com902ebe52012-06-29 14:21:22 +000045 case DRAW_DATA: return "Draw Data";
robertphillips@google.com67baba42013-01-02 20:20:31 +000046 case DRAW_OVAL: return "Draw Oval";
chudy@google.com902ebe52012-06-29 14:21:22 +000047 case DRAW_PAINT: return "Draw Paint";
48 case DRAW_PATH: return "Draw Path";
49 case DRAW_PICTURE: return "Draw Picture";
50 case DRAW_POINTS: return "Draw Points";
51 case DRAW_POS_TEXT: return "Draw Pos Text";
52 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
53 case DRAW_RECT: return "Draw Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000054 case DRAW_RRECT: return "Draw RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000055 case DRAW_SPRITE: return "Draw Sprite";
56 case DRAW_TEXT: return "Draw Text";
57 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
58 case DRAW_VERTICES: return "Draw Vertices";
59 case RESTORE: return "Restore";
60 case ROTATE: return "Rotate";
61 case SAVE: return "Save";
62 case SAVE_LAYER: return "Save Layer";
63 case SCALE: return "Scale";
64 case SET_MATRIX: return "Set Matrix";
65 case SKEW: return "Skew";
66 case TRANSLATE: return "Translate";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000067 case NOOP: return "NoOp";
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000068 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
69 case COMMENT: return "Comment";
70 case END_COMMENT_GROUP: return "EndCommentGroup";
commit-bot@chromium.org3d305202014-02-24 17:28:55 +000071 case DRAW_DRRECT: return "Draw DRRect";
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +000072 case PUSH_CULL: return "PushCull";
73 case POP_CULL: return "PopCull";
chudy@google.com902ebe52012-06-29 14:21:22 +000074 default:
75 SkDebugf("DrawType error 0x%08x\n", type);
76 SkASSERT(0);
77 break;
78 }
79 SkDEBUGFAIL("DrawType UNUSED\n");
80 return NULL;
81}
82
chudy@google.com97cee972012-08-07 20:41:37 +000083SkString SkDrawCommand::toString() {
84 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000085}
86
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000087SkClearCommand::SkClearCommand(SkColor color) : INHERITED(DRAW_CLEAR) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000088 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000089 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000090}
91
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000092void SkClearCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000093 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000094}
95
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000096namespace {
97
98void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
99 const SkISize& size = canvas->getDeviceSize();
100
101 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
102
103 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
104 if (bounds.width() > bounds.height()) {
105 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
106 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
107 } else {
108 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
109 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
110 }
111 canvas->translate(-bounds.centerX(), -bounds.centerY());
112}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000113
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000114
115void render_path(SkCanvas* canvas, const SkPath& path) {
116 canvas->clear(0xFFFFFFFF);
117 canvas->save();
118
119 const SkRect& bounds = path.getBounds();
120
121 xlate_and_scale_to_bounds(canvas, bounds);
122
123 SkPaint p;
124 p.setColor(SK_ColorBLACK);
125 p.setStyle(SkPaint::kStroke_Style);
126
127 canvas->drawPath(path, p);
128 canvas->restore();
129}
130
131void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
132 const SkISize& size = canvas->getDeviceSize();
133
134 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
135 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
136
137 if (input.width() > input.height()) {
138 yScale *= input.height() / (float) input.width();
139 } else {
140 xScale *= input.width() / (float) input.height();
141 }
142
143 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
144 xScale * input.width(),
145 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000146
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000147 canvas->clear(0xFFFFFFFF);
148 canvas->drawBitmapRect(input, NULL, dst);
149
150 if (NULL != srcRect) {
151 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
152 srcRect->fTop * yScale + SK_Scalar1,
153 srcRect->fRight * xScale + SK_Scalar1,
154 srcRect->fBottom * yScale + SK_Scalar1);
155 SkPaint p;
156 p.setColor(SK_ColorRED);
157 p.setStyle(SkPaint::kStroke_Style);
158
159 canvas->drawRect(r, p);
160 }
161}
162
163void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
164 canvas->clear(0xFFFFFFFF);
165 canvas->save();
166
167 const SkRect& bounds = rrect.getBounds();
168
169 xlate_and_scale_to_bounds(canvas, bounds);
170
171 SkPaint p;
172 p.setColor(SK_ColorBLACK);
173 p.setStyle(SkPaint::kStroke_Style);
174
175 canvas->drawRRect(rrect, p);
176 canvas->restore();
177}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000178
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000179void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
180 canvas->clear(0xFFFFFFFF);
181 canvas->save();
182
183 const SkRect& bounds = outer.getBounds();
184
185 xlate_and_scale_to_bounds(canvas, bounds);
186
187 SkPaint p;
188 p.setColor(SK_ColorBLACK);
189 p.setStyle(SkPaint::kStroke_Style);
190
191 canvas->drawDRRect(outer, inner, p);
192 canvas->restore();
193}
194
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000195};
196
197
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000198SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
199 : INHERITED(CLIP_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000200 fPath = path;
201 fOp = op;
202 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000203
robertphillips@google.com91217d02013-03-17 18:33:46 +0000204 fInfo.push(SkObjectParser::PathToString(path));
205 fInfo.push(SkObjectParser::RegionOpToString(op));
206 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000207}
208
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000209void SkClipPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000210 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000211}
212
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000213bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000214 render_path(canvas, fPath);
215 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000216}
217
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000218SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000219 : INHERITED(CLIP_REGION) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000220 fRegion = region;
221 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000222
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000223 fInfo.push(SkObjectParser::RegionToString(region));
224 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000225}
226
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000227void SkClipRegionCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000228 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000229}
230
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000231SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
232 : INHERITED(CLIP_RECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000233 fRect = rect;
234 fOp = op;
235 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000236
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000237 fInfo.push(SkObjectParser::RectToString(rect));
238 fInfo.push(SkObjectParser::RegionOpToString(op));
239 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000240}
241
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000242void SkClipRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000243 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000244}
245
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000246SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000247 : INHERITED(CLIP_RRECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000248 fRRect = rrect;
249 fOp = op;
250 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000251
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000252 fInfo.push(SkObjectParser::RRectToString(rrect));
253 fInfo.push(SkObjectParser::RegionOpToString(op));
254 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000255}
256
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000257void SkClipRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000258 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000259}
260
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000261bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000262 render_rrect(canvas, fRRect);
263 return true;
264}
265
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000266SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
267 : INHERITED(CONCAT) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000268 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000269
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000270 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000271}
272
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000273void SkConcatCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000274 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000275}
276
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000277SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700278 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000279 : INHERITED(DRAW_BITMAP) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000280 fBitmap = bitmap;
281 fLeft = left;
282 fTop = top;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000283 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000284 fPaint = *paint;
285 fPaintPtr = &fPaint;
286 } else {
287 fPaintPtr = NULL;
288 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000289
290 fInfo.push(SkObjectParser::BitmapToString(bitmap));
291 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
292 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
293 if (NULL != paint) {
294 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000295 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000296}
297
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000298void SkDrawBitmapCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000299 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000300}
301
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000302bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000303 render_bitmap(canvas, fBitmap);
304 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000305}
306
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000307SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
308 const SkMatrix& matrix,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000309 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000310 : INHERITED(DRAW_BITMAP_MATRIX) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000311 fBitmap = bitmap;
312 fMatrix = matrix;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000313 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000314 fPaint = *paint;
315 fPaintPtr = &fPaint;
316 } else {
317 fPaintPtr = NULL;
318 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000319
320 fInfo.push(SkObjectParser::BitmapToString(bitmap));
321 fInfo.push(SkObjectParser::MatrixToString(matrix));
322 if (NULL != paint) {
323 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000324 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000325}
326
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000327void SkDrawBitmapMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000328 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000329}
330
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000331bool SkDrawBitmapMatrixCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000332 render_bitmap(canvas, fBitmap);
333 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000334}
335
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000336SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000337 const SkRect& dst, const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000338 : INHERITED(DRAW_BITMAP_NINE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000339 fBitmap = bitmap;
340 fCenter = center;
341 fDst = dst;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000342 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000343 fPaint = *paint;
344 fPaintPtr = &fPaint;
345 } else {
346 fPaintPtr = NULL;
347 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000348
349 fInfo.push(SkObjectParser::BitmapToString(bitmap));
350 fInfo.push(SkObjectParser::IRectToString(center));
351 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
352 if (NULL != paint) {
353 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000354 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000355}
356
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000357void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000358 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000359}
360
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000361bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000362 render_bitmap(canvas, fBitmap);
363 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000364}
365
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000366SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000367 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000368 SkCanvas::DrawBitmapRectFlags flags)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000369 : INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000370 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000371 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000372 fSrc = *src;
373 } else {
374 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000375 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000376 fDst = dst;
377
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000378 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000379 fPaint = *paint;
380 fPaintPtr = &fPaint;
381 } else {
382 fPaintPtr = NULL;
383 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000384 fFlags = flags;
385
robertphillips@google.com91217d02013-03-17 18:33:46 +0000386 fInfo.push(SkObjectParser::BitmapToString(bitmap));
387 if (NULL != src) {
388 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
389 }
390 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
391 if (NULL != paint) {
392 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000393 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000394 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000397void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000398 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000399}
400
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000401bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000402 render_bitmap(canvas, fBitmap, this->srcRect());
403 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000404}
405
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000406SkDrawDataCommand::SkDrawDataCommand(const void* data, size_t length)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000407 : INHERITED(DRAW_DATA) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000408 fData = new char[length];
409 memcpy(fData, data, length);
410 fLength = length;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000411
412 // TODO: add display of actual data?
413 SkString* str = new SkString;
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000414 str->appendf("length: %d", (int) length);
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000415 fInfo.push(str);
chudy@google.com902ebe52012-06-29 14:21:22 +0000416}
417
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000418void SkDrawDataCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000419 canvas->drawData(fData, fLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000420}
421
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000422SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000423 : INHERITED(BEGIN_COMMENT_GROUP)
424 , fDescription(description) {
425 SkString* temp = new SkString;
426 temp->appendf("Description: %s", description);
427 fInfo.push(temp);
428}
429
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000430SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000431 : INHERITED(COMMENT)
432 , fKywd(kywd)
433 , fValue(value) {
434 SkString* temp = new SkString;
435 temp->appendf("%s: %s", kywd, value);
436 fInfo.push(temp);
437}
438
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000439SkEndCommentGroupCommand::SkEndCommentGroupCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000440 : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000441}
442
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000443SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
444 : INHERITED(DRAW_OVAL) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000445 fOval = oval;
446 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000447
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000448 fInfo.push(SkObjectParser::RectToString(oval));
449 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000450}
451
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000452void SkDrawOvalCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000453 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000454}
455
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000456bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000457 canvas->clear(0xFFFFFFFF);
458 canvas->save();
459
460 xlate_and_scale_to_bounds(canvas, fOval);
461
462 SkPaint p;
463 p.setColor(SK_ColorBLACK);
464 p.setStyle(SkPaint::kStroke_Style);
465
466 canvas->drawOval(fOval, p);
467 canvas->restore();
468
469 return true;
470}
471
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000472SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
473 : INHERITED(DRAW_PAINT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000474 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000475
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000476 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000477}
478
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000479void SkDrawPaintCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000480 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000481}
482
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000483bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000484 canvas->clear(0xFFFFFFFF);
485 canvas->drawPaint(fPaint);
486 return true;
487}
488
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000489SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
490 : INHERITED(DRAW_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000491 fPath = path;
492 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000493
robertphillips@google.com91217d02013-03-17 18:33:46 +0000494 fInfo.push(SkObjectParser::PathToString(path));
495 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000496}
497
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000498void SkDrawPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000499 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000500}
501
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000502bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000503 render_path(canvas, fPath);
504 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000505}
506
robertphillipsb3f319f2014-08-13 10:46:23 -0700507SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
508 const SkMatrix* matrix,
509 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000510 : INHERITED(DRAW_PICTURE)
robertphillipsb3f319f2014-08-13 10:46:23 -0700511 , fPicture(SkRef(picture))
512 , fMatrixPtr(NULL)
513 , fPaintPtr(NULL) {
514
515 if (NULL != matrix) {
516 fMatrix = *matrix;
517 fMatrixPtr = &fMatrix;
518 }
519 if (NULL != paint) {
520 fPaint = *paint;
521 fPaintPtr = &fPaint;
522 }
523
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000524 SkString* temp = new SkString;
robertphillips9b14f262014-06-04 05:40:44 -0700525 temp->appendf("SkPicture: W: %d H: %d", picture->width(), picture->height());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000526 fInfo.push(temp);
robertphillipsb3f319f2014-08-13 10:46:23 -0700527 if (NULL != matrix) {
528 fInfo.push(SkObjectParser::MatrixToString(*matrix));
529 }
530 if (NULL != paint) {
531 fInfo.push(SkObjectParser::PaintToString(*paint));
532 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000533}
534
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000535void SkDrawPictureCommand::execute(SkCanvas* canvas) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700536 canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000537}
538
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000539bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
540 canvas->clear(0xFFFFFFFF);
541 canvas->save();
542
robertphillips9b14f262014-06-04 05:40:44 -0700543 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()),
544 SkIntToScalar(fPicture->height()));
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000545 xlate_and_scale_to_bounds(canvas, bounds);
546
robertphillips9b14f262014-06-04 05:40:44 -0700547 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000548
549 canvas->restore();
550
551 return true;
552}
553
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000554SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000555 const SkPoint pts[], const SkPaint& paint)
556 : INHERITED(DRAW_POINTS) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000557 fMode = mode;
558 fCount = count;
559 fPts = new SkPoint[count];
560 memcpy(fPts, pts, count * sizeof(SkPoint));
561 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000562
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000563 fInfo.push(SkObjectParser::PointsToString(pts, count));
564 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
565 "Points: "));
566 fInfo.push(SkObjectParser::PointModeToString(mode));
567 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000568}
569
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000570void SkDrawPointsCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000571 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000572}
573
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000574bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000575 canvas->clear(0xFFFFFFFF);
576 canvas->save();
577
578 SkRect bounds;
579
580 bounds.setEmpty();
581 for (unsigned int i = 0; i < fCount; ++i) {
582 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
583 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000584
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000585 xlate_and_scale_to_bounds(canvas, bounds);
586
587 SkPaint p;
588 p.setColor(SK_ColorBLACK);
589 p.setStyle(SkPaint::kStroke_Style);
590
591 canvas->drawPoints(fMode, fCount, fPts, p);
592 canvas->restore();
593
594 return true;
595}
596
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000597SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000598 const SkPoint pos[], const SkPaint& paint)
599 : INHERITED(DRAW_POS_TEXT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000600 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000601
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000602 fText = new char[byteLength];
603 memcpy(fText, text, byteLength);
604 fByteLength = byteLength;
605
606 fPos = new SkPoint[numPts];
607 memcpy(fPos, pos, numPts * sizeof(SkPoint));
608
609 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000610
611 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000612 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000613 fInfo.push(SkObjectParser::PointsToString(pos, 1));
614 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000615}
616
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000617void SkDrawPosTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000618 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000619}
620
621
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000622SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
623 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000624 const SkPaint& paint)
625 : INHERITED(DRAW_POS_TEXT_H) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000626 size_t numPts = paint.countText(text, byteLength);
627
628 fText = new char[byteLength];
629 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000630 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000631
632 fXpos = new SkScalar[numPts];
633 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
634
robertphillips@google.com91217d02013-03-17 18:33:46 +0000635 fConstY = constY;
636 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000637
robertphillips@google.com91217d02013-03-17 18:33:46 +0000638 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
639 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
640 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
641 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000642}
643
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000644void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000645 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000646}
647
fmalitab7425172014-08-26 07:56:44 -0700648SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
649 const SkPaint& paint)
650 : INHERITED(DRAW_TEXT_BLOB)
651 , fBlob(blob)
652 , fXPos(x)
653 , fYPos(y)
654 , fPaint(paint) {
655
656 blob->ref();
657
658 // FIXME: push blob info
659 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
660 fInfo.push(SkObjectParser::ScalarToString(x, "YPOS: "));
661 fInfo.push(SkObjectParser::PaintToString(paint));
662}
663
664void SkDrawTextBlobCommand::execute(SkCanvas* canvas) {
665 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
666}
667
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000668SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
669 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000670 fRect = rect;
671 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000672
robertphillips@google.com91217d02013-03-17 18:33:46 +0000673 fInfo.push(SkObjectParser::RectToString(rect));
674 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000675}
676
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000677void SkDrawRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000678 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000679}
680
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000681SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
682 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000683 fRRect = rrect;
684 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000685
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000686 fInfo.push(SkObjectParser::RRectToString(rrect));
687 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000688}
689
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000690void SkDrawRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000691 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000692}
693
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000694bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000695 render_rrect(canvas, fRRect);
696 return true;
697}
698
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000699SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000700 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000701 const SkPaint& paint)
702 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000703 fOuter = outer;
704 fInner = inner;
705 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000706
707 fInfo.push(SkObjectParser::RRectToString(outer));
708 fInfo.push(SkObjectParser::RRectToString(inner));
709 fInfo.push(SkObjectParser::PaintToString(paint));
710}
711
712void SkDrawDRRectCommand::execute(SkCanvas* canvas) {
713 canvas->drawDRRect(fOuter, fInner, fPaint);
714}
715
716bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
717 render_drrect(canvas, fOuter, fInner);
718 return true;
719}
720
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000721SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000722 const SkPaint* paint)
723 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000724 fBitmap = bitmap;
725 fLeft = left;
726 fTop = top;
727 if (NULL != paint) {
728 fPaint = *paint;
729 fPaintPtr = &fPaint;
730 } else {
731 fPaintPtr = NULL;
732 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000733
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000734 fInfo.push(SkObjectParser::BitmapToString(bitmap));
735 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
736 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
737 if (NULL != paint) {
738 fInfo.push(SkObjectParser::PaintToString(*paint));
739 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000740}
741
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000742void SkDrawSpriteCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000743 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000744}
745
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000746bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000747 render_bitmap(canvas, fBitmap);
748 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000749}
750
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000751SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000752 const SkPaint& paint)
753 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000754 fText = new char[byteLength];
755 memcpy(fText, text, byteLength);
756 fByteLength = byteLength;
757 fX = x;
758 fY = y;
759 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000760
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000761 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
762 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
763 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
764 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000765}
766
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000767void SkDrawTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000768 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000769}
770
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000771SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
772 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000773 const SkPaint& paint)
774 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000775 fText = new char[byteLength];
776 memcpy(fText, text, byteLength);
777 fByteLength = byteLength;
778 fPath = path;
779 if (NULL != matrix) {
780 fMatrix = *matrix;
781 } else {
782 fMatrix.setIdentity();
783 }
784 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000785
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000786 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
787 fInfo.push(SkObjectParser::PathToString(path));
788 if (NULL != matrix) {
789 fInfo.push(SkObjectParser::MatrixToString(*matrix));
790 }
791 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000792}
793
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000794void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000795 canvas->drawTextOnPath(fText, fByteLength, fPath,
796 fMatrix.isIdentity() ? NULL : &fMatrix,
797 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000798}
799
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000800SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
801 const SkPoint vertices[], const SkPoint texs[],
802 const SkColor colors[], SkXfermode* xfermode,
803 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000804 const SkPaint& paint)
805 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000806 fVmode = vmode;
807
808 fVertexCount = vertexCount;
809
810 fVertices = new SkPoint[vertexCount];
811 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
812
813 if (NULL != texs) {
814 fTexs = new SkPoint[vertexCount];
815 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
816 } else {
817 fTexs = NULL;
818 }
819
820 if (NULL != colors) {
821 fColors = new SkColor[vertexCount];
822 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
823 } else {
824 fColors = NULL;
825 }
826
827 fXfermode = xfermode;
828 if (NULL != fXfermode) {
829 fXfermode->ref();
830 }
831
832 if (indexCount > 0) {
833 fIndices = new uint16_t[indexCount];
834 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
835 } else {
836 fIndices = NULL;
837 }
838
839 fIndexCount = indexCount;
840 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000841
chudy@google.com902ebe52012-06-29 14:21:22 +0000842 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000843 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
844 fInfo.push(SkObjectParser::PaintToString(paint));
845}
846
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000847SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000848 delete [] fVertices;
849 delete [] fTexs;
850 delete [] fColors;
851 SkSafeUnref(fXfermode);
852 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000853}
854
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000855void SkDrawVerticesCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000856 canvas->drawVertices(fVmode, fVertexCount, fVertices,
857 fTexs, fColors, fXfermode, fIndices,
858 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000859}
860
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000861SkRestoreCommand::SkRestoreCommand()
862 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000863 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000864}
865
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000866void SkRestoreCommand::execute(SkCanvas* canvas) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000867 canvas->restore();
868}
869
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000870void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000871 (*state)--;
872}
873
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000874SkRotateCommand::SkRotateCommand(SkScalar degrees)
875 : INHERITED(ROTATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000876 fDegrees = degrees;
chudy@google.com902ebe52012-06-29 14:21:22 +0000877
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000878 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000879}
880
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000881void SkRotateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000882 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000883}
884
Florin Malita5f6102d2014-06-30 10:13:28 -0400885SkSaveCommand::SkSaveCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000886 : INHERITED(SAVE) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000887}
888
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000889void SkSaveCommand::execute(SkCanvas* canvas) {
Florin Malita5f6102d2014-06-30 10:13:28 -0400890 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000891}
892
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000893void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000894 (*state)++;
895}
896
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000897SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000898 SkCanvas::SaveFlags flags)
899 : INHERITED(SAVE_LAYER) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000900 if (NULL != bounds) {
901 fBounds = *bounds;
902 } else {
903 fBounds.setEmpty();
904 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000905
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000906 if (NULL != paint) {
907 fPaint = *paint;
908 fPaintPtr = &fPaint;
909 } else {
910 fPaintPtr = NULL;
911 }
912 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000913
914 if (NULL != bounds) {
915 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
916 }
917 if (NULL != paint) {
918 fInfo.push(SkObjectParser::PaintToString(*paint));
919 }
920 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000921}
922
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000923void SkSaveLayerCommand::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000924 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000925 fPaintPtr,
926 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000927}
928
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000929void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) {
930 canvas->save();
931}
932
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000933void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000934 (*state)++;
935}
936
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000937SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
938 : INHERITED(SCALE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000939 fSx = sx;
940 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000941
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000942 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
943 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000944}
945
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000946void SkScaleCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000947 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000948}
949
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000950SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
951 : INHERITED(SET_MATRIX) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000952 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000953
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000954 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000955}
956
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000957void SkSetMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000958 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000959}
960
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000961SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
962 : INHERITED(SKEW) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000963 fSx = sx;
964 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000965
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000966 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
967 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000968}
969
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000970void SkSkewCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000971 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000972}
973
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000974SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
975 : INHERITED(TRANSLATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000976 fDx = dx;
977 fDy = dy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000978
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000979 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
980 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000981}
982
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000983void SkTranslateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000984 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000985}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000986
987SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000988 : INHERITED(PUSH_CULL)
989 , fCullRect(cullRect) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000990 fInfo.push(SkObjectParser::RectToString(cullRect));
991}
992
993void SkPushCullCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000994 canvas->pushCull(fCullRect);
995}
996
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000997void SkPushCullCommand::vizExecute(SkCanvas* canvas) {
998 canvas->pushCull(fCullRect);
999
1000 SkPaint p;
1001 p.setColor(SK_ColorCYAN);
1002 p.setStyle(SkPaint::kStroke_Style);
1003 canvas->drawRect(fCullRect, p);
1004}
1005
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001006SkPopCullCommand::SkPopCullCommand() : INHERITED(POP_CULL) { }
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001007
1008void SkPopCullCommand::execute(SkCanvas* canvas) {
1009 canvas->popCull();
1010}