xref: /aosp_15_r20/external/skia/src/svg/SkSVGDevice.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/core/SkCanvas.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkTypes.h"
14 #include "include/private/base/SkTArray.h"
15 #include "include/private/base/SkTypeTraits.h"
16 #include "include/utils/SkParsePath.h"
17 #include "src/core/SkClipStackDevice.h"
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <memory>
22 #include <type_traits>
23 
24 namespace sktext {
25 class GlyphRunList;
26 }
27 
28 class SkDevice;
29 class SkBitmap;
30 class SkBlender;
31 class SkClipStack;
32 class SkData;
33 class SkImage;
34 class SkMesh;
35 class SkPaint;
36 class SkPath;
37 class SkRRect;
38 class SkVertices;
39 class SkXMLWriter;
40 struct SkISize;
41 struct SkPoint;
42 struct SkRect;
43 struct SkSamplingOptions;
44 
45 class SkSVGDevice final : public SkClipStackDevice {
46 public:
47     static sk_sp<SkDevice> Make(const SkISize& size, std::unique_ptr<SkXMLWriter>, uint32_t flags);
48 
49     void drawPaint(const SkPaint& paint) override;
50     void drawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
51     void drawPoints(SkCanvas::PointMode mode, size_t count,
52                     const SkPoint[], const SkPaint& paint) override;
53     void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
54                        const SkSamplingOptions&, const SkPaint& paint,
55                        SkCanvas::SrcRectConstraint constraint) override;
56     void drawRect(const SkRect& r, const SkPaint& paint) override;
57     void drawOval(const SkRect& oval, const SkPaint& paint) override;
58     void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
59     void drawPath(const SkPath& path,
60                   const SkPaint& paint,
61                   bool pathIsMutable = false) override;
62 
63     void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override;
64     void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
65 
66 private:
67     SkSVGDevice(const SkISize& size, std::unique_ptr<SkXMLWriter>, uint32_t);
68     ~SkSVGDevice() override;
69 
70     void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint& paint) override;
71 
72     struct MxCp;
73     void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint);
74 
75     void syncClipStack(const SkClipStack&);
76 
77     SkParsePath::PathEncoding pathEncoding() const;
78 
79     class AutoElement;
80     class ResourceBucket;
81 
82     const std::unique_ptr<SkXMLWriter>    fWriter;
83     const std::unique_ptr<ResourceBucket> fResourceBucket;
84     const uint32_t                        fFlags;
85 
86     struct ClipRec {
87         std::unique_ptr<AutoElement> fClipPathElem;
88         uint32_t                     fGenID;
89 
90         static_assert(::sk_is_trivially_relocatable<decltype(fClipPathElem)>::value);
91 
92         using sk_is_trivially_relocatable = std::true_type;
93     };
94 
95     std::unique_ptr<AutoElement> fRootElement;
96     skia_private::TArray<ClipRec> fClipStack;
97 };
98 
99 #endif // SkSVGDevice_DEFINED
100