• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
11 #include "SkBitmap.h"
12 #include "SkCanvas.h"
13 #include "SkFlattenable.h"
14 #include "SkTLazy.h"
15 #include "SkPath.h"
16 #include "SkRegion.h"
17 #include "SkRRect.h"
18 #include "SkRSXform.h"
19 #include "SkString.h"
20 #include "SkTDArray.h"
21 #include "SkVertices.h"
22 #include "SkJSONCPP.h"
23 #include "UrlDataManager.h"
24 
25 class SkDrawCommand {
26 public:
27     enum OpType {
28         kBeginDrawPicture_OpType,
29         kClipPath_OpType,
30         kClipRegion_OpType,
31         kClipRect_OpType,
32         kClipRRect_OpType,
33         kConcat_OpType,
34         kDrawAnnotation_OpType,
35         kDrawBitmap_OpType,
36         kDrawBitmapNine_OpType,
37         kDrawBitmapRect_OpType,
38         kDrawClear_OpType,
39         kDrawDRRect_OpType,
40         kDrawImage_OpType,
41         kDrawImageLattice_OpType,
42         kDrawImageRect_OpType,
43         kDrawOval_OpType,
44         kDrawPaint_OpType,
45         kDrawPatch_OpType,
46         kDrawPath_OpType,
47         kDrawPoints_OpType,
48         kDrawPosText_OpType,
49         kDrawPosTextH_OpType,
50         kDrawRect_OpType,
51         kDrawRRect_OpType,
52         kDrawText_OpType,
53         kDrawTextBlob_OpType,
54         kDrawTextOnPath_OpType,
55         kDrawTextRSXform_OpType,
56         kDrawVertices_OpType,
57         kEndDrawPicture_OpType,
58         kRestore_OpType,
59         kSave_OpType,
60         kSaveLayer_OpType,
61         kSetMatrix_OpType,
62 
63         kLast_OpType = kSetMatrix_OpType
64     };
65 
66     static const int kOpTypeCount = kLast_OpType + 1;
67 
68     static void WritePNG(const uint8_t* rgba, unsigned width, unsigned height,
69                          SkWStream& out, bool isOpaque);
70 
71     SkDrawCommand(OpType opType);
72 
73     virtual ~SkDrawCommand();
74 
75     virtual SkString toString() const;
76 
toCString()77     virtual const char* toCString() const {
78         return GetCommandString(fOpType);
79     }
80 
isVisible()81     bool isVisible() const {
82         return fVisible;
83     }
84 
setVisible(bool toggle)85     void setVisible(bool toggle) {
86         fVisible = toggle;
87     }
88 
Info()89     const SkTDArray<SkString*>* Info() const { return &fInfo; }
90     virtual void execute(SkCanvas*) const = 0;
vizExecute(SkCanvas *)91     virtual void vizExecute(SkCanvas*) const {}
92 
setUserMatrix(const SkMatrix &)93     virtual void setUserMatrix(const SkMatrix&) {}
94 
95     // The next "active" system is only used by save, saveLayer, and restore.
96     // It is used to determine which saveLayers are currently active (at a
97     // given point in the rendering).
98     //      saves just return a kPushLayer action but don't track active state
99     //      restores just return a kPopLayer action
100     //      saveLayers return kPushLayer but also track the active state
101     enum Action {
102         kNone_Action,
103         kPopLayer_Action,
104         kPushLayer_Action,
105     };
action()106     virtual Action action() const { return kNone_Action; }
setActive(bool active)107     virtual void setActive(bool active) {}
active()108     virtual bool active() const { return false; }
109 
getType()110     OpType getType() const { return fOpType; }
111 
render(SkCanvas * canvas)112     virtual bool render(SkCanvas* canvas) const { return false; }
113 
114     virtual Json::Value toJSON(UrlDataManager& urlDataManager) const;
115 
116     /* Converts a JSON representation of a command into a newly-allocated SkDrawCommand object. It
117      * is the caller's responsibility to delete this object. This method may return null if an error
118      * occurs.
119      */
120     static SkDrawCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
121 
122     static const char* GetCommandString(OpType type);
123 
124     // Helper methods for converting things to JSON
125     static Json::Value MakeJsonColor(const SkColor color);
126     static Json::Value MakeJsonColor4f(const SkColor4f& color);
127     static Json::Value MakeJsonPoint(const SkPoint& point);
128     static Json::Value MakeJsonPoint(SkScalar x, SkScalar y);
129     static Json::Value MakeJsonRect(const SkRect& rect);
130     static Json::Value MakeJsonIRect(const SkIRect&);
131     static Json::Value MakeJsonMatrix(const SkMatrix&);
132     static Json::Value MakeJsonScalar(SkScalar);
133     static Json::Value MakeJsonPath(const SkPath& path);
134     static Json::Value MakeJsonRegion(const SkRegion& region);
135     static Json::Value MakeJsonPaint(const SkPaint& paint, UrlDataManager& urlDataManager);
136     static Json::Value MakeJsonLattice(const SkCanvas::Lattice& lattice);
137 
138     static void flatten(const SkFlattenable* flattenable, Json::Value* target,
139                         UrlDataManager& urlDataManager);
140     static bool flatten(const SkImage& image, Json::Value* target,
141                         UrlDataManager& urlDataManager);
142     static bool flatten(const SkBitmap& bitmap, Json::Value* target,
143                         UrlDataManager& urlDataManager);
144 
145 protected:
146     SkTDArray<SkString*> fInfo;
147 
148 private:
149     OpType fOpType;
150     bool   fVisible;
151 };
152 
153 class SkRestoreCommand : public SkDrawCommand {
154 public:
155     SkRestoreCommand();
156     void execute(SkCanvas* canvas) const override;
action()157     Action action() const override { return kPopLayer_Action; }
158     static SkRestoreCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
159 
160 private:
161     typedef SkDrawCommand INHERITED;
162 };
163 
164 class SkClearCommand : public SkDrawCommand {
165 public:
166     SkClearCommand(SkColor color);
167     void execute(SkCanvas* canvas) const override;
168     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
169     static SkClearCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
170 
171 private:
172     SkColor fColor;
173 
174     typedef SkDrawCommand INHERITED;
175 };
176 
177 class SkClipPathCommand : public SkDrawCommand {
178 public:
179     SkClipPathCommand(const SkPath& path, SkClipOp op, bool doAA);
180     void execute(SkCanvas* canvas) const override;
181     bool render(SkCanvas* canvas) const override;
182     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
183     static SkClipPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
184 
185 private:
186     SkPath   fPath;
187     SkClipOp fOp;
188     bool     fDoAA;
189 
190     typedef SkDrawCommand INHERITED;
191 };
192 
193 class SkClipRegionCommand : public SkDrawCommand {
194 public:
195     SkClipRegionCommand(const SkRegion& region, SkClipOp op);
196     void execute(SkCanvas* canvas) const override;
197     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
198     static SkClipRegionCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
199 
200 private:
201     SkRegion fRegion;
202     SkClipOp fOp;
203 
204     typedef SkDrawCommand INHERITED;
205 };
206 
207 class SkClipRectCommand : public SkDrawCommand {
208 public:
209     SkClipRectCommand(const SkRect& rect, SkClipOp op, bool doAA);
210     void execute(SkCanvas* canvas) const override;
211     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
212     static SkClipRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
213 
rect()214     const SkRect& rect() const { return fRect; }
op()215     SkClipOp op() const { return fOp; }
doAA()216     bool doAA() const { return fDoAA; }
217 
218 private:
219     SkRect   fRect;
220     SkClipOp fOp;
221     bool     fDoAA;
222 
223     typedef SkDrawCommand INHERITED;
224 };
225 
226 class SkClipRRectCommand : public SkDrawCommand {
227 public:
228     SkClipRRectCommand(const SkRRect& rrect, SkClipOp op, bool doAA);
229     void execute(SkCanvas* canvas) const override;
230     bool render(SkCanvas* canvas) const override;
231     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
232     static SkClipRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
233 
rrect()234     const SkRRect& rrect() const { return fRRect; }
op()235     SkClipOp op() const { return fOp; }
doAA()236     bool doAA() const { return fDoAA; }
237 
238 private:
239     SkRRect  fRRect;
240     SkClipOp fOp;
241     bool     fDoAA;
242 
243     typedef SkDrawCommand INHERITED;
244 };
245 
246 class SkConcatCommand : public SkDrawCommand {
247 public:
248     SkConcatCommand(const SkMatrix& matrix);
249     void execute(SkCanvas* canvas) const override;
250     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
251     static SkConcatCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
252 
253 private:
254     SkMatrix fMatrix;
255 
256     typedef SkDrawCommand INHERITED;
257 };
258 
259 class SkDrawAnnotationCommand : public SkDrawCommand {
260 public:
261     SkDrawAnnotationCommand(const SkRect&, const char key[], sk_sp<SkData> value);
262     void execute(SkCanvas* canvas) const override;
263     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
264     static SkDrawAnnotationCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
265 
266 private:
267     SkRect          fRect;
268     SkString        fKey;
269     sk_sp<SkData>   fValue;
270 
271     typedef SkDrawCommand INHERITED;
272 };
273 
274 class SkDrawBitmapCommand : public SkDrawCommand {
275 public:
276     SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
277                         const SkPaint* paint);
278     void execute(SkCanvas* canvas) const override;
279     bool render(SkCanvas* canvas) const override;
280     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
281     static SkDrawBitmapCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
282 
283 private:
284     SkBitmap fBitmap;
285     SkScalar fLeft;
286     SkScalar fTop;
287     SkPaint  fPaint;
288     SkPaint* fPaintPtr;
289 
290     typedef SkDrawCommand INHERITED;
291 };
292 
293 class SkDrawBitmapNineCommand : public SkDrawCommand {
294 public:
295     SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
296                             const SkRect& dst, const SkPaint* paint);
297     void execute(SkCanvas* canvas) const override;
298     bool render(SkCanvas* canvas) const override;
299     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
300     static SkDrawBitmapNineCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
301 
302 private:
303     SkBitmap fBitmap;
304     SkIRect  fCenter;
305     SkRect   fDst;
306     SkPaint  fPaint;
307     SkPaint* fPaintPtr;
308 
309     typedef SkDrawCommand INHERITED;
310 };
311 
312 class SkDrawBitmapRectCommand : public SkDrawCommand {
313 public:
314     SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
315                             const SkRect& dst, const SkPaint* paint,
316                             SkCanvas::SrcRectConstraint);
317     void execute(SkCanvas* canvas) const override;
318     bool render(SkCanvas* canvas) const override;
319     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
320     static SkDrawBitmapRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
321 
bitmap()322     const SkBitmap& bitmap() const { return fBitmap; }
323 
324     // The non-const 'paint' method allows modification of this object's
325     // SkPaint. For this reason the ctor and setPaint method make a local copy.
326     // The 'fPaintPtr' member acts a signal that the local SkPaint is valid
327     // (since only an SkPaint* is passed into the ctor).
paint()328     const SkPaint* paint() const { return fPaintPtr; }
paint()329     SkPaint* paint() { return fPaintPtr; }
330 
setPaint(const SkPaint & paint)331     void setPaint(const SkPaint& paint) { fPaint = paint; fPaintPtr = &fPaint; }
332 
srcRect()333     const SkRect* srcRect() const { return fSrc.isEmpty() ? nullptr : &fSrc; }
setSrcRect(const SkRect & src)334     void setSrcRect(const SkRect& src) { fSrc = src; }
335 
dstRect()336     const SkRect& dstRect() const { return fDst; }
setDstRect(const SkRect & dst)337     void setDstRect(const SkRect& dst) { fDst = dst; }
338 
constraint()339     SkCanvas::SrcRectConstraint constraint() const { return fConstraint; }
setConstraint(SkCanvas::SrcRectConstraint constraint)340     void setConstraint(SkCanvas::SrcRectConstraint constraint) { fConstraint = constraint; }
341 
342 private:
343     SkBitmap                      fBitmap;
344     SkRect                        fSrc;
345     SkRect                        fDst;
346     SkPaint                       fPaint;
347     SkPaint*                      fPaintPtr;
348     SkCanvas::SrcRectConstraint   fConstraint;
349 
350     typedef SkDrawCommand INHERITED;
351 };
352 
353 class SkDrawImageCommand : public SkDrawCommand {
354 public:
355     SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint);
356     void execute(SkCanvas* canvas) const override;
357     bool render(SkCanvas* canvas) const override;
358     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
359     static SkDrawImageCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
360 
361 private:
362     sk_sp<const SkImage> fImage;
363     SkScalar             fLeft;
364     SkScalar             fTop;
365     SkTLazy<SkPaint>     fPaint;
366 
367     typedef SkDrawCommand INHERITED;
368 };
369 
370 class SkDrawImageLatticeCommand : public SkDrawCommand {
371 public:
372     SkDrawImageLatticeCommand(const SkImage* image, const SkCanvas::Lattice& lattice,
373                               const SkRect& dst, const SkPaint* paint);
374     void execute(SkCanvas* canvas) const override;
375     bool render(SkCanvas* canvas) const override;
376     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
377 
378 private:
379     sk_sp<const SkImage>        fImage;
380     SkCanvas::Lattice           fLattice;
381     SkRect                      fDst;
382     SkTLazy<SkPaint>            fPaint;
383 
384     typedef SkDrawCommand INHERITED;
385 };
386 
387 class SkDrawImageRectCommand : public SkDrawCommand {
388 public:
389     SkDrawImageRectCommand(const SkImage* image, const SkRect* src, const SkRect& dst,
390                            const SkPaint* paint, SkCanvas::SrcRectConstraint constraint);
391     void execute(SkCanvas* canvas) const override;
392     bool render(SkCanvas* canvas) const override;
393     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
394     static SkDrawImageRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
395 
396 private:
397     sk_sp<const SkImage>        fImage;
398     SkTLazy<SkRect>             fSrc;
399     SkRect                      fDst;
400     SkTLazy<SkPaint>            fPaint;
401     SkCanvas::SrcRectConstraint fConstraint;
402 
403     typedef SkDrawCommand INHERITED;
404 };
405 
406 class SkDrawOvalCommand : public SkDrawCommand {
407 public:
408     SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint);
409     void execute(SkCanvas* canvas) const override;
410     bool render(SkCanvas* canvas) const override;
411     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
412     static SkDrawOvalCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
413 
414 private:
415     SkRect  fOval;
416     SkPaint fPaint;
417 
418     typedef SkDrawCommand INHERITED;
419 };
420 
421 class SkDrawArcCommand : public SkDrawCommand {
422 public:
423     SkDrawArcCommand(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
424                      const SkPaint& paint);
425     void execute(SkCanvas* canvas) const override;
426     bool render(SkCanvas* canvas) const override;
427     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
428     static SkDrawArcCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
429 
430 private:
431     SkRect   fOval;
432     SkScalar fStartAngle;
433     SkScalar fSweepAngle;
434     bool     fUseCenter;
435     SkPaint  fPaint;
436 
437     typedef SkDrawCommand INHERITED;
438 };
439 
440 class SkDrawPaintCommand : public SkDrawCommand {
441 public:
442     SkDrawPaintCommand(const SkPaint& paint);
443     void execute(SkCanvas* canvas) const override;
444     bool render(SkCanvas* canvas) const override;
445     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
446     static SkDrawPaintCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
447 
448 private:
449     SkPaint fPaint;
450 
451     typedef SkDrawCommand INHERITED;
452 };
453 
454 class SkDrawPathCommand : public SkDrawCommand {
455 public:
456     SkDrawPathCommand(const SkPath& path, const SkPaint& paint);
457     void execute(SkCanvas* canvas) const override;
458     bool render(SkCanvas* canvas) const override;
459     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
460     static SkDrawPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
461 
462 private:
463     SkPath   fPath;
464     SkPaint  fPaint;
465 
466     typedef SkDrawCommand INHERITED;
467 };
468 
469 class SkBeginDrawPictureCommand : public SkDrawCommand {
470 public:
471     SkBeginDrawPictureCommand(const SkPicture* picture,
472                               const SkMatrix* matrix,
473                               const SkPaint* paint);
474 
475     void execute(SkCanvas* canvas) const override;
476     bool render(SkCanvas* canvas) const override;
477 
478 private:
479     sk_sp<const SkPicture> fPicture;
480     SkTLazy<SkMatrix>      fMatrix;
481     SkTLazy<SkPaint>       fPaint;
482 
483     typedef SkDrawCommand INHERITED;
484 };
485 
486 class SkEndDrawPictureCommand : public SkDrawCommand {
487 public:
488     SkEndDrawPictureCommand(bool restore);
489 
490     void execute(SkCanvas* canvas) const override;
491 
492 private:
493     bool fRestore;
494 
495     typedef SkDrawCommand INHERITED;
496 };
497 
498 class SkDrawPointsCommand : public SkDrawCommand {
499 public:
500     SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
501                         const SkPaint& paint);
~SkDrawPointsCommand()502     ~SkDrawPointsCommand() override { delete [] fPts; }
503     void execute(SkCanvas* canvas) const override;
504     bool render(SkCanvas* canvas) const override;
505     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
506     static SkDrawPointsCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
507 
508 private:
509     SkCanvas::PointMode fMode;
510     size_t              fCount;
511     SkPoint*            fPts;
512     SkPaint             fPaint;
513 
514     typedef SkDrawCommand INHERITED;
515 };
516 
517 class SkDrawTextCommand : public SkDrawCommand {
518 public:
519     SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
520                       const SkPaint& paint);
~SkDrawTextCommand()521     ~SkDrawTextCommand() override { delete [] fText; }
522     void execute(SkCanvas* canvas) const override;
523     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
524     static SkDrawTextCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
525 
526 private:
527     char*    fText;
528     size_t   fByteLength;
529     SkScalar fX;
530     SkScalar fY;
531     SkPaint  fPaint;
532 
533     typedef SkDrawCommand INHERITED;
534 };
535 
536 class SkDrawPosTextCommand : public SkDrawCommand {
537 public:
538     SkDrawPosTextCommand(const void* text, size_t byteLength, const SkPoint pos[],
539                          const SkPaint& paint);
~SkDrawPosTextCommand()540     ~SkDrawPosTextCommand() override { delete [] fPos; delete [] fText; }
541     void execute(SkCanvas* canvas) const override;
542     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
543     static SkDrawPosTextCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
544 
545 private:
546     char*    fText;
547     size_t   fByteLength;
548     SkPoint* fPos;
549     SkPaint  fPaint;
550 
551     typedef SkDrawCommand INHERITED;
552 };
553 
554 class SkDrawTextOnPathCommand : public SkDrawCommand {
555 public:
556     SkDrawTextOnPathCommand(const void* text, size_t byteLength, const SkPath& path,
557                             const SkMatrix* matrix, const SkPaint& paint);
~SkDrawTextOnPathCommand()558     ~SkDrawTextOnPathCommand() override { delete [] fText; }
559     void execute(SkCanvas* canvas) const override;
560     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
561     static SkDrawTextOnPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
562 
563 private:
564     char*    fText;
565     size_t   fByteLength;
566     SkPath   fPath;
567     SkMatrix fMatrix;
568     SkPaint  fPaint;
569 
570     typedef SkDrawCommand INHERITED;
571 };
572 
573 class SkDrawTextRSXformCommand : public SkDrawCommand {
574 public:
575     SkDrawTextRSXformCommand(const void* text, size_t byteLength, const SkRSXform[],
576                              const SkRect*, const SkPaint& paint);
~SkDrawTextRSXformCommand()577     ~SkDrawTextRSXformCommand() override { delete[] fText; delete[] fXform; }
578     void execute(SkCanvas* canvas) const override;
579     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
580     static SkDrawTextRSXformCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
581 
582 private:
583     char*       fText;
584     size_t      fByteLength;
585     SkRSXform*  fXform;
586     SkRect*     fCull;
587     SkRect      fCullStorage;
588     SkPaint     fPaint;
589 
590     typedef SkDrawCommand INHERITED;
591 };
592 
593 class SkDrawPosTextHCommand : public SkDrawCommand {
594 public:
595     SkDrawPosTextHCommand(const void* text, size_t byteLength, const SkScalar xpos[],
596                           SkScalar constY, const SkPaint& paint);
~SkDrawPosTextHCommand()597     ~SkDrawPosTextHCommand() override { delete [] fXpos; delete [] fText; }
598     void execute(SkCanvas* canvas) const override;
599     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
600     static SkDrawPosTextHCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
601 
602 private:
603     SkScalar* fXpos;
604     char*     fText;
605     size_t    fByteLength;
606     SkScalar  fConstY;
607     SkPaint   fPaint;
608 
609     typedef SkDrawCommand INHERITED;
610 };
611 
612 class SkDrawTextBlobCommand : public SkDrawCommand {
613 public:
614     SkDrawTextBlobCommand(sk_sp<SkTextBlob> blob, SkScalar x, SkScalar y, const SkPaint& paint);
615 
616     void execute(SkCanvas* canvas) const override;
617     bool render(SkCanvas* canvas) const override;
618     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
619     static SkDrawTextBlobCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
620 
621 private:
622     sk_sp<SkTextBlob> fBlob;
623     SkScalar          fXPos;
624     SkScalar          fYPos;
625     SkPaint           fPaint;
626 
627     typedef SkDrawCommand INHERITED;
628 };
629 
630 class SkDrawPatchCommand : public SkDrawCommand {
631 public:
632     SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
633                        const SkPoint texCoords[4], SkBlendMode bmode,
634                        const SkPaint& paint);
635     void execute(SkCanvas* canvas) const override;
636     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
637     static SkDrawPatchCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
638 
639 private:
640     SkPoint fCubics[12];
641     SkColor* fColorsPtr;
642     SkColor  fColors[4];
643     SkPoint* fTexCoordsPtr;
644     SkPoint  fTexCoords[4];
645     SkBlendMode fBlendMode;
646     SkPaint fPaint;
647 
648     typedef SkDrawCommand INHERITED;
649 };
650 
651 
652 class SkDrawRectCommand : public SkDrawCommand {
653 public:
654     SkDrawRectCommand(const SkRect& rect, const SkPaint& paint);
655     void execute(SkCanvas* canvas) const override;
656     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
657     static SkDrawRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
658 
rect()659     const SkRect& rect() const   { return fRect; }
paint()660     const SkPaint& paint() const { return fPaint; }
661 private:
662     SkRect  fRect;
663     SkPaint fPaint;
664 
665     typedef SkDrawCommand INHERITED;
666 };
667 
668 class SkDrawRRectCommand : public SkDrawCommand {
669 public:
670     SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint);
671     void execute(SkCanvas* canvas) const override;
672     bool render(SkCanvas* canvas) const override;
673     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
674     static SkDrawRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
675 
676 private:
677     SkRRect fRRect;
678     SkPaint fPaint;
679 
680     typedef SkDrawCommand INHERITED;
681 };
682 
683 class SkDrawDRRectCommand : public SkDrawCommand {
684 public:
685     SkDrawDRRectCommand(const SkRRect& outer, const SkRRect& inner,
686                         const SkPaint& paint);
687     void execute(SkCanvas* canvas) const override;
688     bool render(SkCanvas* canvas) const override;
689     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
690     static SkDrawDRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
691 
692 private:
693     SkRRect fOuter;
694     SkRRect fInner;
695     SkPaint fPaint;
696 
697     typedef SkDrawCommand INHERITED;
698 };
699 
700 class SkDrawVerticesCommand : public SkDrawCommand {
701 public:
702     SkDrawVerticesCommand(sk_sp<SkVertices>, SkBlendMode, const SkPaint&);
703 
704     void execute(SkCanvas* canvas) const override;
705 
706 private:
707     sk_sp<SkVertices>   fVertices;
708     SkBlendMode         fBlendMode;
709     SkPaint             fPaint;
710 
711     typedef SkDrawCommand INHERITED;
712 };
713 
714 class SkSaveCommand : public SkDrawCommand {
715 public:
716     SkSaveCommand();
717     void execute(SkCanvas* canvas) const override;
action()718     Action action() const override { return kPushLayer_Action; }
719     static SkSaveCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
720 
721 private:
722     typedef SkDrawCommand INHERITED;
723 };
724 
725 class SkSaveLayerCommand : public SkDrawCommand {
726 public:
727     SkSaveLayerCommand(const SkCanvas::SaveLayerRec&);
728     ~SkSaveLayerCommand() override;
729     void execute(SkCanvas* canvas) const override;
730     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
731     static SkSaveLayerCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
732     void vizExecute(SkCanvas* canvas) const override;
action()733     Action action() const override{ return kPushLayer_Action; }
setActive(bool active)734     void setActive(bool active) override { fActive = active; }
active()735     bool active() const override { return fActive; }
736 
paint()737     const SkPaint* paint() const { return fPaintPtr; }
738 
739 private:
740     SkRect               fBounds;
741     SkPaint              fPaint;
742     SkPaint*             fPaintPtr;
743     const SkImageFilter* fBackdrop;
744     uint32_t       fSaveLayerFlags;
745 
746     bool        fActive;
747 
748     typedef SkDrawCommand INHERITED;
749 };
750 
751 class SkSetMatrixCommand : public SkDrawCommand {
752 public:
753     SkSetMatrixCommand(const SkMatrix& matrix);
754     void setUserMatrix(const SkMatrix&) override;
755     void execute(SkCanvas* canvas) const override;
756     Json::Value toJSON(UrlDataManager& urlDataManager) const override;
757     static SkSetMatrixCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
758 
759 private:
760     SkMatrix fUserMatrix;
761     SkMatrix fMatrix;
762 
763     typedef SkDrawCommand INHERITED;
764 };
765 #endif
766 
767