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/SkSVGFeOffset.h"
9
10 #include "include/core/SkImageFilter.h"
11 #include "include/core/SkM44.h"
12 #include "include/effects/SkImageFilters.h"
13 #include "modules/svg/include/SkSVGAttributeParser.h"
14 #include "modules/svg/include/SkSVGFilterContext.h"
15 #include "modules/svg/include/SkSVGRenderContext.h"
16
17 #include <utility>
18
parseAndSetAttribute(const char * name,const char * value)19 bool SkSVGFeOffset::parseAndSetAttribute(const char* name, const char* value) {
20 return INHERITED::parseAndSetAttribute(name, value) ||
21 this->setDx(SkSVGAttributeParser::parse<SkSVGNumberType>("dx", name, value)) ||
22 this->setDy(SkSVGAttributeParser::parse<SkSVGNumberType>("dy", name, value));
23 }
24
onMakeImageFilter(const SkSVGRenderContext & ctx,const SkSVGFilterContext & fctx) const25 sk_sp<SkImageFilter> SkSVGFeOffset::onMakeImageFilter(const SkSVGRenderContext& ctx,
26 const SkSVGFilterContext& fctx) const {
27 const auto d = SkV2{this->getDx(), this->getDy()}
28 * ctx.transformForCurrentOBB(fctx.primitiveUnits()).scale;
29
30 sk_sp<SkImageFilter> in =
31 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx));
32 return SkImageFilters::Offset(d.x, d.y, std::move(in), this->resolveFilterSubregion(ctx, fctx));
33 }
34