Coverage Report

Created: 2021-08-22 09:07

/src/skia/modules/svg/include/SkSVGFe.h
Line
Count
Source (jump to first uncovered line)
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
15
class SkImageFilter;
16
class SkSVGFilterContext;
17
18
class SkSVGFe : public SkSVGHiddenContainer {
19
public:
20
50.6k
    static bool IsFilterEffect(const sk_sp<SkSVGNode>& node) {
21
50.6k
        switch (node->tag()) {
22
0
            case SkSVGTag::kFeBlend:
23
0
            case SkSVGTag::kFeColorMatrix:
24
13.6k
            case SkSVGTag::kFeComposite:
25
13.6k
            case SkSVGTag::kFeDiffuseLighting:
26
13.6k
            case SkSVGTag::kFeDisplacementMap:
27
21.8k
            case SkSVGTag::kFeFlood:
28
21.8k
            case SkSVGTag::kFeGaussianBlur:
29
21.8k
            case SkSVGTag::kFeImage:
30
21.8k
            case SkSVGTag::kFeMorphology:
31
23.2k
            case SkSVGTag::kFeOffset:
32
23.2k
            case SkSVGTag::kFeSpecularLighting:
33
23.2k
            case SkSVGTag::kFeTurbulence:
34
23.2k
                return true;
35
27.4k
            default:
36
27.4k
                return false;
37
50.6k
        }
38
50.6k
    }
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
64
protected:
65
10.6k
    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
74
private:
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