Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 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 | |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 13 | #include "modules/svg/include/SkSVGHiddenContainer.h" |
| 14 | |
| 15 | class SkImageFilter; |
| 16 | class SkSVGFilterContext; |
| 17 | |
| 18 | class SkSVGFe : public SkSVGHiddenContainer { |
| 19 | public: |
Tyler Denniston | dada960 | 2020-11-03 10:04:25 -0500 | [diff] [blame] | 20 | static bool IsFilterEffect(const sk_sp<SkSVGNode>& node) { |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 21 | return node->tag() == SkSVGTag::kFeTurbulence || node->tag() == SkSVGTag::kFeColorMatrix || |
Tyler Denniston | 187d811 | 2021-01-12 09:34:23 -0500 | [diff] [blame] | 22 | node->tag() == SkSVGTag::kFeComposite || node->tag() == SkSVGTag::kFeFlood || |
Tyler Denniston | a25e1a3 | 2021-01-15 12:38:29 -0500 | [diff] [blame] | 23 | node->tag() == SkSVGTag::kFeGaussianBlur || node->tag() == SkSVGTag::kFeOffset || |
Tyler Denniston | 4c89481be | 2021-01-20 09:41:22 -0500 | [diff] [blame] | 24 | node->tag() == SkSVGTag::kFeBlend || node->tag() == SkSVGTag::kFeMorphology; |
Tyler Denniston | dada960 | 2020-11-03 10:04:25 -0500 | [diff] [blame] | 25 | } |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 26 | |
| 27 | sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx, |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 28 | const SkSVGFilterContext& fctx) const; |
| 29 | |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame] | 30 | // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion |
| 31 | SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const; |
| 32 | |
Tyler Denniston | 7bb85db | 2021-01-13 12:08:04 -0500 | [diff] [blame] | 33 | /** |
| 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 Denniston | c7e4824 | 2021-01-20 17:31:36 -0500 | [diff] [blame^] | 38 | virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext&, |
| 39 | const SkSVGFilterContext&) const; |
Tyler Denniston | 7bb85db | 2021-01-13 12:08:04 -0500 | [diff] [blame] | 40 | |
| 41 | /** Propagates any inherited presentation attributes in the given context. */ |
| 42 | void applyProperties(SkSVGRenderContext*) const; |
| 43 | |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 44 | SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType(SkSVGFeInputType::Type::kSourceGraphic)) |
| 45 | SVG_ATTR(Result, SkSVGStringType, SkSVGStringType()) |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame] | 46 | SVG_OPTIONAL_ATTR(X, SkSVGLength) |
| 47 | SVG_OPTIONAL_ATTR(Y, SkSVGLength) |
| 48 | SVG_OPTIONAL_ATTR(Width, SkSVGLength) |
| 49 | SVG_OPTIONAL_ATTR(Height, SkSVGLength) |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 50 | |
| 51 | protected: |
| 52 | explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {} |
| 53 | |
| 54 | virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&, |
| 55 | const SkSVGFilterContext&) const = 0; |
| 56 | |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame] | 57 | virtual std::vector<SkSVGFeInputType> getInputs() const = 0; |
| 58 | |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 59 | bool parseAndSetAttribute(const char*, const char*) override; |
| 60 | |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 61 | private: |
Tyler Denniston | 0a145b7 | 2021-01-11 10:51:41 -0500 | [diff] [blame] | 62 | /** |
| 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 Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 69 | using INHERITED = SkSVGHiddenContainer; |
| 70 | }; |
| 71 | |
| 72 | #endif // SkSVGFe_DEFINED |