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