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 SkBaseDevice; 29 class SkBitmap; 30 class SkBlender; 31 class SkClipStack; 32 class SkData; 33 class SkImage; 34 class SkPaint; 35 class SkPath; 36 class SkRRect; 37 class SkVertices; 38 class SkXMLWriter; 39 struct SkISize; 40 struct SkPoint; 41 struct SkRect; 42 struct SkSamplingOptions; 43 #ifdef SK_ENABLE_SKSL 44 class SkMesh; 45 #endif 46 47 class SkSVGDevice final : public SkClipStackDevice { 48 public: 49 static sk_sp<SkBaseDevice> Make(const SkISize& size, std::unique_ptr<SkXMLWriter>, 50 uint32_t flags); 51 52 protected: 53 void drawPaint(const SkPaint& paint) override; 54 void drawAnnotation(const SkRect& rect, const char key[], SkData* value) override; 55 void drawPoints(SkCanvas::PointMode mode, size_t count, 56 const SkPoint[], const SkPaint& paint) override; 57 void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, 58 const SkSamplingOptions&, const SkPaint& paint, 59 SkCanvas::SrcRectConstraint constraint) override; 60 void drawRect(const SkRect& r, const SkPaint& paint) override; 61 void drawOval(const SkRect& oval, const SkPaint& paint) override; 62 void drawRRect(const SkRRect& rr, const SkPaint& paint) override; 63 void drawPath(const SkPath& path, 64 const SkPaint& paint, 65 bool pathIsMutable = false) override; 66 67 void onDrawGlyphRunList(SkCanvas*, 68 const sktext::GlyphRunList&, 69 const SkPaint& initialPaint, 70 const SkPaint& drawingPaint) override; 71 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override; 72 #ifdef SK_ENABLE_SKSL 73 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override; 74 #endif 75 private: 76 SkSVGDevice(const SkISize& size, std::unique_ptr<SkXMLWriter>, uint32_t); 77 ~SkSVGDevice() override; 78 79 struct MxCp; 80 void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint); 81 82 void syncClipStack(const SkClipStack&); 83 84 SkParsePath::PathEncoding pathEncoding() const; 85 86 class AutoElement; 87 class ResourceBucket; 88 89 const std::unique_ptr<SkXMLWriter> fWriter; 90 const std::unique_ptr<ResourceBucket> fResourceBucket; 91 const uint32_t fFlags; 92 93 struct ClipRec { 94 std::unique_ptr<AutoElement> fClipPathElem; 95 uint32_t fGenID; 96 97 static_assert(::sk_is_trivially_relocatable<decltype(fClipPathElem)>::value); 98 99 using sk_is_trivially_relocatable = std::true_type; 100 }; 101 102 std::unique_ptr<AutoElement> fRootElement; 103 SkTArray<ClipRec> fClipStack; 104 105 using INHERITED = SkClipStackDevice; 106 }; 107 108 #endif // SkSVGDevice_DEFINED 109