blob: 8e1612fad77544187ea3868f4b77bb51e4f01a6f [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";
fmalita651c9202015-07-22 10:23:01 -070039 case kDrawImage_OpType: return "DrawImage";
40 case kDrawImageRect_OpType: return "DrawImageRect";
robertphillips9bafc302015-02-13 11:13:00 -080041 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";
fmalita160ebb22015-04-01 20:58:37 -070055 case kEndDrawPicture_OpType: return "EndDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080056 case kRestore_OpType: return "Restore";
57 case kSave_OpType: return "Save";
58 case kSaveLayer_OpType: return "SaveLayer";
59 case kSetMatrix_OpType: return "SetMatrix";
chudy@google.com902ebe52012-06-29 14:21:22 +000060 default:
robertphillips9bafc302015-02-13 11:13:00 -080061 SkDebugf("OpType error 0x%08x\n", type);
chudy@google.com902ebe52012-06-29 14:21:22 +000062 SkASSERT(0);
63 break;
64 }
65 SkDEBUGFAIL("DrawType UNUSED\n");
66 return NULL;
67}
68
fmalita8c89c522014-11-08 16:18:56 -080069SkString SkDrawCommand::toString() const {
robertphillips9bafc302015-02-13 11:13:00 -080070 return SkString(GetCommandString(fOpType));
chudy@google.com902ebe52012-06-29 14:21:22 +000071}
72
robertphillips9bafc302015-02-13 11:13:00 -080073SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000074 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000075 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000076}
77
fmalita8c89c522014-11-08 16:18:56 -080078void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000079 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000080}
81
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000082namespace {
83
84void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
85 const SkISize& size = canvas->getDeviceSize();
86
87 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
88
89 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
90 if (bounds.width() > bounds.height()) {
91 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
92 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
93 } else {
94 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
95 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
96 }
97 canvas->translate(-bounds.centerX(), -bounds.centerY());
98}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +000099
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000100
101void render_path(SkCanvas* canvas, const SkPath& path) {
102 canvas->clear(0xFFFFFFFF);
103 canvas->save();
104
105 const SkRect& bounds = path.getBounds();
106
107 xlate_and_scale_to_bounds(canvas, bounds);
108
109 SkPaint p;
110 p.setColor(SK_ColorBLACK);
111 p.setStyle(SkPaint::kStroke_Style);
112
113 canvas->drawPath(path, p);
114 canvas->restore();
115}
116
117void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) {
118 const SkISize& size = canvas->getDeviceSize();
119
120 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
121 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
122
123 if (input.width() > input.height()) {
124 yScale *= input.height() / (float) input.width();
125 } else {
126 xScale *= input.width() / (float) input.height();
127 }
128
129 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
130 xScale * input.width(),
131 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000132
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000133 canvas->clear(0xFFFFFFFF);
reede47829b2015-08-06 10:02:53 -0700134 canvas->drawBitmapRect(input, dst, nullptr);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000135
bsalomon49f085d2014-09-05 13:34:00 -0700136 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000137 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
138 srcRect->fTop * yScale + SK_Scalar1,
139 srcRect->fRight * xScale + SK_Scalar1,
140 srcRect->fBottom * yScale + SK_Scalar1);
141 SkPaint p;
142 p.setColor(SK_ColorRED);
143 p.setStyle(SkPaint::kStroke_Style);
144
145 canvas->drawRect(r, p);
146 }
147}
148
149void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
150 canvas->clear(0xFFFFFFFF);
151 canvas->save();
152
153 const SkRect& bounds = rrect.getBounds();
154
155 xlate_and_scale_to_bounds(canvas, bounds);
156
157 SkPaint p;
158 p.setColor(SK_ColorBLACK);
159 p.setStyle(SkPaint::kStroke_Style);
160
161 canvas->drawRRect(rrect, p);
162 canvas->restore();
163}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000164
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000165void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
166 canvas->clear(0xFFFFFFFF);
167 canvas->save();
168
169 const SkRect& bounds = outer.getBounds();
170
171 xlate_and_scale_to_bounds(canvas, bounds);
172
173 SkPaint p;
174 p.setColor(SK_ColorBLACK);
175 p.setStyle(SkPaint::kStroke_Style);
176
177 canvas->drawDRRect(outer, inner, p);
178 canvas->restore();
179}
180
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000181};
182
183
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000184SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800185 : INHERITED(kClipPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000186 fPath = path;
187 fOp = op;
188 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000189
robertphillips@google.com91217d02013-03-17 18:33:46 +0000190 fInfo.push(SkObjectParser::PathToString(path));
191 fInfo.push(SkObjectParser::RegionOpToString(op));
192 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000193}
194
fmalita8c89c522014-11-08 16:18:56 -0800195void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000196 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000197}
198
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000199bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000200 render_path(canvas, fPath);
201 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000202}
203
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000204SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips9bafc302015-02-13 11:13:00 -0800205 : INHERITED(kClipRegion_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000206 fRegion = region;
207 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000208
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000209 fInfo.push(SkObjectParser::RegionToString(region));
210 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000211}
212
fmalita8c89c522014-11-08 16:18:56 -0800213void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000214 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000215}
216
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000217SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800218 : INHERITED(kClipRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000219 fRect = rect;
220 fOp = op;
221 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000222
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000223 fInfo.push(SkObjectParser::RectToString(rect));
224 fInfo.push(SkObjectParser::RegionOpToString(op));
225 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000226}
227
fmalita8c89c522014-11-08 16:18:56 -0800228void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000229 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000230}
231
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000232SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800233 : INHERITED(kClipRRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000234 fRRect = rrect;
235 fOp = op;
236 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000237
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000238 fInfo.push(SkObjectParser::RRectToString(rrect));
239 fInfo.push(SkObjectParser::RegionOpToString(op));
240 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000241}
242
fmalita8c89c522014-11-08 16:18:56 -0800243void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000244 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000245}
246
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000247bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000248 render_rrect(canvas, fRRect);
249 return true;
250}
251
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000252SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800253 : INHERITED(kConcat_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000254 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000255
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000256 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000257}
258
fmalita8c89c522014-11-08 16:18:56 -0800259void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000260 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000261}
262
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000263SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700264 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800265 : INHERITED(kDrawBitmap_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000266 fBitmap = bitmap;
267 fLeft = left;
268 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700269 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000270 fPaint = *paint;
271 fPaintPtr = &fPaint;
272 } else {
273 fPaintPtr = NULL;
274 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000275
276 fInfo.push(SkObjectParser::BitmapToString(bitmap));
277 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
278 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700279 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000280 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000281 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000282}
283
fmalita8c89c522014-11-08 16:18:56 -0800284void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000285 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000286}
287
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000288bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000289 render_bitmap(canvas, fBitmap);
290 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000291}
292
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000293SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000294 const SkRect& dst, const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800295 : INHERITED(kDrawBitmapNine_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000296 fBitmap = bitmap;
297 fCenter = center;
298 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700299 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000300 fPaint = *paint;
301 fPaintPtr = &fPaint;
302 } else {
303 fPaintPtr = NULL;
304 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000305
306 fInfo.push(SkObjectParser::BitmapToString(bitmap));
307 fInfo.push(SkObjectParser::IRectToString(center));
308 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700309 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000310 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000311 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000312}
313
fmalita8c89c522014-11-08 16:18:56 -0800314void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000315 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000316}
317
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000318bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000319 render_bitmap(canvas, fBitmap);
320 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000321}
322
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000323SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000324 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700325 SkCanvas::SrcRectConstraint constraint)
robertphillips9bafc302015-02-13 11:13:00 -0800326 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000327 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700328 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000329 fSrc = *src;
330 } else {
331 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000332 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000333 fDst = dst;
334
bsalomon49f085d2014-09-05 13:34:00 -0700335 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000336 fPaint = *paint;
337 fPaintPtr = &fPaint;
338 } else {
339 fPaintPtr = NULL;
340 }
reeda5517e22015-07-14 10:54:12 -0700341 fConstraint = constraint;
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000342
robertphillips@google.com91217d02013-03-17 18:33:46 +0000343 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700344 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000345 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
346 }
347 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700348 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000349 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000350 }
reeda5517e22015-07-14 10:54:12 -0700351 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000352}
353
fmalita8c89c522014-11-08 16:18:56 -0800354void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700355 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000356}
357
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000358bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000359 render_bitmap(canvas, fBitmap, this->srcRect());
360 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000361}
362
fmalita651c9202015-07-22 10:23:01 -0700363SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top,
364 const SkPaint* paint)
365 : INHERITED(kDrawImage_OpType)
366 , fImage(SkRef(image))
367 , fLeft(left)
368 , fTop(top) {
369
370 if (paint) {
371 fPaint.set(*paint);
372 }
373}
374
375void SkDrawImageCommand::execute(SkCanvas* canvas) const {
376 canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull());
377}
378
379bool SkDrawImageCommand::render(SkCanvas* canvas) const {
380 SkAutoCanvasRestore acr(canvas, true);
381 canvas->clear(0xFFFFFFFF);
382
383 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
384 SkIntToScalar(fImage->width()),
385 SkIntToScalar(fImage->height())));
386 this->execute(canvas);
387 return true;
388}
389
390SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src,
391 const SkRect& dst, const SkPaint* paint,
392 SkCanvas::SrcRectConstraint constraint)
393 : INHERITED(kDrawImageRect_OpType)
394 , fImage(SkRef(image))
395 , fDst(dst)
396 , fConstraint(constraint) {
397
398 if (src) {
399 fSrc.set(*src);
400 }
401
402 if (paint) {
403 fPaint.set(*paint);
404 }
405}
406
407void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700408 canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
fmalita651c9202015-07-22 10:23:01 -0700409}
410
411bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
412 SkAutoCanvasRestore acr(canvas, true);
413 canvas->clear(0xFFFFFFFF);
414
415 xlate_and_scale_to_bounds(canvas, fDst);
416
417 this->execute(canvas);
418 return true;
419}
420
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000421SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800422 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000423 fOval = oval;
424 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000425
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000426 fInfo.push(SkObjectParser::RectToString(oval));
427 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000428}
429
fmalita8c89c522014-11-08 16:18:56 -0800430void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000431 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000432}
433
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000434bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000435 canvas->clear(0xFFFFFFFF);
436 canvas->save();
437
438 xlate_and_scale_to_bounds(canvas, fOval);
439
440 SkPaint p;
441 p.setColor(SK_ColorBLACK);
442 p.setStyle(SkPaint::kStroke_Style);
443
444 canvas->drawOval(fOval, p);
445 canvas->restore();
446
447 return true;
448}
449
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000450SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800451 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000452 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000453
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000454 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000455}
456
fmalita8c89c522014-11-08 16:18:56 -0800457void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000458 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000459}
460
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000461bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000462 canvas->clear(0xFFFFFFFF);
463 canvas->drawPaint(fPaint);
464 return true;
465}
466
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000467SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800468 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000469 fPath = path;
470 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000471
robertphillips@google.com91217d02013-03-17 18:33:46 +0000472 fInfo.push(SkObjectParser::PathToString(path));
473 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000474}
475
fmalita8c89c522014-11-08 16:18:56 -0800476void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000477 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000478}
479
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000480bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000481 render_path(canvas, fPath);
482 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000483}
484
fmalita160ebb22015-04-01 20:58:37 -0700485SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
486 const SkMatrix* matrix,
487 const SkPaint* paint)
488 : INHERITED(kBeginDrawPicture_OpType)
489 , fPicture(SkRef(picture)) {
490
491 SkString* str = new SkString;
492 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
493 picture->cullRect().fLeft, picture->cullRect().fTop,
494 picture->cullRect().fRight, picture->cullRect().fBottom);
495 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700496
bsalomon49f085d2014-09-05 13:34:00 -0700497 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700498 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700499 fInfo.push(SkObjectParser::MatrixToString(*matrix));
500 }
fmalita160ebb22015-04-01 20:58:37 -0700501
bsalomon49f085d2014-09-05 13:34:00 -0700502 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700503 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700504 fInfo.push(SkObjectParser::PaintToString(*paint));
505 }
fmalita160ebb22015-04-01 20:58:37 -0700506
507}
508
509void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
510 if (fPaint.isValid()) {
511 SkRect bounds = fPicture->cullRect();
512 if (fMatrix.isValid()) {
513 fMatrix.get()->mapRect(&bounds);
514 }
515 canvas->saveLayer(&bounds, fPaint.get());
516 }
517
518 if (fMatrix.isValid()) {
519 if (!fPaint.isValid()) {
520 canvas->save();
521 }
522 canvas->concat(*fMatrix.get());
523 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000524}
525
fmalita160ebb22015-04-01 20:58:37 -0700526bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000527 canvas->clear(0xFFFFFFFF);
528 canvas->save();
529
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700530 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000531
robertphillips9b14f262014-06-04 05:40:44 -0700532 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000533
534 canvas->restore();
535
536 return true;
537}
538
fmalita160ebb22015-04-01 20:58:37 -0700539SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
540 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
541
542void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
543 if (fRestore) {
544 canvas->restore();
545 }
546}
547
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000548SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000549 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800550 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000551 fMode = mode;
552 fCount = count;
553 fPts = new SkPoint[count];
554 memcpy(fPts, pts, count * sizeof(SkPoint));
555 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000556
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000557 fInfo.push(SkObjectParser::PointsToString(pts, count));
558 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
559 "Points: "));
560 fInfo.push(SkObjectParser::PointModeToString(mode));
561 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000562}
563
fmalita8c89c522014-11-08 16:18:56 -0800564void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000565 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000566}
567
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000568bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000569 canvas->clear(0xFFFFFFFF);
570 canvas->save();
571
572 SkRect bounds;
573
574 bounds.setEmpty();
575 for (unsigned int i = 0; i < fCount; ++i) {
576 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
577 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000578
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000579 xlate_and_scale_to_bounds(canvas, bounds);
580
581 SkPaint p;
582 p.setColor(SK_ColorBLACK);
583 p.setStyle(SkPaint::kStroke_Style);
584
585 canvas->drawPoints(fMode, fCount, fPts, p);
586 canvas->restore();
587
588 return true;
589}
590
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000591SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000592 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800593 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000594 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000595
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000596 fText = new char[byteLength];
597 memcpy(fText, text, byteLength);
598 fByteLength = byteLength;
599
600 fPos = new SkPoint[numPts];
601 memcpy(fPos, pos, numPts * sizeof(SkPoint));
602
603 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000604
605 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000606 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000607 fInfo.push(SkObjectParser::PointsToString(pos, 1));
608 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000609}
610
fmalita8c89c522014-11-08 16:18:56 -0800611void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000612 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000613}
614
615
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000616SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
617 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000618 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800619 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000620 size_t numPts = paint.countText(text, byteLength);
621
622 fText = new char[byteLength];
623 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000624 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000625
626 fXpos = new SkScalar[numPts];
627 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
628
robertphillips@google.com91217d02013-03-17 18:33:46 +0000629 fConstY = constY;
630 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000631
robertphillips@google.com91217d02013-03-17 18:33:46 +0000632 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
633 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
634 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
635 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000636}
637
fmalita8c89c522014-11-08 16:18:56 -0800638void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000639 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000640}
641
fmalitab7425172014-08-26 07:56:44 -0700642SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
643 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800644 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700645 , fBlob(blob)
646 , fXPos(x)
647 , fYPos(y)
648 , fPaint(paint) {
649
650 blob->ref();
651
652 // FIXME: push blob info
653 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800654 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
655 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700656 fInfo.push(SkObjectParser::PaintToString(paint));
657}
658
fmalita8c89c522014-11-08 16:18:56 -0800659void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700660 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
661}
662
fmalita55773872014-08-29 15:08:20 -0700663bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
664 canvas->clear(SK_ColorWHITE);
665 canvas->save();
666
667 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
668 xlate_and_scale_to_bounds(canvas, bounds);
669
670 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
671
672 canvas->restore();
673
674 return true;
675}
676
robertphillips9bafc302015-02-13 11:13:00 -0800677SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
678 const SkPoint texCoords[4], SkXfermode* xfermode,
679 const SkPaint& paint)
680 : INHERITED(kDrawPatch_OpType) {
681 memcpy(fCubics, cubics, sizeof(fCubics));
682 memcpy(fColors, colors, sizeof(fColors));
683 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
684 fXfermode.reset(xfermode);
685 fPaint = paint;
686
687 fInfo.push(SkObjectParser::PaintToString(paint));
688}
689
690void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
691 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
692}
693
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000694SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800695 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000696 fRect = rect;
697 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000698
robertphillips@google.com91217d02013-03-17 18:33:46 +0000699 fInfo.push(SkObjectParser::RectToString(rect));
700 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000701}
702
fmalita8c89c522014-11-08 16:18:56 -0800703void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000704 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000705}
706
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000707SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800708 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000709 fRRect = rrect;
710 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000711
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000712 fInfo.push(SkObjectParser::RRectToString(rrect));
713 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000714}
715
fmalita8c89c522014-11-08 16:18:56 -0800716void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000717 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000718}
719
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000720bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000721 render_rrect(canvas, fRRect);
722 return true;
723}
724
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000725SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000726 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000727 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800728 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000729 fOuter = outer;
730 fInner = inner;
731 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000732
733 fInfo.push(SkObjectParser::RRectToString(outer));
734 fInfo.push(SkObjectParser::RRectToString(inner));
735 fInfo.push(SkObjectParser::PaintToString(paint));
736}
737
fmalita8c89c522014-11-08 16:18:56 -0800738void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000739 canvas->drawDRRect(fOuter, fInner, fPaint);
740}
741
742bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
743 render_drrect(canvas, fOuter, fInner);
744 return true;
745}
746
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000747SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000748 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800749 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000750 fBitmap = bitmap;
751 fLeft = left;
752 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700753 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000754 fPaint = *paint;
755 fPaintPtr = &fPaint;
756 } else {
757 fPaintPtr = NULL;
758 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000759
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000760 fInfo.push(SkObjectParser::BitmapToString(bitmap));
761 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
762 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700763 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000764 fInfo.push(SkObjectParser::PaintToString(*paint));
765 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000766}
767
fmalita8c89c522014-11-08 16:18:56 -0800768void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000769 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000770}
771
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000772bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000773 render_bitmap(canvas, fBitmap);
774 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000775}
776
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000777SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000778 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800779 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000780 fText = new char[byteLength];
781 memcpy(fText, text, byteLength);
782 fByteLength = byteLength;
783 fX = x;
784 fY = y;
785 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000786
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000787 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
788 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
789 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
790 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000791}
792
fmalita8c89c522014-11-08 16:18:56 -0800793void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000794 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000795}
796
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000797SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
798 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000799 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800800 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000801 fText = new char[byteLength];
802 memcpy(fText, text, byteLength);
803 fByteLength = byteLength;
804 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700805 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000806 fMatrix = *matrix;
807 } else {
808 fMatrix.setIdentity();
809 }
810 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000811
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000812 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
813 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700814 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000815 fInfo.push(SkObjectParser::MatrixToString(*matrix));
816 }
817 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000818}
819
fmalita8c89c522014-11-08 16:18:56 -0800820void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000821 canvas->drawTextOnPath(fText, fByteLength, fPath,
822 fMatrix.isIdentity() ? NULL : &fMatrix,
823 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000824}
825
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000826SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
827 const SkPoint vertices[], const SkPoint texs[],
828 const SkColor colors[], SkXfermode* xfermode,
829 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000830 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800831 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000832 fVmode = vmode;
833
834 fVertexCount = vertexCount;
835
836 fVertices = new SkPoint[vertexCount];
837 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
838
bsalomon49f085d2014-09-05 13:34:00 -0700839 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000840 fTexs = new SkPoint[vertexCount];
841 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
842 } else {
843 fTexs = NULL;
844 }
845
bsalomon49f085d2014-09-05 13:34:00 -0700846 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000847 fColors = new SkColor[vertexCount];
848 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
849 } else {
850 fColors = NULL;
851 }
852
853 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700854 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000855 fXfermode->ref();
856 }
857
858 if (indexCount > 0) {
859 fIndices = new uint16_t[indexCount];
860 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
861 } else {
862 fIndices = NULL;
863 }
864
865 fIndexCount = indexCount;
866 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000867
chudy@google.com902ebe52012-06-29 14:21:22 +0000868 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000869 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
870 fInfo.push(SkObjectParser::PaintToString(paint));
871}
872
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000873SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000874 delete [] fVertices;
875 delete [] fTexs;
876 delete [] fColors;
877 SkSafeUnref(fXfermode);
878 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000879}
880
fmalita8c89c522014-11-08 16:18:56 -0800881void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000882 canvas->drawVertices(fVmode, fVertexCount, fVertices,
883 fTexs, fColors, fXfermode, fIndices,
884 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000885}
886
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000887SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800888 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000889 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000890}
891
fmalita8c89c522014-11-08 16:18:56 -0800892void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000893 canvas->restore();
894}
895
Florin Malita5f6102d2014-06-30 10:13:28 -0400896SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800897 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000898}
899
fmalita8c89c522014-11-08 16:18:56 -0800900void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400901 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000902}
903
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000904SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000905 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800906 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700907 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000908 fBounds = *bounds;
909 } else {
910 fBounds.setEmpty();
911 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000912
bsalomon49f085d2014-09-05 13:34:00 -0700913 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000914 fPaint = *paint;
915 fPaintPtr = &fPaint;
916 } else {
917 fPaintPtr = NULL;
918 }
919 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000920
bsalomon49f085d2014-09-05 13:34:00 -0700921 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000922 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
923 }
bsalomon49f085d2014-09-05 13:34:00 -0700924 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000925 fInfo.push(SkObjectParser::PaintToString(*paint));
926 }
927 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000928}
929
fmalita8c89c522014-11-08 16:18:56 -0800930void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000931 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000932 fPaintPtr,
933 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000934}
935
fmalita8c89c522014-11-08 16:18:56 -0800936void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000937 canvas->save();
938}
939
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000940SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800941 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700942 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000943 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000944
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000945 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000946}
947
robertphillips70171682014-10-16 14:28:28 -0700948void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
949 fUserMatrix = userMatrix;
950}
951
fmalita8c89c522014-11-08 16:18:56 -0800952void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700953 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
954 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000955}
956