blob: 3a073962ccacbbeaf72940b14233b13798b014a4 [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";
fmalita30313502014-08-27 08:41:25 -070057 case DRAW_TEXT_BLOB: return "Draw Text Blob";
chudy@google.com902ebe52012-06-29 14:21:22 +000058 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
59 case DRAW_VERTICES: return "Draw Vertices";
60 case RESTORE: return "Restore";
61 case ROTATE: return "Rotate";
62 case SAVE: return "Save";
63 case SAVE_LAYER: return "Save Layer";
64 case SCALE: return "Scale";
65 case SET_MATRIX: return "Set Matrix";
66 case SKEW: return "Skew";
67 case TRANSLATE: return "Translate";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000068 case NOOP: return "NoOp";
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000069 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
70 case COMMENT: return "Comment";
71 case END_COMMENT_GROUP: return "EndCommentGroup";
commit-bot@chromium.org3d305202014-02-24 17:28:55 +000072 case DRAW_DRRECT: return "Draw DRRect";
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +000073 case PUSH_CULL: return "PushCull";
74 case POP_CULL: return "PopCull";
chudy@google.com902ebe52012-06-29 14:21:22 +000075 default:
76 SkDebugf("DrawType error 0x%08x\n", type);
77 SkASSERT(0);
78 break;
79 }
80 SkDEBUGFAIL("DrawType UNUSED\n");
81 return NULL;
82}
83
chudy@google.com97cee972012-08-07 20:41:37 +000084SkString SkDrawCommand::toString() {
85 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000086}
87
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000088SkClearCommand::SkClearCommand(SkColor color) : INHERITED(DRAW_CLEAR) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000089 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000090 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000091}
92
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000093void SkClearCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000094 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000095}
96
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000097namespace {
98
99void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
100 const SkISize& size = canvas->getDeviceSize();
101
102 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
103
104 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
105 if (bounds.width() > bounds.height()) {
106 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
107 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
108 } else {
109 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
110 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
111 }
112 canvas->translate(-bounds.centerX(), -bounds.centerY());
113}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000114
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000115
116void render_path(SkCanvas* canvas, const SkPath& path) {
117 canvas->clear(0xFFFFFFFF);
118 canvas->save();
119
120 const SkRect& bounds = path.getBounds();
121
122 xlate_and_scale_to_bounds(canvas, bounds);
123
124 SkPaint p;
125 p.setColor(SK_ColorBLACK);
126 p.setStyle(SkPaint::kStroke_Style);
127
128 canvas->drawPath(path, p);
129 canvas->restore();
130}
131
132void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
133 const SkISize& size = canvas->getDeviceSize();
134
135 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
136 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
137
138 if (input.width() > input.height()) {
139 yScale *= input.height() / (float) input.width();
140 } else {
141 xScale *= input.width() / (float) input.height();
142 }
143
144 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
145 xScale * input.width(),
146 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000147
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000148 canvas->clear(0xFFFFFFFF);
149 canvas->drawBitmapRect(input, NULL, dst);
150
151 if (NULL != srcRect) {
152 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
153 srcRect->fTop * yScale + SK_Scalar1,
154 srcRect->fRight * xScale + SK_Scalar1,
155 srcRect->fBottom * yScale + SK_Scalar1);
156 SkPaint p;
157 p.setColor(SK_ColorRED);
158 p.setStyle(SkPaint::kStroke_Style);
159
160 canvas->drawRect(r, p);
161 }
162}
163
164void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
165 canvas->clear(0xFFFFFFFF);
166 canvas->save();
167
168 const SkRect& bounds = rrect.getBounds();
169
170 xlate_and_scale_to_bounds(canvas, bounds);
171
172 SkPaint p;
173 p.setColor(SK_ColorBLACK);
174 p.setStyle(SkPaint::kStroke_Style);
175
176 canvas->drawRRect(rrect, p);
177 canvas->restore();
178}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000179
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000180void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
181 canvas->clear(0xFFFFFFFF);
182 canvas->save();
183
184 const SkRect& bounds = outer.getBounds();
185
186 xlate_and_scale_to_bounds(canvas, bounds);
187
188 SkPaint p;
189 p.setColor(SK_ColorBLACK);
190 p.setStyle(SkPaint::kStroke_Style);
191
192 canvas->drawDRRect(outer, inner, p);
193 canvas->restore();
194}
195
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000196};
197
198
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000199SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
200 : INHERITED(CLIP_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000201 fPath = path;
202 fOp = op;
203 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000204
robertphillips@google.com91217d02013-03-17 18:33:46 +0000205 fInfo.push(SkObjectParser::PathToString(path));
206 fInfo.push(SkObjectParser::RegionOpToString(op));
207 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000208}
209
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000210void SkClipPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000211 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000212}
213
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000214bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000215 render_path(canvas, fPath);
216 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000217}
218
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000219SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000220 : INHERITED(CLIP_REGION) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000221 fRegion = region;
222 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000223
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000224 fInfo.push(SkObjectParser::RegionToString(region));
225 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000226}
227
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000228void SkClipRegionCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000229 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000230}
231
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000232SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
233 : INHERITED(CLIP_RECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000234 fRect = rect;
235 fOp = op;
236 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000237
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000238 fInfo.push(SkObjectParser::RectToString(rect));
239 fInfo.push(SkObjectParser::RegionOpToString(op));
240 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000241}
242
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000243void SkClipRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000244 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000245}
246
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000247SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000248 : INHERITED(CLIP_RRECT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000249 fRRect = rrect;
250 fOp = op;
251 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000252
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000253 fInfo.push(SkObjectParser::RRectToString(rrect));
254 fInfo.push(SkObjectParser::RegionOpToString(op));
255 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000256}
257
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000258void SkClipRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000259 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000260}
261
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000262bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000263 render_rrect(canvas, fRRect);
264 return true;
265}
266
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000267SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
268 : INHERITED(CONCAT) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000269 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000270
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000271 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000272}
273
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000274void SkConcatCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000275 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000276}
277
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000278SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700279 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000280 : INHERITED(DRAW_BITMAP) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000281 fBitmap = bitmap;
282 fLeft = left;
283 fTop = top;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000284 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000285 fPaint = *paint;
286 fPaintPtr = &fPaint;
287 } else {
288 fPaintPtr = NULL;
289 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000290
291 fInfo.push(SkObjectParser::BitmapToString(bitmap));
292 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
293 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
294 if (NULL != paint) {
295 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000296 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000297}
298
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000299void SkDrawBitmapCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000300 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000301}
302
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000303bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000304 render_bitmap(canvas, fBitmap);
305 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000306}
307
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000308SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
309 const SkMatrix& matrix,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000310 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000311 : INHERITED(DRAW_BITMAP_MATRIX) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000312 fBitmap = bitmap;
313 fMatrix = matrix;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000314 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000315 fPaint = *paint;
316 fPaintPtr = &fPaint;
317 } else {
318 fPaintPtr = NULL;
319 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000320
321 fInfo.push(SkObjectParser::BitmapToString(bitmap));
322 fInfo.push(SkObjectParser::MatrixToString(matrix));
323 if (NULL != paint) {
324 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000325 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000326}
327
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000328void SkDrawBitmapMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000329 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000330}
331
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000332bool SkDrawBitmapMatrixCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000333 render_bitmap(canvas, fBitmap);
334 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000335}
336
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000337SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000338 const SkRect& dst, const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000339 : INHERITED(DRAW_BITMAP_NINE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000340 fBitmap = bitmap;
341 fCenter = center;
342 fDst = dst;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000343 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000344 fPaint = *paint;
345 fPaintPtr = &fPaint;
346 } else {
347 fPaintPtr = NULL;
348 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000349
350 fInfo.push(SkObjectParser::BitmapToString(bitmap));
351 fInfo.push(SkObjectParser::IRectToString(center));
352 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
353 if (NULL != paint) {
354 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000355 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000356}
357
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000358void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000359 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000360}
361
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000362bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000363 render_bitmap(canvas, fBitmap);
364 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000365}
366
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000367SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000368 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000369 SkCanvas::DrawBitmapRectFlags flags)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000370 : INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000371 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000372 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000373 fSrc = *src;
374 } else {
375 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000376 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000377 fDst = dst;
378
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000379 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000380 fPaint = *paint;
381 fPaintPtr = &fPaint;
382 } else {
383 fPaintPtr = NULL;
384 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000385 fFlags = flags;
386
robertphillips@google.com91217d02013-03-17 18:33:46 +0000387 fInfo.push(SkObjectParser::BitmapToString(bitmap));
388 if (NULL != src) {
389 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
390 }
391 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
392 if (NULL != paint) {
393 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000394 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000395 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000396}
397
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000398void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000399 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000400}
401
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000402bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000403 render_bitmap(canvas, fBitmap, this->srcRect());
404 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000405}
406
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000407SkDrawDataCommand::SkDrawDataCommand(const void* data, size_t length)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000408 : INHERITED(DRAW_DATA) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000409 fData = new char[length];
410 memcpy(fData, data, length);
411 fLength = length;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000412
413 // TODO: add display of actual data?
414 SkString* str = new SkString;
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000415 str->appendf("length: %d", (int) length);
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000416 fInfo.push(str);
chudy@google.com902ebe52012-06-29 14:21:22 +0000417}
418
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000419void SkDrawDataCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000420 canvas->drawData(fData, fLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000421}
422
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000423SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000424 : INHERITED(BEGIN_COMMENT_GROUP)
425 , fDescription(description) {
426 SkString* temp = new SkString;
427 temp->appendf("Description: %s", description);
428 fInfo.push(temp);
429}
430
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000431SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000432 : INHERITED(COMMENT)
433 , fKywd(kywd)
434 , fValue(value) {
435 SkString* temp = new SkString;
436 temp->appendf("%s: %s", kywd, value);
437 fInfo.push(temp);
438}
439
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000440SkEndCommentGroupCommand::SkEndCommentGroupCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000441 : INHERITED(END_COMMENT_GROUP) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000442}
443
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000444SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
445 : INHERITED(DRAW_OVAL) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000446 fOval = oval;
447 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000448
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000449 fInfo.push(SkObjectParser::RectToString(oval));
450 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000451}
452
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000453void SkDrawOvalCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000454 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000455}
456
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000457bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000458 canvas->clear(0xFFFFFFFF);
459 canvas->save();
460
461 xlate_and_scale_to_bounds(canvas, fOval);
462
463 SkPaint p;
464 p.setColor(SK_ColorBLACK);
465 p.setStyle(SkPaint::kStroke_Style);
466
467 canvas->drawOval(fOval, p);
468 canvas->restore();
469
470 return true;
471}
472
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000473SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
474 : INHERITED(DRAW_PAINT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000475 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000476
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000477 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000478}
479
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000480void SkDrawPaintCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000481 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000482}
483
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000484bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000485 canvas->clear(0xFFFFFFFF);
486 canvas->drawPaint(fPaint);
487 return true;
488}
489
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000490SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
491 : INHERITED(DRAW_PATH) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000492 fPath = path;
493 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000494
robertphillips@google.com91217d02013-03-17 18:33:46 +0000495 fInfo.push(SkObjectParser::PathToString(path));
496 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000497}
498
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000499void SkDrawPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000500 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000501}
502
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000503bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000504 render_path(canvas, fPath);
505 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000506}
507
robertphillipsb3f319f2014-08-13 10:46:23 -0700508SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
509 const SkMatrix* matrix,
510 const SkPaint* paint)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000511 : INHERITED(DRAW_PICTURE)
robertphillipsb3f319f2014-08-13 10:46:23 -0700512 , fPicture(SkRef(picture))
513 , fMatrixPtr(NULL)
514 , fPaintPtr(NULL) {
515
516 if (NULL != matrix) {
517 fMatrix = *matrix;
518 fMatrixPtr = &fMatrix;
519 }
520 if (NULL != paint) {
521 fPaint = *paint;
522 fPaintPtr = &fPaint;
523 }
524
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000525 SkString* temp = new SkString;
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700526 temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
527 picture->cullRect().fLeft, picture->cullRect().fTop,
528 picture->cullRect().fRight, picture->cullRect().fBottom);
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000529 fInfo.push(temp);
robertphillipsb3f319f2014-08-13 10:46:23 -0700530 if (NULL != matrix) {
531 fInfo.push(SkObjectParser::MatrixToString(*matrix));
532 }
533 if (NULL != paint) {
534 fInfo.push(SkObjectParser::PaintToString(*paint));
535 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000536}
537
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000538void SkDrawPictureCommand::execute(SkCanvas* canvas) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700539 canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000540}
541
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000542bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
543 canvas->clear(0xFFFFFFFF);
544 canvas->save();
545
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700546 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000547
robertphillips9b14f262014-06-04 05:40:44 -0700548 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000549
550 canvas->restore();
551
552 return true;
553}
554
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000555SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000556 const SkPoint pts[], const SkPaint& paint)
557 : INHERITED(DRAW_POINTS) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000558 fMode = mode;
559 fCount = count;
560 fPts = new SkPoint[count];
561 memcpy(fPts, pts, count * sizeof(SkPoint));
562 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000563
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000564 fInfo.push(SkObjectParser::PointsToString(pts, count));
565 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
566 "Points: "));
567 fInfo.push(SkObjectParser::PointModeToString(mode));
568 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000569}
570
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000571void SkDrawPointsCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000572 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000573}
574
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000575bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000576 canvas->clear(0xFFFFFFFF);
577 canvas->save();
578
579 SkRect bounds;
580
581 bounds.setEmpty();
582 for (unsigned int i = 0; i < fCount; ++i) {
583 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
584 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000585
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000586 xlate_and_scale_to_bounds(canvas, bounds);
587
588 SkPaint p;
589 p.setColor(SK_ColorBLACK);
590 p.setStyle(SkPaint::kStroke_Style);
591
592 canvas->drawPoints(fMode, fCount, fPts, p);
593 canvas->restore();
594
595 return true;
596}
597
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000598SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000599 const SkPoint pos[], const SkPaint& paint)
600 : INHERITED(DRAW_POS_TEXT) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000601 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000602
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000603 fText = new char[byteLength];
604 memcpy(fText, text, byteLength);
605 fByteLength = byteLength;
606
607 fPos = new SkPoint[numPts];
608 memcpy(fPos, pos, numPts * sizeof(SkPoint));
609
610 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000611
612 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000613 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000614 fInfo.push(SkObjectParser::PointsToString(pos, 1));
615 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000616}
617
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000618void SkDrawPosTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000619 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000620}
621
622
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000623SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
624 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000625 const SkPaint& paint)
626 : INHERITED(DRAW_POS_TEXT_H) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000627 size_t numPts = paint.countText(text, byteLength);
628
629 fText = new char[byteLength];
630 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000631 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000632
633 fXpos = new SkScalar[numPts];
634 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
635
robertphillips@google.com91217d02013-03-17 18:33:46 +0000636 fConstY = constY;
637 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000638
robertphillips@google.com91217d02013-03-17 18:33:46 +0000639 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
640 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
641 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
642 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000643}
644
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000645void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000646 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000647}
648
fmalitab7425172014-08-26 07:56:44 -0700649SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
650 const SkPaint& paint)
651 : INHERITED(DRAW_TEXT_BLOB)
652 , fBlob(blob)
653 , fXPos(x)
654 , fYPos(y)
655 , fPaint(paint) {
656
657 blob->ref();
658
659 // FIXME: push blob info
660 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
661 fInfo.push(SkObjectParser::ScalarToString(x, "YPOS: "));
662 fInfo.push(SkObjectParser::PaintToString(paint));
663}
664
665void SkDrawTextBlobCommand::execute(SkCanvas* canvas) {
666 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
667}
668
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000669SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
670 : INHERITED(DRAW_RECT) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000671 fRect = rect;
672 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000673
robertphillips@google.com91217d02013-03-17 18:33:46 +0000674 fInfo.push(SkObjectParser::RectToString(rect));
675 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000676}
677
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000678void SkDrawRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000679 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000680}
681
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000682SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
683 : INHERITED(DRAW_RRECT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000684 fRRect = rrect;
685 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000686
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000687 fInfo.push(SkObjectParser::RRectToString(rrect));
688 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000689}
690
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000691void SkDrawRRectCommand::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000692 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000693}
694
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000695bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000696 render_rrect(canvas, fRRect);
697 return true;
698}
699
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000700SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000701 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000702 const SkPaint& paint)
703 : INHERITED(DRAW_DRRECT) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000704 fOuter = outer;
705 fInner = inner;
706 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000707
708 fInfo.push(SkObjectParser::RRectToString(outer));
709 fInfo.push(SkObjectParser::RRectToString(inner));
710 fInfo.push(SkObjectParser::PaintToString(paint));
711}
712
713void SkDrawDRRectCommand::execute(SkCanvas* canvas) {
714 canvas->drawDRRect(fOuter, fInner, fPaint);
715}
716
717bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
718 render_drrect(canvas, fOuter, fInner);
719 return true;
720}
721
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000722SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000723 const SkPaint* paint)
724 : INHERITED(DRAW_SPRITE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000725 fBitmap = bitmap;
726 fLeft = left;
727 fTop = top;
728 if (NULL != paint) {
729 fPaint = *paint;
730 fPaintPtr = &fPaint;
731 } else {
732 fPaintPtr = NULL;
733 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000734
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000735 fInfo.push(SkObjectParser::BitmapToString(bitmap));
736 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
737 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
738 if (NULL != paint) {
739 fInfo.push(SkObjectParser::PaintToString(*paint));
740 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000741}
742
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000743void SkDrawSpriteCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000744 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000745}
746
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000747bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000748 render_bitmap(canvas, fBitmap);
749 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000750}
751
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000752SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000753 const SkPaint& paint)
754 : INHERITED(DRAW_TEXT) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000755 fText = new char[byteLength];
756 memcpy(fText, text, byteLength);
757 fByteLength = byteLength;
758 fX = x;
759 fY = y;
760 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000761
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000762 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
763 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
764 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
765 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000766}
767
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000768void SkDrawTextCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000769 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000770}
771
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000772SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
773 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000774 const SkPaint& paint)
775 : INHERITED(DRAW_TEXT_ON_PATH) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000776 fText = new char[byteLength];
777 memcpy(fText, text, byteLength);
778 fByteLength = byteLength;
779 fPath = path;
780 if (NULL != matrix) {
781 fMatrix = *matrix;
782 } else {
783 fMatrix.setIdentity();
784 }
785 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000786
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000787 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
788 fInfo.push(SkObjectParser::PathToString(path));
789 if (NULL != matrix) {
790 fInfo.push(SkObjectParser::MatrixToString(*matrix));
791 }
792 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000793}
794
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000795void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000796 canvas->drawTextOnPath(fText, fByteLength, fPath,
797 fMatrix.isIdentity() ? NULL : &fMatrix,
798 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000799}
800
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000801SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
802 const SkPoint vertices[], const SkPoint texs[],
803 const SkColor colors[], SkXfermode* xfermode,
804 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000805 const SkPaint& paint)
806 : INHERITED(DRAW_VERTICES) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000807 fVmode = vmode;
808
809 fVertexCount = vertexCount;
810
811 fVertices = new SkPoint[vertexCount];
812 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
813
814 if (NULL != texs) {
815 fTexs = new SkPoint[vertexCount];
816 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
817 } else {
818 fTexs = NULL;
819 }
820
821 if (NULL != colors) {
822 fColors = new SkColor[vertexCount];
823 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
824 } else {
825 fColors = NULL;
826 }
827
828 fXfermode = xfermode;
829 if (NULL != fXfermode) {
830 fXfermode->ref();
831 }
832
833 if (indexCount > 0) {
834 fIndices = new uint16_t[indexCount];
835 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
836 } else {
837 fIndices = NULL;
838 }
839
840 fIndexCount = indexCount;
841 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000842
chudy@google.com902ebe52012-06-29 14:21:22 +0000843 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000844 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
845 fInfo.push(SkObjectParser::PaintToString(paint));
846}
847
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000848SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000849 delete [] fVertices;
850 delete [] fTexs;
851 delete [] fColors;
852 SkSafeUnref(fXfermode);
853 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000854}
855
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000856void SkDrawVerticesCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000857 canvas->drawVertices(fVmode, fVertexCount, fVertices,
858 fTexs, fColors, fXfermode, fIndices,
859 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000860}
861
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000862SkRestoreCommand::SkRestoreCommand()
863 : INHERITED(RESTORE) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000864 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000865}
866
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000867void SkRestoreCommand::execute(SkCanvas* canvas) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000868 canvas->restore();
869}
870
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000871void SkRestoreCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000872 (*state)--;
873}
874
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000875SkRotateCommand::SkRotateCommand(SkScalar degrees)
876 : INHERITED(ROTATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000877 fDegrees = degrees;
chudy@google.com902ebe52012-06-29 14:21:22 +0000878
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000879 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000880}
881
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000882void SkRotateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000883 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000884}
885
Florin Malita5f6102d2014-06-30 10:13:28 -0400886SkSaveCommand::SkSaveCommand()
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000887 : INHERITED(SAVE) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000888}
889
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000890void SkSaveCommand::execute(SkCanvas* canvas) {
Florin Malita5f6102d2014-06-30 10:13:28 -0400891 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000892}
893
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000894void SkSaveCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000895 (*state)++;
896}
897
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000898SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000899 SkCanvas::SaveFlags flags)
900 : INHERITED(SAVE_LAYER) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000901 if (NULL != bounds) {
902 fBounds = *bounds;
903 } else {
904 fBounds.setEmpty();
905 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000906
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000907 if (NULL != paint) {
908 fPaint = *paint;
909 fPaintPtr = &fPaint;
910 } else {
911 fPaintPtr = NULL;
912 }
913 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000914
915 if (NULL != bounds) {
916 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
917 }
918 if (NULL != paint) {
919 fInfo.push(SkObjectParser::PaintToString(*paint));
920 }
921 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000922}
923
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000924void SkSaveLayerCommand::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000925 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000926 fPaintPtr,
927 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000928}
929
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000930void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) {
931 canvas->save();
932}
933
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000934void SkSaveLayerCommand::trackSaveState(int* state) {
tomhudson@google.com0699e022012-11-27 16:09:42 +0000935 (*state)++;
936}
937
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000938SkScaleCommand::SkScaleCommand(SkScalar sx, SkScalar sy)
939 : INHERITED(SCALE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000940 fSx = sx;
941 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000942
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000943 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
944 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000945}
946
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000947void SkScaleCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000948 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000949}
950
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000951SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
952 : INHERITED(SET_MATRIX) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000953 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000954
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000955 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000956}
957
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000958void SkSetMatrixCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000959 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000960}
961
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000962SkSkewCommand::SkSkewCommand(SkScalar sx, SkScalar sy)
963 : INHERITED(SKEW) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000964 fSx = sx;
965 fSy = sy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000966
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000967 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
968 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000969}
970
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000971void SkSkewCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000972 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000973}
974
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000975SkTranslateCommand::SkTranslateCommand(SkScalar dx, SkScalar dy)
976 : INHERITED(TRANSLATE) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000977 fDx = dx;
978 fDy = dy;
chudy@google.com902ebe52012-06-29 14:21:22 +0000979
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000980 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
981 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000982}
983
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000984void SkTranslateCommand::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000985 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000986}
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000987
988SkPushCullCommand::SkPushCullCommand(const SkRect& cullRect)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000989 : INHERITED(PUSH_CULL)
990 , fCullRect(cullRect) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000991 fInfo.push(SkObjectParser::RectToString(cullRect));
992}
993
994void SkPushCullCommand::execute(SkCanvas* canvas) {
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000995 canvas->pushCull(fCullRect);
996}
997
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000998void SkPushCullCommand::vizExecute(SkCanvas* canvas) {
999 canvas->pushCull(fCullRect);
1000
1001 SkPaint p;
1002 p.setColor(SK_ColorCYAN);
1003 p.setStyle(SkPaint::kStroke_Style);
1004 canvas->drawRect(fCullRect, p);
1005}
1006
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +00001007SkPopCullCommand::SkPopCullCommand() : INHERITED(POP_CULL) { }
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +00001008
1009void SkPopCullCommand::execute(SkCanvas* canvas) {
1010 canvas->popCull();
1011}