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 #include "modules/svg/include/SkSVGFeGaussianBlur.h"
9
10 #include "include/core/SkM44.h"
11 #include "include/effects/SkImageFilters.h"
12 #include "modules/svg/include/SkSVGAttributeParser.h"
13 #include "modules/svg/include/SkSVGFilterContext.h"
14 #include "modules/svg/include/SkSVGRenderContext.h"
15
16 class SkImageFilter;
17
parseAndSetAttribute(const char * name,const char * value)18 bool SkSVGFeGaussianBlur::parseAndSetAttribute(const char* name, const char* value) {
19 return INHERITED::parseAndSetAttribute(name, value) ||
20 this->setStdDeviation(SkSVGAttributeParser::parse<SkSVGFeGaussianBlur::StdDeviation>(
21 "stdDeviation", name, value));
22 }
23
onMakeImageFilter(const SkSVGRenderContext & ctx,const SkSVGFilterContext & fctx) const24 sk_sp<SkImageFilter> SkSVGFeGaussianBlur::onMakeImageFilter(const SkSVGRenderContext& ctx,
25 const SkSVGFilterContext& fctx) const {
26 const auto sigma = SkV2{fStdDeviation.fX, fStdDeviation.fY}
27 * ctx.transformForCurrentOBB(fctx.primitiveUnits()).scale;
28
29 return SkImageFilters::Blur(
30 sigma.x, sigma.y,
31 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
32 this->resolveFilterSubregion(ctx, fctx));
33 }
34
35 template <>
parse(SkSVGFeGaussianBlur::StdDeviation * stdDeviation)36 bool SkSVGAttributeParser::parse<SkSVGFeGaussianBlur::StdDeviation>(
37 SkSVGFeGaussianBlur::StdDeviation* stdDeviation) {
38 std::vector<SkSVGNumberType> values;
39 if (!this->parse(&values)) {
40 return false;
41 }
42
43 stdDeviation->fX = values[0];
44 stdDeviation->fY = values.size() > 1 ? values[1] : values[0];
45 return true;
46 }
47