blob: 09b18896bcc7adf661ce8138f7760fc08fb43385 [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) {
robertphillips9bafc302015-02-13 11:13:00 -080028 case kBeginCommentGroup_OpType: return "BeginCommentGroup";
fmalita160ebb22015-04-01 20:58:37 -070029 case kBeginDrawPicture_OpType: return "BeginDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080030 case kClipPath_OpType: return "ClipPath";
31 case kClipRegion_OpType: return "ClipRegion";
32 case kClipRect_OpType: return "ClipRect";
33 case kClipRRect_OpType: return "ClipRRect";
34 case kComment_OpType: return "Comment";
35 case kConcat_OpType: return "Concat";
36 case kDrawBitmap_OpType: return "DrawBitmap";
37 case kDrawBitmapNine_OpType: return "DrawBitmapNine";
38 case kDrawBitmapRect_OpType: return "DrawBitmapRect";
39 case kDrawClear_OpType: return "DrawClear";
40 case kDrawDRRect_OpType: return "DrawDRRect";
41 case kDrawOval_OpType: return "DrawOval";
42 case kDrawPaint_OpType: return "DrawPaint";
43 case kDrawPatch_OpType: return "DrawPatch";
44 case kDrawPath_OpType: return "DrawPath";
robertphillips9bafc302015-02-13 11:13:00 -080045 case kDrawPoints_OpType: return "DrawPoints";
46 case kDrawPosText_OpType: return "DrawPosText";
47 case kDrawPosTextH_OpType: return "DrawPosTextH";
48 case kDrawRect_OpType: return "DrawRect";
49 case kDrawRRect_OpType: return "DrawRRect";
50 case kDrawSprite_OpType: return "DrawSprite";
51 case kDrawText_OpType: return "DrawText";
52 case kDrawTextBlob_OpType: return "DrawTextBlob";
53 case kDrawTextOnPath_OpType: return "DrawTextOnPath";
54 case kDrawVertices_OpType: return "DrawVertices";
55 case kEndCommentGroup_OpType: return "EndCommentGroup";
fmalita160ebb22015-04-01 20:58:37 -070056 case kEndDrawPicture_OpType: return "EndDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080057 case kRestore_OpType: return "Restore";
58 case kSave_OpType: return "Save";
59 case kSaveLayer_OpType: return "SaveLayer";
60 case kSetMatrix_OpType: return "SetMatrix";
chudy@google.com902ebe52012-06-29 14:21:22 +000061 default:
robertphillips9bafc302015-02-13 11:13:00 -080062 SkDebugf("OpType error 0x%08x\n", type);
chudy@google.com902ebe52012-06-29 14:21:22 +000063 SkASSERT(0);
64 break;
65 }
66 SkDEBUGFAIL("DrawType UNUSED\n");
67 return NULL;
68}
69
fmalita8c89c522014-11-08 16:18:56 -080070SkString SkDrawCommand::toString() const {
robertphillips9bafc302015-02-13 11:13:00 -080071 return SkString(GetCommandString(fOpType));
chudy@google.com902ebe52012-06-29 14:21:22 +000072}
73
robertphillips9bafc302015-02-13 11:13:00 -080074SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000075 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000076 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000077}
78
fmalita8c89c522014-11-08 16:18:56 -080079void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000080 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000081}
82
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000083namespace {
84
85void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
86 const SkISize& size = canvas->getDeviceSize();
87
88 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
89
90 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
91 if (bounds.width() > bounds.height()) {
92 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
93 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
94 } else {
95 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
96 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
97 }
98 canvas->translate(-bounds.centerX(), -bounds.centerY());
99}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000100
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000101
102void render_path(SkCanvas* canvas, const SkPath& path) {
103 canvas->clear(0xFFFFFFFF);
104 canvas->save();
105
106 const SkRect& bounds = path.getBounds();
107
108 xlate_and_scale_to_bounds(canvas, bounds);
109
110 SkPaint p;
111 p.setColor(SK_ColorBLACK);
112 p.setStyle(SkPaint::kStroke_Style);
113
114 canvas->drawPath(path, p);
115 canvas->restore();
116}
117
118void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
119 const SkISize& size = canvas->getDeviceSize();
120
121 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
122 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
123
124 if (input.width() > input.height()) {
125 yScale *= input.height() / (float) input.width();
126 } else {
127 xScale *= input.width() / (float) input.height();
128 }
129
130 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
131 xScale * input.width(),
132 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000133
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000134 canvas->clear(0xFFFFFFFF);
135 canvas->drawBitmapRect(input, NULL, dst);
136
bsalomon49f085d2014-09-05 13:34:00 -0700137 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000138 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
139 srcRect->fTop * yScale + SK_Scalar1,
140 srcRect->fRight * xScale + SK_Scalar1,
141 srcRect->fBottom * yScale + SK_Scalar1);
142 SkPaint p;
143 p.setColor(SK_ColorRED);
144 p.setStyle(SkPaint::kStroke_Style);
145
146 canvas->drawRect(r, p);
147 }
148}
149
150void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
151 canvas->clear(0xFFFFFFFF);
152 canvas->save();
153
154 const SkRect& bounds = rrect.getBounds();
155
156 xlate_and_scale_to_bounds(canvas, bounds);
157
158 SkPaint p;
159 p.setColor(SK_ColorBLACK);
160 p.setStyle(SkPaint::kStroke_Style);
161
162 canvas->drawRRect(rrect, p);
163 canvas->restore();
164}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000165
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000166void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
167 canvas->clear(0xFFFFFFFF);
168 canvas->save();
169
170 const SkRect& bounds = outer.getBounds();
171
172 xlate_and_scale_to_bounds(canvas, bounds);
173
174 SkPaint p;
175 p.setColor(SK_ColorBLACK);
176 p.setStyle(SkPaint::kStroke_Style);
177
178 canvas->drawDRRect(outer, inner, p);
179 canvas->restore();
180}
181
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000182};
183
184
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000185SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800186 : INHERITED(kClipPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000187 fPath = path;
188 fOp = op;
189 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000190
robertphillips@google.com91217d02013-03-17 18:33:46 +0000191 fInfo.push(SkObjectParser::PathToString(path));
192 fInfo.push(SkObjectParser::RegionOpToString(op));
193 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000194}
195
fmalita8c89c522014-11-08 16:18:56 -0800196void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000197 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000198}
199
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000200bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000201 render_path(canvas, fPath);
202 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000203}
204
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000205SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips9bafc302015-02-13 11:13:00 -0800206 : INHERITED(kClipRegion_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000207 fRegion = region;
208 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000209
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000210 fInfo.push(SkObjectParser::RegionToString(region));
211 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000212}
213
fmalita8c89c522014-11-08 16:18:56 -0800214void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000215 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000216}
217
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000218SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800219 : INHERITED(kClipRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000220 fRect = rect;
221 fOp = op;
222 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000223
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000224 fInfo.push(SkObjectParser::RectToString(rect));
225 fInfo.push(SkObjectParser::RegionOpToString(op));
226 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000227}
228
fmalita8c89c522014-11-08 16:18:56 -0800229void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000230 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000231}
232
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000233SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800234 : INHERITED(kClipRRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000235 fRRect = rrect;
236 fOp = op;
237 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000238
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000239 fInfo.push(SkObjectParser::RRectToString(rrect));
240 fInfo.push(SkObjectParser::RegionOpToString(op));
241 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000242}
243
fmalita8c89c522014-11-08 16:18:56 -0800244void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000245 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000246}
247
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000248bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000249 render_rrect(canvas, fRRect);
250 return true;
251}
252
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000253SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800254 : INHERITED(kConcat_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000255 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000256
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000257 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000258}
259
fmalita8c89c522014-11-08 16:18:56 -0800260void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000261 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000262}
263
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000264SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700265 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800266 : INHERITED(kDrawBitmap_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000267 fBitmap = bitmap;
268 fLeft = left;
269 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700270 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000271 fPaint = *paint;
272 fPaintPtr = &fPaint;
273 } else {
274 fPaintPtr = NULL;
275 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000276
277 fInfo.push(SkObjectParser::BitmapToString(bitmap));
278 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
279 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700280 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000281 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000282 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000283}
284
fmalita8c89c522014-11-08 16:18:56 -0800285void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000286 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000287}
288
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000289bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000290 render_bitmap(canvas, fBitmap);
291 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000292}
293
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000294SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000295 const SkRect& dst, const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800296 : INHERITED(kDrawBitmapNine_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000297 fBitmap = bitmap;
298 fCenter = center;
299 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700300 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000301 fPaint = *paint;
302 fPaintPtr = &fPaint;
303 } else {
304 fPaintPtr = NULL;
305 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000306
307 fInfo.push(SkObjectParser::BitmapToString(bitmap));
308 fInfo.push(SkObjectParser::IRectToString(center));
309 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700310 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000311 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000312 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000313}
314
fmalita8c89c522014-11-08 16:18:56 -0800315void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000316 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000317}
318
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000319bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000320 render_bitmap(canvas, fBitmap);
321 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000322}
323
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000324SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000325 const SkRect& dst, const SkPaint* paint,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000326 SkCanvas::DrawBitmapRectFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800327 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000328 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700329 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000330 fSrc = *src;
331 } else {
332 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000333 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000334 fDst = dst;
335
bsalomon49f085d2014-09-05 13:34:00 -0700336 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000337 fPaint = *paint;
338 fPaintPtr = &fPaint;
339 } else {
340 fPaintPtr = NULL;
341 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000342 fFlags = flags;
343
robertphillips@google.com91217d02013-03-17 18:33:46 +0000344 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700345 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000346 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
347 }
348 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700349 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000350 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000351 }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000352 fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000353}
354
fmalita8c89c522014-11-08 16:18:56 -0800355void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000356 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000357}
358
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000359bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000360 render_bitmap(canvas, fBitmap, this->srcRect());
361 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000362}
363
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000364SkBeginCommentGroupCommand::SkBeginCommentGroupCommand(const char* description)
robertphillips9bafc302015-02-13 11:13:00 -0800365 : INHERITED(kBeginCommentGroup_OpType)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000366 , fDescription(description) {
367 SkString* temp = new SkString;
368 temp->appendf("Description: %s", description);
369 fInfo.push(temp);
370}
371
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000372SkCommentCommand::SkCommentCommand(const char* kywd, const char* value)
robertphillips9bafc302015-02-13 11:13:00 -0800373 : INHERITED(kComment_OpType)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000374 , fKywd(kywd)
375 , fValue(value) {
376 SkString* temp = new SkString;
377 temp->appendf("%s: %s", kywd, value);
378 fInfo.push(temp);
379}
380
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000381SkEndCommentGroupCommand::SkEndCommentGroupCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800382 : INHERITED(kEndCommentGroup_OpType) {
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000383}
384
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000385SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800386 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000387 fOval = oval;
388 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000389
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000390 fInfo.push(SkObjectParser::RectToString(oval));
391 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000392}
393
fmalita8c89c522014-11-08 16:18:56 -0800394void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000395 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000396}
397
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000398bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000399 canvas->clear(0xFFFFFFFF);
400 canvas->save();
401
402 xlate_and_scale_to_bounds(canvas, fOval);
403
404 SkPaint p;
405 p.setColor(SK_ColorBLACK);
406 p.setStyle(SkPaint::kStroke_Style);
407
408 canvas->drawOval(fOval, p);
409 canvas->restore();
410
411 return true;
412}
413
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000414SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800415 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000416 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000417
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000418 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000419}
420
fmalita8c89c522014-11-08 16:18:56 -0800421void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000422 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000423}
424
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000425bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000426 canvas->clear(0xFFFFFFFF);
427 canvas->drawPaint(fPaint);
428 return true;
429}
430
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000431SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800432 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000433 fPath = path;
434 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000435
robertphillips@google.com91217d02013-03-17 18:33:46 +0000436 fInfo.push(SkObjectParser::PathToString(path));
437 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000438}
439
fmalita8c89c522014-11-08 16:18:56 -0800440void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000441 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000442}
443
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000444bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000445 render_path(canvas, fPath);
446 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000447}
448
fmalita160ebb22015-04-01 20:58:37 -0700449SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
450 const SkMatrix* matrix,
451 const SkPaint* paint)
452 : INHERITED(kBeginDrawPicture_OpType)
453 , fPicture(SkRef(picture)) {
454
455 SkString* str = new SkString;
456 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
457 picture->cullRect().fLeft, picture->cullRect().fTop,
458 picture->cullRect().fRight, picture->cullRect().fBottom);
459 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700460
bsalomon49f085d2014-09-05 13:34:00 -0700461 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700462 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700463 fInfo.push(SkObjectParser::MatrixToString(*matrix));
464 }
fmalita160ebb22015-04-01 20:58:37 -0700465
bsalomon49f085d2014-09-05 13:34:00 -0700466 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700467 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700468 fInfo.push(SkObjectParser::PaintToString(*paint));
469 }
fmalita160ebb22015-04-01 20:58:37 -0700470
471}
472
473void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
474 if (fPaint.isValid()) {
475 SkRect bounds = fPicture->cullRect();
476 if (fMatrix.isValid()) {
477 fMatrix.get()->mapRect(&bounds);
478 }
479 canvas->saveLayer(&bounds, fPaint.get());
480 }
481
482 if (fMatrix.isValid()) {
483 if (!fPaint.isValid()) {
484 canvas->save();
485 }
486 canvas->concat(*fMatrix.get());
487 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000488}
489
fmalita160ebb22015-04-01 20:58:37 -0700490bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000491 canvas->clear(0xFFFFFFFF);
492 canvas->save();
493
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700494 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000495
robertphillips9b14f262014-06-04 05:40:44 -0700496 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000497
498 canvas->restore();
499
500 return true;
501}
502
fmalita160ebb22015-04-01 20:58:37 -0700503SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
504 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
505
506void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
507 if (fRestore) {
508 canvas->restore();
509 }
510}
511
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000512SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000513 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800514 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000515 fMode = mode;
516 fCount = count;
517 fPts = new SkPoint[count];
518 memcpy(fPts, pts, count * sizeof(SkPoint));
519 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000520
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000521 fInfo.push(SkObjectParser::PointsToString(pts, count));
522 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
523 "Points: "));
524 fInfo.push(SkObjectParser::PointModeToString(mode));
525 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000526}
527
fmalita8c89c522014-11-08 16:18:56 -0800528void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000529 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000530}
531
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000532bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000533 canvas->clear(0xFFFFFFFF);
534 canvas->save();
535
536 SkRect bounds;
537
538 bounds.setEmpty();
539 for (unsigned int i = 0; i < fCount; ++i) {
540 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
541 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000542
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000543 xlate_and_scale_to_bounds(canvas, bounds);
544
545 SkPaint p;
546 p.setColor(SK_ColorBLACK);
547 p.setStyle(SkPaint::kStroke_Style);
548
549 canvas->drawPoints(fMode, fCount, fPts, p);
550 canvas->restore();
551
552 return true;
553}
554
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000555SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000556 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800557 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000558 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000559
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000560 fText = new char[byteLength];
561 memcpy(fText, text, byteLength);
562 fByteLength = byteLength;
563
564 fPos = new SkPoint[numPts];
565 memcpy(fPos, pos, numPts * sizeof(SkPoint));
566
567 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000568
569 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000570 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000571 fInfo.push(SkObjectParser::PointsToString(pos, 1));
572 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000573}
574
fmalita8c89c522014-11-08 16:18:56 -0800575void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000576 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000577}
578
579
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000580SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
581 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000582 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800583 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000584 size_t numPts = paint.countText(text, byteLength);
585
586 fText = new char[byteLength];
587 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000588 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000589
590 fXpos = new SkScalar[numPts];
591 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
592
robertphillips@google.com91217d02013-03-17 18:33:46 +0000593 fConstY = constY;
594 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000595
robertphillips@google.com91217d02013-03-17 18:33:46 +0000596 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
597 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
598 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
599 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000600}
601
fmalita8c89c522014-11-08 16:18:56 -0800602void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000603 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000604}
605
fmalitab7425172014-08-26 07:56:44 -0700606SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
607 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800608 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700609 , fBlob(blob)
610 , fXPos(x)
611 , fYPos(y)
612 , fPaint(paint) {
613
614 blob->ref();
615
616 // FIXME: push blob info
617 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800618 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
619 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700620 fInfo.push(SkObjectParser::PaintToString(paint));
621}
622
fmalita8c89c522014-11-08 16:18:56 -0800623void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700624 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
625}
626
fmalita55773872014-08-29 15:08:20 -0700627bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
628 canvas->clear(SK_ColorWHITE);
629 canvas->save();
630
631 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
632 xlate_and_scale_to_bounds(canvas, bounds);
633
634 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
635
636 canvas->restore();
637
638 return true;
639}
640
robertphillips9bafc302015-02-13 11:13:00 -0800641SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
642 const SkPoint texCoords[4], SkXfermode* xfermode,
643 const SkPaint& paint)
644 : INHERITED(kDrawPatch_OpType) {
645 memcpy(fCubics, cubics, sizeof(fCubics));
646 memcpy(fColors, colors, sizeof(fColors));
647 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
648 fXfermode.reset(xfermode);
649 fPaint = paint;
650
651 fInfo.push(SkObjectParser::PaintToString(paint));
652}
653
654void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
655 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
656}
657
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000658SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800659 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000660 fRect = rect;
661 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000662
robertphillips@google.com91217d02013-03-17 18:33:46 +0000663 fInfo.push(SkObjectParser::RectToString(rect));
664 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000665}
666
fmalita8c89c522014-11-08 16:18:56 -0800667void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000668 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000669}
670
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000671SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800672 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000673 fRRect = rrect;
674 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000675
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000676 fInfo.push(SkObjectParser::RRectToString(rrect));
677 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000678}
679
fmalita8c89c522014-11-08 16:18:56 -0800680void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000681 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000682}
683
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000684bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000685 render_rrect(canvas, fRRect);
686 return true;
687}
688
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000689SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000690 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000691 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800692 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000693 fOuter = outer;
694 fInner = inner;
695 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000696
697 fInfo.push(SkObjectParser::RRectToString(outer));
698 fInfo.push(SkObjectParser::RRectToString(inner));
699 fInfo.push(SkObjectParser::PaintToString(paint));
700}
701
fmalita8c89c522014-11-08 16:18:56 -0800702void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000703 canvas->drawDRRect(fOuter, fInner, fPaint);
704}
705
706bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
707 render_drrect(canvas, fOuter, fInner);
708 return true;
709}
710
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000711SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000712 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800713 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000714 fBitmap = bitmap;
715 fLeft = left;
716 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700717 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000718 fPaint = *paint;
719 fPaintPtr = &fPaint;
720 } else {
721 fPaintPtr = NULL;
722 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000723
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000724 fInfo.push(SkObjectParser::BitmapToString(bitmap));
725 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
726 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700727 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000728 fInfo.push(SkObjectParser::PaintToString(*paint));
729 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000730}
731
fmalita8c89c522014-11-08 16:18:56 -0800732void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000733 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000734}
735
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000736bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000737 render_bitmap(canvas, fBitmap);
738 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000739}
740
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000741SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000742 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800743 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000744 fText = new char[byteLength];
745 memcpy(fText, text, byteLength);
746 fByteLength = byteLength;
747 fX = x;
748 fY = y;
749 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000750
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000751 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
752 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
753 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
754 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000755}
756
fmalita8c89c522014-11-08 16:18:56 -0800757void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000758 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000759}
760
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000761SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
762 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000763 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800764 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000765 fText = new char[byteLength];
766 memcpy(fText, text, byteLength);
767 fByteLength = byteLength;
768 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700769 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000770 fMatrix = *matrix;
771 } else {
772 fMatrix.setIdentity();
773 }
774 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000775
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000776 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
777 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700778 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000779 fInfo.push(SkObjectParser::MatrixToString(*matrix));
780 }
781 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000782}
783
fmalita8c89c522014-11-08 16:18:56 -0800784void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000785 canvas->drawTextOnPath(fText, fByteLength, fPath,
786 fMatrix.isIdentity() ? NULL : &fMatrix,
787 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000788}
789
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000790SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
791 const SkPoint vertices[], const SkPoint texs[],
792 const SkColor colors[], SkXfermode* xfermode,
793 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000794 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800795 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000796 fVmode = vmode;
797
798 fVertexCount = vertexCount;
799
800 fVertices = new SkPoint[vertexCount];
801 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
802
bsalomon49f085d2014-09-05 13:34:00 -0700803 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000804 fTexs = new SkPoint[vertexCount];
805 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
806 } else {
807 fTexs = NULL;
808 }
809
bsalomon49f085d2014-09-05 13:34:00 -0700810 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000811 fColors = new SkColor[vertexCount];
812 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
813 } else {
814 fColors = NULL;
815 }
816
817 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700818 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000819 fXfermode->ref();
820 }
821
822 if (indexCount > 0) {
823 fIndices = new uint16_t[indexCount];
824 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
825 } else {
826 fIndices = NULL;
827 }
828
829 fIndexCount = indexCount;
830 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000831
chudy@google.com902ebe52012-06-29 14:21:22 +0000832 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000833 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
834 fInfo.push(SkObjectParser::PaintToString(paint));
835}
836
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000837SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000838 delete [] fVertices;
839 delete [] fTexs;
840 delete [] fColors;
841 SkSafeUnref(fXfermode);
842 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000843}
844
fmalita8c89c522014-11-08 16:18:56 -0800845void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000846 canvas->drawVertices(fVmode, fVertexCount, fVertices,
847 fTexs, fColors, fXfermode, fIndices,
848 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000849}
850
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000851SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800852 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000853 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000854}
855
fmalita8c89c522014-11-08 16:18:56 -0800856void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000857 canvas->restore();
858}
859
Florin Malita5f6102d2014-06-30 10:13:28 -0400860SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800861 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000862}
863
fmalita8c89c522014-11-08 16:18:56 -0800864void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400865 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000866}
867
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000868SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000869 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800870 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700871 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000872 fBounds = *bounds;
873 } else {
874 fBounds.setEmpty();
875 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000876
bsalomon49f085d2014-09-05 13:34:00 -0700877 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000878 fPaint = *paint;
879 fPaintPtr = &fPaint;
880 } else {
881 fPaintPtr = NULL;
882 }
883 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000884
bsalomon49f085d2014-09-05 13:34:00 -0700885 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000886 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
887 }
bsalomon49f085d2014-09-05 13:34:00 -0700888 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000889 fInfo.push(SkObjectParser::PaintToString(*paint));
890 }
891 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000892}
893
fmalita8c89c522014-11-08 16:18:56 -0800894void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000895 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000896 fPaintPtr,
897 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000898}
899
fmalita8c89c522014-11-08 16:18:56 -0800900void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000901 canvas->save();
902}
903
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000904SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800905 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700906 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000907 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000908
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000909 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000910}
911
robertphillips70171682014-10-16 14:28:28 -0700912void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
913 fUserMatrix = userMatrix;
914}
915
fmalita8c89c522014-11-08 16:18:56 -0800916void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700917 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
918 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000919}
920