Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSVGFeDisplacementMap.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
14
15bool SkSVGFeDisplacementMap::parseAndSetAttribute(const char* name, const char* value) {
17 this->setIn2(SkSVGAttributeParser::parse<SkSVGFeInputType>("in2", name, value)) ||
18 this->setXChannelSelector(
19 SkSVGAttributeParser::parse<SkSVGFeDisplacementMap::ChannelSelector>(
20 "xChannelSelector", name, value)) ||
21 this->setYChannelSelector(
22 SkSVGAttributeParser::parse<SkSVGFeDisplacementMap::ChannelSelector>(
23 "yChannelSelector", name, value)) ||
24 this->setScale(SkSVGAttributeParser::parse<SkSVGNumberType>("scale", name, value));
25}
26
28 const SkSVGRenderContext& ctx, const SkSVGFilterContext& fctx) const {
29 const SkRect cropRect = this->resolveFilterSubregion(ctx, fctx);
30 const SkSVGColorspace colorspace = this->resolveColorspace(ctx, fctx);
31
32 // According to spec https://www.w3.org/TR/SVG11/filters.html#feDisplacementMapElement,
33 // the 'in' source image must remain in its current colorspace.
34 sk_sp<SkImageFilter> in = fctx.resolveInput(ctx, this->getIn());
35 sk_sp<SkImageFilter> in2 = fctx.resolveInput(ctx, this->getIn2(), colorspace);
36
37 SkScalar scale = fScale;
39 const auto obbt = ctx.transformForCurrentOBB(fctx.primitiveUnits());
40 scale = SkSVGLengthContext({obbt.scale.x, obbt.scale.y})
43 }
44
46 fXChannelSelector, fYChannelSelector, scale, in2, in, cropRect);
47}
48
50 const SkSVGFilterContext& fctx) const {
51 // According to spec https://www.w3.org/TR/SVG11/filters.html#feDisplacementMapElement,
52 // the 'in' source image must remain in its current colorspace, which means the colorspace of
53 // this FE node is the same as the input.
54 return fctx.resolveInputColorspace(ctx, this->getIn());
55}
56
57template <>
58bool SkSVGAttributeParser::parse<SkSVGFeDisplacementMap::ChannelSelector>(
60 static constexpr std::tuple<const char*, SkSVGFeDisplacementMap::ChannelSelector> gMap[] = {
61 { "R", SkSVGFeDisplacementMap::ChannelSelector::kR },
62 { "G", SkSVGFeDisplacementMap::ChannelSelector::kG },
63 { "B", SkSVGFeDisplacementMap::ChannelSelector::kB },
64 { "A", SkSVGFeDisplacementMap::ChannelSelector::kA },
65 };
66
67 return this->parseEnumMap(gMap, channel) && this->parseEOSToken();
68}
SkColorChannel
Definition SkColor.h:228
SkSVGColorspace
Definition SkSVGTypes.h:719
static sk_sp< SkImageFilter > DisplacementMap(SkColorChannel xChannelSelector, SkColorChannel yChannelSelector, SkScalar scale, sk_sp< SkImageFilter > displacement, sk_sp< SkImageFilter > color, const CropRect &cropRect={})
SkSVGColorspace resolveColorspace(const SkSVGRenderContext &, const SkSVGFilterContext &) const final
sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const override
bool parseAndSetAttribute(const char *, const char *) override
SkRect resolveFilterSubregion(const SkSVGRenderContext &, const SkSVGFilterContext &) const
Definition SkSVGFe.cpp:54
bool parseAndSetAttribute(const char *, const char *) override
Definition SkSVGFe.cpp:93
SkSVGColorspace resolveInputColorspace(const SkSVGRenderContext &, const SkSVGFeInputType &) const
sk_sp< SkImageFilter > resolveInput(const SkSVGRenderContext &, const SkSVGFeInputType &) const
const SkSVGObjectBoundingBoxUnits & primitiveUnits() const
OBBTransform transformForCurrentOBB(SkSVGObjectBoundingBoxUnits) const
float SkScalar
Definition extension.cpp:12
uint8_t value
const char * name
Definition fuchsia.cc:50
const Scalar scale