blob: 25ed1662cf8c2f5cd660cb2fc808add34c9de752 [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 Dennistonb25caae2020-11-09 12:46:02 -050021 return node->tag() == SkSVGTag::kFeTurbulence || node->tag() == SkSVGTag::kFeColorMatrix ||
Tyler Denniston187d8112021-01-12 09:34:23 -050022 node->tag() == SkSVGTag::kFeComposite || node->tag() == SkSVGTag::kFeFlood ||
Tyler Dennistona25e1a32021-01-15 12:38:29 -050023 node->tag() == SkSVGTag::kFeGaussianBlur || node->tag() == SkSVGTag::kFeOffset ||
Tyler Dennistonf005c8a2021-01-25 12:56:13 -050024 node->tag() == SkSVGTag::kFeBlend || node->tag() == SkSVGTag::kFeMorphology ||
Tyler Denniston8eedcd22021-01-27 09:18:06 -050025 node->tag() == SkSVGTag::kFeDisplacementMap ||
Tyler Denniston8cfe7182021-04-29 14:54:25 -040026 node->tag() == SkSVGTag::kFeSpecularLighting ||
27 node->tag() == SkSVGTag::kFeDiffuseLighting;
Tyler Dennistondada9602020-11-03 10:04:25 -050028 }
Tyler Dennistondf208a32020-10-30 16:01:54 -040029
30 sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx,
Tyler Dennistonb25caae2020-11-09 12:46:02 -050031 const SkSVGFilterContext& fctx) const;
32
Tyler Denniston62a683e2020-12-11 11:47:55 -050033 // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion
34 SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
35
Tyler Denniston7bb85db2021-01-13 12:08:04 -050036 /**
37 * Resolves the colorspace within which this filter effect should be applied.
38 * Spec: https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties
39 * 'color-interpolation-filters' property.
40 */
Tyler Dennistonc7e48242021-01-20 17:31:36 -050041 virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext&,
42 const SkSVGFilterContext&) const;
Tyler Denniston7bb85db2021-01-13 12:08:04 -050043
44 /** Propagates any inherited presentation attributes in the given context. */
45 void applyProperties(SkSVGRenderContext*) const;
46
Tyler Dennistonbd916602021-01-22 13:00:31 -050047 SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType())
Tyler Dennistonb25caae2020-11-09 12:46:02 -050048 SVG_ATTR(Result, SkSVGStringType, SkSVGStringType())
Tyler Denniston62a683e2020-12-11 11:47:55 -050049 SVG_OPTIONAL_ATTR(X, SkSVGLength)
50 SVG_OPTIONAL_ATTR(Y, SkSVGLength)
51 SVG_OPTIONAL_ATTR(Width, SkSVGLength)
52 SVG_OPTIONAL_ATTR(Height, SkSVGLength)
Tyler Dennistondf208a32020-10-30 16:01:54 -040053
54protected:
55 explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {}
56
57 virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
58 const SkSVGFilterContext&) const = 0;
59
Tyler Denniston62a683e2020-12-11 11:47:55 -050060 virtual std::vector<SkSVGFeInputType> getInputs() const = 0;
61
Tyler Dennistonb25caae2020-11-09 12:46:02 -050062 bool parseAndSetAttribute(const char*, const char*) override;
63
Tyler Dennistondf208a32020-10-30 16:01:54 -040064private:
Tyler Denniston0a145b72021-01-11 10:51:41 -050065 /**
66 * Resolves the rect specified by the x, y, width and height attributes (if specified) on this
67 * filter effect. These attributes are resolved according to the given length context and
68 * the value of 'primitiveUnits' on the parent <filter> element.
69 */
70 SkRect resolveBoundaries(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
71
Tyler Dennistondf208a32020-10-30 16:01:54 -040072 using INHERITED = SkSVGHiddenContainer;
73};
74
75#endif // SkSVGFe_DEFINED