blob: 0a365c04b50105cf658fadc4ebd80c828708aee1 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKDRAWCOMMAND_H_
9#define SKDRAWCOMMAND_H_
10
chudy@google.com902ebe52012-06-29 14:21:22 +000011#include "SkCanvas.h"
bungemand3ebb482015-08-05 13:57:49 -070012#include "SkTLazy.h"
13#include "SkPath.h"
14#include "SkRRect.h"
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000015#include "SkString.h"
bungemand3ebb482015-08-05 13:57:49 -070016#include "SkTDArray.h"
ethannicholas50a8dd02016-02-10 05:40:46 -080017#include "SkJSONCPP.h"
ethannicholasf62a8b72016-02-11 10:35:21 -080018#include "UrlDataManager.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
ethannicholasf62a8b72016-02-11 10:35:21 -0800103 virtual Json::Value toJSON(UrlDataManager& urlDataManager) const;
ethannicholas50a8dd02016-02-10 05:40:46 -0800104
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 */
ethannicholasf62a8b72016-02-11 10:35:21 -0800109 static SkDrawCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800110
robertphillips9bafc302015-02-13 11:13:00 -0800111 static const char* GetCommandString(OpType type);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000112
joshualittbd724132016-03-03 11:39:38 -0800113 // Helper methods for converting things to JSON
114 static Json::Value MakeJsonIRect(const SkIRect&);
115 static Json::Value MakeJsonMatrix(const SkMatrix&);
116
chudy@google.com902ebe52012-06-29 14:21:22 +0000117protected:
chudy@google.com97cee972012-08-07 20:41:37 +0000118 SkTDArray<SkString*> fInfo;
chudy@google.com902ebe52012-06-29 14:21:22 +0000119
120private:
robertphillips9bafc302015-02-13 11:13:00 -0800121 OpType fOpType;
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000122 bool fVisible;
chudy@google.com902ebe52012-06-29 14:21:22 +0000123};
124
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000125class SkRestoreCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000126public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000127 SkRestoreCommand();
mtklein36352bf2015-03-25 18:17:31 -0700128 void execute(SkCanvas* canvas) const override;
129 Action action() const override { return kPopLayer_Action; }
ethannicholasf62a8b72016-02-11 10:35:21 -0800130 static SkRestoreCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000131
132private:
133 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000134};
135
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000136class SkClearCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000137public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000138 SkClearCommand(SkColor color);
mtklein36352bf2015-03-25 18:17:31 -0700139 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800140 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
141 static SkClearCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800142
chudy@google.com902ebe52012-06-29 14:21:22 +0000143private:
144 SkColor fColor;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000145
146 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000147};
148
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000149class SkClipPathCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000150public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000151 SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA);
mtklein36352bf2015-03-25 18:17:31 -0700152 void execute(SkCanvas* canvas) const override;
153 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800154 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
155 static SkClipPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800156
chudy@google.com902ebe52012-06-29 14:21:22 +0000157private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000158 SkPath fPath;
chudy@google.com902ebe52012-06-29 14:21:22 +0000159 SkRegion::Op fOp;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000160 bool fDoAA;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000161
162 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000163};
164
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000165class SkClipRegionCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000166public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000167 SkClipRegionCommand(const SkRegion& region, SkRegion::Op op);
mtklein36352bf2015-03-25 18:17:31 -0700168 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800169 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
170 static SkClipRegionCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800171
chudy@google.com902ebe52012-06-29 14:21:22 +0000172private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000173 SkRegion fRegion;
chudy@google.com902ebe52012-06-29 14:21:22 +0000174 SkRegion::Op fOp;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000175
176 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000177};
178
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000179class SkClipRectCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000180public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000181 SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA);
mtklein36352bf2015-03-25 18:17:31 -0700182 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800183 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
184 static SkClipRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000185
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000186 const SkRect& rect() const { return fRect; }
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000187 SkRegion::Op op() const { return fOp; }
188 bool doAA() const { return fDoAA; }
189
chudy@google.com902ebe52012-06-29 14:21:22 +0000190private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000191 SkRect fRect;
chudy@google.com902ebe52012-06-29 14:21:22 +0000192 SkRegion::Op fOp;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000193 bool fDoAA;
194
195 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000196};
197
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000198class SkClipRRectCommand : public SkDrawCommand {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000199public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000200 SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA);
mtklein36352bf2015-03-25 18:17:31 -0700201 void execute(SkCanvas* canvas) const override;
202 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800203 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
204 static SkClipRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000205
206 const SkRRect& rrect() const { return fRRect; }
207 SkRegion::Op op() const { return fOp; }
208 bool doAA() const { return fDoAA; }
209
robertphillips@google.com67baba42013-01-02 20:20:31 +0000210private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000211 SkRRect fRRect;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000212 SkRegion::Op fOp;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000213 bool fDoAA;
214
215 typedef SkDrawCommand INHERITED;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000216};
217
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000218class SkConcatCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000219public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000220 SkConcatCommand(const SkMatrix& matrix);
mtklein36352bf2015-03-25 18:17:31 -0700221 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800222 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
223 static SkConcatCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800224
chudy@google.com902ebe52012-06-29 14:21:22 +0000225private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000226 SkMatrix fMatrix;
227
228 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000229};
230
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000231class SkDrawBitmapCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000232public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000233 SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000234 const SkPaint* paint);
mtklein36352bf2015-03-25 18:17:31 -0700235 void execute(SkCanvas* canvas) const override;
236 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800237 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
238 static SkDrawBitmapCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800239
chudy@google.com902ebe52012-06-29 14:21:22 +0000240private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000241 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000242 SkScalar fLeft;
243 SkScalar fTop;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000244 SkPaint fPaint;
245 SkPaint* fPaintPtr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000246
247 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000248};
249
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000250class SkDrawBitmapNineCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000251public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000252 SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000253 const SkRect& dst, const SkPaint* paint);
mtklein36352bf2015-03-25 18:17:31 -0700254 void execute(SkCanvas* canvas) const override;
255 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800256 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
257 static SkDrawBitmapNineCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800258
chudy@google.com902ebe52012-06-29 14:21:22 +0000259private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000260 SkBitmap fBitmap;
261 SkIRect fCenter;
262 SkRect fDst;
263 SkPaint fPaint;
264 SkPaint* fPaintPtr;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000265
266 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000267};
268
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000269class SkDrawBitmapRectCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000270public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000271 SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000272 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -0700273 SkCanvas::SrcRectConstraint);
mtklein36352bf2015-03-25 18:17:31 -0700274 void execute(SkCanvas* canvas) const override;
275 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800276 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
277 static SkDrawBitmapRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000278
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000279 const SkBitmap& bitmap() const { return fBitmap; }
280
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000281 // The non-const 'paint' method allows modification of this object's
282 // SkPaint. For this reason the ctor and setPaint method make a local copy.
283 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid
284 // (since only an SkPaint* is passed into the ctor).
285 const SkPaint* paint() const { return fPaintPtr; }
286 SkPaint* paint() { return fPaintPtr; }
287
288 void setPaint(const SkPaint& paint) { fPaint = paint; fPaintPtr = &fPaint; }
289
halcanary96fcdcc2015-08-27 07:41:13 -0700290 const SkRect* srcRect() const { return fSrc.isEmpty() ? nullptr : &fSrc; }
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000291 void setSrcRect(const SkRect& src) { fSrc = src; }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000292
293 const SkRect& dstRect() const { return fDst; }
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000294 void setDstRect(const SkRect& dst) { fDst = dst; }
295
reeda5517e22015-07-14 10:54:12 -0700296 SkCanvas::SrcRectConstraint constraint() const { return fConstraint; }
297 void setConstraint(SkCanvas::SrcRectConstraint constraint) { fConstraint = constraint; }
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000298
chudy@google.com902ebe52012-06-29 14:21:22 +0000299private:
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000300 SkBitmap fBitmap;
301 SkRect fSrc;
302 SkRect fDst;
303 SkPaint fPaint;
304 SkPaint* fPaintPtr;
reeda5517e22015-07-14 10:54:12 -0700305 SkCanvas::SrcRectConstraint fConstraint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000306
307 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000308};
309
fmalita651c9202015-07-22 10:23:01 -0700310class SkDrawImageCommand : public SkDrawCommand {
311public:
312 SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint);
313 void execute(SkCanvas* canvas) const override;
314 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800315 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
316 static SkDrawImageCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800317
fmalita651c9202015-07-22 10:23:01 -0700318private:
319 SkAutoTUnref<const SkImage> fImage;
320 SkScalar fLeft;
321 SkScalar fTop;
322 SkTLazy<SkPaint> fPaint;
323
324 typedef SkDrawCommand INHERITED;
325};
326
327class SkDrawImageRectCommand : public SkDrawCommand {
328public:
329 SkDrawImageRectCommand(const SkImage* image, const SkRect* src, const SkRect& dst,
330 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint);
331 void execute(SkCanvas* canvas) const override;
332 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800333 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
334 static SkDrawImageRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800335
fmalita651c9202015-07-22 10:23:01 -0700336private:
337 SkAutoTUnref<const SkImage> fImage;
338 SkTLazy<SkRect> fSrc;
339 SkRect fDst;
340 SkTLazy<SkPaint> fPaint;
341 SkCanvas::SrcRectConstraint fConstraint;
342
343 typedef SkDrawCommand INHERITED;
344};
345
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000346class SkDrawOvalCommand : public SkDrawCommand {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000347public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000348 SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700349 void execute(SkCanvas* canvas) const override;
350 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800351 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
352 static SkDrawOvalCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800353
robertphillips@google.com67baba42013-01-02 20:20:31 +0000354private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000355 SkRect fOval;
356 SkPaint fPaint;
357
358 typedef SkDrawCommand INHERITED;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000359};
360
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000361class SkDrawPaintCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000362public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000363 SkDrawPaintCommand(const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700364 void execute(SkCanvas* canvas) const override;
365 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800366 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
367 static SkDrawPaintCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800368
chudy@google.com902ebe52012-06-29 14:21:22 +0000369private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000370 SkPaint fPaint;
371
372 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000373};
374
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000375class SkDrawPathCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000376public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000377 SkDrawPathCommand(const SkPath& path, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700378 void execute(SkCanvas* canvas) const override;
379 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800380 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
381 static SkDrawPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000382
chudy@google.com902ebe52012-06-29 14:21:22 +0000383private:
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000384 SkPath fPath;
385 SkPaint fPaint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000386
387 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000388};
389
fmalita160ebb22015-04-01 20:58:37 -0700390class SkBeginDrawPictureCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000391public:
fmalita160ebb22015-04-01 20:58:37 -0700392 SkBeginDrawPictureCommand(const SkPicture* picture,
393 const SkMatrix* matrix,
394 const SkPaint* paint);
395
mtklein36352bf2015-03-25 18:17:31 -0700396 void execute(SkCanvas* canvas) const override;
397 bool render(SkCanvas* canvas) const override;
commit-bot@chromium.orge898e9c2013-11-21 17:08:12 +0000398
chudy@google.com902ebe52012-06-29 14:21:22 +0000399private:
robertphillips9b14f262014-06-04 05:40:44 -0700400 SkAutoTUnref<const SkPicture> fPicture;
fmalita160ebb22015-04-01 20:58:37 -0700401 SkTLazy<SkMatrix> fMatrix;
402 SkTLazy<SkPaint> fPaint;
403
404 typedef SkDrawCommand INHERITED;
405};
406
407class SkEndDrawPictureCommand : public SkDrawCommand {
408public:
409 SkEndDrawPictureCommand(bool restore);
410
411 void execute(SkCanvas* canvas) const override;
412
413private:
414 bool fRestore;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000415
416 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000417};
418
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000419class SkDrawPointsCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000420public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000421 SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000422 const SkPaint& paint);
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000423 virtual ~SkDrawPointsCommand() { delete [] fPts; }
mtklein36352bf2015-03-25 18:17:31 -0700424 void execute(SkCanvas* canvas) const override;
425 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800426 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
427 static SkDrawPointsCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800428
chudy@google.com902ebe52012-06-29 14:21:22 +0000429private:
chudy@google.com902ebe52012-06-29 14:21:22 +0000430 SkCanvas::PointMode fMode;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000431 size_t fCount;
432 SkPoint* fPts;
433 SkPaint fPaint;
434
435 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000436};
437
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000438class SkDrawTextCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000439public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000440 SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000441 const SkPaint& paint);
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000442 virtual ~SkDrawTextCommand() { delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700443 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800444 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
445 static SkDrawTextCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800446
chudy@google.com902ebe52012-06-29 14:21:22 +0000447private:
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000448 char* fText;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000449 size_t fByteLength;
chudy@google.com902ebe52012-06-29 14:21:22 +0000450 SkScalar fX;
451 SkScalar fY;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000452 SkPaint fPaint;
453
454 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000455};
456
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000457class SkDrawPosTextCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000458public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000459 SkDrawPosTextCommand(const void* text, size_t byteLength, const SkPoint pos[],
460 const SkPaint& paint);
461 virtual ~SkDrawPosTextCommand() { delete [] fPos; delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700462 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800463 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
464 static SkDrawPosTextCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800465
chudy@google.com902ebe52012-06-29 14:21:22 +0000466private:
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000467 char* fText;
468 size_t fByteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000469 SkPoint* fPos;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000470 SkPaint fPaint;
471
472 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000473};
474
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000475class SkDrawTextOnPathCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000476public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000477 SkDrawTextOnPathCommand(const void* text, size_t byteLength, const SkPath& path,
478 const SkMatrix* matrix, const SkPaint& paint);
479 virtual ~SkDrawTextOnPathCommand() { delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700480 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800481 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
482 static SkDrawTextOnPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800483
chudy@google.com902ebe52012-06-29 14:21:22 +0000484private:
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000485 char* fText;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000486 size_t fByteLength;
487 SkPath fPath;
488 SkMatrix fMatrix;
489 SkPaint fPaint;
490
491 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000492};
493
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000494class SkDrawPosTextHCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000495public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000496 SkDrawPosTextHCommand(const void* text, size_t byteLength, const SkScalar xpos[],
497 SkScalar constY, const SkPaint& paint);
498 virtual ~SkDrawPosTextHCommand() { delete [] fXpos; delete [] fText; }
mtklein36352bf2015-03-25 18:17:31 -0700499 void execute(SkCanvas* canvas) const override;
bungeman51190df2016-03-09 07:42:54 -0800500 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
501 static SkDrawPosTextHCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800502
chudy@google.com902ebe52012-06-29 14:21:22 +0000503private:
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000504 SkScalar* fXpos;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000505 char* fText;
506 size_t fByteLength;
507 SkScalar fConstY;
508 SkPaint fPaint;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000509
510 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000511};
512
fmalitab7425172014-08-26 07:56:44 -0700513class SkDrawTextBlobCommand : public SkDrawCommand {
514public:
515 SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
516
mtklein36352bf2015-03-25 18:17:31 -0700517 void execute(SkCanvas* canvas) const override;
518 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800519 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
520 static SkDrawTextBlobCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
fmalitab7425172014-08-26 07:56:44 -0700521
522private:
523 SkAutoTUnref<const SkTextBlob> fBlob;
524 SkScalar fXPos;
525 SkScalar fYPos;
526 SkPaint fPaint;
527
528 typedef SkDrawCommand INHERITED;
529};
530
robertphillips9bafc302015-02-13 11:13:00 -0800531class SkDrawPatchCommand : public SkDrawCommand {
532public:
533 SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
534 const SkPoint texCoords[4], SkXfermode* xmode,
535 const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700536 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800537 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
538 static SkDrawPatchCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
robertphillips9bafc302015-02-13 11:13:00 -0800539
540private:
541 SkPoint fCubics[12];
ethannicholas1446a9a2016-02-10 14:05:02 -0800542 SkColor* fColorsPtr;
543 SkColor fColors[4];
544 SkPoint* fTexCoordsPtr;
545 SkPoint fTexCoords[4];
robertphillips9bafc302015-02-13 11:13:00 -0800546 SkAutoTUnref<SkXfermode> fXfermode;
547 SkPaint fPaint;
548
549 typedef SkDrawCommand INHERITED;
550};
551
552
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000553class SkDrawRectCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000554public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000555 SkDrawRectCommand(const SkRect& rect, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700556 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800557 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
558 static SkDrawRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000559
robertphillips@google.com91217d02013-03-17 18:33:46 +0000560 const SkRect& rect() const { return fRect; }
561 const SkPaint& paint() const { return fPaint; }
chudy@google.com902ebe52012-06-29 14:21:22 +0000562private:
robertphillips@google.com91217d02013-03-17 18:33:46 +0000563 SkRect fRect;
564 SkPaint fPaint;
565
566 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000567};
568
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000569class SkDrawRRectCommand : public SkDrawCommand {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000570public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000571 SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700572 void execute(SkCanvas* canvas) const override;
573 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800574 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
575 static SkDrawRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800576
robertphillips@google.com67baba42013-01-02 20:20:31 +0000577private:
578 SkRRect fRRect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000579 SkPaint fPaint;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000580
581 typedef SkDrawCommand INHERITED;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000582};
583
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000584class SkDrawDRRectCommand : public SkDrawCommand {
585public:
586 SkDrawDRRectCommand(const SkRRect& outer, const SkRRect& inner,
587 const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -0700588 void execute(SkCanvas* canvas) const override;
589 bool render(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800590 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
591 static SkDrawDRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800592
commit-bot@chromium.org3d305202014-02-24 17:28:55 +0000593private:
594 SkRRect fOuter;
595 SkRRect fInner;
596 SkPaint fPaint;
597
598 typedef SkDrawCommand INHERITED;
599};
600
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000601class SkDrawVerticesCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000602public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000603 SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
604 const SkPoint vertices[], const SkPoint texs[],
605 const SkColor colors[], SkXfermode* xfermode,
606 const uint16_t indices[], int indexCount,
607 const SkPaint& paint);
608 virtual ~SkDrawVerticesCommand();
mtklein36352bf2015-03-25 18:17:31 -0700609 void execute(SkCanvas* canvas) const override;
ethannicholas50a8dd02016-02-10 05:40:46 -0800610
chudy@google.com902ebe52012-06-29 14:21:22 +0000611private:
612 SkCanvas::VertexMode fVmode;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000613 int fVertexCount;
614 SkPoint* fVertices;
615 SkPoint* fTexs;
616 SkColor* fColors;
chudy@google.com902ebe52012-06-29 14:21:22 +0000617 SkXfermode* fXfermode;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000618 uint16_t* fIndices;
619 int fIndexCount;
620 SkPaint fPaint;
621
622 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000623};
624
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000625class SkSaveCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000626public:
Florin Malita5f6102d2014-06-30 10:13:28 -0400627 SkSaveCommand();
mtklein36352bf2015-03-25 18:17:31 -0700628 void execute(SkCanvas* canvas) const override;
629 Action action() const override { return kPushLayer_Action; }
ethannicholasf62a8b72016-02-11 10:35:21 -0800630 static SkSaveCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800631
chudy@google.com902ebe52012-06-29 14:21:22 +0000632private:
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000633 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000634};
635
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000636class SkSaveLayerCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000637public:
reed4960eee2015-12-18 07:09:18 -0800638 SkSaveLayerCommand(const SkCanvas::SaveLayerRec&);
ethannicholas50a8dd02016-02-10 05:40:46 -0800639 virtual ~SkSaveLayerCommand();
mtklein36352bf2015-03-25 18:17:31 -0700640 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800641 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
642 static SkSaveLayerCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
mtklein36352bf2015-03-25 18:17:31 -0700643 void vizExecute(SkCanvas* canvas) const override;
644 Action action() const override{ return kPushLayer_Action; }
645 void setActive(bool active) override { fActive = active; }
646 bool active() const override { return fActive; }
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000647
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000648 const SkPaint* paint() const { return fPaintPtr; }
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000649
chudy@google.com902ebe52012-06-29 14:21:22 +0000650private:
ethannicholas50a8dd02016-02-10 05:40:46 -0800651 SkRect fBounds;
652 SkPaint fPaint;
653 SkPaint* fPaintPtr;
654 const SkImageFilter* fBackdrop;
655 uint32_t fSaveLayerFlags;
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000656
reed4960eee2015-12-18 07:09:18 -0800657 bool fActive;
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000658
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000659 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000660};
661
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000662class SkSetMatrixCommand : public SkDrawCommand {
chudy@google.com902ebe52012-06-29 14:21:22 +0000663public:
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000664 SkSetMatrixCommand(const SkMatrix& matrix);
mtklein36352bf2015-03-25 18:17:31 -0700665 void setUserMatrix(const SkMatrix&) override;
666 void execute(SkCanvas* canvas) const override;
ethannicholasf62a8b72016-02-11 10:35:21 -0800667 Json::Value toJSON(UrlDataManager& urlDataManager) const override;
668 static SkSetMatrixCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
ethannicholas50a8dd02016-02-10 05:40:46 -0800669
chudy@google.com902ebe52012-06-29 14:21:22 +0000670private:
robertphillips70171682014-10-16 14:28:28 -0700671 SkMatrix fUserMatrix;
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000672 SkMatrix fMatrix;
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000673
674 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000675};
676
chudy@google.com902ebe52012-06-29 14:21:22 +0000677#endif