1 /*
2  * Copyright 2015 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 SkSVGDevice_DEFINED
9 #define SkSVGDevice_DEFINED
10 
11 #include "SkClipStackDevice.h"
12 #include "SkTemplates.h"
13 
14 class SkXMLWriter;
15 
16 class SkSVGDevice : public SkClipStackDevice {
17 public:
18     static SkBaseDevice* Create(const SkISize& size, SkXMLWriter* writer);
19 
20 protected:
21     void drawPaint(const SkPaint& paint) override;
22     void drawPoints(SkCanvas::PointMode mode, size_t count,
23                     const SkPoint[], const SkPaint& paint) override;
24     void drawRect(const SkRect& r, const SkPaint& paint) override;
25     void drawOval(const SkRect& oval, const SkPaint& paint) override;
26     void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
27     void drawPath(const SkPath& path,
28                   const SkPaint& paint,
29                   const SkMatrix* prePathMatrix = nullptr,
30                   bool pathIsMutable = false) override;
31 
32     void drawBitmap(const SkBitmap& bitmap,
33                     const SkMatrix& matrix, const SkPaint& paint) override;
34     void drawSprite(const SkBitmap& bitmap,
35                     int x, int y, const SkPaint& paint) override;
36     void drawBitmapRect(const SkBitmap&,
37                         const SkRect* srcOrNull, const SkRect& dst,
38                         const SkPaint& paint, SkCanvas::SrcRectConstraint) override;
39 
40     void drawText(const void* text, size_t len,
41                   SkScalar x, SkScalar y, const SkPaint& paint) override;
42     void drawPosText(const void* text, size_t len,
43                      const SkScalar pos[], int scalarsPerPos,
44                      const SkPoint& offset, const SkPaint& paint) override;
45     void drawTextOnPath(const void* text, size_t len,
46                         const SkPath& path, const SkMatrix* matrix,
47                         const SkPaint& paint) override;
48     void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) override;
49 
50     void drawDevice(SkBaseDevice*, int x, int y,
51                     const SkPaint&) override;
52 
53 private:
54     SkSVGDevice(const SkISize& size, SkXMLWriter* writer);
55     ~SkSVGDevice() override;
56 
57     struct MxCp;
58     void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint);
59 
60     class AutoElement;
61     class ResourceBucket;
62 
63     SkXMLWriter*                    fWriter;
64     std::unique_ptr<AutoElement>    fRootElement;
65     std::unique_ptr<ResourceBucket> fResourceBucket;
66 
67     typedef SkClipStackDevice INHERITED;
68 };
69 
70 #endif // SkSVGDevice_DEFINED
71