blob: c0ab3a0a4e915d17c0eef6fd3b46d4a594649528 [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#ifndef SKDRAWCOMMAND_H_
10#define SKDRAWCOMMAND_H_
11
chudy@google.com902ebe52012-06-29 14:21:22 +000012#include "SkCanvas.h"
bungemand3ebb482015-08-05 13:57:49 -070013#include "SkTLazy.h"
14#include "SkPath.h"
15#include "SkRRect.h"
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000016#include "SkString.h"
bungemand3ebb482015-08-05 13:57:49 -070017#include "SkTDArray.h"
ethannicholas50a8dd02016-02-10 05:40:46 -080018#include "SkJSONCPP.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000019
fmalita@google.com86681b32013-06-13 20:59:14 +000020class SK_API SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +000021public:
robertphillips9bafc302015-02-13 11:13:00 -080022 enum OpType {
fmalita160ebb22015-04-01 20:58:37 -070023 kBeginDrawPicture_OpType,
robertphillips9bafc302015-02-13 11:13:00 -080024 kClipPath_OpType,
25 kClipRegion_OpType,
26 kClipRect_OpType,
27 kClipRRect_OpType,
robertphillips9bafc302015-02-13 11:13:00 -080028 kConcat_OpType,
29 kDrawBitmap_OpType,
30 kDrawBitmapNine_OpType,
31 kDrawBitmapRect_OpType,
32 kDrawClear_OpType,
33 kDrawDRRect_OpType,
fmalita651c9202015-07-22 10:23:01 -070034 kDrawImage_OpType,
35 kDrawImageRect_OpType,
robertphillips9bafc302015-02-13 11:13:00 -080036 kDrawOval_OpType,
37 kDrawPaint_OpType,
38 kDrawPatch_OpType,
39 kDrawPath_OpType,
robertphillips9bafc302015-02-13 11:13:00 -080040 kDrawPoints_OpType,
41 kDrawPosText_OpType,
42 kDrawPosTextH_OpType,
43 kDrawRect_OpType,
44 kDrawRRect_OpType,
robertphillips9bafc302015-02-13 11:13:00 -080045 kDrawText_OpType,
46 kDrawTextBlob_OpType,
47 kDrawTextOnPath_OpType,
48 kDrawVertices_OpType,
fmalita160ebb22015-04-01 20:58:37 -070049 kEndDrawPicture_OpType,
robertphillips9bafc302015-02-13 11:13:00 -080050 kRestore_OpType,
51 kSave_OpType,
52 kSaveLayer_OpType,
53 kSetMatrix_OpType,
robertphillips72942b82015-02-12 06:37:12 -080054
robertphillips9bafc302015-02-13 11:13:00 -080055 kLast_OpType = kSetMatrix_OpType
56 };
57
58 static const int kOpTypeCount = kLast_OpType + 1;
59
60 SkDrawCommand(OpType opType);
chudy@google.com902ebe52012-06-29 14:21:22 +000061
62 virtual ~SkDrawCommand();
63
fmalita8c89c522014-11-08 16:18:56 -080064 virtual SkString toString() const;
chudy@google.com902ebe52012-06-29 14:21:22 +000065
fmalita8c89c522014-11-08 16:18:56 -080066 virtual const char* toCString() const {
robertphillips9bafc302015-02-13 11:13:00 -080067 return GetCommandString(fOpType);
chudy@google.com902ebe52012-06-29 14:21:22 +000068 }
69
chudy@google.com0b5bbb02012-07-31 19:55:32 +000070 bool isVisible() const {
71 return fVisible;
72 }
73
74 void setVisible(bool toggle) {
75 fVisible = toggle;
76 }
chudy@google.com902ebe52012-06-29 14:21:22 +000077
fmalita8c89c522014-11-08 16:18:56 -080078 const SkTDArray<SkString*>* Info() const { return &fInfo; }
79 virtual void execute(SkCanvas*) const = 0;
80 virtual void vizExecute(SkCanvas*) const {}
robertphillips70171682014-10-16 14:28:28 -070081
fmalita8c89c522014-11-08 16:18:56 -080082 virtual void setUserMatrix(const SkMatrix&) {}
robertphillips70171682014-10-16 14:28:28 -070083
mtkleinf0f14112014-12-12 08:46:25 -080084 // The next "active" system is only used by save, saveLayer, and restore.
85 // It is used to determine which saveLayers are currently active (at a
commit-bot@chromium.org768ac852014-03-03 16:32:17 +000086 // given point in the rendering).
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000087 // saves just return a kPushLayer action but don't track active state
88 // restores just return a kPopLayer action
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +000089 // saveLayers return kPushLayer but also track the active state
commit-bot@chromium.org768ac852014-03-03 16:32:17 +000090 enum Action {
91 kNone_Action,
commit-bot@chromium.org1643b2c2014-03-03 23:25:41 +000092 kPopLayer_Action,
93 kPushLayer_Action,
commit-bot@chromium.org768ac852014-03-03 16:32:17 +000094 };
95 virtual Action action() const { return kNone_Action; }
96 virtual void setActive(bool active) {}
97 virtual bool active() const { return false; }
98
robertphillips9bafc302015-02-13 11:13:00 -080099 OpType getType() const { return fOpType; }
chudy@google.com902ebe52012-06-29 14:21:22 +0000100
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +0000101 virtual bool render(SkCanvas* canvas) const { return false; }
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000102
ethannicholas50a8dd02016-02-10 05:40:46 -0800103 virtual Json::Value toJSON() const;
104
105 /* Converts a JSON representation of a command into a newly-allocated SkDrawCommand object. It
106 * is the caller's responsibility to delete this object. This method may return null if an error
107 * occurs.
108 */
109 static SkDrawCommand* fromJSON(Json::Value& command);
110
robertphillips9bafc302015-02-13 11:13:00 -0800111 static const char* GetCommandString(OpType type);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000112
chudy@google.com902ebe52012-06-29 14:21:22 +0000113protected:
chudy@google.com97cee972012-08-07 20:41:37 +0000114 SkTDArray<SkString*> fInfo;
chudy@google.com902ebe52012-06-29 14:21:22 +0000115
116private:
robertphillips9bafc302015-02-13 11:13:00 -0800117 OpType fOpType;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000118 bool fVisible;
chudy@google.com902ebe52012-06-29 14:21:22 +0000119};
120
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000121class SkRestoreCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000122public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000123 SkRestoreCommand();
mtklein36352bf2015-03-25 18:17:31 -0700124 void execute(SkCanvas* canvas) const override;
125 Action action() const override { return kPopLayer_Action; }
ethannicholas50a8dd02016-02-10 05:40:46 -0800126 static SkRestoreCommand* fromJSON(Json::Value& command);
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000127
128private:
129 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000130};
131
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000132class SkClearCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000133public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000134 SkClearCommand(SkColor color);
mtklein36352bf2015-03-25 18:17:31 -0700135 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800136 Json::Value toJSON() const override;
137 static SkClearCommand* fromJSON(Json::Value& command);
138
chudy@google.com902ebe52012-06-29 14:21:22 +0000139private:
140 SkColor fColor;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000141
142 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000143};
144
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000145class SkClipPathCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000146public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000147 SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA);
mtklein36352bf2015-03-25 18:17:31 -0700148 void execute(SkCanvas* canvas) const override;
149 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800150 Json::Value toJSON() const override;
151 static SkClipPathCommand* fromJSON(Json::Value& command);
152
chudy@google.com902ebe52012-06-29 14:21:22 +0000153private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000154 SkPath fPath;
chudy@google.com902ebe52012-06-29 14:21:22 +0000155 SkRegion::Op fOp;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000156 bool fDoAA;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000157
158 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000159};
160
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000161class SkClipRegionCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000162public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000163 SkClipRegionCommand(const SkRegion& region, SkRegion::Op op);
mtklein36352bf2015-03-25 18:17:31 -0700164 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800165 Json::Value toJSON() const override;
166 static SkClipRegionCommand* fromJSON(Json::Value& command);
167
chudy@google.com902ebe52012-06-29 14:21:22 +0000168private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000169 SkRegion fRegion;
chudy@google.com902ebe52012-06-29 14:21:22 +0000170 SkRegion::Op fOp;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000171
172 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000173};
174
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000175class SkClipRectCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000176public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000177 SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA);
mtklein36352bf2015-03-25 18:17:31 -0700178 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800179 Json::Value toJSON() const override;
180 static SkClipRectCommand* fromJSON(Json::Value& command);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000181
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000182 const SkRect& rect() const { return fRect; }
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000183 SkRegion::Op op() const { return fOp; }
184 bool doAA() const { return fDoAA; }
185
chudy@google.com902ebe52012-06-29 14:21:22 +0000186private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000187 SkRect fRect;
chudy@google.com902ebe52012-06-29 14:21:22 +0000188 SkRegion::Op fOp;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000189 bool fDoAA;
190
191 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000192};
193
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000194class SkClipRRectCommand : public SkDrawCommand {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000195public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000196 SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA);
mtklein36352bf2015-03-25 18:17:31 -0700197 void execute(SkCanvas* canvas) const override;
198 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800199 Json::Value toJSON() const override;
200 static SkClipRRectCommand* fromJSON(Json::Value& command);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000201
202 const SkRRect& rrect() const { return fRRect; }
203 SkRegion::Op op() const { return fOp; }
204 bool doAA() const { return fDoAA; }
205
robertphillips@google.com67baba42013-01-02 20:20:31 +0000206private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000207 SkRRect fRRect;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000208 SkRegion::Op fOp;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000209 bool fDoAA;
210
211 typedef SkDrawCommand INHERITED;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000212};
213
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000214class SkConcatCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000215public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000216 SkConcatCommand(const SkMatrix& matrix);
mtklein36352bf2015-03-25 18:17:31 -0700217 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800218 Json::Value toJSON() const override;
219 static SkConcatCommand* fromJSON(Json::Value& command);
220
chudy@google.com902ebe52012-06-29 14:21:22 +0000221private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000222 SkMatrix fMatrix;
223
224 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000225};
226
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000227class SkDrawBitmapCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000228public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000229 SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000230 const SkPaint* paint);
mtklein36352bf2015-03-25 18:17:31 -0700231 void execute(SkCanvas* canvas) const override;
232 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800233 Json::Value toJSON() const override;
234 static SkDrawBitmapCommand* fromJSON(Json::Value& command);
235
chudy@google.com902ebe52012-06-29 14:21:22 +0000236private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000237 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000238 SkScalar fLeft;
239 SkScalar fTop;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000240 SkPaint fPaint;
241 SkPaint* fPaintPtr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000242
243 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000244};
245
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000246class SkDrawBitmapNineCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000247public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000248 SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000249 const SkRect& dst, const SkPaint* paint);
mtklein36352bf2015-03-25 18:17:31 -0700250 void execute(SkCanvas* canvas) const override;
251 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800252 Json::Value toJSON() const override;
253 static SkDrawBitmapNineCommand* fromJSON(Json::Value& command);
254
chudy@google.com902ebe52012-06-29 14:21:22 +0000255private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000256 SkBitmap fBitmap;
257 SkIRect fCenter;
258 SkRect fDst;
259 SkPaint fPaint;
260 SkPaint* fPaintPtr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000261
262 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000263};
264
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000265class SkDrawBitmapRectCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000266public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000267 SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000268 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700269 SkCanvas::SrcRectConstraint);
mtklein36352bf2015-03-25 18:17:31 -0700270 void execute(SkCanvas* canvas) const override;
271 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800272 Json::Value toJSON() const override;
273 static SkDrawBitmapRectCommand* fromJSON(Json::Value& command);
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000274
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000275 const SkBitmap& bitmap() const { return fBitmap; }
276
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000277 // The non-const 'paint' method allows modification of this object's
278 // SkPaint. For this reason the ctor and setPaint method make a local copy.
279 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid
280 // (since only an SkPaint* is passed into the ctor).
281 const SkPaint* paint() const { return fPaintPtr; }
282 SkPaint* paint() { return fPaintPtr; }
283
284 void setPaint(const SkPaint& paint) { fPaint = paint; fPaintPtr = &fPaint; }
285
halcanary96fcdcc2015-08-27 07:41:13 -0700286 const SkRect* srcRect() const { return fSrc.isEmpty() ? nullptr : &fSrc; }
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000287 void setSrcRect(const SkRect& src) { fSrc = src; }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000288
289 const SkRect& dstRect() const { return fDst; }
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000290 void setDstRect(const SkRect& dst) { fDst = dst; }
291
reeda5517e22015-07-14 10:54:12 -0700292 SkCanvas::SrcRectConstraint constraint() const { return fConstraint; }
293 void setConstraint(SkCanvas::SrcRectConstraint constraint) { fConstraint = constraint; }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000294
chudy@google.com902ebe52012-06-29 14:21:22 +0000295private:
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000296 SkBitmap fBitmap;
297 SkRect fSrc;
298 SkRect fDst;
299 SkPaint fPaint;
300 SkPaint* fPaintPtr;
reeda5517e22015-07-14 10:54:12 -0700301 SkCanvas::SrcRectConstraint fConstraint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000302
303 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000304};
305
fmalita651c9202015-07-22 10:23:01 -0700306class SkDrawImageCommand : public SkDrawCommand {
307public:
308 SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint);
309 void execute(SkCanvas* canvas) const override;
310 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800311 Json::Value toJSON() const override;
312 static SkDrawImageCommand* fromJSON(Json::Value& command);
313
fmalita651c9202015-07-22 10:23:01 -0700314private:
315 SkAutoTUnref<const SkImage> fImage;
316 SkScalar fLeft;
317 SkScalar fTop;
318 SkTLazy<SkPaint> fPaint;
319
320 typedef SkDrawCommand INHERITED;
321};
322
323class SkDrawImageRectCommand : public SkDrawCommand {
324public:
325 SkDrawImageRectCommand(const SkImage* image, const SkRect* src, const SkRect& dst,
326 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint);
327 void execute(SkCanvas* canvas) const override;
328 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800329 Json::Value toJSON() const override;
330 static SkDrawImageRectCommand* fromJSON(Json::Value& command);
331
fmalita651c9202015-07-22 10:23:01 -0700332private:
333 SkAutoTUnref<const SkImage> fImage;
334 SkTLazy<SkRect> fSrc;
335 SkRect fDst;
336 SkTLazy<SkPaint> fPaint;
337 SkCanvas::SrcRectConstraint fConstraint;
338
339 typedef SkDrawCommand INHERITED;
340};
341
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000342class SkDrawOvalCommand : public SkDrawCommand {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000343public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000344 SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700345 void execute(SkCanvas* canvas) const override;
346 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800347 Json::Value toJSON() const override;
348 static SkDrawOvalCommand* fromJSON(Json::Value& command);
349
robertphillips@google.com67baba42013-01-02 20:20:31 +0000350private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000351 SkRect fOval;
352 SkPaint fPaint;
353
354 typedef SkDrawCommand INHERITED;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000355};
356
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000357class SkDrawPaintCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000358public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000359 SkDrawPaintCommand(const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700360 void execute(SkCanvas* canvas) const override;
361 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800362 Json::Value toJSON() const override;
363 static SkDrawPaintCommand* fromJSON(Json::Value& command);
364
chudy@google.com902ebe52012-06-29 14:21:22 +0000365private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000366 SkPaint fPaint;
367
368 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000369};
370
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000371class SkDrawPathCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000372public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000373 SkDrawPathCommand(const SkPath& path, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700374 void execute(SkCanvas* canvas) const override;
375 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800376 Json::Value toJSON() const override;
377 static SkDrawPathCommand* fromJSON(Json::Value& command);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000378
chudy@google.com902ebe52012-06-29 14:21:22 +0000379private:
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000380 SkPath fPath;
381 SkPaint fPaint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000382
383 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000384};
385
fmalita160ebb22015-04-01 20:58:37 -0700386class SkBeginDrawPictureCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000387public:
fmalita160ebb22015-04-01 20:58:37 -0700388 SkBeginDrawPictureCommand(const SkPicture* picture,
389 const SkMatrix* matrix,
390 const SkPaint* paint);
391
mtklein36352bf2015-03-25 18:17:31 -0700392 void execute(SkCanvas* canvas) const override;
393 bool render(SkCanvas* canvas) const override;
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000394
chudy@google.com902ebe52012-06-29 14:21:22 +0000395private:
robertphillips9b14f262014-06-04 05:40:44 -0700396 SkAutoTUnref<const SkPicture> fPicture;
fmalita160ebb22015-04-01 20:58:37 -0700397 SkTLazy<SkMatrix> fMatrix;
398 SkTLazy<SkPaint> fPaint;
399
400 typedef SkDrawCommand INHERITED;
401};
402
403class SkEndDrawPictureCommand : public SkDrawCommand {
404public:
405 SkEndDrawPictureCommand(bool restore);
406
407 void execute(SkCanvas* canvas) const override;
408
409private:
410 bool fRestore;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000411
412 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000413};
414
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000415class SkDrawPointsCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000416public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000417 SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000418 const SkPaint& paint);
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000419 virtual ~SkDrawPointsCommand() { delete [] fPts; }
mtklein36352bf2015-03-25 18:17:31 -0700420 void execute(SkCanvas* canvas) const override;
421 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800422 Json::Value toJSON() const override;
423 static SkDrawPointsCommand* fromJSON(Json::Value& command);
424
chudy@google.com902ebe52012-06-29 14:21:22 +0000425private:
chudy@google.com902ebe52012-06-29 14:21:22 +0000426 SkCanvas::PointMode fMode;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000427 size_t fCount;
428 SkPoint* fPts;
429 SkPaint fPaint;
430
431 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000432};
433
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000434class SkDrawTextCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000435public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000436 SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000437 const SkPaint& paint);
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000438 virtual ~SkDrawTextCommand() { delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700439 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800440 Json::Value toJSON() const override;
441 static SkDrawTextCommand* fromJSON(Json::Value& command);
442
chudy@google.com902ebe52012-06-29 14:21:22 +0000443private:
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000444 char* fText;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000445 size_t fByteLength;
chudy@google.com902ebe52012-06-29 14:21:22 +0000446 SkScalar fX;
447 SkScalar fY;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000448 SkPaint fPaint;
449
450 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000451};
452
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000453class SkDrawPosTextCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000454public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000455 SkDrawPosTextCommand(const void* text, size_t byteLength, const SkPoint pos[],
456 const SkPaint& paint);
457 virtual ~SkDrawPosTextCommand() { delete [] fPos; delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700458 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800459 Json::Value toJSON() const override;
460 static SkDrawPosTextCommand* fromJSON(Json::Value& command);
461
chudy@google.com902ebe52012-06-29 14:21:22 +0000462private:
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000463 char* fText;
464 size_t fByteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000465 SkPoint* fPos;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000466 SkPaint fPaint;
467
468 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000469};
470
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000471class SkDrawTextOnPathCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000472public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000473 SkDrawTextOnPathCommand(const void* text, size_t byteLength, const SkPath& path,
474 const SkMatrix* matrix, const SkPaint& paint);
475 virtual ~SkDrawTextOnPathCommand() { delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700476 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800477 Json::Value toJSON() const override;
478 static SkDrawTextOnPathCommand* fromJSON(Json::Value& command);
479
chudy@google.com902ebe52012-06-29 14:21:22 +0000480private:
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000481 char* fText;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000482 size_t fByteLength;
483 SkPath fPath;
484 SkMatrix fMatrix;
485 SkPaint fPaint;
486
487 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000488};
489
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000490class SkDrawPosTextHCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000491public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000492 SkDrawPosTextHCommand(const void* text, size_t byteLength, const SkScalar xpos[],
493 SkScalar constY, const SkPaint& paint);
494 virtual ~SkDrawPosTextHCommand() { delete [] fXpos; delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700495 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800496
chudy@google.com902ebe52012-06-29 14:21:22 +0000497private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000498 SkScalar* fXpos;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000499 char* fText;
500 size_t fByteLength;
501 SkScalar fConstY;
502 SkPaint fPaint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000503
504 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000505};
506
fmalitab7425172014-08-26 07:56:44 -0700507class SkDrawTextBlobCommand : public SkDrawCommand {
508public:
509 SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
510
mtklein36352bf2015-03-25 18:17:31 -0700511 void execute(SkCanvas* canvas) const override;
512 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800513 Json::Value toJSON() const override;
514 static SkDrawTextBlobCommand* fromJSON(Json::Value& command);
fmalitab7425172014-08-26 07:56:44 -0700515
516private:
517 SkAutoTUnref<const SkTextBlob> fBlob;
518 SkScalar fXPos;
519 SkScalar fYPos;
520 SkPaint fPaint;
521
522 typedef SkDrawCommand INHERITED;
523};
524
robertphillips9bafc302015-02-13 11:13:00 -0800525class SkDrawPatchCommand : public SkDrawCommand {
526public:
527 SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
528 const SkPoint texCoords[4], SkXfermode* xmode,
529 const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700530 void execute(SkCanvas* canvas) const override;
ethannicholas1446a9a2016-02-10 14:05:02 -0800531 Json::Value toJSON() const override;
532 static SkDrawPatchCommand* fromJSON(Json::Value& command);
robertphillips9bafc302015-02-13 11:13:00 -0800533
534private:
535 SkPoint fCubics[12];
ethannicholas1446a9a2016-02-10 14:05:02 -0800536 SkColor* fColorsPtr;
537 SkColor fColors[4];
538 SkPoint* fTexCoordsPtr;
539 SkPoint fTexCoords[4];
robertphillips9bafc302015-02-13 11:13:00 -0800540 SkAutoTUnref<SkXfermode> fXfermode;
541 SkPaint fPaint;
542
543 typedef SkDrawCommand INHERITED;
544};
545
546
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000547class SkDrawRectCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000548public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000549 SkDrawRectCommand(const SkRect& rect, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700550 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800551 Json::Value toJSON() const override;
552 static SkDrawRectCommand* fromJSON(Json::Value& command);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000553
robertphillips@google.com91217d02013-03-17 18:33:46 +0000554 const SkRect& rect() const { return fRect; }
555 const SkPaint& paint() const { return fPaint; }
chudy@google.com902ebe52012-06-29 14:21:22 +0000556private:
robertphillips@google.com91217d02013-03-17 18:33:46 +0000557 SkRect fRect;
558 SkPaint fPaint;
559
560 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000561};
562
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000563class SkDrawRRectCommand : public SkDrawCommand {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000564public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000565 SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700566 void execute(SkCanvas* canvas) const override;
567 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800568 Json::Value toJSON() const override;
569 static SkDrawRRectCommand* fromJSON(Json::Value& command);
570
robertphillips@google.com67baba42013-01-02 20:20:31 +0000571private:
572 SkRRect fRRect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000573 SkPaint fPaint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000574
575 typedef SkDrawCommand INHERITED;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000576};
577
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000578class SkDrawDRRectCommand : public SkDrawCommand {
579public:
580 SkDrawDRRectCommand(const SkRRect& outer, const SkRRect& inner,
581 const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700582 void execute(SkCanvas* canvas) const override;
583 bool render(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800584 Json::Value toJSON() const override;
585 static SkDrawDRRectCommand* fromJSON(Json::Value& command);
586
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000587private:
588 SkRRect fOuter;
589 SkRRect fInner;
590 SkPaint fPaint;
591
592 typedef SkDrawCommand INHERITED;
593};
594
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000595class SkDrawVerticesCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000596public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000597 SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
598 const SkPoint vertices[], const SkPoint texs[],
599 const SkColor colors[], SkXfermode* xfermode,
600 const uint16_t indices[], int indexCount,
601 const SkPaint& paint);
602 virtual ~SkDrawVerticesCommand();
mtklein36352bf2015-03-25 18:17:31 -0700603 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800604
chudy@google.com902ebe52012-06-29 14:21:22 +0000605private:
606 SkCanvas::VertexMode fVmode;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000607 int fVertexCount;
608 SkPoint* fVertices;
609 SkPoint* fTexs;
610 SkColor* fColors;
chudy@google.com902ebe52012-06-29 14:21:22 +0000611 SkXfermode* fXfermode;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000612 uint16_t* fIndices;
613 int fIndexCount;
614 SkPaint fPaint;
615
616 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000617};
618
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000619class SkSaveCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000620public:
Florin Malita5f6102d2014-06-30 10:13:28 -0400621 SkSaveCommand();
mtklein36352bf2015-03-25 18:17:31 -0700622 void execute(SkCanvas* canvas) const override;
623 Action action() const override { return kPushLayer_Action; }
ethannicholas50a8dd02016-02-10 05:40:46 -0800624 static SkSaveCommand* fromJSON(Json::Value& command);
625
chudy@google.com902ebe52012-06-29 14:21:22 +0000626private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000627 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000628};
629
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000630class SkSaveLayerCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000631public:
reed4960eee2015-12-18 07:09:18 -0800632 SkSaveLayerCommand(const SkCanvas::SaveLayerRec&);
ethannicholas50a8dd02016-02-10 05:40:46 -0800633 virtual ~SkSaveLayerCommand();
mtklein36352bf2015-03-25 18:17:31 -0700634 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800635 Json::Value toJSON() const override;
636 static SkSaveLayerCommand* fromJSON(Json::Value& command);
mtklein36352bf2015-03-25 18:17:31 -0700637 void vizExecute(SkCanvas* canvas) const override;
638 Action action() const override{ return kPushLayer_Action; }
639 void setActive(bool active) override { fActive = active; }
640 bool active() const override { return fActive; }
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000641
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000642 const SkPaint* paint() const { return fPaintPtr; }
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000643
chudy@google.com902ebe52012-06-29 14:21:22 +0000644private:
ethannicholas50a8dd02016-02-10 05:40:46 -0800645 SkRect fBounds;
646 SkPaint fPaint;
647 SkPaint* fPaintPtr;
648 const SkImageFilter* fBackdrop;
649 uint32_t fSaveLayerFlags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000650
reed4960eee2015-12-18 07:09:18 -0800651 bool fActive;
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000652
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000653 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000654};
655
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000656class SkSetMatrixCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000657public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000658 SkSetMatrixCommand(const SkMatrix& matrix);
mtklein36352bf2015-03-25 18:17:31 -0700659 void setUserMatrix(const SkMatrix&) override;
660 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800661 Json::Value toJSON() const override;
662 static SkSetMatrixCommand* fromJSON(Json::Value& command);
663
chudy@google.com902ebe52012-06-29 14:21:22 +0000664private:
robertphillips70171682014-10-16 14:28:28 -0700665 SkMatrix fUserMatrix;
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000666 SkMatrix fMatrix;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000667
668 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000669};
670
chudy@google.com902ebe52012-06-29 14:21:22 +0000671#endif