blob: a9415dd924ef97bb54be03f20ab85b498931cd56 [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");
halcanary96fcdcc2015-08-27 07:41:13 -070066 return nullptr;
chudy@google.com902ebe52012-06-29 14:21:22 +000067}
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
halcanary96fcdcc2015-08-27 07:41:13 -0700117void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = nullptr) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000118 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 {
halcanary96fcdcc2015-08-27 07:41:13 -0700273 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000274 }
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 {
halcanary96fcdcc2015-08-27 07:41:13 -0700303 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000304 }
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 {
halcanary96fcdcc2015-08-27 07:41:13 -0700339 fPaintPtr = nullptr;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000340 }
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 }
robertphillips80af6452015-08-24 08:27:38 -0700405
406 fInfo.push(SkObjectParser::ImageToString(image));
407 if (src) {
408 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
409 }
410 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
411 if (paint) {
412 fInfo.push(SkObjectParser::PaintToString(*paint));
413 }
414 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
fmalita651c9202015-07-22 10:23:01 -0700415}
416
417void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700418 canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
fmalita651c9202015-07-22 10:23:01 -0700419}
420
421bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
422 SkAutoCanvasRestore acr(canvas, true);
423 canvas->clear(0xFFFFFFFF);
424
425 xlate_and_scale_to_bounds(canvas, fDst);
426
427 this->execute(canvas);
428 return true;
429}
430
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000431SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800432 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000433 fOval = oval;
434 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000435
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000436 fInfo.push(SkObjectParser::RectToString(oval));
437 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000438}
439
fmalita8c89c522014-11-08 16:18:56 -0800440void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000441 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000442}
443
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000444bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000445 canvas->clear(0xFFFFFFFF);
446 canvas->save();
447
448 xlate_and_scale_to_bounds(canvas, fOval);
449
450 SkPaint p;
451 p.setColor(SK_ColorBLACK);
452 p.setStyle(SkPaint::kStroke_Style);
453
454 canvas->drawOval(fOval, p);
455 canvas->restore();
456
457 return true;
458}
459
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000460SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800461 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000462 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000463
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000464 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000465}
466
fmalita8c89c522014-11-08 16:18:56 -0800467void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000468 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000469}
470
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000471bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000472 canvas->clear(0xFFFFFFFF);
473 canvas->drawPaint(fPaint);
474 return true;
475}
476
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000477SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800478 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000479 fPath = path;
480 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000481
robertphillips@google.com91217d02013-03-17 18:33:46 +0000482 fInfo.push(SkObjectParser::PathToString(path));
483 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000484}
485
fmalita8c89c522014-11-08 16:18:56 -0800486void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000487 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000488}
489
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000490bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000491 render_path(canvas, fPath);
492 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000493}
494
fmalita160ebb22015-04-01 20:58:37 -0700495SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
496 const SkMatrix* matrix,
497 const SkPaint* paint)
498 : INHERITED(kBeginDrawPicture_OpType)
499 , fPicture(SkRef(picture)) {
500
501 SkString* str = new SkString;
502 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
503 picture->cullRect().fLeft, picture->cullRect().fTop,
504 picture->cullRect().fRight, picture->cullRect().fBottom);
505 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700506
bsalomon49f085d2014-09-05 13:34:00 -0700507 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700508 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700509 fInfo.push(SkObjectParser::MatrixToString(*matrix));
510 }
fmalita160ebb22015-04-01 20:58:37 -0700511
bsalomon49f085d2014-09-05 13:34:00 -0700512 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700513 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700514 fInfo.push(SkObjectParser::PaintToString(*paint));
515 }
fmalita160ebb22015-04-01 20:58:37 -0700516
517}
518
519void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
520 if (fPaint.isValid()) {
521 SkRect bounds = fPicture->cullRect();
522 if (fMatrix.isValid()) {
523 fMatrix.get()->mapRect(&bounds);
524 }
525 canvas->saveLayer(&bounds, fPaint.get());
526 }
527
528 if (fMatrix.isValid()) {
529 if (!fPaint.isValid()) {
530 canvas->save();
531 }
532 canvas->concat(*fMatrix.get());
533 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000534}
535
fmalita160ebb22015-04-01 20:58:37 -0700536bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000537 canvas->clear(0xFFFFFFFF);
538 canvas->save();
539
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700540 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000541
robertphillips9b14f262014-06-04 05:40:44 -0700542 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000543
544 canvas->restore();
545
546 return true;
547}
548
fmalita160ebb22015-04-01 20:58:37 -0700549SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
550 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
551
552void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
553 if (fRestore) {
554 canvas->restore();
555 }
556}
557
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000558SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000559 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800560 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000561 fMode = mode;
562 fCount = count;
563 fPts = new SkPoint[count];
564 memcpy(fPts, pts, count * sizeof(SkPoint));
565 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000566
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000567 fInfo.push(SkObjectParser::PointsToString(pts, count));
568 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
569 "Points: "));
570 fInfo.push(SkObjectParser::PointModeToString(mode));
571 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000572}
573
fmalita8c89c522014-11-08 16:18:56 -0800574void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000575 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000576}
577
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000578bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000579 canvas->clear(0xFFFFFFFF);
580 canvas->save();
581
582 SkRect bounds;
583
584 bounds.setEmpty();
585 for (unsigned int i = 0; i < fCount; ++i) {
586 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
587 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000588
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000589 xlate_and_scale_to_bounds(canvas, bounds);
590
591 SkPaint p;
592 p.setColor(SK_ColorBLACK);
593 p.setStyle(SkPaint::kStroke_Style);
594
595 canvas->drawPoints(fMode, fCount, fPts, p);
596 canvas->restore();
597
598 return true;
599}
600
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000601SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000602 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800603 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000604 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000605
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000606 fText = new char[byteLength];
607 memcpy(fText, text, byteLength);
608 fByteLength = byteLength;
609
610 fPos = new SkPoint[numPts];
611 memcpy(fPos, pos, numPts * sizeof(SkPoint));
612
613 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000614
615 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000616 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000617 fInfo.push(SkObjectParser::PointsToString(pos, 1));
618 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000619}
620
fmalita8c89c522014-11-08 16:18:56 -0800621void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000622 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000623}
624
625
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000626SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
627 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000628 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800629 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000630 size_t numPts = paint.countText(text, byteLength);
631
632 fText = new char[byteLength];
633 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000634 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000635
636 fXpos = new SkScalar[numPts];
637 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
638
robertphillips@google.com91217d02013-03-17 18:33:46 +0000639 fConstY = constY;
640 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000641
robertphillips@google.com91217d02013-03-17 18:33:46 +0000642 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
643 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
644 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
645 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000646}
647
fmalita8c89c522014-11-08 16:18:56 -0800648void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000649 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000650}
651
fmalitab7425172014-08-26 07:56:44 -0700652SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
653 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800654 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700655 , fBlob(blob)
656 , fXPos(x)
657 , fYPos(y)
658 , fPaint(paint) {
659
660 blob->ref();
661
662 // FIXME: push blob info
663 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800664 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
665 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700666 fInfo.push(SkObjectParser::PaintToString(paint));
667}
668
fmalita8c89c522014-11-08 16:18:56 -0800669void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700670 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
671}
672
fmalita55773872014-08-29 15:08:20 -0700673bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
674 canvas->clear(SK_ColorWHITE);
675 canvas->save();
676
677 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
678 xlate_and_scale_to_bounds(canvas, bounds);
679
680 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
681
682 canvas->restore();
683
684 return true;
685}
686
robertphillips9bafc302015-02-13 11:13:00 -0800687SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
688 const SkPoint texCoords[4], SkXfermode* xfermode,
689 const SkPaint& paint)
690 : INHERITED(kDrawPatch_OpType) {
691 memcpy(fCubics, cubics, sizeof(fCubics));
692 memcpy(fColors, colors, sizeof(fColors));
693 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
694 fXfermode.reset(xfermode);
695 fPaint = paint;
696
697 fInfo.push(SkObjectParser::PaintToString(paint));
698}
699
700void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
701 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
702}
703
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000704SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800705 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000706 fRect = rect;
707 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000708
robertphillips@google.com91217d02013-03-17 18:33:46 +0000709 fInfo.push(SkObjectParser::RectToString(rect));
710 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000711}
712
fmalita8c89c522014-11-08 16:18:56 -0800713void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000714 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000715}
716
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000717SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800718 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000719 fRRect = rrect;
720 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000721
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000722 fInfo.push(SkObjectParser::RRectToString(rrect));
723 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000724}
725
fmalita8c89c522014-11-08 16:18:56 -0800726void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000727 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000728}
729
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000730bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000731 render_rrect(canvas, fRRect);
732 return true;
733}
734
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000735SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000736 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000737 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800738 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000739 fOuter = outer;
740 fInner = inner;
741 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000742
743 fInfo.push(SkObjectParser::RRectToString(outer));
744 fInfo.push(SkObjectParser::RRectToString(inner));
745 fInfo.push(SkObjectParser::PaintToString(paint));
746}
747
fmalita8c89c522014-11-08 16:18:56 -0800748void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000749 canvas->drawDRRect(fOuter, fInner, fPaint);
750}
751
752bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
753 render_drrect(canvas, fOuter, fInner);
754 return true;
755}
756
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000757SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000758 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800759 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000760 fBitmap = bitmap;
761 fLeft = left;
762 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700763 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000764 fPaint = *paint;
765 fPaintPtr = &fPaint;
766 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700767 fPaintPtr = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000768 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000769
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000770 fInfo.push(SkObjectParser::BitmapToString(bitmap));
771 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
772 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700773 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000774 fInfo.push(SkObjectParser::PaintToString(*paint));
775 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000776}
777
fmalita8c89c522014-11-08 16:18:56 -0800778void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000779 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000780}
781
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000782bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000783 render_bitmap(canvas, fBitmap);
784 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000785}
786
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000787SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000788 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800789 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000790 fText = new char[byteLength];
791 memcpy(fText, text, byteLength);
792 fByteLength = byteLength;
793 fX = x;
794 fY = y;
795 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000796
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000797 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
798 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
799 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
800 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000801}
802
fmalita8c89c522014-11-08 16:18:56 -0800803void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000804 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000805}
806
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000807SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
808 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000809 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800810 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000811 fText = new char[byteLength];
812 memcpy(fText, text, byteLength);
813 fByteLength = byteLength;
814 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700815 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000816 fMatrix = *matrix;
817 } else {
818 fMatrix.setIdentity();
819 }
820 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000821
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000822 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
823 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700824 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000825 fInfo.push(SkObjectParser::MatrixToString(*matrix));
826 }
827 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000828}
829
fmalita8c89c522014-11-08 16:18:56 -0800830void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000831 canvas->drawTextOnPath(fText, fByteLength, fPath,
halcanary96fcdcc2015-08-27 07:41:13 -0700832 fMatrix.isIdentity() ? nullptr : &fMatrix,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000833 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000834}
835
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000836SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
837 const SkPoint vertices[], const SkPoint texs[],
838 const SkColor colors[], SkXfermode* xfermode,
839 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000840 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800841 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000842 fVmode = vmode;
843
844 fVertexCount = vertexCount;
845
846 fVertices = new SkPoint[vertexCount];
847 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
848
bsalomon49f085d2014-09-05 13:34:00 -0700849 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000850 fTexs = new SkPoint[vertexCount];
851 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
852 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700853 fTexs = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000854 }
855
bsalomon49f085d2014-09-05 13:34:00 -0700856 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000857 fColors = new SkColor[vertexCount];
858 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
859 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700860 fColors = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000861 }
862
863 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700864 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000865 fXfermode->ref();
866 }
867
868 if (indexCount > 0) {
869 fIndices = new uint16_t[indexCount];
870 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
871 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700872 fIndices = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000873 }
874
875 fIndexCount = indexCount;
876 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000877
chudy@google.com902ebe52012-06-29 14:21:22 +0000878 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000879 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
880 fInfo.push(SkObjectParser::PaintToString(paint));
881}
882
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000883SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000884 delete [] fVertices;
885 delete [] fTexs;
886 delete [] fColors;
887 SkSafeUnref(fXfermode);
888 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000889}
890
fmalita8c89c522014-11-08 16:18:56 -0800891void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000892 canvas->drawVertices(fVmode, fVertexCount, fVertices,
893 fTexs, fColors, fXfermode, fIndices,
894 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000895}
896
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000897SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800898 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000899 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000900}
901
fmalita8c89c522014-11-08 16:18:56 -0800902void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000903 canvas->restore();
904}
905
Florin Malita5f6102d2014-06-30 10:13:28 -0400906SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800907 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000908}
909
fmalita8c89c522014-11-08 16:18:56 -0800910void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400911 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000912}
913
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000914SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000915 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800916 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700917 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000918 fBounds = *bounds;
919 } else {
920 fBounds.setEmpty();
921 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000922
bsalomon49f085d2014-09-05 13:34:00 -0700923 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000924 fPaint = *paint;
925 fPaintPtr = &fPaint;
926 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700927 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000928 }
929 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000930
bsalomon49f085d2014-09-05 13:34:00 -0700931 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000932 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
933 }
bsalomon49f085d2014-09-05 13:34:00 -0700934 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000935 fInfo.push(SkObjectParser::PaintToString(*paint));
936 }
937 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000938}
939
fmalita8c89c522014-11-08 16:18:56 -0800940void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700941 canvas->saveLayer(fBounds.isEmpty() ? nullptr : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000942 fPaintPtr,
943 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000944}
945
fmalita8c89c522014-11-08 16:18:56 -0800946void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000947 canvas->save();
948}
949
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000950SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800951 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700952 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000953 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000954
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000955 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000956}
957
robertphillips70171682014-10-16 14:28:28 -0700958void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
959 fUserMatrix = userMatrix;
960}
961
fmalita8c89c522014-11-08 16:18:56 -0800962void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700963 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
964 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000965}
966