• 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(const SkGlyphRunList& glyphRunList, const SkPaint& paint) override;
39     void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) override;
40 
41 private:
42     SkSVGDevice(const SkISize& size, std::unique_ptr<SkXMLWriter>, uint32_t);
43     ~SkSVGDevice() override;
44 
45     struct MxCp;
46     void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint);
47 
48     void syncClipStack(const SkClipStack&);
49 
50     SkParsePath::PathEncoding pathEncoding() const;
51 
52     class AutoElement;
53     class ResourceBucket;
54 
55     const std::unique_ptr<SkXMLWriter>    fWriter;
56     const std::unique_ptr<ResourceBucket> fResourceBucket;
57     const uint32_t                        fFlags;
58 
59     struct ClipRec {
60         std::unique_ptr<AutoElement> fClipPathElem;
61         uint32_t                     fGenID;
62     };
63 
64     std::unique_ptr<AutoElement>    fRootElement;
65     SkTArray<ClipRec>               fClipStack;
66 
67     using INHERITED = SkClipStackDevice;
68 };
69 
70 #endif // SkSVGDevice_DEFINED
71