blob: 66f0c14f2d2ef66085bcc3d3b18ac4a05f0702c7 [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);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000103
104 const SkRect& bounds = path.getBounds();
fmalitab0cd8b72015-10-06 07:24:03 -0700105 if (bounds.isEmpty()) {
106 return;
107 }
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000108
fmalitab0cd8b72015-10-06 07:24:03 -0700109 SkAutoCanvasRestore acr(canvas, true);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000110 xlate_and_scale_to_bounds(canvas, bounds);
111
112 SkPaint p;
113 p.setColor(SK_ColorBLACK);
114 p.setStyle(SkPaint::kStroke_Style);
115
116 canvas->drawPath(path, p);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000117}
118
halcanary96fcdcc2015-08-27 07:41:13 -0700119void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = nullptr) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000120 const SkISize& size = canvas->getDeviceSize();
121
122 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
123 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
124
125 if (input.width() > input.height()) {
126 yScale *= input.height() / (float) input.width();
127 } else {
128 xScale *= input.width() / (float) input.height();
129 }
130
131 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
132 xScale * input.width(),
133 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000134
robertphillips96a5cff2015-09-24 06:56:27 -0700135 static const int kNumBlocks = 8;
136
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000137 canvas->clear(0xFFFFFFFF);
robertphillips96a5cff2015-09-24 06:56:27 -0700138 SkISize block = {
139 canvas->imageInfo().width()/kNumBlocks,
140 canvas->imageInfo().height()/kNumBlocks
141 };
142 for (int y = 0; y < kNumBlocks; ++y) {
143 for (int x = 0; x < kNumBlocks; ++x) {
144 SkPaint paint;
145 paint.setColor((x+y)%2 ? SK_ColorLTGRAY : SK_ColorDKGRAY);
146 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x*block.width()),
147 SkIntToScalar(y*block.height()),
148 SkIntToScalar(block.width()),
149 SkIntToScalar(block.height()));
150 canvas->drawRect(r, paint);
151 }
152 }
153
reede47829b2015-08-06 10:02:53 -0700154 canvas->drawBitmapRect(input, dst, nullptr);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000155
bsalomon49f085d2014-09-05 13:34:00 -0700156 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000157 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
158 srcRect->fTop * yScale + SK_Scalar1,
159 srcRect->fRight * xScale + SK_Scalar1,
160 srcRect->fBottom * yScale + SK_Scalar1);
161 SkPaint p;
162 p.setColor(SK_ColorRED);
163 p.setStyle(SkPaint::kStroke_Style);
164
165 canvas->drawRect(r, p);
166 }
167}
168
169void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
170 canvas->clear(0xFFFFFFFF);
171 canvas->save();
172
173 const SkRect& bounds = rrect.getBounds();
174
175 xlate_and_scale_to_bounds(canvas, bounds);
176
177 SkPaint p;
178 p.setColor(SK_ColorBLACK);
179 p.setStyle(SkPaint::kStroke_Style);
180
181 canvas->drawRRect(rrect, p);
182 canvas->restore();
183}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000184
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000185void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
186 canvas->clear(0xFFFFFFFF);
187 canvas->save();
188
189 const SkRect& bounds = outer.getBounds();
190
191 xlate_and_scale_to_bounds(canvas, bounds);
192
193 SkPaint p;
194 p.setColor(SK_ColorBLACK);
195 p.setStyle(SkPaint::kStroke_Style);
196
197 canvas->drawDRRect(outer, inner, p);
198 canvas->restore();
199}
200
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000201};
202
203
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000204SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800205 : INHERITED(kClipPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000206 fPath = path;
207 fOp = op;
208 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000209
robertphillips@google.com91217d02013-03-17 18:33:46 +0000210 fInfo.push(SkObjectParser::PathToString(path));
211 fInfo.push(SkObjectParser::RegionOpToString(op));
212 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000213}
214
fmalita8c89c522014-11-08 16:18:56 -0800215void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000216 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000217}
218
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000219bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000220 render_path(canvas, fPath);
221 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000222}
223
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000224SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips9bafc302015-02-13 11:13:00 -0800225 : INHERITED(kClipRegion_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000226 fRegion = region;
227 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000228
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000229 fInfo.push(SkObjectParser::RegionToString(region));
230 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000231}
232
fmalita8c89c522014-11-08 16:18:56 -0800233void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000234 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000235}
236
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000237SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800238 : INHERITED(kClipRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000239 fRect = rect;
240 fOp = op;
241 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000242
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000243 fInfo.push(SkObjectParser::RectToString(rect));
244 fInfo.push(SkObjectParser::RegionOpToString(op));
245 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000246}
247
fmalita8c89c522014-11-08 16:18:56 -0800248void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000249 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000250}
251
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000252SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800253 : INHERITED(kClipRRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000254 fRRect = rrect;
255 fOp = op;
256 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000257
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000258 fInfo.push(SkObjectParser::RRectToString(rrect));
259 fInfo.push(SkObjectParser::RegionOpToString(op));
260 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000261}
262
fmalita8c89c522014-11-08 16:18:56 -0800263void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000264 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000265}
266
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000267bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000268 render_rrect(canvas, fRRect);
269 return true;
270}
271
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000272SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800273 : INHERITED(kConcat_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000274 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000275
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000276 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000277}
278
fmalita8c89c522014-11-08 16:18:56 -0800279void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000280 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000281}
282
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000283SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700284 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800285 : INHERITED(kDrawBitmap_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000286 fBitmap = bitmap;
287 fLeft = left;
288 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700289 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000290 fPaint = *paint;
291 fPaintPtr = &fPaint;
292 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700293 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000294 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000295
296 fInfo.push(SkObjectParser::BitmapToString(bitmap));
297 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
298 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700299 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000300 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000301 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000302}
303
fmalita8c89c522014-11-08 16:18:56 -0800304void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000305 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000306}
307
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000308bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000309 render_bitmap(canvas, fBitmap);
310 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000311}
312
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000313SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000314 const SkRect& dst, const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800315 : INHERITED(kDrawBitmapNine_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000316 fBitmap = bitmap;
317 fCenter = center;
318 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700319 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000320 fPaint = *paint;
321 fPaintPtr = &fPaint;
322 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700323 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000324 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000325
326 fInfo.push(SkObjectParser::BitmapToString(bitmap));
327 fInfo.push(SkObjectParser::IRectToString(center));
328 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700329 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000330 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000331 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000332}
333
fmalita8c89c522014-11-08 16:18:56 -0800334void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000335 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000336}
337
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000338bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips2b829822015-11-18 12:59:42 -0800339 SkRect tmp = SkRect::Make(fCenter);
340 render_bitmap(canvas, fBitmap, &tmp);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000341 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000342}
343
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000344SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000345 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700346 SkCanvas::SrcRectConstraint constraint)
robertphillips9bafc302015-02-13 11:13:00 -0800347 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000348 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700349 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000350 fSrc = *src;
351 } else {
352 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000353 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000354 fDst = dst;
355
bsalomon49f085d2014-09-05 13:34:00 -0700356 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000357 fPaint = *paint;
358 fPaintPtr = &fPaint;
359 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700360 fPaintPtr = nullptr;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000361 }
reeda5517e22015-07-14 10:54:12 -0700362 fConstraint = constraint;
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000363
robertphillips@google.com91217d02013-03-17 18:33:46 +0000364 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700365 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000366 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
367 }
368 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700369 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000370 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000371 }
reeda5517e22015-07-14 10:54:12 -0700372 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000373}
374
fmalita8c89c522014-11-08 16:18:56 -0800375void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700376 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000377}
378
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000379bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000380 render_bitmap(canvas, fBitmap, this->srcRect());
381 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000382}
383
fmalita651c9202015-07-22 10:23:01 -0700384SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top,
385 const SkPaint* paint)
386 : INHERITED(kDrawImage_OpType)
387 , fImage(SkRef(image))
388 , fLeft(left)
389 , fTop(top) {
390
fmalita7361bf02015-10-29 12:13:48 -0700391 fInfo.push(SkObjectParser::ImageToString(image));
392 fInfo.push(SkObjectParser::ScalarToString(left, "Left: "));
393 fInfo.push(SkObjectParser::ScalarToString(top, "Top: "));
394
fmalita651c9202015-07-22 10:23:01 -0700395 if (paint) {
396 fPaint.set(*paint);
fmalita7361bf02015-10-29 12:13:48 -0700397 fInfo.push(SkObjectParser::PaintToString(*paint));
fmalita651c9202015-07-22 10:23:01 -0700398 }
399}
400
401void SkDrawImageCommand::execute(SkCanvas* canvas) const {
402 canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull());
403}
404
405bool SkDrawImageCommand::render(SkCanvas* canvas) const {
406 SkAutoCanvasRestore acr(canvas, true);
407 canvas->clear(0xFFFFFFFF);
408
409 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
410 SkIntToScalar(fImage->width()),
411 SkIntToScalar(fImage->height())));
412 this->execute(canvas);
413 return true;
414}
415
416SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src,
417 const SkRect& dst, const SkPaint* paint,
418 SkCanvas::SrcRectConstraint constraint)
419 : INHERITED(kDrawImageRect_OpType)
420 , fImage(SkRef(image))
421 , fDst(dst)
422 , fConstraint(constraint) {
423
424 if (src) {
425 fSrc.set(*src);
426 }
427
428 if (paint) {
429 fPaint.set(*paint);
430 }
robertphillips80af6452015-08-24 08:27:38 -0700431
432 fInfo.push(SkObjectParser::ImageToString(image));
433 if (src) {
434 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
435 }
436 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
437 if (paint) {
438 fInfo.push(SkObjectParser::PaintToString(*paint));
439 }
440 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
fmalita651c9202015-07-22 10:23:01 -0700441}
442
443void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700444 canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
fmalita651c9202015-07-22 10:23:01 -0700445}
446
447bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
448 SkAutoCanvasRestore acr(canvas, true);
449 canvas->clear(0xFFFFFFFF);
450
451 xlate_and_scale_to_bounds(canvas, fDst);
452
453 this->execute(canvas);
454 return true;
455}
456
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000457SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800458 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000459 fOval = oval;
460 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000461
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000462 fInfo.push(SkObjectParser::RectToString(oval));
463 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000464}
465
fmalita8c89c522014-11-08 16:18:56 -0800466void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000467 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000468}
469
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000470bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000471 canvas->clear(0xFFFFFFFF);
472 canvas->save();
473
474 xlate_and_scale_to_bounds(canvas, fOval);
475
476 SkPaint p;
477 p.setColor(SK_ColorBLACK);
478 p.setStyle(SkPaint::kStroke_Style);
479
480 canvas->drawOval(fOval, p);
481 canvas->restore();
482
483 return true;
484}
485
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000486SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800487 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000488 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000489
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000490 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000491}
492
fmalita8c89c522014-11-08 16:18:56 -0800493void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000494 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495}
496
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000497bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000498 canvas->clear(0xFFFFFFFF);
499 canvas->drawPaint(fPaint);
500 return true;
501}
502
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000503SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800504 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000505 fPath = path;
506 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000507
robertphillips@google.com91217d02013-03-17 18:33:46 +0000508 fInfo.push(SkObjectParser::PathToString(path));
509 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000510}
511
fmalita8c89c522014-11-08 16:18:56 -0800512void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000513 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000514}
515
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000516bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000517 render_path(canvas, fPath);
518 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000519}
520
fmalita160ebb22015-04-01 20:58:37 -0700521SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
522 const SkMatrix* matrix,
523 const SkPaint* paint)
524 : INHERITED(kBeginDrawPicture_OpType)
525 , fPicture(SkRef(picture)) {
526
527 SkString* str = new SkString;
528 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
529 picture->cullRect().fLeft, picture->cullRect().fTop,
530 picture->cullRect().fRight, picture->cullRect().fBottom);
531 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700532
bsalomon49f085d2014-09-05 13:34:00 -0700533 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700534 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700535 fInfo.push(SkObjectParser::MatrixToString(*matrix));
536 }
fmalita160ebb22015-04-01 20:58:37 -0700537
bsalomon49f085d2014-09-05 13:34:00 -0700538 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700539 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700540 fInfo.push(SkObjectParser::PaintToString(*paint));
541 }
fmalita160ebb22015-04-01 20:58:37 -0700542
543}
544
545void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
546 if (fPaint.isValid()) {
547 SkRect bounds = fPicture->cullRect();
548 if (fMatrix.isValid()) {
549 fMatrix.get()->mapRect(&bounds);
550 }
551 canvas->saveLayer(&bounds, fPaint.get());
552 }
553
554 if (fMatrix.isValid()) {
555 if (!fPaint.isValid()) {
556 canvas->save();
557 }
558 canvas->concat(*fMatrix.get());
559 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000560}
561
fmalita160ebb22015-04-01 20:58:37 -0700562bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000563 canvas->clear(0xFFFFFFFF);
564 canvas->save();
565
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700566 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000567
robertphillips9b14f262014-06-04 05:40:44 -0700568 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000569
570 canvas->restore();
571
572 return true;
573}
574
fmalita160ebb22015-04-01 20:58:37 -0700575SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
576 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
577
578void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
579 if (fRestore) {
580 canvas->restore();
581 }
582}
583
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000584SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000585 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800586 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000587 fMode = mode;
588 fCount = count;
589 fPts = new SkPoint[count];
590 memcpy(fPts, pts, count * sizeof(SkPoint));
591 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000592
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000593 fInfo.push(SkObjectParser::PointsToString(pts, count));
594 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
595 "Points: "));
596 fInfo.push(SkObjectParser::PointModeToString(mode));
597 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000598}
599
fmalita8c89c522014-11-08 16:18:56 -0800600void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000601 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000602}
603
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000604bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000605 canvas->clear(0xFFFFFFFF);
606 canvas->save();
607
608 SkRect bounds;
609
610 bounds.setEmpty();
611 for (unsigned int i = 0; i < fCount; ++i) {
612 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
613 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000614
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000615 xlate_and_scale_to_bounds(canvas, bounds);
616
617 SkPaint p;
618 p.setColor(SK_ColorBLACK);
619 p.setStyle(SkPaint::kStroke_Style);
620
621 canvas->drawPoints(fMode, fCount, fPts, p);
622 canvas->restore();
623
624 return true;
625}
626
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000627SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000628 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800629 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000630 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000631
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000632 fText = new char[byteLength];
633 memcpy(fText, text, byteLength);
634 fByteLength = byteLength;
635
636 fPos = new SkPoint[numPts];
637 memcpy(fPos, pos, numPts * sizeof(SkPoint));
638
639 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000640
641 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000642 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000643 fInfo.push(SkObjectParser::PointsToString(pos, 1));
644 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000645}
646
fmalita8c89c522014-11-08 16:18:56 -0800647void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000648 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000649}
650
651
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000652SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
653 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000654 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800655 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000656 size_t numPts = paint.countText(text, byteLength);
657
658 fText = new char[byteLength];
659 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000660 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000661
662 fXpos = new SkScalar[numPts];
663 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
664
robertphillips@google.com91217d02013-03-17 18:33:46 +0000665 fConstY = constY;
666 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000667
robertphillips@google.com91217d02013-03-17 18:33:46 +0000668 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
669 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
670 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
671 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000672}
673
fmalita8c89c522014-11-08 16:18:56 -0800674void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000675 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000676}
677
fmalitab7425172014-08-26 07:56:44 -0700678SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
679 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800680 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700681 , fBlob(blob)
682 , fXPos(x)
683 , fYPos(y)
684 , fPaint(paint) {
685
686 blob->ref();
687
688 // FIXME: push blob info
689 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800690 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
691 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700692 fInfo.push(SkObjectParser::PaintToString(paint));
693}
694
fmalita8c89c522014-11-08 16:18:56 -0800695void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700696 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
697}
698
fmalita55773872014-08-29 15:08:20 -0700699bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
700 canvas->clear(SK_ColorWHITE);
701 canvas->save();
702
703 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
704 xlate_and_scale_to_bounds(canvas, bounds);
705
706 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
707
708 canvas->restore();
709
710 return true;
711}
712
robertphillips9bafc302015-02-13 11:13:00 -0800713SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
714 const SkPoint texCoords[4], SkXfermode* xfermode,
715 const SkPaint& paint)
716 : INHERITED(kDrawPatch_OpType) {
717 memcpy(fCubics, cubics, sizeof(fCubics));
718 memcpy(fColors, colors, sizeof(fColors));
719 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
720 fXfermode.reset(xfermode);
721 fPaint = paint;
722
723 fInfo.push(SkObjectParser::PaintToString(paint));
724}
725
726void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
727 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
728}
729
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000730SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800731 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000732 fRect = rect;
733 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000734
robertphillips@google.com91217d02013-03-17 18:33:46 +0000735 fInfo.push(SkObjectParser::RectToString(rect));
736 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000737}
738
fmalita8c89c522014-11-08 16:18:56 -0800739void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000740 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000741}
742
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000743SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800744 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000745 fRRect = rrect;
746 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000747
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000748 fInfo.push(SkObjectParser::RRectToString(rrect));
749 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000750}
751
fmalita8c89c522014-11-08 16:18:56 -0800752void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000753 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000754}
755
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000756bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000757 render_rrect(canvas, fRRect);
758 return true;
759}
760
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000761SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000762 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000763 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800764 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000765 fOuter = outer;
766 fInner = inner;
767 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000768
769 fInfo.push(SkObjectParser::RRectToString(outer));
770 fInfo.push(SkObjectParser::RRectToString(inner));
771 fInfo.push(SkObjectParser::PaintToString(paint));
772}
773
fmalita8c89c522014-11-08 16:18:56 -0800774void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000775 canvas->drawDRRect(fOuter, fInner, fPaint);
776}
777
778bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
779 render_drrect(canvas, fOuter, fInner);
780 return true;
781}
782
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000783SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000784 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800785 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000786 fBitmap = bitmap;
787 fLeft = left;
788 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700789 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000790 fPaint = *paint;
791 fPaintPtr = &fPaint;
792 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700793 fPaintPtr = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000794 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000795
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000796 fInfo.push(SkObjectParser::BitmapToString(bitmap));
797 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
798 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700799 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000800 fInfo.push(SkObjectParser::PaintToString(*paint));
801 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000802}
803
fmalita8c89c522014-11-08 16:18:56 -0800804void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000805 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000806}
807
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000808bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000809 render_bitmap(canvas, fBitmap);
810 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000811}
812
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000813SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000814 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800815 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000816 fText = new char[byteLength];
817 memcpy(fText, text, byteLength);
818 fByteLength = byteLength;
819 fX = x;
820 fY = y;
821 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000822
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000823 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
824 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
825 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
826 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000827}
828
fmalita8c89c522014-11-08 16:18:56 -0800829void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000830 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000831}
832
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000833SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
834 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000835 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800836 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000837 fText = new char[byteLength];
838 memcpy(fText, text, byteLength);
839 fByteLength = byteLength;
840 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700841 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000842 fMatrix = *matrix;
843 } else {
844 fMatrix.setIdentity();
845 }
846 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000847
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000848 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
849 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700850 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000851 fInfo.push(SkObjectParser::MatrixToString(*matrix));
852 }
853 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000854}
855
fmalita8c89c522014-11-08 16:18:56 -0800856void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000857 canvas->drawTextOnPath(fText, fByteLength, fPath,
halcanary96fcdcc2015-08-27 07:41:13 -0700858 fMatrix.isIdentity() ? nullptr : &fMatrix,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000859 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000860}
861
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000862SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
863 const SkPoint vertices[], const SkPoint texs[],
864 const SkColor colors[], SkXfermode* xfermode,
865 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000866 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800867 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000868 fVmode = vmode;
869
870 fVertexCount = vertexCount;
871
872 fVertices = new SkPoint[vertexCount];
873 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
874
bsalomon49f085d2014-09-05 13:34:00 -0700875 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000876 fTexs = new SkPoint[vertexCount];
877 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
878 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700879 fTexs = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000880 }
881
bsalomon49f085d2014-09-05 13:34:00 -0700882 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000883 fColors = new SkColor[vertexCount];
884 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
885 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700886 fColors = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000887 }
888
889 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700890 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000891 fXfermode->ref();
892 }
893
894 if (indexCount > 0) {
895 fIndices = new uint16_t[indexCount];
896 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
897 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700898 fIndices = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000899 }
900
901 fIndexCount = indexCount;
902 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000903
chudy@google.com902ebe52012-06-29 14:21:22 +0000904 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000905 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
906 fInfo.push(SkObjectParser::PaintToString(paint));
907}
908
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000909SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000910 delete [] fVertices;
911 delete [] fTexs;
912 delete [] fColors;
913 SkSafeUnref(fXfermode);
914 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000915}
916
fmalita8c89c522014-11-08 16:18:56 -0800917void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000918 canvas->drawVertices(fVmode, fVertexCount, fVertices,
919 fTexs, fColors, fXfermode, fIndices,
920 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000921}
922
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000923SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800924 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000925 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000926}
927
fmalita8c89c522014-11-08 16:18:56 -0800928void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000929 canvas->restore();
930}
931
Florin Malita5f6102d2014-06-30 10:13:28 -0400932SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800933 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000934}
935
fmalita8c89c522014-11-08 16:18:56 -0800936void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400937 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000938}
939
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000940SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000941 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800942 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700943 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000944 fBounds = *bounds;
945 } else {
946 fBounds.setEmpty();
947 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000948
bsalomon49f085d2014-09-05 13:34:00 -0700949 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000950 fPaint = *paint;
951 fPaintPtr = &fPaint;
952 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700953 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000954 }
955 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000956
bsalomon49f085d2014-09-05 13:34:00 -0700957 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000958 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
959 }
bsalomon49f085d2014-09-05 13:34:00 -0700960 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000961 fInfo.push(SkObjectParser::PaintToString(*paint));
962 }
963 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000964}
965
fmalita8c89c522014-11-08 16:18:56 -0800966void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700967 canvas->saveLayer(fBounds.isEmpty() ? nullptr : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000968 fPaintPtr,
969 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000970}
971
fmalita8c89c522014-11-08 16:18:56 -0800972void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000973 canvas->save();
974}
975
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000976SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800977 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700978 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000979 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000980
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000981 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000982}
983
robertphillips70171682014-10-16 14:28:28 -0700984void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
985 fUserMatrix = userMatrix;
986}
987
fmalita8c89c522014-11-08 16:18:56 -0800988void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700989 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
990 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000991}
992