blob: 71a7344046191147fe696194cd1649783590bad0 [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"
robertphillips9bafc302015-02-13 11:13:00 -080012#include "SkPicture.h"
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
robertphillips9bafc302015-02-13 11:13:00 -080017const char* SkDrawCommand::kDrawRectString = "DrawRect";
18const char* SkDrawCommand::kClipRectString = "ClipRect";
robertphillips72942b82015-02-12 06:37:12 -080019
robertphillips9bafc302015-02-13 11:13:00 -080020SkDrawCommand::SkDrawCommand(OpType type)
21 : fOpType(type)
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000022 , fOffset(0)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000023 , fVisible(true) {
24}
25
chudy@google.com902ebe52012-06-29 14:21:22 +000026SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000027 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000028}
29
robertphillips9bafc302015-02-13 11:13:00 -080030const char* SkDrawCommand::GetCommandString(OpType type) {
chudy@google.com902ebe52012-06-29 14:21:22 +000031 switch (type) {
robertphillips9bafc302015-02-13 11:13:00 -080032 case kBeginCommentGroup_OpType: return "BeginCommentGroup";
33 case kClipPath_OpType: return "ClipPath";
34 case kClipRegion_OpType: return "ClipRegion";
35 case kClipRect_OpType: return "ClipRect";
36 case kClipRRect_OpType: return "ClipRRect";
37 case kComment_OpType: return "Comment";
38 case kConcat_OpType: return "Concat";
39 case kDrawBitmap_OpType: return "DrawBitmap";
40 case kDrawBitmapNine_OpType: return "DrawBitmapNine";
41 case kDrawBitmapRect_OpType: return "DrawBitmapRect";
42 case kDrawClear_OpType: return "DrawClear";
43 case kDrawDRRect_OpType: return "DrawDRRect";
44 case kDrawOval_OpType: return "DrawOval";
45 case kDrawPaint_OpType: return "DrawPaint";
46 case kDrawPatch_OpType: return "DrawPatch";
47 case kDrawPath_OpType: return "DrawPath";
48 case kDrawPicture_OpType: return "DrawPicture";
49 case kDrawPoints_OpType: return "DrawPoints";
50 case kDrawPosText_OpType: return "DrawPosText";
51 case kDrawPosTextH_OpType: return "DrawPosTextH";
52 case kDrawRect_OpType: return "DrawRect";
53 case kDrawRRect_OpType: return "DrawRRect";
54 case kDrawSprite_OpType: return "DrawSprite";
55 case kDrawText_OpType: return "DrawText";
56 case kDrawTextBlob_OpType: return "DrawTextBlob";
57 case kDrawTextOnPath_OpType: return "DrawTextOnPath";
58 case kDrawVertices_OpType: return "DrawVertices";
59 case kEndCommentGroup_OpType: return "EndCommentGroup";
60 case kRestore_OpType: return "Restore";
61 case kSave_OpType: return "Save";
62 case kSaveLayer_OpType: return "SaveLayer";
63 case kSetMatrix_OpType: return "SetMatrix";
chudy@google.com902ebe52012-06-29 14:21:22 +000064 default:
robertphillips9bafc302015-02-13 11:13:00 -080065 SkDebugf("OpType error 0x%08x\n", type);
chudy@google.com902ebe52012-06-29 14:21:22 +000066 SkASSERT(0);
67 break;
68 }
69 SkDEBUGFAIL("DrawType UNUSED\n");
70 return NULL;
71}
72
fmalita8c89c522014-11-08 16:18:56 -080073SkString SkDrawCommand::toString() const {
robertphillips9bafc302015-02-13 11:13:00 -080074 return SkString(GetCommandString(fOpType));
chudy@google.com902ebe52012-06-29 14:21:22 +000075}
76
robertphillips9bafc302015-02-13 11:13:00 -080077SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000078 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000079 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000080}
81
fmalita8c89c522014-11-08 16:18:56 -080082void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000083 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000084}
85
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000086namespace {
87
88void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
89 const SkISize& size = canvas->getDeviceSize();
90
91 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
92
93 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
94 if (bounds.width() > bounds.height()) {
95 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
96 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
97 } else {
98 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
99 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
100 }
101 canvas->translate(-bounds.centerX(), -bounds.centerY());
102}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000103
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000104
105void render_path(SkCanvas* canvas, const SkPath& path) {
106 canvas->clear(0xFFFFFFFF);
107 canvas->save();
108
109 const SkRect& bounds = path.getBounds();
110
111 xlate_and_scale_to_bounds(canvas, bounds);
112
113 SkPaint p;
114 p.setColor(SK_ColorBLACK);
115 p.setStyle(SkPaint::kStroke_Style);
116
117 canvas->drawPath(path, p);
118 canvas->restore();
119}
120
121void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
122 const SkISize& size = canvas->getDeviceSize();
123
124 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
125 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
126
127 if (input.width() > input.height()) {
128 yScale *= input.height() / (float) input.width();
129 } else {
130 xScale *= input.width() / (float) input.height();
131 }
132
133 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
134 xScale * input.width(),
135 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000136
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000137 canvas->clear(0xFFFFFFFF);
138 canvas->drawBitmapRect(input, NULL, dst);
139
bsalomon49f085d2014-09-05 13:34:00 -0700140 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000141 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
142 srcRect->fTop * yScale + SK_Scalar1,
143 srcRect->fRight * xScale + SK_Scalar1,
144 srcRect->fBottom * yScale + SK_Scalar1);
145 SkPaint p;
146 p.setColor(SK_ColorRED);
147 p.setStyle(SkPaint::kStroke_Style);
148
149 canvas->drawRect(r, p);
150 }
151}
152
153void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
154 canvas->clear(0xFFFFFFFF);
155 canvas->save();
156
157 const SkRect& bounds = rrect.getBounds();
158
159 xlate_and_scale_to_bounds(canvas, bounds);
160
161 SkPaint p;
162 p.setColor(SK_ColorBLACK);
163 p.setStyle(SkPaint::kStroke_Style);
164
165 canvas->drawRRect(rrect, p);
166 canvas->restore();
167}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000168
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000169void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
170 canvas->clear(0xFFFFFFFF);
171 canvas->save();
172
173 const SkRect& bounds = outer.getBounds();
174
175 xlate_and_scale_to_bounds(canvas, bounds);
176
177 SkPaint p;
178 p.setColor(SK_ColorBLACK);
179 p.setStyle(SkPaint::kStroke_Style);
180
181 canvas->drawDRRect(outer, inner, p);
182 canvas->restore();
183}
184
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000185};
186
187
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000188SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800189 : INHERITED(kClipPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000190 fPath = path;
191 fOp = op;
192 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000193
robertphillips@google.com91217d02013-03-17 18:33:46 +0000194 fInfo.push(SkObjectParser::PathToString(path));
195 fInfo.push(SkObjectParser::RegionOpToString(op));
196 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000197}
198
fmalita8c89c522014-11-08 16:18:56 -0800199void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000200 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000201}
202
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000203bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000204 render_path(canvas, fPath);
205 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000206}
207
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000208SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips9bafc302015-02-13 11:13:00 -0800209 : INHERITED(kClipRegion_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000210 fRegion = region;
211 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000212
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000213 fInfo.push(SkObjectParser::RegionToString(region));
214 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000215}
216
fmalita8c89c522014-11-08 16:18:56 -0800217void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000218 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000219}
220
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000221SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800222 : INHERITED(kClipRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000223 fRect = rect;
224 fOp = op;
225 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000226
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000227 fInfo.push(SkObjectParser::RectToString(rect));
228 fInfo.push(SkObjectParser::RegionOpToString(op));
229 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000230}
231
fmalita8c89c522014-11-08 16:18:56 -0800232void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000233 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000234}
235
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000236SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800237 : INHERITED(kClipRRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000238 fRRect = rrect;
239 fOp = op;
240 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000241
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000242 fInfo.push(SkObjectParser::RRectToString(rrect));
243 fInfo.push(SkObjectParser::RegionOpToString(op));
244 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000245}
246
fmalita8c89c522014-11-08 16:18:56 -0800247void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000248 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000249}
250
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000251bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000252 render_rrect(canvas, fRRect);
253 return true;
254}
255
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000256SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800257 : INHERITED(kConcat_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000258 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000259
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000260 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000261}
262
fmalita8c89c522014-11-08 16:18:56 -0800263void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000264 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000265}
266
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000267SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700268 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800269 : INHERITED(kDrawBitmap_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000270 fBitmap = bitmap;
271 fLeft = left;
272 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700273 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000274 fPaint = *paint;
275 fPaintPtr = &fPaint;
276 } else {
277 fPaintPtr = NULL;
278 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000279
280 fInfo.push(SkObjectParser::BitmapToString(bitmap));
281 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
282 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700283 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000284 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000285 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000286}
287
fmalita8c89c522014-11-08 16:18:56 -0800288void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000289 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000290}
291
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000292bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000293 render_bitmap(canvas, fBitmap);
294 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000295}
296
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000297SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000298 const SkRect& dst, const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800299 : INHERITED(kDrawBitmapNine_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000300 fBitmap = bitmap;
301 fCenter = center;
302 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700303 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000304 fPaint = *paint;
305 fPaintPtr = &fPaint;
306 } else {
307 fPaintPtr = NULL;
308 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000309
310 fInfo.push(SkObjectParser::BitmapToString(bitmap));
311 fInfo.push(SkObjectParser::IRectToString(center));
312 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700313 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000314 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000315 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000316}
317
fmalita8c89c522014-11-08 16:18:56 -0800318void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000319 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000320}
321
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000322bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000323 render_bitmap(canvas, fBitmap);
324 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000325}
326
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000327SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000328 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000329 SkCanvas::DrawBitmapRectFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800330 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000331 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700332 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000333 fSrc = *src;
334 } else {
335 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000336 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000337 fDst = dst;
338
bsalomon49f085d2014-09-05 13:34:00 -0700339 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000340 fPaint = *paint;
341 fPaintPtr = &fPaint;
342 } else {
343 fPaintPtr = NULL;
344 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000345 fFlags = flags;
346
robertphillips@google.com91217d02013-03-17 18:33:46 +0000347 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700348 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000349 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
350 }
351 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700352 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000353 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000354 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000355 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000356}
357
fmalita8c89c522014-11-08 16:18:56 -0800358void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000359 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000360}
361
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000362bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000363 render_bitmap(canvas, fBitmap, this->srcRect());
364 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000365}
366
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000367SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips9bafc302015-02-13 11:13:00 -0800368 : INHERITED(kBeginCommentGroup_OpType)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000369 , fDescription(description) {
370 SkString* temp = new SkString;
371 temp->appendf("Description: %s", description);
372 fInfo.push(temp);
373}
374
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000375SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips9bafc302015-02-13 11:13:00 -0800376 : INHERITED(kComment_OpType)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000377 , fKywd(kywd)
378 , fValue(value) {
379 SkString* temp = new SkString;
380 temp->appendf("%s: %s", kywd, value);
381 fInfo.push(temp);
382}
383
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000384SkEndCommentGroupCommand::SkEndCommentGroupCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800385 : INHERITED(kEndCommentGroup_OpType) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000386}
387
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000388SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800389 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000390 fOval = oval;
391 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000392
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000393 fInfo.push(SkObjectParser::RectToString(oval));
394 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000395}
396
fmalita8c89c522014-11-08 16:18:56 -0800397void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000398 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000399}
400
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000401bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000402 canvas->clear(0xFFFFFFFF);
403 canvas->save();
404
405 xlate_and_scale_to_bounds(canvas, fOval);
406
407 SkPaint p;
408 p.setColor(SK_ColorBLACK);
409 p.setStyle(SkPaint::kStroke_Style);
410
411 canvas->drawOval(fOval, p);
412 canvas->restore();
413
414 return true;
415}
416
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000417SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800418 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000419 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000420
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000421 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000422}
423
fmalita8c89c522014-11-08 16:18:56 -0800424void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000425 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000426}
427
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000428bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000429 canvas->clear(0xFFFFFFFF);
430 canvas->drawPaint(fPaint);
431 return true;
432}
433
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000434SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800435 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000436 fPath = path;
437 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000438
robertphillips@google.com91217d02013-03-17 18:33:46 +0000439 fInfo.push(SkObjectParser::PathToString(path));
440 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000441}
442
fmalita8c89c522014-11-08 16:18:56 -0800443void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000444 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000445}
446
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000447bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000448 render_path(canvas, fPath);
449 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000450}
451
robertphillipsb3f319f2014-08-13 10:46:23 -0700452SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
453 const SkMatrix* matrix,
454 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800455 : INHERITED(kDrawPicture_OpType)
robertphillipsb3f319f2014-08-13 10:46:23 -0700456 , fPicture(SkRef(picture))
457 , fMatrixPtr(NULL)
458 , fPaintPtr(NULL) {
459
bsalomon49f085d2014-09-05 13:34:00 -0700460 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700461 fMatrix = *matrix;
462 fMatrixPtr = &fMatrix;
463 }
bsalomon49f085d2014-09-05 13:34:00 -0700464 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700465 fPaint = *paint;
466 fPaintPtr = &fPaint;
467 }
468
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000469 SkString* temp = new SkString;
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700470 temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
471 picture->cullRect().fLeft, picture->cullRect().fTop,
472 picture->cullRect().fRight, picture->cullRect().fBottom);
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000473 fInfo.push(temp);
bsalomon49f085d2014-09-05 13:34:00 -0700474 if (matrix) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700475 fInfo.push(SkObjectParser::MatrixToString(*matrix));
476 }
bsalomon49f085d2014-09-05 13:34:00 -0700477 if (paint) {
robertphillipsb3f319f2014-08-13 10:46:23 -0700478 fInfo.push(SkObjectParser::PaintToString(*paint));
479 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000480}
481
fmalita8c89c522014-11-08 16:18:56 -0800482void SkDrawPictureCommand::execute(SkCanvas* canvas) const {
robertphillipsb3f319f2014-08-13 10:46:23 -0700483 canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000484}
485
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000486bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
487 canvas->clear(0xFFFFFFFF);
488 canvas->save();
489
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700490 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000491
robertphillips9b14f262014-06-04 05:40:44 -0700492 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000493
494 canvas->restore();
495
496 return true;
497}
498
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000499SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000500 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800501 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000502 fMode = mode;
503 fCount = count;
504 fPts = new SkPoint[count];
505 memcpy(fPts, pts, count * sizeof(SkPoint));
506 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000507
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000508 fInfo.push(SkObjectParser::PointsToString(pts, count));
509 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
510 "Points: "));
511 fInfo.push(SkObjectParser::PointModeToString(mode));
512 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000513}
514
fmalita8c89c522014-11-08 16:18:56 -0800515void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000516 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000517}
518
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000519bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000520 canvas->clear(0xFFFFFFFF);
521 canvas->save();
522
523 SkRect bounds;
524
525 bounds.setEmpty();
526 for (unsigned int i = 0; i < fCount; ++i) {
527 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
528 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000529
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000530 xlate_and_scale_to_bounds(canvas, bounds);
531
532 SkPaint p;
533 p.setColor(SK_ColorBLACK);
534 p.setStyle(SkPaint::kStroke_Style);
535
536 canvas->drawPoints(fMode, fCount, fPts, p);
537 canvas->restore();
538
539 return true;
540}
541
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000542SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000543 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800544 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000545 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000546
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000547 fText = new char[byteLength];
548 memcpy(fText, text, byteLength);
549 fByteLength = byteLength;
550
551 fPos = new SkPoint[numPts];
552 memcpy(fPos, pos, numPts * sizeof(SkPoint));
553
554 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000555
556 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000557 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000558 fInfo.push(SkObjectParser::PointsToString(pos, 1));
559 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000560}
561
fmalita8c89c522014-11-08 16:18:56 -0800562void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000563 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000564}
565
566
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000567SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
568 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000569 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800570 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000571 size_t numPts = paint.countText(text, byteLength);
572
573 fText = new char[byteLength];
574 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000575 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000576
577 fXpos = new SkScalar[numPts];
578 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
579
robertphillips@google.com91217d02013-03-17 18:33:46 +0000580 fConstY = constY;
581 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000582
robertphillips@google.com91217d02013-03-17 18:33:46 +0000583 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
584 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
585 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
586 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000587}
588
fmalita8c89c522014-11-08 16:18:56 -0800589void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000590 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000591}
592
fmalitab7425172014-08-26 07:56:44 -0700593SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
594 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800595 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700596 , fBlob(blob)
597 , fXPos(x)
598 , fYPos(y)
599 , fPaint(paint) {
600
601 blob->ref();
602
603 // FIXME: push blob info
604 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800605 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
606 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700607 fInfo.push(SkObjectParser::PaintToString(paint));
608}
609
fmalita8c89c522014-11-08 16:18:56 -0800610void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700611 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
612}
613
fmalita55773872014-08-29 15:08:20 -0700614bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
615 canvas->clear(SK_ColorWHITE);
616 canvas->save();
617
618 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
619 xlate_and_scale_to_bounds(canvas, bounds);
620
621 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
622
623 canvas->restore();
624
625 return true;
626}
627
robertphillips9bafc302015-02-13 11:13:00 -0800628SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
629 const SkPoint texCoords[4], SkXfermode* xfermode,
630 const SkPaint& paint)
631 : INHERITED(kDrawPatch_OpType) {
632 memcpy(fCubics, cubics, sizeof(fCubics));
633 memcpy(fColors, colors, sizeof(fColors));
634 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
635 fXfermode.reset(xfermode);
636 fPaint = paint;
637
638 fInfo.push(SkObjectParser::PaintToString(paint));
639}
640
641void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
642 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
643}
644
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000645SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800646 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000647 fRect = rect;
648 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000649
robertphillips@google.com91217d02013-03-17 18:33:46 +0000650 fInfo.push(SkObjectParser::RectToString(rect));
651 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000652}
653
fmalita8c89c522014-11-08 16:18:56 -0800654void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000655 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000656}
657
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000658SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800659 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000660 fRRect = rrect;
661 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000662
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000663 fInfo.push(SkObjectParser::RRectToString(rrect));
664 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000665}
666
fmalita8c89c522014-11-08 16:18:56 -0800667void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000668 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000669}
670
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000671bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000672 render_rrect(canvas, fRRect);
673 return true;
674}
675
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000676SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000677 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000678 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800679 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000680 fOuter = outer;
681 fInner = inner;
682 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000683
684 fInfo.push(SkObjectParser::RRectToString(outer));
685 fInfo.push(SkObjectParser::RRectToString(inner));
686 fInfo.push(SkObjectParser::PaintToString(paint));
687}
688
fmalita8c89c522014-11-08 16:18:56 -0800689void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000690 canvas->drawDRRect(fOuter, fInner, fPaint);
691}
692
693bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
694 render_drrect(canvas, fOuter, fInner);
695 return true;
696}
697
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000698SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000699 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800700 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000701 fBitmap = bitmap;
702 fLeft = left;
703 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700704 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000705 fPaint = *paint;
706 fPaintPtr = &fPaint;
707 } else {
708 fPaintPtr = NULL;
709 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000710
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000711 fInfo.push(SkObjectParser::BitmapToString(bitmap));
712 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
713 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700714 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000715 fInfo.push(SkObjectParser::PaintToString(*paint));
716 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000717}
718
fmalita8c89c522014-11-08 16:18:56 -0800719void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000720 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000721}
722
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000723bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000724 render_bitmap(canvas, fBitmap);
725 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000726}
727
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000728SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000729 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800730 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000731 fText = new char[byteLength];
732 memcpy(fText, text, byteLength);
733 fByteLength = byteLength;
734 fX = x;
735 fY = y;
736 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000737
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000738 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
739 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
740 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
741 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000742}
743
fmalita8c89c522014-11-08 16:18:56 -0800744void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000745 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000746}
747
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000748SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
749 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000750 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800751 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000752 fText = new char[byteLength];
753 memcpy(fText, text, byteLength);
754 fByteLength = byteLength;
755 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700756 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000757 fMatrix = *matrix;
758 } else {
759 fMatrix.setIdentity();
760 }
761 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000762
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000763 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
764 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700765 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000766 fInfo.push(SkObjectParser::MatrixToString(*matrix));
767 }
768 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000769}
770
fmalita8c89c522014-11-08 16:18:56 -0800771void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000772 canvas->drawTextOnPath(fText, fByteLength, fPath,
773 fMatrix.isIdentity() ? NULL : &fMatrix,
774 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000775}
776
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000777SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
778 const SkPoint vertices[], const SkPoint texs[],
779 const SkColor colors[], SkXfermode* xfermode,
780 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000781 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800782 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000783 fVmode = vmode;
784
785 fVertexCount = vertexCount;
786
787 fVertices = new SkPoint[vertexCount];
788 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
789
bsalomon49f085d2014-09-05 13:34:00 -0700790 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000791 fTexs = new SkPoint[vertexCount];
792 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
793 } else {
794 fTexs = NULL;
795 }
796
bsalomon49f085d2014-09-05 13:34:00 -0700797 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000798 fColors = new SkColor[vertexCount];
799 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
800 } else {
801 fColors = NULL;
802 }
803
804 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700805 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000806 fXfermode->ref();
807 }
808
809 if (indexCount > 0) {
810 fIndices = new uint16_t[indexCount];
811 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
812 } else {
813 fIndices = NULL;
814 }
815
816 fIndexCount = indexCount;
817 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000818
chudy@google.com902ebe52012-06-29 14:21:22 +0000819 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000820 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
821 fInfo.push(SkObjectParser::PaintToString(paint));
822}
823
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000824SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000825 delete [] fVertices;
826 delete [] fTexs;
827 delete [] fColors;
828 SkSafeUnref(fXfermode);
829 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000830}
831
fmalita8c89c522014-11-08 16:18:56 -0800832void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000833 canvas->drawVertices(fVmode, fVertexCount, fVertices,
834 fTexs, fColors, fXfermode, fIndices,
835 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000836}
837
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000838SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800839 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000840 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000841}
842
fmalita8c89c522014-11-08 16:18:56 -0800843void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000844 canvas->restore();
845}
846
Florin Malita5f6102d2014-06-30 10:13:28 -0400847SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800848 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000849}
850
fmalita8c89c522014-11-08 16:18:56 -0800851void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400852 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000853}
854
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000855SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000856 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800857 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700858 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000859 fBounds = *bounds;
860 } else {
861 fBounds.setEmpty();
862 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000863
bsalomon49f085d2014-09-05 13:34:00 -0700864 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000865 fPaint = *paint;
866 fPaintPtr = &fPaint;
867 } else {
868 fPaintPtr = NULL;
869 }
870 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000871
bsalomon49f085d2014-09-05 13:34:00 -0700872 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000873 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
874 }
bsalomon49f085d2014-09-05 13:34:00 -0700875 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000876 fInfo.push(SkObjectParser::PaintToString(*paint));
877 }
878 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000879}
880
fmalita8c89c522014-11-08 16:18:56 -0800881void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000882 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000883 fPaintPtr,
884 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000885}
886
fmalita8c89c522014-11-08 16:18:56 -0800887void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000888 canvas->save();
889}
890
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000891SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800892 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700893 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000894 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000895
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000896 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000897}
898
robertphillips70171682014-10-16 14:28:28 -0700899void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
900 fUserMatrix = userMatrix;
901}
902
fmalita8c89c522014-11-08 16:18:56 -0800903void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700904 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
905 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000906}
907