blob: a2d990e8afa06886142e4649ea49c8249ede5c9f [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 Denniston4c89481be2021-01-20 09:41:22 -050024 node->tag() == SkSVGTag::kFeBlend || node->tag() == SkSVGTag::kFeMorphology;
Tyler Dennistondada9602020-11-03 10:04:25 -050025 }
Tyler Dennistondf208a32020-10-30 16:01:54 -040026
27 sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx,
Tyler Dennistonb25caae2020-11-09 12:46:02 -050028 const SkSVGFilterContext& fctx) const;
29
Tyler Denniston62a683e2020-12-11 11:47:55 -050030 // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion
31 SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
32
Tyler Denniston7bb85db2021-01-13 12:08:04 -050033 /**
34 * Resolves the colorspace within which this filter effect should be applied.
35 * Spec: https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties
36 * 'color-interpolation-filters' property.
37 */
Tyler Dennistonc7e48242021-01-20 17:31:36 -050038 virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext&,
39 const SkSVGFilterContext&) const;
Tyler Denniston7bb85db2021-01-13 12:08:04 -050040
41 /** Propagates any inherited presentation attributes in the given context. */
42 void applyProperties(SkSVGRenderContext*) const;
43
Tyler Dennistonb25caae2020-11-09 12:46:02 -050044 SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType(SkSVGFeInputType::Type::kSourceGraphic))
45 SVG_ATTR(Result, SkSVGStringType, SkSVGStringType())
Tyler Denniston62a683e2020-12-11 11:47:55 -050046 SVG_OPTIONAL_ATTR(X, SkSVGLength)
47 SVG_OPTIONAL_ATTR(Y, SkSVGLength)
48 SVG_OPTIONAL_ATTR(Width, SkSVGLength)
49 SVG_OPTIONAL_ATTR(Height, SkSVGLength)
Tyler Dennistondf208a32020-10-30 16:01:54 -040050
51protected:
52 explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {}
53
54 virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
55 const SkSVGFilterContext&) const = 0;
56
Tyler Denniston62a683e2020-12-11 11:47:55 -050057 virtual std::vector<SkSVGFeInputType> getInputs() const = 0;
58
Tyler Dennistonb25caae2020-11-09 12:46:02 -050059 bool parseAndSetAttribute(const char*, const char*) override;
60
Tyler Dennistondf208a32020-10-30 16:01:54 -040061private:
Tyler Denniston0a145b72021-01-11 10:51:41 -050062 /**
63 * Resolves the rect specified by the x, y, width and height attributes (if specified) on this
64 * filter effect. These attributes are resolved according to the given length context and
65 * the value of 'primitiveUnits' on the parent <filter> element.
66 */
67 SkRect resolveBoundaries(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
68
Tyler Dennistondf208a32020-10-30 16:01:54 -040069 using INHERITED = SkSVGHiddenContainer;
70};
71
72#endif // SkSVGFe_DEFINED