blob: 330c2c9183cecf156a995c0b0b4d2feddeeb8190 [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"
fmalitae77f2da2015-12-08 18:59:18 -080014#include "SkTextBlobRunIterator.h"
fmalitab7425172014-08-26 07:56:44 -070015
chudy@google.com902ebe52012-06-29 14:21:22 +000016// TODO(chudy): Refactor into non subclass model.
17
robertphillips9bafc302015-02-13 11:13:00 -080018SkDrawCommand::SkDrawCommand(OpType type)
19 : fOpType(type)
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000020 , fVisible(true) {
21}
22
chudy@google.com902ebe52012-06-29 14:21:22 +000023SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000024 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000025}
26
robertphillips9bafc302015-02-13 11:13:00 -080027const char* SkDrawCommand::GetCommandString(OpType type) {
chudy@google.com902ebe52012-06-29 14:21:22 +000028 switch (type) {
fmalita160ebb22015-04-01 20:58:37 -070029 case kBeginDrawPicture_OpType: return "BeginDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080030 case kClipPath_OpType: return "ClipPath";
31 case kClipRegion_OpType: return "ClipRegion";
32 case kClipRect_OpType: return "ClipRect";
33 case kClipRRect_OpType: return "ClipRRect";
robertphillips9bafc302015-02-13 11:13:00 -080034 case kConcat_OpType: return "Concat";
35 case kDrawBitmap_OpType: return "DrawBitmap";
36 case kDrawBitmapNine_OpType: return "DrawBitmapNine";
37 case kDrawBitmapRect_OpType: return "DrawBitmapRect";
38 case kDrawClear_OpType: return "DrawClear";
39 case kDrawDRRect_OpType: return "DrawDRRect";
fmalita651c9202015-07-22 10:23:01 -070040 case kDrawImage_OpType: return "DrawImage";
41 case kDrawImageRect_OpType: return "DrawImageRect";
robertphillips9bafc302015-02-13 11:13:00 -080042 case kDrawOval_OpType: return "DrawOval";
43 case kDrawPaint_OpType: return "DrawPaint";
44 case kDrawPatch_OpType: return "DrawPatch";
45 case kDrawPath_OpType: return "DrawPath";
robertphillips9bafc302015-02-13 11:13:00 -080046 case kDrawPoints_OpType: return "DrawPoints";
47 case kDrawPosText_OpType: return "DrawPosText";
48 case kDrawPosTextH_OpType: return "DrawPosTextH";
49 case kDrawRect_OpType: return "DrawRect";
50 case kDrawRRect_OpType: return "DrawRRect";
51 case kDrawSprite_OpType: return "DrawSprite";
52 case kDrawText_OpType: return "DrawText";
53 case kDrawTextBlob_OpType: return "DrawTextBlob";
54 case kDrawTextOnPath_OpType: return "DrawTextOnPath";
55 case kDrawVertices_OpType: return "DrawVertices";
fmalita160ebb22015-04-01 20:58:37 -070056 case kEndDrawPicture_OpType: return "EndDrawPicture";
robertphillips9bafc302015-02-13 11:13:00 -080057 case kRestore_OpType: return "Restore";
58 case kSave_OpType: return "Save";
59 case kSaveLayer_OpType: return "SaveLayer";
60 case kSetMatrix_OpType: return "SetMatrix";
chudy@google.com902ebe52012-06-29 14:21:22 +000061 default:
robertphillips9bafc302015-02-13 11:13:00 -080062 SkDebugf("OpType error 0x%08x\n", type);
chudy@google.com902ebe52012-06-29 14:21:22 +000063 SkASSERT(0);
64 break;
65 }
66 SkDEBUGFAIL("DrawType UNUSED\n");
halcanary96fcdcc2015-08-27 07:41:13 -070067 return nullptr;
chudy@google.com902ebe52012-06-29 14:21:22 +000068}
69
fmalita8c89c522014-11-08 16:18:56 -080070SkString SkDrawCommand::toString() const {
robertphillips9bafc302015-02-13 11:13:00 -080071 return SkString(GetCommandString(fOpType));
chudy@google.com902ebe52012-06-29 14:21:22 +000072}
73
robertphillips9bafc302015-02-13 11:13:00 -080074SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000075 fColor = color;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000076 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000077}
78
fmalita8c89c522014-11-08 16:18:56 -080079void SkClearCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000080 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000081}
82
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000083namespace {
84
85void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
86 const SkISize& size = canvas->getDeviceSize();
87
88 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
89
90 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
91 if (bounds.width() > bounds.height()) {
92 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
93 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
94 } else {
95 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
96 SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
97 }
98 canvas->translate(-bounds.centerX(), -bounds.centerY());
99}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000100
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000101
102void render_path(SkCanvas* canvas, const SkPath& path) {
103 canvas->clear(0xFFFFFFFF);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000104
105 const SkRect& bounds = path.getBounds();
fmalitab0cd8b72015-10-06 07:24:03 -0700106 if (bounds.isEmpty()) {
107 return;
108 }
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000109
fmalitab0cd8b72015-10-06 07:24:03 -0700110 SkAutoCanvasRestore acr(canvas, true);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000111 xlate_and_scale_to_bounds(canvas, bounds);
112
113 SkPaint p;
114 p.setColor(SK_ColorBLACK);
115 p.setStyle(SkPaint::kStroke_Style);
116
117 canvas->drawPath(path, p);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000118}
119
halcanary96fcdcc2015-08-27 07:41:13 -0700120void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = nullptr) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000121 const SkISize& size = canvas->getDeviceSize();
122
123 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
124 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
125
126 if (input.width() > input.height()) {
127 yScale *= input.height() / (float) input.width();
128 } else {
129 xScale *= input.width() / (float) input.height();
130 }
131
132 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
133 xScale * input.width(),
134 yScale * input.height());
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000135
robertphillips96a5cff2015-09-24 06:56:27 -0700136 static const int kNumBlocks = 8;
137
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000138 canvas->clear(0xFFFFFFFF);
robertphillips96a5cff2015-09-24 06:56:27 -0700139 SkISize block = {
140 canvas->imageInfo().width()/kNumBlocks,
141 canvas->imageInfo().height()/kNumBlocks
142 };
143 for (int y = 0; y < kNumBlocks; ++y) {
144 for (int x = 0; x < kNumBlocks; ++x) {
145 SkPaint paint;
146 paint.setColor((x+y)%2 ? SK_ColorLTGRAY : SK_ColorDKGRAY);
147 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x*block.width()),
148 SkIntToScalar(y*block.height()),
149 SkIntToScalar(block.width()),
150 SkIntToScalar(block.height()));
151 canvas->drawRect(r, paint);
152 }
153 }
154
reede47829b2015-08-06 10:02:53 -0700155 canvas->drawBitmapRect(input, dst, nullptr);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000156
bsalomon49f085d2014-09-05 13:34:00 -0700157 if (srcRect) {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000158 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
159 srcRect->fTop * yScale + SK_Scalar1,
160 srcRect->fRight * xScale + SK_Scalar1,
161 srcRect->fBottom * yScale + SK_Scalar1);
162 SkPaint p;
163 p.setColor(SK_ColorRED);
164 p.setStyle(SkPaint::kStroke_Style);
165
166 canvas->drawRect(r, p);
167 }
168}
169
170void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
171 canvas->clear(0xFFFFFFFF);
172 canvas->save();
173
174 const SkRect& bounds = rrect.getBounds();
175
176 xlate_and_scale_to_bounds(canvas, bounds);
177
178 SkPaint p;
179 p.setColor(SK_ColorBLACK);
180 p.setStyle(SkPaint::kStroke_Style);
181
182 canvas->drawRRect(rrect, p);
183 canvas->restore();
184}
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000185
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000186void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
187 canvas->clear(0xFFFFFFFF);
188 canvas->save();
189
190 const SkRect& bounds = outer.getBounds();
191
192 xlate_and_scale_to_bounds(canvas, bounds);
193
194 SkPaint p;
195 p.setColor(SK_ColorBLACK);
196 p.setStyle(SkPaint::kStroke_Style);
197
198 canvas->drawDRRect(outer, inner, p);
199 canvas->restore();
200}
201
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000202};
203
204
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000205SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800206 : INHERITED(kClipPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000207 fPath = path;
208 fOp = op;
209 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000210
robertphillips@google.com91217d02013-03-17 18:33:46 +0000211 fInfo.push(SkObjectParser::PathToString(path));
212 fInfo.push(SkObjectParser::RegionOpToString(op));
213 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000214}
215
fmalita8c89c522014-11-08 16:18:56 -0800216void SkClipPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000217 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000218}
219
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000220bool SkClipPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000221 render_path(canvas, fPath);
222 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000223}
224
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000225SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
robertphillips9bafc302015-02-13 11:13:00 -0800226 : INHERITED(kClipRegion_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000227 fRegion = region;
228 fOp = op;
chudy@google.com902ebe52012-06-29 14:21:22 +0000229
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000230 fInfo.push(SkObjectParser::RegionToString(region));
231 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000232}
233
fmalita8c89c522014-11-08 16:18:56 -0800234void SkClipRegionCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000235 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000236}
237
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000238SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800239 : INHERITED(kClipRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000240 fRect = rect;
241 fOp = op;
242 fDoAA = doAA;
chudy@google.com902ebe52012-06-29 14:21:22 +0000243
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000244 fInfo.push(SkObjectParser::RectToString(rect));
245 fInfo.push(SkObjectParser::RegionOpToString(op));
246 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000247}
248
fmalita8c89c522014-11-08 16:18:56 -0800249void SkClipRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000250 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000251}
252
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000253SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
robertphillips9bafc302015-02-13 11:13:00 -0800254 : INHERITED(kClipRRect_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000255 fRRect = rrect;
256 fOp = op;
257 fDoAA = doAA;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000258
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000259 fInfo.push(SkObjectParser::RRectToString(rrect));
260 fInfo.push(SkObjectParser::RegionOpToString(op));
261 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000262}
263
fmalita8c89c522014-11-08 16:18:56 -0800264void SkClipRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000265 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000266}
267
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000268bool SkClipRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000269 render_rrect(canvas, fRRect);
270 return true;
271}
272
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000273SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800274 : INHERITED(kConcat_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000275 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000276
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000277 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000278}
279
fmalita8c89c522014-11-08 16:18:56 -0800280void SkConcatCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000281 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000282}
283
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000284SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillipsb3f319f2014-08-13 10:46:23 -0700285 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800286 : INHERITED(kDrawBitmap_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000287 fBitmap = bitmap;
288 fLeft = left;
289 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700290 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000291 fPaint = *paint;
292 fPaintPtr = &fPaint;
293 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700294 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000295 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000296
297 fInfo.push(SkObjectParser::BitmapToString(bitmap));
298 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
299 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700300 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000301 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000302 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000303}
304
fmalita8c89c522014-11-08 16:18:56 -0800305void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000306 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000307}
308
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000309bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000310 render_bitmap(canvas, fBitmap);
311 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000312}
313
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000314SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +0000315 const SkRect& dst, const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800316 : INHERITED(kDrawBitmapNine_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000317 fBitmap = bitmap;
318 fCenter = center;
319 fDst = dst;
bsalomon49f085d2014-09-05 13:34:00 -0700320 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000321 fPaint = *paint;
322 fPaintPtr = &fPaint;
323 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700324 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000325 }
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000326
327 fInfo.push(SkObjectParser::BitmapToString(bitmap));
328 fInfo.push(SkObjectParser::IRectToString(center));
329 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700330 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000331 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000332 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000333}
334
fmalita8c89c522014-11-08 16:18:56 -0800335void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000336 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000337}
338
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000339bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
robertphillips2b829822015-11-18 12:59:42 -0800340 SkRect tmp = SkRect::Make(fCenter);
341 render_bitmap(canvas, fBitmap, &tmp);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000342 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000343}
344
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000345SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000346 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700347 SkCanvas::SrcRectConstraint constraint)
robertphillips9bafc302015-02-13 11:13:00 -0800348 : INHERITED(kDrawBitmapRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000349 fBitmap = bitmap;
bsalomon49f085d2014-09-05 13:34:00 -0700350 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000351 fSrc = *src;
352 } else {
353 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000354 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000355 fDst = dst;
356
bsalomon49f085d2014-09-05 13:34:00 -0700357 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000358 fPaint = *paint;
359 fPaintPtr = &fPaint;
360 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700361 fPaintPtr = nullptr;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000362 }
reeda5517e22015-07-14 10:54:12 -0700363 fConstraint = constraint;
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000364
robertphillips@google.com91217d02013-03-17 18:33:46 +0000365 fInfo.push(SkObjectParser::BitmapToString(bitmap));
bsalomon49f085d2014-09-05 13:34:00 -0700366 if (src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000367 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
368 }
369 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
bsalomon49f085d2014-09-05 13:34:00 -0700370 if (paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000371 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000372 }
reeda5517e22015-07-14 10:54:12 -0700373 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000374}
375
fmalita8c89c522014-11-08 16:18:56 -0800376void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700377 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000378}
379
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000380bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000381 render_bitmap(canvas, fBitmap, this->srcRect());
382 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000383}
384
fmalita651c9202015-07-22 10:23:01 -0700385SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top,
386 const SkPaint* paint)
387 : INHERITED(kDrawImage_OpType)
388 , fImage(SkRef(image))
389 , fLeft(left)
390 , fTop(top) {
391
fmalita7361bf02015-10-29 12:13:48 -0700392 fInfo.push(SkObjectParser::ImageToString(image));
393 fInfo.push(SkObjectParser::ScalarToString(left, "Left: "));
394 fInfo.push(SkObjectParser::ScalarToString(top, "Top: "));
395
fmalita651c9202015-07-22 10:23:01 -0700396 if (paint) {
397 fPaint.set(*paint);
fmalita7361bf02015-10-29 12:13:48 -0700398 fInfo.push(SkObjectParser::PaintToString(*paint));
fmalita651c9202015-07-22 10:23:01 -0700399 }
400}
401
402void SkDrawImageCommand::execute(SkCanvas* canvas) const {
403 canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull());
404}
405
406bool SkDrawImageCommand::render(SkCanvas* canvas) const {
407 SkAutoCanvasRestore acr(canvas, true);
408 canvas->clear(0xFFFFFFFF);
409
410 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
411 SkIntToScalar(fImage->width()),
412 SkIntToScalar(fImage->height())));
413 this->execute(canvas);
414 return true;
415}
416
417SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src,
418 const SkRect& dst, const SkPaint* paint,
419 SkCanvas::SrcRectConstraint constraint)
420 : INHERITED(kDrawImageRect_OpType)
421 , fImage(SkRef(image))
422 , fDst(dst)
423 , fConstraint(constraint) {
424
425 if (src) {
426 fSrc.set(*src);
427 }
428
429 if (paint) {
430 fPaint.set(*paint);
431 }
robertphillips80af6452015-08-24 08:27:38 -0700432
433 fInfo.push(SkObjectParser::ImageToString(image));
434 if (src) {
435 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
436 }
437 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
438 if (paint) {
439 fInfo.push(SkObjectParser::PaintToString(*paint));
440 }
441 fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
fmalita651c9202015-07-22 10:23:01 -0700442}
443
444void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
reede47829b2015-08-06 10:02:53 -0700445 canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint);
fmalita651c9202015-07-22 10:23:01 -0700446}
447
448bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
449 SkAutoCanvasRestore acr(canvas, true);
450 canvas->clear(0xFFFFFFFF);
451
452 xlate_and_scale_to_bounds(canvas, fDst);
453
454 this->execute(canvas);
455 return true;
456}
457
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000458SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800459 : INHERITED(kDrawOval_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000460 fOval = oval;
461 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000462
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000463 fInfo.push(SkObjectParser::RectToString(oval));
464 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000465}
466
fmalita8c89c522014-11-08 16:18:56 -0800467void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000468 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000469}
470
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000471bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000472 canvas->clear(0xFFFFFFFF);
473 canvas->save();
474
475 xlate_and_scale_to_bounds(canvas, fOval);
476
477 SkPaint p;
478 p.setColor(SK_ColorBLACK);
479 p.setStyle(SkPaint::kStroke_Style);
480
481 canvas->drawOval(fOval, p);
482 canvas->restore();
483
484 return true;
485}
486
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000487SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800488 : INHERITED(kDrawPaint_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000489 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000490
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000491 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000492}
493
fmalita8c89c522014-11-08 16:18:56 -0800494void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000495 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000496}
497
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000498bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000499 canvas->clear(0xFFFFFFFF);
500 canvas->drawPaint(fPaint);
501 return true;
502}
503
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000504SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800505 : INHERITED(kDrawPath_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000506 fPath = path;
507 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000508
robertphillips@google.com91217d02013-03-17 18:33:46 +0000509 fInfo.push(SkObjectParser::PathToString(path));
510 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000511}
512
fmalita8c89c522014-11-08 16:18:56 -0800513void SkDrawPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000514 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000515}
516
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000517bool SkDrawPathCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000518 render_path(canvas, fPath);
519 return true;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000520}
521
fmalita160ebb22015-04-01 20:58:37 -0700522SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
523 const SkMatrix* matrix,
524 const SkPaint* paint)
525 : INHERITED(kBeginDrawPicture_OpType)
526 , fPicture(SkRef(picture)) {
527
528 SkString* str = new SkString;
529 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
530 picture->cullRect().fLeft, picture->cullRect().fTop,
531 picture->cullRect().fRight, picture->cullRect().fBottom);
532 fInfo.push(str);
robertphillipsb3f319f2014-08-13 10:46:23 -0700533
bsalomon49f085d2014-09-05 13:34:00 -0700534 if (matrix) {
fmalita160ebb22015-04-01 20:58:37 -0700535 fMatrix.set(*matrix);
robertphillipsb3f319f2014-08-13 10:46:23 -0700536 fInfo.push(SkObjectParser::MatrixToString(*matrix));
537 }
fmalita160ebb22015-04-01 20:58:37 -0700538
bsalomon49f085d2014-09-05 13:34:00 -0700539 if (paint) {
fmalita160ebb22015-04-01 20:58:37 -0700540 fPaint.set(*paint);
robertphillipsb3f319f2014-08-13 10:46:23 -0700541 fInfo.push(SkObjectParser::PaintToString(*paint));
542 }
fmalita160ebb22015-04-01 20:58:37 -0700543
544}
545
546void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
547 if (fPaint.isValid()) {
548 SkRect bounds = fPicture->cullRect();
549 if (fMatrix.isValid()) {
550 fMatrix.get()->mapRect(&bounds);
551 }
552 canvas->saveLayer(&bounds, fPaint.get());
553 }
554
555 if (fMatrix.isValid()) {
556 if (!fPaint.isValid()) {
557 canvas->save();
558 }
559 canvas->concat(*fMatrix.get());
560 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000561}
562
fmalita160ebb22015-04-01 20:58:37 -0700563bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000564 canvas->clear(0xFFFFFFFF);
565 canvas->save();
566
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700567 xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000568
robertphillips9b14f262014-06-04 05:40:44 -0700569 canvas->drawPicture(fPicture.get());
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000570
571 canvas->restore();
572
573 return true;
574}
575
fmalita160ebb22015-04-01 20:58:37 -0700576SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
577 : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
578
579void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
580 if (fRestore) {
581 canvas->restore();
582 }
583}
584
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000585SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000586 const SkPoint pts[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800587 : INHERITED(kDrawPoints_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000588 fMode = mode;
589 fCount = count;
590 fPts = new SkPoint[count];
591 memcpy(fPts, pts, count * sizeof(SkPoint));
592 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000593
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000594 fInfo.push(SkObjectParser::PointsToString(pts, count));
595 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
596 "Points: "));
597 fInfo.push(SkObjectParser::PointModeToString(mode));
598 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000599}
600
fmalita8c89c522014-11-08 16:18:56 -0800601void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000602 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000603}
604
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000605bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000606 canvas->clear(0xFFFFFFFF);
607 canvas->save();
608
609 SkRect bounds;
610
611 bounds.setEmpty();
612 for (unsigned int i = 0; i < fCount; ++i) {
613 bounds.growToInclude(fPts[i].fX, fPts[i].fY);
614 }
skia.committer@gmail.coma0090832013-06-07 07:01:06 +0000615
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000616 xlate_and_scale_to_bounds(canvas, bounds);
617
618 SkPaint p;
619 p.setColor(SK_ColorBLACK);
620 p.setStyle(SkPaint::kStroke_Style);
621
622 canvas->drawPoints(fMode, fCount, fPts, p);
623 canvas->restore();
624
625 return true;
626}
627
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000628SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000629 const SkPoint pos[], const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800630 : INHERITED(kDrawPosText_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000631 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000632
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000633 fText = new char[byteLength];
634 memcpy(fText, text, byteLength);
635 fByteLength = byteLength;
636
637 fPos = new SkPoint[numPts];
638 memcpy(fPos, pos, numPts * sizeof(SkPoint));
639
640 fPaint = paint;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000641
642 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000643 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000644 fInfo.push(SkObjectParser::PointsToString(pos, 1));
645 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000646}
647
fmalita8c89c522014-11-08 16:18:56 -0800648void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000649 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000650}
651
652
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000653SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
654 const SkScalar xpos[], SkScalar constY,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000655 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800656 : INHERITED(kDrawPosTextH_OpType) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000657 size_t numPts = paint.countText(text, byteLength);
658
659 fText = new char[byteLength];
660 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000661 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000662
663 fXpos = new SkScalar[numPts];
664 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
665
robertphillips@google.com91217d02013-03-17 18:33:46 +0000666 fConstY = constY;
667 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000668
robertphillips@google.com91217d02013-03-17 18:33:46 +0000669 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
670 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
671 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
672 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000673}
674
fmalita8c89c522014-11-08 16:18:56 -0800675void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000676 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000677}
678
fmalitab7425172014-08-26 07:56:44 -0700679SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
680 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800681 : INHERITED(kDrawTextBlob_OpType)
fmalitae77f2da2015-12-08 18:59:18 -0800682 , fBlob(SkRef(blob))
fmalitab7425172014-08-26 07:56:44 -0700683 , fXPos(x)
684 , fYPos(y)
685 , fPaint(paint) {
686
fmalitae77f2da2015-12-08 18:59:18 -0800687 SkAutoTDelete<SkString> runsStr(new SkString);
fmalitab7425172014-08-26 07:56:44 -0700688 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: "));
fmalitae77f2da2015-12-08 18:59:18 -0800691 fInfo.push(runsStr);
fmalitab7425172014-08-26 07:56:44 -0700692 fInfo.push(SkObjectParser::PaintToString(paint));
fmalitae77f2da2015-12-08 18:59:18 -0800693
694 unsigned runs = 0;
695 SkPaint runPaint(paint);
696 SkTextBlobRunIterator iter(blob);
697 while (!iter.done()) {
698 SkAutoTDelete<SkString> label(new SkString);
699 label->printf("==== Run [%d] ====", runs++);
700 fInfo.push(label.release());
701
702 fInfo.push(SkObjectParser::IntToString(iter.glyphCount(), "GlyphCount: "));
703 iter.applyFontToPaint(&runPaint);
704 fInfo.push(SkObjectParser::PaintToString(runPaint));
705
706 iter.next();
707 }
708
709 runsStr->printf("Runs: %d", runs);
710 // runStr is owned by fInfo at this point.
711 runsStr.release();
fmalitab7425172014-08-26 07:56:44 -0700712}
713
fmalita8c89c522014-11-08 16:18:56 -0800714void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
fmalitab7425172014-08-26 07:56:44 -0700715 canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
716}
717
fmalita55773872014-08-29 15:08:20 -0700718bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
719 canvas->clear(SK_ColorWHITE);
720 canvas->save();
721
722 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
723 xlate_and_scale_to_bounds(canvas, bounds);
724
725 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
726
727 canvas->restore();
728
729 return true;
730}
731
robertphillips9bafc302015-02-13 11:13:00 -0800732SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
733 const SkPoint texCoords[4], SkXfermode* xfermode,
734 const SkPaint& paint)
735 : INHERITED(kDrawPatch_OpType) {
736 memcpy(fCubics, cubics, sizeof(fCubics));
737 memcpy(fColors, colors, sizeof(fColors));
738 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
739 fXfermode.reset(xfermode);
740 fPaint = paint;
741
742 fInfo.push(SkObjectParser::PaintToString(paint));
743}
744
745void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
746 canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint);
747}
748
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000749SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800750 : INHERITED(kDrawRect_OpType) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000751 fRect = rect;
752 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000753
robertphillips@google.com91217d02013-03-17 18:33:46 +0000754 fInfo.push(SkObjectParser::RectToString(rect));
755 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000756}
757
fmalita8c89c522014-11-08 16:18:56 -0800758void SkDrawRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000759 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000760}
761
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000762SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800763 : INHERITED(kDrawRRect_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000764 fRRect = rrect;
765 fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000766
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000767 fInfo.push(SkObjectParser::RRectToString(rrect));
768 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000769}
770
fmalita8c89c522014-11-08 16:18:56 -0800771void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000772 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000773}
774
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000775bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000776 render_rrect(canvas, fRRect);
777 return true;
778}
779
skia.committer@gmail.com90667ba2014-02-25 03:05:18 +0000780SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000781 const SkRRect& inner,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000782 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800783 : INHERITED(kDrawDRRect_OpType) {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000784 fOuter = outer;
785 fInner = inner;
786 fPaint = paint;
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000787
788 fInfo.push(SkObjectParser::RRectToString(outer));
789 fInfo.push(SkObjectParser::RRectToString(inner));
790 fInfo.push(SkObjectParser::PaintToString(paint));
791}
792
fmalita8c89c522014-11-08 16:18:56 -0800793void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000794 canvas->drawDRRect(fOuter, fInner, fPaint);
795}
796
797bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
798 render_drrect(canvas, fOuter, fInner);
799 return true;
800}
801
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000802SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000803 const SkPaint* paint)
robertphillips9bafc302015-02-13 11:13:00 -0800804 : INHERITED(kDrawSprite_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000805 fBitmap = bitmap;
806 fLeft = left;
807 fTop = top;
bsalomon49f085d2014-09-05 13:34:00 -0700808 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000809 fPaint = *paint;
810 fPaintPtr = &fPaint;
811 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700812 fPaintPtr = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000813 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000814
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000815 fInfo.push(SkObjectParser::BitmapToString(bitmap));
816 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
817 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
bsalomon49f085d2014-09-05 13:34:00 -0700818 if (paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000819 fInfo.push(SkObjectParser::PaintToString(*paint));
820 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000821}
822
fmalita8c89c522014-11-08 16:18:56 -0800823void SkDrawSpriteCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000824 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000825}
826
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000827bool SkDrawSpriteCommand::render(SkCanvas* canvas) const {
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000828 render_bitmap(canvas, fBitmap);
829 return true;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000830}
831
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000832SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000833 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800834 : INHERITED(kDrawText_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000835 fText = new char[byteLength];
836 memcpy(fText, text, byteLength);
837 fByteLength = byteLength;
838 fX = x;
839 fY = y;
840 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000841
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000842 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
843 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
844 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
845 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000846}
847
fmalita8c89c522014-11-08 16:18:56 -0800848void SkDrawTextCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000849 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000850}
851
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000852SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
853 const SkPath& path, const SkMatrix* matrix,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000854 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800855 : INHERITED(kDrawTextOnPath_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000856 fText = new char[byteLength];
857 memcpy(fText, text, byteLength);
858 fByteLength = byteLength;
859 fPath = path;
bsalomon49f085d2014-09-05 13:34:00 -0700860 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000861 fMatrix = *matrix;
862 } else {
863 fMatrix.setIdentity();
864 }
865 fPaint = paint;
chudy@google.com902ebe52012-06-29 14:21:22 +0000866
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000867 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
868 fInfo.push(SkObjectParser::PathToString(path));
bsalomon49f085d2014-09-05 13:34:00 -0700869 if (matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000870 fInfo.push(SkObjectParser::MatrixToString(*matrix));
871 }
872 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000873}
874
fmalita8c89c522014-11-08 16:18:56 -0800875void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000876 canvas->drawTextOnPath(fText, fByteLength, fPath,
halcanary96fcdcc2015-08-27 07:41:13 -0700877 fMatrix.isIdentity() ? nullptr : &fMatrix,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000878 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000879}
880
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000881SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
882 const SkPoint vertices[], const SkPoint texs[],
883 const SkColor colors[], SkXfermode* xfermode,
884 const uint16_t indices[], int indexCount,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000885 const SkPaint& paint)
robertphillips9bafc302015-02-13 11:13:00 -0800886 : INHERITED(kDrawVertices_OpType) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000887 fVmode = vmode;
888
889 fVertexCount = vertexCount;
890
891 fVertices = new SkPoint[vertexCount];
892 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
893
bsalomon49f085d2014-09-05 13:34:00 -0700894 if (texs) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000895 fTexs = new SkPoint[vertexCount];
896 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
897 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700898 fTexs = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000899 }
900
bsalomon49f085d2014-09-05 13:34:00 -0700901 if (colors) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000902 fColors = new SkColor[vertexCount];
903 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
904 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700905 fColors = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000906 }
907
908 fXfermode = xfermode;
bsalomon49f085d2014-09-05 13:34:00 -0700909 if (fXfermode) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000910 fXfermode->ref();
911 }
912
913 if (indexCount > 0) {
914 fIndices = new uint16_t[indexCount];
915 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
916 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700917 fIndices = nullptr;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000918 }
919
920 fIndexCount = indexCount;
921 fPaint = paint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000922
chudy@google.com902ebe52012-06-29 14:21:22 +0000923 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000924 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
925 fInfo.push(SkObjectParser::PaintToString(paint));
926}
927
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000928SkDrawVerticesCommand::~SkDrawVerticesCommand() {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000929 delete [] fVertices;
930 delete [] fTexs;
931 delete [] fColors;
932 SkSafeUnref(fXfermode);
933 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000934}
935
fmalita8c89c522014-11-08 16:18:56 -0800936void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000937 canvas->drawVertices(fVmode, fVertexCount, fVertices,
938 fTexs, fColors, fXfermode, fIndices,
939 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000940}
941
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000942SkRestoreCommand::SkRestoreCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800943 : INHERITED(kRestore_OpType) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000944 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000945}
946
fmalita8c89c522014-11-08 16:18:56 -0800947void SkRestoreCommand::execute(SkCanvas* canvas) const {
chudy@google.com902ebe52012-06-29 14:21:22 +0000948 canvas->restore();
949}
950
Florin Malita5f6102d2014-06-30 10:13:28 -0400951SkSaveCommand::SkSaveCommand()
robertphillips9bafc302015-02-13 11:13:00 -0800952 : INHERITED(kSave_OpType) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000953}
954
fmalita8c89c522014-11-08 16:18:56 -0800955void SkSaveCommand::execute(SkCanvas* canvas) const {
Florin Malita5f6102d2014-06-30 10:13:28 -0400956 canvas->save();
chudy@google.com902ebe52012-06-29 14:21:22 +0000957}
958
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000959SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000960 SkCanvas::SaveFlags flags)
robertphillips9bafc302015-02-13 11:13:00 -0800961 : INHERITED(kSaveLayer_OpType) {
bsalomon49f085d2014-09-05 13:34:00 -0700962 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000963 fBounds = *bounds;
964 } else {
965 fBounds.setEmpty();
966 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000967
bsalomon49f085d2014-09-05 13:34:00 -0700968 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000969 fPaint = *paint;
970 fPaintPtr = &fPaint;
971 } else {
halcanary96fcdcc2015-08-27 07:41:13 -0700972 fPaintPtr = nullptr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000973 }
974 fFlags = flags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000975
bsalomon49f085d2014-09-05 13:34:00 -0700976 if (bounds) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000977 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
978 }
bsalomon49f085d2014-09-05 13:34:00 -0700979 if (paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000980 fInfo.push(SkObjectParser::PaintToString(*paint));
981 }
982 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000983}
984
fmalita8c89c522014-11-08 16:18:56 -0800985void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700986 canvas->saveLayer(fBounds.isEmpty() ? nullptr : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000987 fPaintPtr,
988 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000989}
990
fmalita8c89c522014-11-08 16:18:56 -0800991void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +0000992 canvas->save();
993}
994
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000995SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
robertphillips9bafc302015-02-13 11:13:00 -0800996 : INHERITED(kSetMatrix_OpType) {
robertphillips70171682014-10-16 14:28:28 -0700997 fUserMatrix.reset();
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000998 fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000999
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +00001000 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +00001001}
1002
robertphillips70171682014-10-16 14:28:28 -07001003void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
1004 fUserMatrix = userMatrix;
1005}
1006
fmalita8c89c522014-11-08 16:18:56 -08001007void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
robertphillips70171682014-10-16 14:28:28 -07001008 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
1009 canvas->setMatrix(temp);
chudy@google.com902ebe52012-06-29 14:21:22 +00001010}
1011