blob: 8be6de9b28e1dd9179fdc5aba19993bb92ecfa27 [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 {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000339 render_bitmap(canvas, fBitmap);
340 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000341}
342
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000343SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000344 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700345 SkCanvas::SrcRectConstraint constraint)
robertphillips9bafc302015-02-13 11:13:00 -0800346 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000347 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700348 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000349 fSrc = *src;
350 } else {
351 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000352 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000353 fDst = dst;
354
bsalomon49f085d2014-09-05 13:34:00 -0700355 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000356 fPaint = *paint;
357 fPaintPtr = &fPaint;
358 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700359 fPaintPtr = nullptr;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000360 }
reeda5517e22015-07-14 10:54:12 -0700361 fConstraint = constraint;
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000362
robertphillips@google.com91217d02013-03-17 18:33:46 +0000363 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700364 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000365 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
366 }
367 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700368 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000369 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000370 }
reeda5517e22015-07-14 10:54:12 -0700371 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000372}
373
fmalita8c89c522014-11-08 16:18:56 -0800374void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700375 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000376}
377
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000378bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000379 render_bitmap(canvas, fBitmap, this->srcRect());
380 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000381}
382
fmalita651c9202015-07-22 10:23:01 -0700383SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top,
384 const SkPaint* paint)
385 : INHERITED(kDrawImage_OpType)
386 , fImage(SkRef(image))
387 , fLeft(left)
388 , fTop(top) {
389
fmalita7361bf02015-10-29 12:13:48 -0700390 fInfo.push(SkObjectParser::ImageToString(image));
391 fInfo.push(SkObjectParser::ScalarToString(left, "Left: "));
392 fInfo.push(SkObjectParser::ScalarToString(top, "Top: "));
393
fmalita651c9202015-07-22 10:23:01 -0700394 if (paint) {
395 fPaint.set(*paint);
fmalita7361bf02015-10-29 12:13:48 -0700396 fInfo.push(SkObjectParser::PaintToString(*paint));
fmalita651c9202015-07-22 10:23:01 -0700397 }
398}
399
400void SkDrawImageCommand::execute(SkCanvas* canvas) const {
401 canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull());
402}
403
404bool SkDrawImageCommand::render(SkCanvas* canvas) const {
405 SkAutoCanvasRestore acr(canvas, true);
406 canvas->clear(0xFFFFFFFF);
407
408 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
409 SkIntToScalar(fImage->width()),
410 SkIntToScalar(fImage->height())));
411 this->execute(canvas);
412 return true;
413}
414
415SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src,
416 const SkRect& dst, const SkPaint* paint,
417 SkCanvas::SrcRectConstraint constraint)
418 : INHERITED(kDrawImageRect_OpType)
419 , fImage(SkRef(image))
420 , fDst(dst)
421 , fConstraint(constraint) {
422
423 if (src) {
424 fSrc.set(*src);
425 }
426
427 if (paint) {
428 fPaint.set(*paint);
429 }
robertphillips80af6452015-08-24 08:27:38 -0700430
431 fInfo.push(SkObjectParser::ImageToString(image));
432 if (src) {
433 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
434 }
435 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
436 if (paint) {
437 fInfo.push(SkObjectParser::PaintToString(*paint));
438 }
439 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
fmalita651c9202015-07-22 10:23:01 -0700440}
441
442void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700443 canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
fmalita651c9202015-07-22 10:23:01 -0700444}
445
446bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
447 SkAutoCanvasRestore acr(canvas, true);
448 canvas->clear(0xFFFFFFFF);
449
450 xlate_and_scale_to_bounds(canvas, fDst);
451
452 this->execute(canvas);
453 return true;
454}
455
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000456SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800457 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000458 fOval = oval;
459 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000460
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000461 fInfo.push(SkObjectParser::RectToString(oval));
462 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000463}
464
fmalita8c89c522014-11-08 16:18:56 -0800465void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000466 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000467}
468
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000469bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000470 canvas->clear(0xFFFFFFFF);
471 canvas->save();
472
473 xlate_and_scale_to_bounds(canvas, fOval);
474
475 SkPaint p;
476 p.setColor(SK_ColorBLACK);
477 p.setStyle(SkPaint::kStroke_Style);
478
479 canvas->drawOval(fOval, p);
480 canvas->restore();
481
482 return true;
483}
484
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000485SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800486 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000487 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000488
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000489 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000490}
491
fmalita8c89c522014-11-08 16:18:56 -0800492void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000493 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000494}
495
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000496bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000497 canvas->clear(0xFFFFFFFF);
498 canvas->drawPaint(fPaint);
499 return true;
500}
501
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000502SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800503 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000504 fPath = path;
505 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000506
robertphillips@google.com91217d02013-03-17 18:33:46 +0000507 fInfo.push(SkObjectParser::PathToString(path));
508 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000509}
510
fmalita8c89c522014-11-08 16:18:56 -0800511void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000512 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000513}
514
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000515bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000516 render_path(canvas, fPath);
517 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000518}
519
fmalita160ebb22015-04-01 20:58:37 -0700520SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
521 const SkMatrix* matrix,
522 const SkPaint* paint)
523 : INHERITED(kBeginDrawPicture_OpType)
524 , fPicture(SkRef(picture)) {
525
526 SkString* str = new SkString;
527 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
528 picture->cullRect().fLeft, picture->cullRect().fTop,
529 picture->cullRect().fRight, picture->cullRect().fBottom);
530 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700531
bsalomon49f085d2014-09-05 13:34:00 -0700532 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700533 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700534 fInfo.push(SkObjectParser::MatrixToString(*matrix));
535 }
fmalita160ebb22015-04-01 20:58:37 -0700536
bsalomon49f085d2014-09-05 13:34:00 -0700537 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700538 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700539 fInfo.push(SkObjectParser::PaintToString(*paint));
540 }
fmalita160ebb22015-04-01 20:58:37 -0700541
542}
543
544void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
545 if (fPaint.isValid()) {
546 SkRect bounds = fPicture->cullRect();
547 if (fMatrix.isValid()) {
548 fMatrix.get()->mapRect(&bounds);
549 }
550 canvas->saveLayer(&bounds, fPaint.get());
551 }
552
553 if (fMatrix.isValid()) {
554 if (!fPaint.isValid()) {
555 canvas->save();
556 }
557 canvas->concat(*fMatrix.get());
558 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000559}
560
fmalita160ebb22015-04-01 20:58:37 -0700561bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000562 canvas->clear(0xFFFFFFFF);
563 canvas->save();
564
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700565 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000566
robertphillips9b14f262014-06-04 05:40:44 -0700567 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000568
569 canvas->restore();
570
571 return true;
572}
573
fmalita160ebb22015-04-01 20:58:37 -0700574SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
575 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
576
577void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
578 if (fRestore) {
579 canvas->restore();
580 }
581}
582
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000583SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000584 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800585 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000586 fMode = mode;
587 fCount = count;
588 fPts = new SkPoint[count];
589 memcpy(fPts, pts, count * sizeof(SkPoint));
590 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000591
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000592 fInfo.push(SkObjectParser::PointsToString(pts, count));
593 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
594 "Points: "));
595 fInfo.push(SkObjectParser::PointModeToString(mode));
596 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000597}
598
fmalita8c89c522014-11-08 16:18:56 -0800599void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000600 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000601}
602
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000603bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000604 canvas->clear(0xFFFFFFFF);
605 canvas->save();
606
607 SkRect bounds;
608
609 bounds.setEmpty();
610 for (unsigned int i = 0; i < fCount; ++i) {
611 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
612 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000613
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000614 xlate_and_scale_to_bounds(canvas, bounds);
615
616 SkPaint p;
617 p.setColor(SK_ColorBLACK);
618 p.setStyle(SkPaint::kStroke_Style);
619
620 canvas->drawPoints(fMode, fCount, fPts, p);
621 canvas->restore();
622
623 return true;
624}
625
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000626SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000627 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800628 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000629 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000630
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000631 fText = new char[byteLength];
632 memcpy(fText, text, byteLength);
633 fByteLength = byteLength;
634
635 fPos = new SkPoint[numPts];
636 memcpy(fPos, pos, numPts * sizeof(SkPoint));
637
638 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000639
640 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000641 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000642 fInfo.push(SkObjectParser::PointsToString(pos, 1));
643 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000644}
645
fmalita8c89c522014-11-08 16:18:56 -0800646void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000647 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000648}
649
650
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000651SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
652 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000653 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800654 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000655 size_t numPts = paint.countText(text, byteLength);
656
657 fText = new char[byteLength];
658 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000659 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000660
661 fXpos = new SkScalar[numPts];
662 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
663
robertphillips@google.com91217d02013-03-17 18:33:46 +0000664 fConstY = constY;
665 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000666
robertphillips@google.com91217d02013-03-17 18:33:46 +0000667 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
668 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
669 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
670 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000671}
672
fmalita8c89c522014-11-08 16:18:56 -0800673void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000674 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000675}
676
fmalitab7425172014-08-26 07:56:44 -0700677SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
678 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800679 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700680 , fBlob(blob)
681 , fXPos(x)
682 , fYPos(y)
683 , fPaint(paint) {
684
685 blob->ref();
686
687 // FIXME: push blob info
688 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800689 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
690 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700691 fInfo.push(SkObjectParser::PaintToString(paint));
692}
693
fmalita8c89c522014-11-08 16:18:56 -0800694void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700695 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
696}
697
fmalita55773872014-08-29 15:08:20 -0700698bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
699 canvas->clear(SK_ColorWHITE);
700 canvas->save();
701
702 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
703 xlate_and_scale_to_bounds(canvas, bounds);
704
705 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
706
707 canvas->restore();
708
709 return true;
710}
711
robertphillips9bafc302015-02-13 11:13:00 -0800712SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
713 const SkPoint texCoords[4], SkXfermode* xfermode,
714 const SkPaint& paint)
715 : INHERITED(kDrawPatch_OpType) {
716 memcpy(fCubics, cubics, sizeof(fCubics));
717 memcpy(fColors, colors, sizeof(fColors));
718 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
719 fXfermode.reset(xfermode);
720 fPaint = paint;
721
722 fInfo.push(SkObjectParser::PaintToString(paint));
723}
724
725void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
726 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
727}
728
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000729SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800730 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000731 fRect = rect;
732 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000733
robertphillips@google.com91217d02013-03-17 18:33:46 +0000734 fInfo.push(SkObjectParser::RectToString(rect));
735 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000736}
737
fmalita8c89c522014-11-08 16:18:56 -0800738void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000739 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000740}
741
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000742SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800743 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000744 fRRect = rrect;
745 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000746
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000747 fInfo.push(SkObjectParser::RRectToString(rrect));
748 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000749}
750
fmalita8c89c522014-11-08 16:18:56 -0800751void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000752 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000753}
754
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000755bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000756 render_rrect(canvas, fRRect);
757 return true;
758}
759
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000760SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000761 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000762 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800763 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000764 fOuter = outer;
765 fInner = inner;
766 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000767
768 fInfo.push(SkObjectParser::RRectToString(outer));
769 fInfo.push(SkObjectParser::RRectToString(inner));
770 fInfo.push(SkObjectParser::PaintToString(paint));
771}
772
fmalita8c89c522014-11-08 16:18:56 -0800773void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000774 canvas->drawDRRect(fOuter, fInner, fPaint);
775}
776
777bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
778 render_drrect(canvas, fOuter, fInner);
779 return true;
780}
781
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000782SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000783 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800784 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000785 fBitmap = bitmap;
786 fLeft = left;
787 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700788 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000789 fPaint = *paint;
790 fPaintPtr = &fPaint;
791 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700792 fPaintPtr = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000793 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000794
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000795 fInfo.push(SkObjectParser::BitmapToString(bitmap));
796 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
797 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700798 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000799 fInfo.push(SkObjectParser::PaintToString(*paint));
800 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000801}
802
fmalita8c89c522014-11-08 16:18:56 -0800803void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000804 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000805}
806
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000807bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000808 render_bitmap(canvas, fBitmap);
809 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000810}
811
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000812SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000813 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800814 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000815 fText = new char[byteLength];
816 memcpy(fText, text, byteLength);
817 fByteLength = byteLength;
818 fX = x;
819 fY = y;
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::ScalarToString(x, "SkScalar x: "));
824 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
825 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000826}
827
fmalita8c89c522014-11-08 16:18:56 -0800828void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000829 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000830}
831
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000832SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
833 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000834 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800835 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000836 fText = new char[byteLength];
837 memcpy(fText, text, byteLength);
838 fByteLength = byteLength;
839 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700840 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000841 fMatrix = *matrix;
842 } else {
843 fMatrix.setIdentity();
844 }
845 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000846
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000847 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
848 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700849 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000850 fInfo.push(SkObjectParser::MatrixToString(*matrix));
851 }
852 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000853}
854
fmalita8c89c522014-11-08 16:18:56 -0800855void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000856 canvas->drawTextOnPath(fText, fByteLength, fPath,
halcanary96fcdcc2015-08-27 07:41:13 -0700857 fMatrix.isIdentity() ? nullptr : &fMatrix,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000858 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000859}
860
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000861SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
862 const SkPoint vertices[], const SkPoint texs[],
863 const SkColor colors[], SkXfermode* xfermode,
864 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000865 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800866 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000867 fVmode = vmode;
868
869 fVertexCount = vertexCount;
870
871 fVertices = new SkPoint[vertexCount];
872 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
873
bsalomon49f085d2014-09-05 13:34:00 -0700874 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000875 fTexs = new SkPoint[vertexCount];
876 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
877 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700878 fTexs = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000879 }
880
bsalomon49f085d2014-09-05 13:34:00 -0700881 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000882 fColors = new SkColor[vertexCount];
883 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
884 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700885 fColors = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000886 }
887
888 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700889 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000890 fXfermode->ref();
891 }
892
893 if (indexCount > 0) {
894 fIndices = new uint16_t[indexCount];
895 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
896 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700897 fIndices = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000898 }
899
900 fIndexCount = indexCount;
901 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000902
chudy@google.com902ebe52012-06-29 14:21:22 +0000903 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000904 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
905 fInfo.push(SkObjectParser::PaintToString(paint));
906}
907
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000908SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000909 delete [] fVertices;
910 delete [] fTexs;
911 delete [] fColors;
912 SkSafeUnref(fXfermode);
913 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000914}
915
fmalita8c89c522014-11-08 16:18:56 -0800916void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000917 canvas->drawVertices(fVmode, fVertexCount, fVertices,
918 fTexs, fColors, fXfermode, fIndices,
919 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000920}
921
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000922SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800923 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000924 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000925}
926
fmalita8c89c522014-11-08 16:18:56 -0800927void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000928 canvas->restore();
929}
930
Florin Malita5f6102d2014-06-30 10:13:28 -0400931SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800932 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000933}
934
fmalita8c89c522014-11-08 16:18:56 -0800935void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400936 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000937}
938
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000939SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000940 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800941 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700942 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000943 fBounds = *bounds;
944 } else {
945 fBounds.setEmpty();
946 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000947
bsalomon49f085d2014-09-05 13:34:00 -0700948 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000949 fPaint = *paint;
950 fPaintPtr = &fPaint;
951 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700952 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000953 }
954 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000955
bsalomon49f085d2014-09-05 13:34:00 -0700956 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000957 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
958 }
bsalomon49f085d2014-09-05 13:34:00 -0700959 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000960 fInfo.push(SkObjectParser::PaintToString(*paint));
961 }
962 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000963}
964
fmalita8c89c522014-11-08 16:18:56 -0800965void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700966 canvas->saveLayer(fBounds.isEmpty() ? nullptr : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000967 fPaintPtr,
968 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000969}
970
fmalita8c89c522014-11-08 16:18:56 -0800971void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000972 canvas->save();
973}
974
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000975SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800976 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700977 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000978 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000979
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000980 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000981}
982
robertphillips70171682014-10-16 14:28:28 -0700983void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
984 fUserMatrix = userMatrix;
985}
986
fmalita8c89c522014-11-08 16:18:56 -0800987void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700988 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
989 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000990}
991