Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSVGFe.cpp
Go to the documentation of this file.
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
13
15 const SkSVGFilterContext& fctx) const {
16 return this->onMakeImageFilter(ctx, fctx);
17}
18
19SkRect SkSVGFe::resolveBoundaries(const SkSVGRenderContext& ctx,
20 const SkSVGFilterContext& fctx) const {
21 const auto x = fX.isValid() ? *fX : SkSVGLength(0, SkSVGLength::Unit::kPercentage);
22 const auto y = fY.isValid() ? *fY : SkSVGLength(0, SkSVGLength::Unit::kPercentage);
23 const auto w = fWidth.isValid() ? *fWidth : SkSVGLength(100, SkSVGLength::Unit::kPercentage);
24 const auto h = fHeight.isValid() ? *fHeight : SkSVGLength(100, SkSVGLength::Unit::kPercentage);
25
26 return ctx.resolveOBBRect(x, y, w, h, fctx.primitiveUnits());
27}
28
29static bool AnyIsStandardInput(const SkSVGFilterContext& fctx,
30 const std::vector<SkSVGFeInputType>& inputs) {
31 for (const auto& in : inputs) {
32 switch (in.type()) {
34 break;
41 return true;
43 // Unspecified means previous result (which may be SourceGraphic).
45 return true;
46 }
47 break;
48 }
49 }
50
51 return false;
52}
53
55 const SkSVGFilterContext& fctx) const {
56 // From https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion,
57 // the default filter effect subregion is equal to the union of the subregions defined
58 // for all "referenced nodes" (filter effect inputs). If there are no inputs, the
59 // default subregion is equal to the filter effects region
60 // (https://www.w3.org/TR/SVG11/filters.html#FilterEffectsRegion).
61 const std::vector<SkSVGFeInputType> inputs = this->getInputs();
62 SkRect defaultSubregion;
63 if (inputs.empty() || AnyIsStandardInput(fctx, inputs)) {
64 defaultSubregion = fctx.filterEffectsRegion();
65 } else {
66 defaultSubregion = fctx.filterPrimitiveSubregion(inputs[0]);
67 for (size_t i = 1; i < inputs.size(); i++) {
68 defaultSubregion.join(fctx.filterPrimitiveSubregion(inputs[i]));
69 }
70 }
71
72 // Next resolve the rect specified by the x, y, width, height attributes on this filter effect.
73 // If those attributes were given, they override the corresponding attribute of the default
74 // filter effect subregion calculated above.
75 const SkRect boundaries = this->resolveBoundaries(ctx, fctx);
76
77 // Compute and return the fully resolved subregion.
78 return SkRect::MakeXYWH(fX.isValid() ? boundaries.fLeft : defaultSubregion.fLeft,
79 fY.isValid() ? boundaries.fTop : defaultSubregion.fTop,
80 fWidth.isValid() ? boundaries.width() : defaultSubregion.width(),
81 fHeight.isValid() ? boundaries.height() : defaultSubregion.height());
82}
83
90
92
93bool SkSVGFe::parseAndSetAttribute(const char* name, const char* value) {
95 this->setIn(SkSVGAttributeParser::parse<SkSVGFeInputType>("in", name, value)) ||
96 this->setResult(SkSVGAttributeParser::parse<SkSVGStringType>("result", name, value)) ||
97 this->setX(SkSVGAttributeParser::parse<SkSVGLength>("x", name, value)) ||
98 this->setY(SkSVGAttributeParser::parse<SkSVGLength>("y", name, value)) ||
99 this->setWidth(SkSVGAttributeParser::parse<SkSVGLength>("width", name, value)) ||
100 this->setHeight(SkSVGAttributeParser::parse<SkSVGLength>("height", name, value));
101}
102
104 static constexpr std::tuple<const char*, SkSVGFeInputType::Type> gTypeMap[] = {
107 {"BackgroundImage", SkSVGFeInputType::Type::kBackgroundImage},
108 {"BackgroundAlpha", SkSVGFeInputType::Type::kBackgroundAlpha},
111 };
112
113 SkSVGStringType resultId;
115 bool parsedValue = false;
116 if (this->parseEnumMap(gTypeMap, &t)) {
118 parsedValue = true;
119 } else if (parse(&resultId)) {
120 *type = SkSVGFeInputType(resultId);
121 parsedValue = true;
122 }
123
124 return parsedValue && this->parseEOSToken();
125}
static bool AnyIsStandardInput(const SkSVGFilterContext &fctx, const std::vector< SkSVGFeInputType > &inputs)
Definition SkSVGFe.cpp:29
SkSVGColorspace
Definition SkSVGTypes.h:719
bool parse(SkSVGIntegerType *v)
SkRect resolveFilterSubregion(const SkSVGRenderContext &, const SkSVGFilterContext &) const
Definition SkSVGFe.cpp:54
virtual std::vector< SkSVGFeInputType > getInputs() const =0
bool parseAndSetAttribute(const char *, const char *) override
Definition SkSVGFe.cpp:93
virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext &, const SkSVGFilterContext &) const
Definition SkSVGFe.cpp:84
sk_sp< SkImageFilter > makeImageFilter(const SkSVGRenderContext &ctx, const SkSVGFilterContext &fctx) const
Definition SkSVGFe.cpp:14
void applyProperties(SkSVGRenderContext *) const
Definition SkSVGFe.cpp:91
virtual sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const =0
const SkRect & filterEffectsRegion() const
bool previousResultIsSourceGraphic() const
const SkSVGObjectBoundingBoxUnits & primitiveUnits() const
const SkRect & filterPrimitiveSubregion(const SkSVGFeInputType &) const
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition SkSVGNode.cpp:90
SkRect resolveOBBRect(const SkSVGLength &x, const SkSVGLength &y, const SkSVGLength &w, const SkSVGLength &h, SkSVGObjectBoundingBoxUnits) const
const SkSVGPresentationContext & presentationContext() const
bool onPrepareToRender(SkSVGRenderContext *) const override
uint8_t value
const char * name
Definition fuchsia.cc:50
double y
double x
SkScalar w
SkScalar h
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762
void join(const SkRect &r)
Definition SkRect.cpp:126
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15
SkSVGProperty< SkSVGColorspace, true > fColorInterpolationFilters
SkSVGPresentationAttributes fInherited