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 | 95b2cf9 | 2021-05-05 09:22:43 -0400 | [diff] [blame] | 21 | 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 Denniston | dada960 | 2020-11-03 10:04:25 -0500 | [diff] [blame] | 38 | } |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 39 | |
| 40 | sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx, |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 41 | const SkSVGFilterContext& fctx) const; |
| 42 | |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame] | 43 | // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion |
| 44 | SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const; |
| 45 | |
Tyler Denniston | 7bb85db | 2021-01-13 12:08:04 -0500 | [diff] [blame] | 46 | /** |
| 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 Denniston | c7e4824 | 2021-01-20 17:31:36 -0500 | [diff] [blame] | 51 | virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext&, |
| 52 | const SkSVGFilterContext&) const; |
Tyler Denniston | 7bb85db | 2021-01-13 12:08:04 -0500 | [diff] [blame] | 53 | |
| 54 | /** Propagates any inherited presentation attributes in the given context. */ |
| 55 | void applyProperties(SkSVGRenderContext*) const; |
| 56 | |
Tyler Denniston | bd91660 | 2021-01-22 13:00:31 -0500 | [diff] [blame] | 57 | SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType()) |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 58 | SVG_ATTR(Result, SkSVGStringType, SkSVGStringType()) |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame] | 59 | SVG_OPTIONAL_ATTR(X, SkSVGLength) |
| 60 | SVG_OPTIONAL_ATTR(Y, SkSVGLength) |
| 61 | SVG_OPTIONAL_ATTR(Width, SkSVGLength) |
| 62 | SVG_OPTIONAL_ATTR(Height, SkSVGLength) |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 63 | |
| 64 | protected: |
| 65 | explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {} |
| 66 | |
| 67 | virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&, |
| 68 | const SkSVGFilterContext&) const = 0; |
| 69 | |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame] | 70 | virtual std::vector<SkSVGFeInputType> getInputs() const = 0; |
| 71 | |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 72 | bool parseAndSetAttribute(const char*, const char*) override; |
| 73 | |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 74 | private: |
Tyler Denniston | 0a145b7 | 2021-01-11 10:51:41 -0500 | [diff] [blame] | 75 | /** |
| 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 Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 82 | using INHERITED = SkSVGHiddenContainer; |
| 83 | }; |
| 84 | |
| 85 | #endif // SkSVGFe_DEFINED |