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 "SkClipStackDevice.h"
12 #include "SkTemplates.h"
13 
14 class SkXMLWriter;
15 
16 class SkSVGDevice : public SkClipStackDevice {
17 public:
18     static SkBaseDevice* Create(const SkISize& size, SkXMLWriter* writer);
19 
20 protected:
21     void drawPaint(const SkPaint& paint) override;
22     void drawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
23     void drawPoints(SkCanvas::PointMode mode, size_t count,
24                     const SkPoint[], const SkPaint& paint) override;
25     void drawRect(const SkRect& r, const SkPaint& paint) override;
26     void drawOval(const SkRect& oval, const SkPaint& paint) override;
27     void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
28     void drawPath(const SkPath& path,
29                   const SkPaint& paint,
30                   bool pathIsMutable = false) override;
31 
32     void drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, const SkPaint& paint) override;
33     void drawSprite(const SkBitmap& bitmap,
34                     int x, int y, const SkPaint& paint) override;
35     void drawBitmapRect(const SkBitmap&,
36                         const SkRect* srcOrNull, const SkRect& dst,
37                         const SkPaint& paint, SkCanvas::SrcRectConstraint) override;
38     void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;
39     void drawVertices(const SkVertices*, const SkVertices::Bone bones[], int boneCount, SkBlendMode,
40                       const SkPaint& paint) override;
41 
42     void drawDevice(SkBaseDevice*, int x, int y,
43                     const SkPaint&) override;
44 
45 private:
46     SkSVGDevice(const SkISize& size, SkXMLWriter* writer);
47     ~SkSVGDevice() override;
48 
49     struct MxCp;
50     void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint);
51 
52     class AutoElement;
53     class ResourceBucket;
54 
55     SkXMLWriter*                    fWriter;
56     std::unique_ptr<AutoElement>    fRootElement;
57     std::unique_ptr<ResourceBucket> fResourceBucket;
58 
59     typedef SkClipStackDevice INHERITED;
60 };
61 
62 #endif // SkSVGDevice_DEFINED
63