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