• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/private/SkTArray.h"
12 #include "include/private/SkTemplates.h"
13 #include "include/utils/SkParsePath.h"
14 #include "src/core/SkClipStackDevice.h"
15 
16 class SkXMLWriter;
17 
18 class SkSVGDevice final : public SkClipStackDevice {
19 public:
20     static sk_sp<SkBaseDevice> Make(const SkISize& size, std::unique_ptr<SkXMLWriter>,
21                                     uint32_t flags);
22 
23 protected:
24     void drawPaint(const SkPaint& paint) override;
25     void drawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
26     void drawPoints(SkCanvas::PointMode mode, size_t count,
27                     const SkPoint[], const SkPaint& paint) override;
28     void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
29                        const SkSamplingOptions&, const SkPaint& paint,
30                        SkCanvas::SrcRectConstraint constraint) override;
31     void drawRect(const SkRect& r, const SkPaint& paint) override;
32     void drawOval(const SkRect& oval, const SkPaint& paint) override;
33     void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
34     void drawPath(const SkPath& path,
35                   const SkPaint& paint,
36                   bool pathIsMutable = false) override;
37 
38     void onDrawGlyphRunList(SkCanvas*, const SkGlyphRunList&, const SkPaint&) override;
39     void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&) override;
40     void drawCustomMesh(SkCustomMesh, sk_sp<SkBlender>, const SkPaint&) override;
41 
42 private:
43     SkSVGDevice(const SkISize& size, std::unique_ptr<SkXMLWriter>, uint32_t);
44     ~SkSVGDevice() override;
45 
46     struct MxCp;
47     void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint);
48 
49     void syncClipStack(const SkClipStack&);
50 
51     SkParsePath::PathEncoding pathEncoding() const;
52 
53     class AutoElement;
54     class ResourceBucket;
55 
56     const std::unique_ptr<SkXMLWriter>    fWriter;
57     const std::unique_ptr<ResourceBucket> fResourceBucket;
58     const uint32_t                        fFlags;
59 
60     struct ClipRec {
61         std::unique_ptr<AutoElement> fClipPathElem;
62         uint32_t                     fGenID;
63     };
64 
65     std::unique_ptr<AutoElement>    fRootElement;
66     SkTArray<ClipRec>               fClipStack;
67 
68     using INHERITED = SkClipStackDevice;
69 };
70 
71 #endif // SkSVGDevice_DEFINED
72