xref: /third_party/skia/modules/svg/include/SkSVGFe.h (revision cb93a386)
1/*
2 * Copyright 2020 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 SkSVGFe_DEFINED
9#define SkSVGFe_DEFINED
10
11#include <vector>
12
13#include "modules/svg/include/SkSVGHiddenContainer.h"
14
15class SkImageFilter;
16class SkSVGFilterContext;
17
18class SkSVGFe : public SkSVGHiddenContainer {
19public:
20    static bool IsFilterEffect(const sk_sp<SkSVGNode>& node) {
21        switch (node->tag()) {
22            case SkSVGTag::kFeBlend:
23            case SkSVGTag::kFeColorMatrix:
24            case SkSVGTag::kFeComposite:
25            case SkSVGTag::kFeDiffuseLighting:
26            case SkSVGTag::kFeDisplacementMap:
27            case SkSVGTag::kFeFlood:
28            case SkSVGTag::kFeGaussianBlur:
29            case SkSVGTag::kFeImage:
30            case SkSVGTag::kFeMorphology:
31            case SkSVGTag::kFeOffset:
32            case SkSVGTag::kFeSpecularLighting:
33            case SkSVGTag::kFeTurbulence:
34                return true;
35            default:
36                return false;
37        }
38    }
39
40    sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx,
41                                         const SkSVGFilterContext& fctx) const;
42
43    // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion
44    SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
45
46    /**
47     * Resolves the colorspace within which this filter effect should be applied.
48     * Spec: https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties
49     * 'color-interpolation-filters' property.
50     */
51    virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext&,
52                                              const SkSVGFilterContext&) const;
53
54    /** Propagates any inherited presentation attributes in the given context. */
55    void applyProperties(SkSVGRenderContext*) const;
56
57    SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType())
58    SVG_ATTR(Result, SkSVGStringType, SkSVGStringType())
59    SVG_OPTIONAL_ATTR(X, SkSVGLength)
60    SVG_OPTIONAL_ATTR(Y, SkSVGLength)
61    SVG_OPTIONAL_ATTR(Width, SkSVGLength)
62    SVG_OPTIONAL_ATTR(Height, SkSVGLength)
63
64protected:
65    explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {}
66
67    virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
68                                                   const SkSVGFilterContext&) const = 0;
69
70    virtual std::vector<SkSVGFeInputType> getInputs() const = 0;
71
72    bool parseAndSetAttribute(const char*, const char*) override;
73
74private:
75    /**
76     * Resolves the rect specified by the x, y, width and height attributes (if specified) on this
77     * filter effect. These attributes are resolved according to the given length context and
78     * the value of 'primitiveUnits' on the parent <filter> element.
79     */
80    SkRect resolveBoundaries(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
81
82    using INHERITED = SkSVGHiddenContainer;
83};
84
85#endif  // SkSVGFe_DEFINED
86