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