blob: 1b0f90acae853ba524ee3ca8f5e26ba8e73f02e7 [file] [log] [blame]
Tyler Dennistondf208a32020-10-30 16:01:54 -04001/*
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
Tyler Denniston62a683e2020-12-11 11:47:55 -050011#include <vector>
12
Tyler Dennistondf208a32020-10-30 16:01:54 -040013#include "modules/svg/include/SkSVGHiddenContainer.h"
14
15class SkImageFilter;
16class SkSVGFilterContext;
17
18class SkSVGFe : public SkSVGHiddenContainer {
19public:
Tyler Dennistondada9602020-11-03 10:04:25 -050020 static bool IsFilterEffect(const sk_sp<SkSVGNode>& node) {
Tyler Denniston95b2cf92021-05-05 09:22:43 -040021 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 }
Tyler Dennistondada9602020-11-03 10:04:25 -050038 }
Tyler Dennistondf208a32020-10-30 16:01:54 -040039
40 sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx,
Tyler Dennistonb25caae2020-11-09 12:46:02 -050041 const SkSVGFilterContext& fctx) const;
42
Tyler Denniston62a683e2020-12-11 11:47:55 -050043 // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion
44 SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
45
Tyler Denniston7bb85db2021-01-13 12:08:04 -050046 /**
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 */
Tyler Dennistonc7e48242021-01-20 17:31:36 -050051 virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext&,
52 const SkSVGFilterContext&) const;
Tyler Denniston7bb85db2021-01-13 12:08:04 -050053
54 /** Propagates any inherited presentation attributes in the given context. */
55 void applyProperties(SkSVGRenderContext*) const;
56
Tyler Dennistonbd916602021-01-22 13:00:31 -050057 SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType())
Tyler Dennistonb25caae2020-11-09 12:46:02 -050058 SVG_ATTR(Result, SkSVGStringType, SkSVGStringType())
Tyler Denniston62a683e2020-12-11 11:47:55 -050059 SVG_OPTIONAL_ATTR(X, SkSVGLength)
60 SVG_OPTIONAL_ATTR(Y, SkSVGLength)
61 SVG_OPTIONAL_ATTR(Width, SkSVGLength)
62 SVG_OPTIONAL_ATTR(Height, SkSVGLength)
Tyler Dennistondf208a32020-10-30 16:01:54 -040063
64protected:
65 explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {}
66
67 virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
68 const SkSVGFilterContext&) const = 0;
69
Tyler Denniston62a683e2020-12-11 11:47:55 -050070 virtual std::vector<SkSVGFeInputType> getInputs() const = 0;
71
Tyler Dennistonb25caae2020-11-09 12:46:02 -050072 bool parseAndSetAttribute(const char*, const char*) override;
73
Tyler Dennistondf208a32020-10-30 16:01:54 -040074private:
Tyler Denniston0a145b72021-01-11 10:51:41 -050075 /**
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
Tyler Dennistondf208a32020-10-30 16:01:54 -040082 using INHERITED = SkSVGHiddenContainer;
83};
84
85#endif // SkSVGFe_DEFINED