blob: 20aad3b9a510b6824d92b63a60d71034631e7d29 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
chudy@google.com902ebe52012-06-29 14:21:22 +000010#include "SkDrawCommand.h"
11#include "SkObjectParser.h"
robertphillips9bafc302015-02-13 11:13:00 -080012#include "SkPicture.h"
fmalitab7425172014-08-26 07:56:44 -070013#include "SkTextBlob.h"
14
chudy@google.com902ebe52012-06-29 14:21:22 +000015// TODO(chudy): Refactor into non subclass model.
16
robertphillips9bafc302015-02-13 11:13:00 -080017SkDrawCommand::SkDrawCommand(OpType type)
18 : fOpType(type)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000019 , fVisible(true) {
20}
21
chudy@google.com902ebe52012-06-29 14:21:22 +000022SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000023 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000024}
25
robertphillips9bafc302015-02-13 11:13:00 -080026const char* SkDrawCommand::GetCommandString(OpType type) {
chudy@google.com902ebe52012-06-29 14:21:22 +000027 switch (type) {
fmalita160ebb22015-04-01 20:58:37 -070028 case kBeginDrawPicture_OpType: return "BeginDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080029 case kClipPath_OpType: return "ClipPath";
30 case kClipRegion_OpType: return "ClipRegion";
31 case kClipRect_OpType: return "ClipRect";
32 case kClipRRect_OpType: return "ClipRRect";
robertphillips9bafc302015-02-13 11:13:00 -080033 case kConcat_OpType: return "Concat";
34 case kDrawBitmap_OpType: return "DrawBitmap";
35 case kDrawBitmapNine_OpType: return "DrawBitmapNine";
36 case kDrawBitmapRect_OpType: return "DrawBitmapRect";
37 case kDrawClear_OpType: return "DrawClear";
38 case kDrawDRRect_OpType: return "DrawDRRect";
fmalita651c9202015-07-22 10:23:01 -070039 case kDrawImage_OpType: return "DrawImage";
40 case kDrawImageRect_OpType: return "DrawImageRect";
robertphillips9bafc302015-02-13 11:13:00 -080041 case kDrawOval_OpType: return "DrawOval";
42 case kDrawPaint_OpType: return "DrawPaint";
43 case kDrawPatch_OpType: return "DrawPatch";
44 case kDrawPath_OpType: return "DrawPath";
robertphillips9bafc302015-02-13 11:13:00 -080045 case kDrawPoints_OpType: return "DrawPoints";
46 case kDrawPosText_OpType: return "DrawPosText";
47 case kDrawPosTextH_OpType: return "DrawPosTextH";
48 case kDrawRect_OpType: return "DrawRect";
49 case kDrawRRect_OpType: return "DrawRRect";
50 case kDrawSprite_OpType: return "DrawSprite";
51 case kDrawText_OpType: return "DrawText";
52 case kDrawTextBlob_OpType: return "DrawTextBlob";
53 case kDrawTextOnPath_OpType: return "DrawTextOnPath";
54 case kDrawVertices_OpType: return "DrawVertices";
fmalita160ebb22015-04-01 20:58:37 -070055 case kEndDrawPicture_OpType: return "EndDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080056 case kRestore_OpType: return "Restore";
57 case kSave_OpType: return "Save";
58 case kSaveLayer_OpType: return "SaveLayer";
59 case kSetMatrix_OpType: return "SetMatrix";
chudy@google.com902ebe52012-06-29 14:21:22 +000060 default:
robertphillips9bafc302015-02-13 11:13:00 -080061 SkDebugf("OpType error 0x%08x\n", type);
chudy@google.com902ebe52012-06-29 14:21:22 +000062 SkASSERT(0);
63 break;
64 }
65 SkDEBUGFAIL("DrawType UNUSED\n");
halcanary96fcdcc2015-08-27 07:41:13 -070066 return nullptr;
chudy@google.com902ebe52012-06-29 14:21:22 +000067}
68
fmalita8c89c522014-11-08 16:18:56 -080069SkString SkDrawCommand::toString() const {
robertphillips9bafc302015-02-13 11:13:00 -080070 return SkString(GetCommandString(fOpType));
chudy@google.com902ebe52012-06-29 14:21:22 +000071}
72
robertphillips9bafc302015-02-13 11:13:00 -080073SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000074 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000075 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000076}
77
fmalita8c89c522014-11-08 16:18:56 -080078void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000079 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000080}
81
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000082namespace {
83
84void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
85 const SkISize& size = canvas->getDeviceSize();
86
87 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
88
89 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
90 if (bounds.width() > bounds.height()) {
91 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
92 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
93 } else {
94 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
95 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
96 }
97 canvas->translate(-bounds.centerX(), -bounds.centerY());
98}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +000099
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000100
101void render_path(SkCanvas* canvas, const SkPath& path) {
102 canvas->clear(0xFFFFFFFF);
103 canvas->save();
104
105 const SkRect& bounds = path.getBounds();
106
107 xlate_and_scale_to_bounds(canvas, bounds);
108
109 SkPaint p;
110 p.setColor(SK_ColorBLACK);
111 p.setStyle(SkPaint::kStroke_Style);
112
113 canvas->drawPath(path, p);
114 canvas->restore();
115}
116
halcanary96fcdcc2015-08-27 07:41:13 -0700117void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = nullptr) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000118 const SkISize& size = canvas->getDeviceSize();
119
120 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
121 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
122
123 if (input.width() > input.height()) {
124 yScale *= input.height() / (float) input.width();
125 } else {
126 xScale *= input.width() / (float) input.height();
127 }
128
129 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
130 xScale * input.width(),
131 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000132
robertphillips96a5cff2015-09-24 06:56:27 -0700133 static const int kNumBlocks = 8;
134
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000135 canvas->clear(0xFFFFFFFF);
robertphillips96a5cff2015-09-24 06:56:27 -0700136 SkISize block = {
137 canvas->imageInfo().width()/kNumBlocks,
138 canvas->imageInfo().height()/kNumBlocks
139 };
140 for (int y = 0; y < kNumBlocks; ++y) {
141 for (int x = 0; x < kNumBlocks; ++x) {
142 SkPaint paint;
143 paint.setColor((x+y)%2 ? SK_ColorLTGRAY : SK_ColorDKGRAY);
144 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x*block.width()),
145 SkIntToScalar(y*block.height()),
146 SkIntToScalar(block.width()),
147 SkIntToScalar(block.height()));
148 canvas->drawRect(r, paint);
149 }
150 }
151
reede47829b2015-08-06 10:02:53 -0700152 canvas->drawBitmapRect(input, dst, nullptr);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000153
bsalomon49f085d2014-09-05 13:34:00 -0700154 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000155 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
156 srcRect->fTop * yScale + SK_Scalar1,
157 srcRect->fRight * xScale + SK_Scalar1,
158 srcRect->fBottom * yScale + SK_Scalar1);
159 SkPaint p;
160 p.setColor(SK_ColorRED);
161 p.setStyle(SkPaint::kStroke_Style);
162
163 canvas->drawRect(r, p);
164 }
165}
166
167void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
168 canvas->clear(0xFFFFFFFF);
169 canvas->save();
170
171 const SkRect& bounds = rrect.getBounds();
172
173 xlate_and_scale_to_bounds(canvas, bounds);
174
175 SkPaint p;
176 p.setColor(SK_ColorBLACK);
177 p.setStyle(SkPaint::kStroke_Style);
178
179 canvas->drawRRect(rrect, p);
180 canvas->restore();
181}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000182
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000183void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
184 canvas->clear(0xFFFFFFFF);
185 canvas->save();
186
187 const SkRect& bounds = outer.getBounds();
188
189 xlate_and_scale_to_bounds(canvas, bounds);
190
191 SkPaint p;
192 p.setColor(SK_ColorBLACK);
193 p.setStyle(SkPaint::kStroke_Style);
194
195 canvas->drawDRRect(outer, inner, p);
196 canvas->restore();
197}
198
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000199};
200
201
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000202SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800203 : INHERITED(kClipPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000204 fPath = path;
205 fOp = op;
206 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000207
robertphillips@google.com91217d02013-03-17 18:33:46 +0000208 fInfo.push(SkObjectParser::PathToString(path));
209 fInfo.push(SkObjectParser::RegionOpToString(op));
210 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000211}
212
fmalita8c89c522014-11-08 16:18:56 -0800213void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000214 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000215}
216
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000217bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000218 render_path(canvas, fPath);
219 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000220}
221
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000222SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips9bafc302015-02-13 11:13:00 -0800223 : INHERITED(kClipRegion_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000224 fRegion = region;
225 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000226
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000227 fInfo.push(SkObjectParser::RegionToString(region));
228 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000229}
230
fmalita8c89c522014-11-08 16:18:56 -0800231void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000232 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000233}
234
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000235SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800236 : INHERITED(kClipRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000237 fRect = rect;
238 fOp = op;
239 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000240
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000241 fInfo.push(SkObjectParser::RectToString(rect));
242 fInfo.push(SkObjectParser::RegionOpToString(op));
243 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000244}
245
fmalita8c89c522014-11-08 16:18:56 -0800246void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000247 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000248}
249
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000250SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800251 : INHERITED(kClipRRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000252 fRRect = rrect;
253 fOp = op;
254 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000255
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000256 fInfo.push(SkObjectParser::RRectToString(rrect));
257 fInfo.push(SkObjectParser::RegionOpToString(op));
258 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000259}
260
fmalita8c89c522014-11-08 16:18:56 -0800261void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000262 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000263}
264
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000265bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000266 render_rrect(canvas, fRRect);
267 return true;
268}
269
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000270SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800271 : INHERITED(kConcat_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000272 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000273
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000274 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000275}
276
fmalita8c89c522014-11-08 16:18:56 -0800277void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000278 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000279}
280
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000281SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700282 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800283 : INHERITED(kDrawBitmap_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000284 fBitmap = bitmap;
285 fLeft = left;
286 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700287 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000288 fPaint = *paint;
289 fPaintPtr = &fPaint;
290 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700291 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000292 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000293
294 fInfo.push(SkObjectParser::BitmapToString(bitmap));
295 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
296 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700297 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000298 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000299 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000300}
301
fmalita8c89c522014-11-08 16:18:56 -0800302void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000303 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000304}
305
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000306bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000307 render_bitmap(canvas, fBitmap);
308 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000309}
310
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000311SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000312 const SkRect& dst, const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800313 : INHERITED(kDrawBitmapNine_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000314 fBitmap = bitmap;
315 fCenter = center;
316 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700317 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000318 fPaint = *paint;
319 fPaintPtr = &fPaint;
320 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700321 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000322 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000323
324 fInfo.push(SkObjectParser::BitmapToString(bitmap));
325 fInfo.push(SkObjectParser::IRectToString(center));
326 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700327 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000328 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000329 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000330}
331
fmalita8c89c522014-11-08 16:18:56 -0800332void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000333 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000334}
335
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000336bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000337 render_bitmap(canvas, fBitmap);
338 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000339}
340
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000341SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000342 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700343 SkCanvas::SrcRectConstraint constraint)
robertphillips9bafc302015-02-13 11:13:00 -0800344 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000345 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700346 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000347 fSrc = *src;
348 } else {
349 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000350 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000351 fDst = dst;
352
bsalomon49f085d2014-09-05 13:34:00 -0700353 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000354 fPaint = *paint;
355 fPaintPtr = &fPaint;
356 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700357 fPaintPtr = nullptr;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000358 }
reeda5517e22015-07-14 10:54:12 -0700359 fConstraint = constraint;
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000360
robertphillips@google.com91217d02013-03-17 18:33:46 +0000361 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700362 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000363 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
364 }
365 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700366 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000367 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000368 }
reeda5517e22015-07-14 10:54:12 -0700369 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000370}
371
fmalita8c89c522014-11-08 16:18:56 -0800372void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700373 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000374}
375
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000376bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000377 render_bitmap(canvas, fBitmap, this->srcRect());
378 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000379}
380
fmalita651c9202015-07-22 10:23:01 -0700381SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top,
382 const SkPaint* paint)
383 : INHERITED(kDrawImage_OpType)
384 , fImage(SkRef(image))
385 , fLeft(left)
386 , fTop(top) {
387
388 if (paint) {
389 fPaint.set(*paint);
390 }
391}
392
393void SkDrawImageCommand::execute(SkCanvas* canvas) const {
394 canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull());
395}
396
397bool SkDrawImageCommand::render(SkCanvas* canvas) const {
398 SkAutoCanvasRestore acr(canvas, true);
399 canvas->clear(0xFFFFFFFF);
400
401 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
402 SkIntToScalar(fImage->width()),
403 SkIntToScalar(fImage->height())));
404 this->execute(canvas);
405 return true;
406}
407
408SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src,
409 const SkRect& dst, const SkPaint* paint,
410 SkCanvas::SrcRectConstraint constraint)
411 : INHERITED(kDrawImageRect_OpType)
412 , fImage(SkRef(image))
413 , fDst(dst)
414 , fConstraint(constraint) {
415
416 if (src) {
417 fSrc.set(*src);
418 }
419
420 if (paint) {
421 fPaint.set(*paint);
422 }
robertphillips80af6452015-08-24 08:27:38 -0700423
424 fInfo.push(SkObjectParser::ImageToString(image));
425 if (src) {
426 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
427 }
428 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
429 if (paint) {
430 fInfo.push(SkObjectParser::PaintToString(*paint));
431 }
432 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
fmalita651c9202015-07-22 10:23:01 -0700433}
434
435void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700436 canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
fmalita651c9202015-07-22 10:23:01 -0700437}
438
439bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
440 SkAutoCanvasRestore acr(canvas, true);
441 canvas->clear(0xFFFFFFFF);
442
443 xlate_and_scale_to_bounds(canvas, fDst);
444
445 this->execute(canvas);
446 return true;
447}
448
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000449SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800450 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000451 fOval = oval;
452 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000453
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000454 fInfo.push(SkObjectParser::RectToString(oval));
455 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000456}
457
fmalita8c89c522014-11-08 16:18:56 -0800458void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000459 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000460}
461
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000462bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000463 canvas->clear(0xFFFFFFFF);
464 canvas->save();
465
466 xlate_and_scale_to_bounds(canvas, fOval);
467
468 SkPaint p;
469 p.setColor(SK_ColorBLACK);
470 p.setStyle(SkPaint::kStroke_Style);
471
472 canvas->drawOval(fOval, p);
473 canvas->restore();
474
475 return true;
476}
477
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000478SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800479 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000480 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000481
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000482 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000483}
484
fmalita8c89c522014-11-08 16:18:56 -0800485void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000486 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000487}
488
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000489bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000490 canvas->clear(0xFFFFFFFF);
491 canvas->drawPaint(fPaint);
492 return true;
493}
494
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000495SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800496 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000497 fPath = path;
498 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000499
robertphillips@google.com91217d02013-03-17 18:33:46 +0000500 fInfo.push(SkObjectParser::PathToString(path));
501 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000502}
503
fmalita8c89c522014-11-08 16:18:56 -0800504void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000505 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000506}
507
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000508bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000509 render_path(canvas, fPath);
510 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000511}
512
fmalita160ebb22015-04-01 20:58:37 -0700513SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
514 const SkMatrix* matrix,
515 const SkPaint* paint)
516 : INHERITED(kBeginDrawPicture_OpType)
517 , fPicture(SkRef(picture)) {
518
519 SkString* str = new SkString;
520 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
521 picture->cullRect().fLeft, picture->cullRect().fTop,
522 picture->cullRect().fRight, picture->cullRect().fBottom);
523 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700524
bsalomon49f085d2014-09-05 13:34:00 -0700525 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700526 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700527 fInfo.push(SkObjectParser::MatrixToString(*matrix));
528 }
fmalita160ebb22015-04-01 20:58:37 -0700529
bsalomon49f085d2014-09-05 13:34:00 -0700530 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700531 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700532 fInfo.push(SkObjectParser::PaintToString(*paint));
533 }
fmalita160ebb22015-04-01 20:58:37 -0700534
535}
536
537void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
538 if (fPaint.isValid()) {
539 SkRect bounds = fPicture->cullRect();
540 if (fMatrix.isValid()) {
541 fMatrix.get()->mapRect(&bounds);
542 }
543 canvas->saveLayer(&bounds, fPaint.get());
544 }
545
546 if (fMatrix.isValid()) {
547 if (!fPaint.isValid()) {
548 canvas->save();
549 }
550 canvas->concat(*fMatrix.get());
551 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000552}
553
fmalita160ebb22015-04-01 20:58:37 -0700554bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000555 canvas->clear(0xFFFFFFFF);
556 canvas->save();
557
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700558 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000559
robertphillips9b14f262014-06-04 05:40:44 -0700560 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000561
562 canvas->restore();
563
564 return true;
565}
566
fmalita160ebb22015-04-01 20:58:37 -0700567SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
568 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
569
570void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
571 if (fRestore) {
572 canvas->restore();
573 }
574}
575
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000576SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000577 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800578 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000579 fMode = mode;
580 fCount = count;
581 fPts = new SkPoint[count];
582 memcpy(fPts, pts, count * sizeof(SkPoint));
583 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000584
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000585 fInfo.push(SkObjectParser::PointsToString(pts, count));
586 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
587 "Points: "));
588 fInfo.push(SkObjectParser::PointModeToString(mode));
589 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000590}
591
fmalita8c89c522014-11-08 16:18:56 -0800592void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000593 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000594}
595
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000596bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000597 canvas->clear(0xFFFFFFFF);
598 canvas->save();
599
600 SkRect bounds;
601
602 bounds.setEmpty();
603 for (unsigned int i = 0; i < fCount; ++i) {
604 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
605 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000606
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000607 xlate_and_scale_to_bounds(canvas, bounds);
608
609 SkPaint p;
610 p.setColor(SK_ColorBLACK);
611 p.setStyle(SkPaint::kStroke_Style);
612
613 canvas->drawPoints(fMode, fCount, fPts, p);
614 canvas->restore();
615
616 return true;
617}
618
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000619SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000620 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800621 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000622 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000623
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000624 fText = new char[byteLength];
625 memcpy(fText, text, byteLength);
626 fByteLength = byteLength;
627
628 fPos = new SkPoint[numPts];
629 memcpy(fPos, pos, numPts * sizeof(SkPoint));
630
631 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000632
633 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000634 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000635 fInfo.push(SkObjectParser::PointsToString(pos, 1));
636 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000637}
638
fmalita8c89c522014-11-08 16:18:56 -0800639void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000640 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000641}
642
643
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000644SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
645 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000646 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800647 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000648 size_t numPts = paint.countText(text, byteLength);
649
650 fText = new char[byteLength];
651 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000652 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000653
654 fXpos = new SkScalar[numPts];
655 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
656
robertphillips@google.com91217d02013-03-17 18:33:46 +0000657 fConstY = constY;
658 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000659
robertphillips@google.com91217d02013-03-17 18:33:46 +0000660 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
661 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
662 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
663 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000664}
665
fmalita8c89c522014-11-08 16:18:56 -0800666void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000667 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000668}
669
fmalitab7425172014-08-26 07:56:44 -0700670SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
671 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800672 : INHERITED(kDrawTextBlob_OpType)
fmalitab7425172014-08-26 07:56:44 -0700673 , fBlob(blob)
674 , fXPos(x)
675 , fYPos(y)
676 , fPaint(paint) {
677
678 blob->ref();
679
680 // FIXME: push blob info
681 fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
fmalitaff3106c2014-12-09 05:28:20 -0800682 fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
683 fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
fmalitab7425172014-08-26 07:56:44 -0700684 fInfo.push(SkObjectParser::PaintToString(paint));
685}
686
fmalita8c89c522014-11-08 16:18:56 -0800687void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700688 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
689}
690
fmalita55773872014-08-29 15:08:20 -0700691bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
692 canvas->clear(SK_ColorWHITE);
693 canvas->save();
694
695 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
696 xlate_and_scale_to_bounds(canvas, bounds);
697
698 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
699
700 canvas->restore();
701
702 return true;
703}
704
robertphillips9bafc302015-02-13 11:13:00 -0800705SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
706 const SkPoint texCoords[4], SkXfermode* xfermode,
707 const SkPaint& paint)
708 : INHERITED(kDrawPatch_OpType) {
709 memcpy(fCubics, cubics, sizeof(fCubics));
710 memcpy(fColors, colors, sizeof(fColors));
711 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
712 fXfermode.reset(xfermode);
713 fPaint = paint;
714
715 fInfo.push(SkObjectParser::PaintToString(paint));
716}
717
718void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
719 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
720}
721
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000722SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800723 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000724 fRect = rect;
725 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000726
robertphillips@google.com91217d02013-03-17 18:33:46 +0000727 fInfo.push(SkObjectParser::RectToString(rect));
728 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000729}
730
fmalita8c89c522014-11-08 16:18:56 -0800731void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000732 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000733}
734
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000735SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800736 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000737 fRRect = rrect;
738 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000739
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000740 fInfo.push(SkObjectParser::RRectToString(rrect));
741 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000742}
743
fmalita8c89c522014-11-08 16:18:56 -0800744void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000745 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000746}
747
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000748bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000749 render_rrect(canvas, fRRect);
750 return true;
751}
752
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000753SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000754 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000755 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800756 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000757 fOuter = outer;
758 fInner = inner;
759 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000760
761 fInfo.push(SkObjectParser::RRectToString(outer));
762 fInfo.push(SkObjectParser::RRectToString(inner));
763 fInfo.push(SkObjectParser::PaintToString(paint));
764}
765
fmalita8c89c522014-11-08 16:18:56 -0800766void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000767 canvas->drawDRRect(fOuter, fInner, fPaint);
768}
769
770bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
771 render_drrect(canvas, fOuter, fInner);
772 return true;
773}
774
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000775SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000776 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800777 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000778 fBitmap = bitmap;
779 fLeft = left;
780 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700781 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000782 fPaint = *paint;
783 fPaintPtr = &fPaint;
784 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700785 fPaintPtr = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000786 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000787
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000788 fInfo.push(SkObjectParser::BitmapToString(bitmap));
789 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
790 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700791 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000792 fInfo.push(SkObjectParser::PaintToString(*paint));
793 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000794}
795
fmalita8c89c522014-11-08 16:18:56 -0800796void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000797 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000798}
799
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000800bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000801 render_bitmap(canvas, fBitmap);
802 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000803}
804
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000805SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000806 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800807 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000808 fText = new char[byteLength];
809 memcpy(fText, text, byteLength);
810 fByteLength = byteLength;
811 fX = x;
812 fY = y;
813 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000814
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000815 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
816 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
817 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
818 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000819}
820
fmalita8c89c522014-11-08 16:18:56 -0800821void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000822 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000823}
824
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000825SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
826 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000827 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800828 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000829 fText = new char[byteLength];
830 memcpy(fText, text, byteLength);
831 fByteLength = byteLength;
832 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700833 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000834 fMatrix = *matrix;
835 } else {
836 fMatrix.setIdentity();
837 }
838 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000839
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000840 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
841 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700842 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000843 fInfo.push(SkObjectParser::MatrixToString(*matrix));
844 }
845 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000846}
847
fmalita8c89c522014-11-08 16:18:56 -0800848void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000849 canvas->drawTextOnPath(fText, fByteLength, fPath,
halcanary96fcdcc2015-08-27 07:41:13 -0700850 fMatrix.isIdentity() ? nullptr : &fMatrix,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000851 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000852}
853
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000854SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
855 const SkPoint vertices[], const SkPoint texs[],
856 const SkColor colors[], SkXfermode* xfermode,
857 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000858 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800859 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000860 fVmode = vmode;
861
862 fVertexCount = vertexCount;
863
864 fVertices = new SkPoint[vertexCount];
865 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
866
bsalomon49f085d2014-09-05 13:34:00 -0700867 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000868 fTexs = new SkPoint[vertexCount];
869 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
870 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700871 fTexs = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000872 }
873
bsalomon49f085d2014-09-05 13:34:00 -0700874 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000875 fColors = new SkColor[vertexCount];
876 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
877 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700878 fColors = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000879 }
880
881 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700882 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000883 fXfermode->ref();
884 }
885
886 if (indexCount > 0) {
887 fIndices = new uint16_t[indexCount];
888 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
889 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700890 fIndices = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000891 }
892
893 fIndexCount = indexCount;
894 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000895
chudy@google.com902ebe52012-06-29 14:21:22 +0000896 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000897 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
898 fInfo.push(SkObjectParser::PaintToString(paint));
899}
900
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000901SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000902 delete [] fVertices;
903 delete [] fTexs;
904 delete [] fColors;
905 SkSafeUnref(fXfermode);
906 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000907}
908
fmalita8c89c522014-11-08 16:18:56 -0800909void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000910 canvas->drawVertices(fVmode, fVertexCount, fVertices,
911 fTexs, fColors, fXfermode, fIndices,
912 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000913}
914
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000915SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800916 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000917 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000918}
919
fmalita8c89c522014-11-08 16:18:56 -0800920void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000921 canvas->restore();
922}
923
Florin Malita5f6102d2014-06-30 10:13:28 -0400924SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800925 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000926}
927
fmalita8c89c522014-11-08 16:18:56 -0800928void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400929 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000930}
931
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000932SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000933 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800934 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700935 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000936 fBounds = *bounds;
937 } else {
938 fBounds.setEmpty();
939 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000940
bsalomon49f085d2014-09-05 13:34:00 -0700941 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000942 fPaint = *paint;
943 fPaintPtr = &fPaint;
944 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700945 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000946 }
947 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000948
bsalomon49f085d2014-09-05 13:34:00 -0700949 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000950 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
951 }
bsalomon49f085d2014-09-05 13:34:00 -0700952 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000953 fInfo.push(SkObjectParser::PaintToString(*paint));
954 }
955 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000956}
957
fmalita8c89c522014-11-08 16:18:56 -0800958void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700959 canvas->saveLayer(fBounds.isEmpty() ? nullptr : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000960 fPaintPtr,
961 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000962}
963
fmalita8c89c522014-11-08 16:18:56 -0800964void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000965 canvas->save();
966}
967
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000968SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800969 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700970 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000971 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000972
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000973 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000974}
975
robertphillips70171682014-10-16 14:28:28 -0700976void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
977 fUserMatrix = userMatrix;
978}
979
fmalita8c89c522014-11-08 16:18:56 -0800980void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -0700981 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
982 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000983}
984