• 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 "src/core/SkClipStackDevice.h"
14 
15 class SkXMLWriter;
16 
17 class SkSVGDevice final : public SkClipStackDevice {
18 public:
19     static sk_sp<SkBaseDevice> Make(const SkISize& size, std::unique_ptr<SkXMLWriter>,
20                                     uint32_t flags);
21 
22 protected:
23     void drawPaint(const SkPaint& paint) override;
24     void drawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
25     void drawPoints(SkCanvas::PointMode mode, size_t count,
26                     const SkPoint[], const SkPaint& paint) override;
27     void drawRect(const SkRect& r, const SkPaint& paint) override;
28     void drawOval(const SkRect& oval, const SkPaint& paint) override;
29     void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
30     void drawPath(const SkPath& path,
31                   const SkPaint& paint,
32                   bool pathIsMutable = false) override;
33 
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     void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;
40     void drawVertices(const SkVertices*, const SkVertices::Bone bones[], int boneCount, SkBlendMode,
41                       const SkPaint& paint) override;
42 
43     void drawDevice(SkBaseDevice*, int x, int y,
44                     const SkPaint&) override;
45 
46 private:
47     SkSVGDevice(const SkISize& size, std::unique_ptr<SkXMLWriter>, uint32_t);
48     ~SkSVGDevice() override;
49 
50     void drawGlyphRunAsText(const SkGlyphRun&, const SkPoint&, const SkPaint&);
51     void drawGlyphRunAsPath(const SkGlyphRun&, const SkPoint&, const SkPaint&);
52 
53     struct MxCp;
54     void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint);
55 
56     void syncClipStack(const SkClipStack&);
57 
58     class AutoElement;
59     class ResourceBucket;
60 
61     const std::unique_ptr<SkXMLWriter>    fWriter;
62     const std::unique_ptr<ResourceBucket> fResourceBucket;
63     const uint32_t                        fFlags;
64 
65     struct ClipRec {
66         std::unique_ptr<AutoElement> fClipPathElem;
67         uint32_t                     fGenID;
68     };
69 
70     std::unique_ptr<AutoElement>    fRootElement;
71     SkTArray<ClipRec>               fClipStack;
72 
73     typedef SkClipStackDevice INHERITED;
74 };
75 
76 #endif // SkSVGDevice_DEFINED
77