blob: 5f0f74ffc0051ac30062d9460dc73bb40bdeca49 [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 -080017SkDrawCommand::SkDrawCommand(OpType type)
18 : fOpType(type)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000019 , fVisible(true) {
20}
21
chudy@google.com902ebe52012-06-29 14:21:22 +000022SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000023 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000024}
25
robertphillips9bafc302015-02-13 11:13:00 -080026const char* SkDrawCommand::GetCommandString(OpType type) {
chudy@google.com902ebe52012-06-29 14:21:22 +000027 switch (type) {
fmalita160ebb22015-04-01 20:58:37 -070028 case kBeginDrawPicture_OpType: return "BeginDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080029 case kClipPath_OpType: return "ClipPath";
30 case kClipRegion_OpType: return "ClipRegion";
31 case kClipRect_OpType: return "ClipRect";
32 case kClipRRect_OpType: return "ClipRRect";
robertphillips9bafc302015-02-13 11:13:00 -080033 case kConcat_OpType: return "Concat";
34 case kDrawBitmap_OpType: return "DrawBitmap";
35 case kDrawBitmapNine_OpType: return "DrawBitmapNine";
36 case kDrawBitmapRect_OpType: return "DrawBitmapRect";
37 case kDrawClear_OpType: return "DrawClear";
38 case kDrawDRRect_OpType: return "DrawDRRect";
39 case kDrawOval_OpType: return "DrawOval";
40 case kDrawPaint_OpType: return "DrawPaint";
41 case kDrawPatch_OpType: return "DrawPatch";
42 case kDrawPath_OpType: return "DrawPath";
robertphillips9bafc302015-02-13 11:13:00 -080043 case kDrawPoints_OpType: return "DrawPoints";
44 case kDrawPosText_OpType: return "DrawPosText";
45 case kDrawPosTextH_OpType: return "DrawPosTextH";
46 case kDrawRect_OpType: return "DrawRect";
47 case kDrawRRect_OpType: return "DrawRRect";
48 case kDrawSprite_OpType: return "DrawSprite";
49 case kDrawText_OpType: return "DrawText";
50 case kDrawTextBlob_OpType: return "DrawTextBlob";
51 case kDrawTextOnPath_OpType: return "DrawTextOnPath";
52 case kDrawVertices_OpType: return "DrawVertices";
fmalita160ebb22015-04-01 20:58:37 -070053 case kEndDrawPicture_OpType: return "EndDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080054 case kRestore_OpType: return "Restore";
55 case kSave_OpType: return "Save";
56 case kSaveLayer_OpType: return "SaveLayer";
57 case kSetMatrix_OpType: return "SetMatrix";
chudy@google.com902ebe52012-06-29 14:21:22 +000058 default:
robertphillips9bafc302015-02-13 11:13:00 -080059 SkDebugf("OpType error 0x%08x\n", type);
chudy@google.com902ebe52012-06-29 14:21:22 +000060 SkASSERT(0);
61 break;
62 }
63 SkDEBUGFAIL("DrawType UNUSED\n");
64 return NULL;
65}
66
fmalita8c89c522014-11-08 16:18:56 -080067SkString SkDrawCommand::toString() const {
robertphillips9bafc302015-02-13 11:13:00 -080068 return SkString(GetCommandString(fOpType));
chudy@google.com902ebe52012-06-29 14:21:22 +000069}
70
robertphillips9bafc302015-02-13 11:13:00 -080071SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000072 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000073 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000074}
75
fmalita8c89c522014-11-08 16:18:56 -080076void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000077 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000078}
79
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000080namespace {
81
82void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
83 const SkISize& size = canvas->getDeviceSize();
84
85 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
86
87 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
88 if (bounds.width() > bounds.height()) {
89 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
90 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
91 } else {
92 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
93 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
94 }
95 canvas->translate(-bounds.centerX(), -bounds.centerY());
96}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +000097
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000098
99void render_path(SkCanvas* canvas, const SkPath& path) {
100 canvas->clear(0xFFFFFFFF);
101 canvas->save();
102
103 const SkRect& bounds = path.getBounds();
104
105 xlate_and_scale_to_bounds(canvas, bounds);
106
107 SkPaint p;
108 p.setColor(SK_ColorBLACK);
109 p.setStyle(SkPaint::kStroke_Style);
110
111 canvas->drawPath(path, p);
112 canvas->restore();
113}
114
115void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
116 const SkISize& size = canvas->getDeviceSize();
117
118 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
119 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
120
121 if (input.width() > input.height()) {
122 yScale *= input.height() / (float) input.width();
123 } else {
124 xScale *= input.width() / (float) input.height();
125 }
126
127 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
128 xScale * input.width(),
129 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000130
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000131 canvas->clear(0xFFFFFFFF);
132 canvas->drawBitmapRect(input, NULL, dst);
133
bsalomon49f085d2014-09-05 13:34:00 -0700134 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000135 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
136 srcRect->fTop * yScale + SK_Scalar1,
137 srcRect->fRight * xScale + SK_Scalar1,
138 srcRect->fBottom * yScale + SK_Scalar1);
139 SkPaint p;
140 p.setColor(SK_ColorRED);
141 p.setStyle(SkPaint::kStroke_Style);
142
143 canvas->drawRect(r, p);
144 }
145}
146
147void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
148 canvas->clear(0xFFFFFFFF);
149 canvas->save();
150
151 const SkRect& bounds = rrect.getBounds();
152
153 xlate_and_scale_to_bounds(canvas, bounds);
154
155 SkPaint p;
156 p.setColor(SK_ColorBLACK);
157 p.setStyle(SkPaint::kStroke_Style);
158
159 canvas->drawRRect(rrect, p);
160 canvas->restore();
161}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000162
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000163void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
164 canvas->clear(0xFFFFFFFF);
165 canvas->save();
166
167 const SkRect& bounds = outer.getBounds();
168
169 xlate_and_scale_to_bounds(canvas, bounds);
170
171 SkPaint p;
172 p.setColor(SK_ColorBLACK);
173 p.setStyle(SkPaint::kStroke_Style);
174
175 canvas->drawDRRect(outer, inner, p);
176 canvas->restore();
177}
178
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000179};
180
181
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000182SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800183 : INHERITED(kClipPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000184 fPath = path;
185 fOp = op;
186 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000187
robertphillips@google.com91217d02013-03-17 18:33:46 +0000188 fInfo.push(SkObjectParser::PathToString(path));
189 fInfo.push(SkObjectParser::RegionOpToString(op));
190 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000191}
192
fmalita8c89c522014-11-08 16:18:56 -0800193void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000194 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000195}
196
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000197bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000198 render_path(canvas, fPath);
199 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000200}
201
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000202SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips9bafc302015-02-13 11:13:00 -0800203 : INHERITED(kClipRegion_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000204 fRegion = region;
205 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000206
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000207 fInfo.push(SkObjectParser::RegionToString(region));
208 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000209}
210
fmalita8c89c522014-11-08 16:18:56 -0800211void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000212 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000213}
214
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000215SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800216 : INHERITED(kClipRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000217 fRect = rect;
218 fOp = op;
219 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000220
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000221 fInfo.push(SkObjectParser::RectToString(rect));
222 fInfo.push(SkObjectParser::RegionOpToString(op));
223 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000224}
225
fmalita8c89c522014-11-08 16:18:56 -0800226void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000227 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000228}
229
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000230SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800231 : INHERITED(kClipRRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000232 fRRect = rrect;
233 fOp = op;
234 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000235
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000236 fInfo.push(SkObjectParser::RRectToString(rrect));
237 fInfo.push(SkObjectParser::RegionOpToString(op));
238 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000239}
240
fmalita8c89c522014-11-08 16:18:56 -0800241void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000242 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000243}
244
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000245bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000246 render_rrect(canvas, fRRect);
247 return true;
248}
249
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000250SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800251 : INHERITED(kConcat_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000252 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000253
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000254 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000255}
256
fmalita8c89c522014-11-08 16:18:56 -0800257void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000258 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000259}
260
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000261SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700262 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800263 : INHERITED(kDrawBitmap_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000264 fBitmap = bitmap;
265 fLeft = left;
266 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700267 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000268 fPaint = *paint;
269 fPaintPtr = &fPaint;
270 } else {
271 fPaintPtr = NULL;
272 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000273
274 fInfo.push(SkObjectParser::BitmapToString(bitmap));
275 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
276 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700277 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000278 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000279 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000280}
281
fmalita8c89c522014-11-08 16:18:56 -0800282void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000283 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000284}
285
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000286bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000287 render_bitmap(canvas, fBitmap);
288 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000289}
290
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000291SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000292 const SkRect& dst, const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800293 : INHERITED(kDrawBitmapNine_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000294 fBitmap = bitmap;
295 fCenter = center;
296 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700297 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000298 fPaint = *paint;
299 fPaintPtr = &fPaint;
300 } else {
301 fPaintPtr = NULL;
302 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000303
304 fInfo.push(SkObjectParser::BitmapToString(bitmap));
305 fInfo.push(SkObjectParser::IRectToString(center));
306 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700307 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000308 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000309 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000310}
311
fmalita8c89c522014-11-08 16:18:56 -0800312void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000313 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000314}
315
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000316bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000317 render_bitmap(canvas, fBitmap);
318 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000319}
320
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000321SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000322 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700323 SkCanvas::SrcRectConstraint constraint)
robertphillips9bafc302015-02-13 11:13:00 -0800324 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000325 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700326 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000327 fSrc = *src;
328 } else {
329 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000330 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000331 fDst = dst;
332
bsalomon49f085d2014-09-05 13:34:00 -0700333 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000334 fPaint = *paint;
335 fPaintPtr = &fPaint;
336 } else {
337 fPaintPtr = NULL;
338 }
reeda5517e22015-07-14 10:54:12 -0700339 fConstraint = constraint;
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000340
robertphillips@google.com91217d02013-03-17 18:33:46 +0000341 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700342 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000343 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
344 }
345 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700346 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000347 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000348 }
reeda5517e22015-07-14 10:54:12 -0700349 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000350}
351
fmalita8c89c522014-11-08 16:18:56 -0800352void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
reeda5517e22015-07-14 10:54:12 -0700353 canvas->drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000354}
355
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000356bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000357 render_bitmap(canvas, fBitmap, this->srcRect());
358 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000359}
360
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000361SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800362 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000363 fOval = oval;
364 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000365
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000366 fInfo.push(SkObjectParser::RectToString(oval));
367 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000368}
369
fmalita8c89c522014-11-08 16:18:56 -0800370void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000371 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000372}
373
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000374bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000375 canvas->clear(0xFFFFFFFF);
376 canvas->save();
377
378 xlate_and_scale_to_bounds(canvas, fOval);
379
380 SkPaint p;
381 p.setColor(SK_ColorBLACK);
382 p.setStyle(SkPaint::kStroke_Style);
383
384 canvas->drawOval(fOval, p);
385 canvas->restore();
386
387 return true;
388}
389
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000390SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800391 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000392 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000393
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000394 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
fmalita8c89c522014-11-08 16:18:56 -0800397void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000398 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000399}
400
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000401bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000402 canvas->clear(0xFFFFFFFF);
403 canvas->drawPaint(fPaint);
404 return true;
405}
406
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000407SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800408 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000409 fPath = path;
410 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000411
robertphillips@google.com91217d02013-03-17 18:33:46 +0000412 fInfo.push(SkObjectParser::PathToString(path));
413 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000414}
415
fmalita8c89c522014-11-08 16:18:56 -0800416void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000417 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000418}
419
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000420bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000421 render_path(canvas, fPath);
422 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000423}
424
fmalita160ebb22015-04-01 20:58:37 -0700425SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
426 const SkMatrix* matrix,
427 const SkPaint* paint)
428 : INHERITED(kBeginDrawPicture_OpType)
429 , fPicture(SkRef(picture)) {
430
431 SkString* str = new SkString;
432 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
433 picture->cullRect().fLeft, picture->cullRect().fTop,
434 picture->cullRect().fRight, picture->cullRect().fBottom);
435 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700436
bsalomon49f085d2014-09-05 13:34:00 -0700437 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700438 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700439 fInfo.push(SkObjectParser::MatrixToString(*matrix));
440 }
fmalita160ebb22015-04-01 20:58:37 -0700441
bsalomon49f085d2014-09-05 13:34:00 -0700442 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700443 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700444 fInfo.push(SkObjectParser::PaintToString(*paint));
445 }
fmalita160ebb22015-04-01 20:58:37 -0700446
447}
448
449void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
450 if (fPaint.isValid()) {
451 SkRect bounds = fPicture->cullRect();
452 if (fMatrix.isValid()) {
453 fMatrix.get()->mapRect(&bounds);
454 }
455 canvas->saveLayer(&bounds, fPaint.get());
456 }
457
458 if (fMatrix.isValid()) {
459 if (!fPaint.isValid()) {
460 canvas->save();
461 }
462 canvas->concat(*fMatrix.get());
463 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000464}
465
fmalita160ebb22015-04-01 20:58:37 -0700466bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000467 canvas->clear(0xFFFFFFFF);
468 canvas->save();
469
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700470 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000471
robertphillips9b14f262014-06-04 05:40:44 -0700472 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000473
474 canvas->restore();
475
476 return true;
477}
478
fmalita160ebb22015-04-01 20:58:37 -0700479SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
480 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
481
482void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
483 if (fRestore) {
484 canvas->restore();
485 }
486}
487
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000488SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000489 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800490 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000491 fMode = mode;
492 fCount = count;
493 fPts = new SkPoint[count];
494 memcpy(fPts, pts, count * sizeof(SkPoint));
495 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000496
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000497 fInfo.push(SkObjectParser::PointsToString(pts, count));
498 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
499 "Points: "));
500 fInfo.push(SkObjectParser::PointModeToString(mode));
501 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000502}
503
fmalita8c89c522014-11-08 16:18:56 -0800504void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000505 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000506}
507
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000508bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000509 canvas->clear(0xFFFFFFFF);
510 canvas->save();
511
512 SkRect bounds;
513
514 bounds.setEmpty();
515 for (unsigned int i = 0; i < fCount; ++i) {
516 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
517 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000518
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000519 xlate_and_scale_to_bounds(canvas, bounds);
520
521 SkPaint p;
522 p.setColor(SK_ColorBLACK);
523 p.setStyle(SkPaint::kStroke_Style);
524
525 canvas->drawPoints(fMode, fCount, fPts, p);
526 canvas->restore();
527
528 return true;
529}
530
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000531SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000532 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800533 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000534 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000535
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000536 fText = new char[byteLength];
537 memcpy(fText, text, byteLength);
538 fByteLength = byteLength;
539
540 fPos = new SkPoint[numPts];
541 memcpy(fPos, pos, numPts * sizeof(SkPoint));
542
543 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000544
545 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000546 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000547 fInfo.push(SkObjectParser::PointsToString(pos, 1));
548 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000549}
550
fmalita8c89c522014-11-08 16:18:56 -0800551void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000552 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000553}
554
555
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000556SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
557 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000558 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800559 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000560 size_t numPts = paint.countText(text, byteLength);
561
562 fText = new char[byteLength];
563 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000564 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000565
566 fXpos = new SkScalar[numPts];
567 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
568
robertphillips@google.com91217d02013-03-17 18:33:46 +0000569 fConstY = constY;
570 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000571
robertphillips@google.com91217d02013-03-17 18:33:46 +0000572 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
573 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
574 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
575 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000576}
577
fmalita8c89c522014-11-08 16:18:56 -0800578void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000579 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000580}
581
fmalitab7425172014-08-26 07:56:44 -0700582SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
583 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800584 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700585 , fBlob(blob)
586 , fXPos(x)
587 , fYPos(y)
588 , fPaint(paint) {
589
590 blob->ref();
591
592 // FIXME: push blob info
593 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800594 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
595 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700596 fInfo.push(SkObjectParser::PaintToString(paint));
597}
598
fmalita8c89c522014-11-08 16:18:56 -0800599void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700600 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
601}
602
fmalita55773872014-08-29 15:08:20 -0700603bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
604 canvas->clear(SK_ColorWHITE);
605 canvas->save();
606
607 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
608 xlate_and_scale_to_bounds(canvas, bounds);
609
610 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
611
612 canvas->restore();
613
614 return true;
615}
616
robertphillips9bafc302015-02-13 11:13:00 -0800617SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
618 const SkPoint texCoords[4], SkXfermode* xfermode,
619 const SkPaint& paint)
620 : INHERITED(kDrawPatch_OpType) {
621 memcpy(fCubics, cubics, sizeof(fCubics));
622 memcpy(fColors, colors, sizeof(fColors));
623 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
624 fXfermode.reset(xfermode);
625 fPaint = paint;
626
627 fInfo.push(SkObjectParser::PaintToString(paint));
628}
629
630void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
631 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
632}
633
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000634SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800635 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000636 fRect = rect;
637 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000638
robertphillips@google.com91217d02013-03-17 18:33:46 +0000639 fInfo.push(SkObjectParser::RectToString(rect));
640 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000641}
642
fmalita8c89c522014-11-08 16:18:56 -0800643void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000644 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000645}
646
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000647SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800648 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000649 fRRect = rrect;
650 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000651
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000652 fInfo.push(SkObjectParser::RRectToString(rrect));
653 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000654}
655
fmalita8c89c522014-11-08 16:18:56 -0800656void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000657 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000658}
659
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000660bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000661 render_rrect(canvas, fRRect);
662 return true;
663}
664
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000665SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000666 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000667 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800668 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000669 fOuter = outer;
670 fInner = inner;
671 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000672
673 fInfo.push(SkObjectParser::RRectToString(outer));
674 fInfo.push(SkObjectParser::RRectToString(inner));
675 fInfo.push(SkObjectParser::PaintToString(paint));
676}
677
fmalita8c89c522014-11-08 16:18:56 -0800678void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000679 canvas->drawDRRect(fOuter, fInner, fPaint);
680}
681
682bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
683 render_drrect(canvas, fOuter, fInner);
684 return true;
685}
686
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000687SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000688 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800689 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000690 fBitmap = bitmap;
691 fLeft = left;
692 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700693 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000694 fPaint = *paint;
695 fPaintPtr = &fPaint;
696 } else {
697 fPaintPtr = NULL;
698 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000699
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000700 fInfo.push(SkObjectParser::BitmapToString(bitmap));
701 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
702 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700703 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000704 fInfo.push(SkObjectParser::PaintToString(*paint));
705 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000706}
707
fmalita8c89c522014-11-08 16:18:56 -0800708void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000709 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000710}
711
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000712bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000713 render_bitmap(canvas, fBitmap);
714 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000715}
716
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000717SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000718 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800719 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000720 fText = new char[byteLength];
721 memcpy(fText, text, byteLength);
722 fByteLength = byteLength;
723 fX = x;
724 fY = y;
725 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000726
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000727 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
728 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
729 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
730 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000731}
732
fmalita8c89c522014-11-08 16:18:56 -0800733void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000734 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000735}
736
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000737SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
738 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000739 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800740 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000741 fText = new char[byteLength];
742 memcpy(fText, text, byteLength);
743 fByteLength = byteLength;
744 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700745 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000746 fMatrix = *matrix;
747 } else {
748 fMatrix.setIdentity();
749 }
750 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000751
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000752 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
753 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700754 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000755 fInfo.push(SkObjectParser::MatrixToString(*matrix));
756 }
757 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000758}
759
fmalita8c89c522014-11-08 16:18:56 -0800760void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000761 canvas->drawTextOnPath(fText, fByteLength, fPath,
762 fMatrix.isIdentity() ? NULL : &fMatrix,
763 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000764}
765
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000766SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
767 const SkPoint vertices[], const SkPoint texs[],
768 const SkColor colors[], SkXfermode* xfermode,
769 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000770 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800771 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000772 fVmode = vmode;
773
774 fVertexCount = vertexCount;
775
776 fVertices = new SkPoint[vertexCount];
777 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
778
bsalomon49f085d2014-09-05 13:34:00 -0700779 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000780 fTexs = new SkPoint[vertexCount];
781 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
782 } else {
783 fTexs = NULL;
784 }
785
bsalomon49f085d2014-09-05 13:34:00 -0700786 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000787 fColors = new SkColor[vertexCount];
788 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
789 } else {
790 fColors = NULL;
791 }
792
793 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700794 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000795 fXfermode->ref();
796 }
797
798 if (indexCount > 0) {
799 fIndices = new uint16_t[indexCount];
800 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
801 } else {
802 fIndices = NULL;
803 }
804
805 fIndexCount = indexCount;
806 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000807
chudy@google.com902ebe52012-06-29 14:21:22 +0000808 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000809 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
810 fInfo.push(SkObjectParser::PaintToString(paint));
811}
812
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000813SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000814 delete [] fVertices;
815 delete [] fTexs;
816 delete [] fColors;
817 SkSafeUnref(fXfermode);
818 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000819}
820
fmalita8c89c522014-11-08 16:18:56 -0800821void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000822 canvas->drawVertices(fVmode, fVertexCount, fVertices,
823 fTexs, fColors, fXfermode, fIndices,
824 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000825}
826
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000827SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800828 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000829 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000830}
831
fmalita8c89c522014-11-08 16:18:56 -0800832void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000833 canvas->restore();
834}
835
Florin Malita5f6102d2014-06-30 10:13:28 -0400836SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800837 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000838}
839
fmalita8c89c522014-11-08 16:18:56 -0800840void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400841 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000842}
843
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000844SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000845 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800846 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700847 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000848 fBounds = *bounds;
849 } else {
850 fBounds.setEmpty();
851 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000852
bsalomon49f085d2014-09-05 13:34:00 -0700853 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000854 fPaint = *paint;
855 fPaintPtr = &fPaint;
856 } else {
857 fPaintPtr = NULL;
858 }
859 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000860
bsalomon49f085d2014-09-05 13:34:00 -0700861 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000862 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
863 }
bsalomon49f085d2014-09-05 13:34:00 -0700864 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000865 fInfo.push(SkObjectParser::PaintToString(*paint));
866 }
867 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000868}
869
fmalita8c89c522014-11-08 16:18:56 -0800870void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000871 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000872 fPaintPtr,
873 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000874}
875
fmalita8c89c522014-11-08 16:18:56 -0800876void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000877 canvas->save();
878}
879
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000880SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800881 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700882 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000883 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000884
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000885 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000886}
887
robertphillips70171682014-10-16 14:28:28 -0700888void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
889 fUserMatrix = userMatrix;
890}
891
fmalita8c89c522014-11-08 16:18:56 -0800892void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700893 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
894 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000895}
896