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 11 #include "include/core/SkRect.h" 12 #include "include/core/SkRefCnt.h" 13 #include "include/private/base/SkAPI.h" 14 #include "modules/svg/include/SkSVGHiddenContainer.h" 15 #include "modules/svg/include/SkSVGNode.h" 16 #include "modules/svg/include/SkSVGTypes.h" 17 #include "src/base/SkTLazy.h" 18 19 #include <vector> 20 21 class SkImageFilter; 22 class SkSVGFilterContext; 23 class SkSVGRenderContext; 24 25 class SK_API SkSVGFe : public SkSVGHiddenContainer { 26 public: IsFilterEffect(const sk_sp<SkSVGNode> & node)27 static bool IsFilterEffect(const sk_sp<SkSVGNode>& node) { 28 switch (node->tag()) { 29 case SkSVGTag::kFeBlend: 30 case SkSVGTag::kFeColorMatrix: 31 case SkSVGTag::kFeComponentTransfer: 32 case SkSVGTag::kFeComposite: 33 case SkSVGTag::kFeDiffuseLighting: 34 case SkSVGTag::kFeDisplacementMap: 35 case SkSVGTag::kFeFlood: 36 case SkSVGTag::kFeGaussianBlur: 37 case SkSVGTag::kFeImage: 38 case SkSVGTag::kFeMerge: 39 case SkSVGTag::kFeMorphology: 40 case SkSVGTag::kFeOffset: 41 case SkSVGTag::kFeSpecularLighting: 42 case SkSVGTag::kFeTurbulence: 43 return true; 44 default: 45 return false; 46 } 47 } 48 49 sk_sp<SkImageFilter> makeImageFilter(const SkSVGRenderContext& ctx, 50 const SkSVGFilterContext& fctx) const; 51 52 // https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion 53 SkRect resolveFilterSubregion(const SkSVGRenderContext&, const SkSVGFilterContext&) const; 54 55 /** 56 * Resolves the colorspace within which this filter effect should be applied. 57 * Spec: https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties 58 * 'color-interpolation-filters' property. 59 */ 60 virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext&, 61 const SkSVGFilterContext&) const; 62 63 /** Propagates any inherited presentation attributes in the given context. */ 64 void applyProperties(SkSVGRenderContext*) const; 65 SVG_ATTR(In,SkSVGFeInputType,SkSVGFeInputType ())66 SVG_ATTR(In, SkSVGFeInputType, SkSVGFeInputType()) 67 SVG_ATTR(Result, SkSVGStringType, SkSVGStringType()) 68 SVG_OPTIONAL_ATTR(X, SkSVGLength) 69 SVG_OPTIONAL_ATTR(Y, SkSVGLength) 70 SVG_OPTIONAL_ATTR(Width, SkSVGLength) 71 SVG_OPTIONAL_ATTR(Height, SkSVGLength) 72 73 protected: 74 explicit SkSVGFe(SkSVGTag t) : INHERITED(t) {} 75 76 virtual sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&, 77 const SkSVGFilterContext&) const = 0; 78 79 virtual std::vector<SkSVGFeInputType> getInputs() const = 0; 80 81 bool parseAndSetAttribute(const char*, const char*) override; 82 83 private: 84 /** 85 * Resolves the rect specified by the x, y, width and height attributes (if specified) on this 86 * filter effect. These attributes are resolved according to the given length context and 87 * the value of 'primitiveUnits' on the parent <filter> element. 88 */ 89 SkRect resolveBoundaries(const SkSVGRenderContext&, const SkSVGFilterContext&) const; 90 91 using INHERITED = SkSVGHiddenContainer; 92 }; 93 94 #endif // SkSVGFe_DEFINED 95