blob: 442ee1e912cb905d8c16dbdc6f94603adccab61b [file] [log] [blame]
Florin Malitab3418102020-10-15 18:10:29 -04001/*
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 "modules/svg/include/SkSVGHiddenContainer.h"
12#include "modules/svg/include/SkSVGTypes.h"
13
14class SkSVGRenderContext;
15
16class SkSVGPattern final : public SkSVGHiddenContainer {
17public:
Florin Malitab3418102020-10-15 18:10:29 -040018 static sk_sp<SkSVGPattern> Make() {
19 return sk_sp<SkSVGPattern>(new SkSVGPattern());
20 }
21
Tyler Dennistone71f5472021-01-27 13:30:59 -050022 SVG_ATTR(Href, SkSVGIRI, SkSVGIRI())
Tyler Denniston627c6d22021-02-08 13:30:45 -050023 SVG_OPTIONAL_ATTR(X , SkSVGLength)
24 SVG_OPTIONAL_ATTR(Y , SkSVGLength)
25 SVG_OPTIONAL_ATTR(Width , SkSVGLength)
26 SVG_OPTIONAL_ATTR(Height , SkSVGLength)
27 SVG_OPTIONAL_ATTR(PatternTransform, SkSVGTransformType)
Florin Malitab3418102020-10-15 18:10:29 -040028
29protected:
30 SkSVGPattern();
31
Tyler Dennistone71f5472021-01-27 13:30:59 -050032 bool parseAndSetAttribute(const char*, const char*) override;
33
Florin Malitab3418102020-10-15 18:10:29 -040034 bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const override;
35
36private:
37 struct PatternAttributes {
38 SkTLazy<SkSVGLength> fX,
39 fY,
40 fWidth,
41 fHeight;
42 SkTLazy<SkSVGTransformType> fPatternTransform;
Tyler Denniston627c6d22021-02-08 13:30:45 -050043 };
Florin Malitab3418102020-10-15 18:10:29 -040044
Florin Malitab3418102020-10-15 18:10:29 -040045 const SkSVGPattern* resolveHref(const SkSVGRenderContext&, PatternAttributes*) const;
46 const SkSVGPattern* hrefTarget(const SkSVGRenderContext&) const;
47
48 // TODO:
49 // - patternUnits
50 // - patternContentUnits
51
52 using INHERITED = SkSVGHiddenContainer;
53};
54
55#endif // SkSVGPattern_DEFINED