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
15class SkXMLWriter;
16
17class SkSVGDevice final : public SkClipStackDevice {
18public:
19 static sk_sp<SkBaseDevice> Make(const SkISize& size, std::unique_ptr<SkXMLWriter>,
20 uint32_t flags);
21
22protected:
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 drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
28 const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) override;
29 void drawRect(const SkRect& r, const SkPaint& paint) override;
30 void drawOval(const SkRect& oval, const SkPaint& paint) override;
31 void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
32 void drawPath(const SkPath& path,
33 const SkPaint& paint,
34 bool pathIsMutable = false) override;
35
36 void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;
37 void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) override;
38
39 void drawDevice(SkBaseDevice*, int x, int y,
40 const SkPaint&) override;
41
42private:
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 class AutoElement;
52 class ResourceBucket;
53
54 const std::unique_ptr<SkXMLWriter> fWriter;
55 const std::unique_ptr<ResourceBucket> fResourceBucket;
56 const uint32_t fFlags;
57
58 struct ClipRec {
59 std::unique_ptr<AutoElement> fClipPathElem;
60 uint32_t fGenID;
61 };
62
63 std::unique_ptr<AutoElement> fRootElement;
64 SkTArray<ClipRec> fClipStack;
65
66 typedef SkClipStackDevice INHERITED;
67};
68
69#endif // SkSVGDevice_DEFINED
70