blob: 92bd9d37c86f2570d6917053f96c62d26bab859b [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 ||
23 node->tag() == SkSVGTag::kFeGaussianBlur;
Tyler Dennistondada9602020-11-03 10:04:25 -050024 }
Tyler Dennistondf208a32020-10-30 16:01:54 -040025
26 sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx,
Tyler Dennistonb25caae2020-11-09 12:46:02 -050027 const SkSVGFilterContext& fctx) const;
28
Tyler Denniston62a683e2020-12-11 11:47:55 -050029 // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion
30 SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
31
Tyler Denniston7bb85db2021-01-13 12:08:04 -050032 /**
33 * Resolves the colorspace within which this filter effect should be applied.
34 * Spec: https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties
35 * 'color-interpolation-filters' property.
36 */
37 SkSVGColorspace resolveColorspace(const SkSVGRenderContext&) const;
38
39 /** Propagates any inherited presentation attributes in the given context. */
40 void applyProperties(SkSVGRenderContext*) const;
41
Tyler Dennistonb25caae2020-11-09 12:46:02 -050042 SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType(SkSVGFeInputType::Type::kSourceGraphic))
43 SVG_ATTR(Result, SkSVGStringType, SkSVGStringType())
Tyler Denniston62a683e2020-12-11 11:47:55 -050044 SVG_OPTIONAL_ATTR(X, SkSVGLength)
45 SVG_OPTIONAL_ATTR(Y, SkSVGLength)
46 SVG_OPTIONAL_ATTR(Width, SkSVGLength)
47 SVG_OPTIONAL_ATTR(Height, SkSVGLength)
Tyler Dennistondf208a32020-10-30 16:01:54 -040048
49protected:
50 explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {}
51
52 virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
53 const SkSVGFilterContext&) const = 0;
54
Tyler Denniston62a683e2020-12-11 11:47:55 -050055 virtual std::vector<SkSVGFeInputType> getInputs() const = 0;
56
Tyler Dennistonb25caae2020-11-09 12:46:02 -050057 bool parseAndSetAttribute(const char*, const char*) override;
58
Tyler Dennistondf208a32020-10-30 16:01:54 -040059private:
Tyler Denniston0a145b72021-01-11 10:51:41 -050060 /**
61 * Resolves the rect specified by the x, y, width and height attributes (if specified) on this
62 * filter effect. These attributes are resolved according to the given length context and
63 * the value of 'primitiveUnits' on the parent <filter> element.
64 */
65 SkRect resolveBoundaries(const SkSVGRenderContext&, const SkSVGFilterContext&) const;
66
Tyler Dennistondf208a32020-10-30 16:01:54 -040067 using INHERITED = SkSVGHiddenContainer;
68};
69
70#endif // SkSVGFe_DEFINED