1 /* 2 * Copyright 2017 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 SkSVGPattern_DEFINED 9 #define SkSVGPattern_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/private/base/SkAPI.h" 13 #include "modules/svg/include/SkSVGHiddenContainer.h" 14 #include "modules/svg/include/SkSVGNode.h" 15 #include "modules/svg/include/SkSVGTypes.h" 16 #include "src/base/SkTLazy.h" 17 18 class SkPaint; 19 class SkSVGRenderContext; 20 21 class SK_API SkSVGPattern final : public SkSVGHiddenContainer { 22 public: Make()23 static sk_sp<SkSVGPattern> Make() { 24 return sk_sp<SkSVGPattern>(new SkSVGPattern()); 25 } 26 27 SVG_ATTR(Href, SkSVGIRI, SkSVGIRI()) 28 SVG_OPTIONAL_ATTR(X , SkSVGLength) 29 SVG_OPTIONAL_ATTR(Y , SkSVGLength) 30 SVG_OPTIONAL_ATTR(Width , SkSVGLength) 31 SVG_OPTIONAL_ATTR(Height , SkSVGLength) 32 SVG_OPTIONAL_ATTR(PatternTransform, SkSVGTransformType) 33 34 protected: 35 SkSVGPattern(); 36 37 bool parseAndSetAttribute(const char*, const char*) override; 38 39 bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const override; 40 41 private: 42 struct PatternAttributes { 43 SkTLazy<SkSVGLength> fX, 44 fY, 45 fWidth, 46 fHeight; 47 SkTLazy<SkSVGTransformType> fPatternTransform; 48 }; 49 50 const SkSVGPattern* resolveHref(const SkSVGRenderContext&, PatternAttributes*) const; 51 const SkSVGPattern* hrefTarget(const SkSVGRenderContext&) const; 52 53 // TODO: 54 // - patternUnits 55 // - patternContentUnits 56 57 using INHERITED = SkSVGHiddenContainer; 58 }; 59 60 #endif // SkSVGPattern_DEFINED 61