1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2020 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/effects/SkImageFilters.h" 9cb93a386Sopenharmony_ci#include "modules/svg/include/SkSVGAttributeParser.h" 10cb93a386Sopenharmony_ci#include "modules/svg/include/SkSVGFeGaussianBlur.h" 11cb93a386Sopenharmony_ci#include "modules/svg/include/SkSVGFilterContext.h" 12cb93a386Sopenharmony_ci#include "modules/svg/include/SkSVGRenderContext.h" 13cb93a386Sopenharmony_ci#include "modules/svg/include/SkSVGValue.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_cibool SkSVGFeGaussianBlur::parseAndSetAttribute(const char* name, const char* value) { 16cb93a386Sopenharmony_ci return INHERITED::parseAndSetAttribute(name, value) || 17cb93a386Sopenharmony_ci this->setStdDeviation(SkSVGAttributeParser::parse<SkSVGFeGaussianBlur::StdDeviation>( 18cb93a386Sopenharmony_ci "stdDeviation", name, value)); 19cb93a386Sopenharmony_ci} 20cb93a386Sopenharmony_ci 21cb93a386Sopenharmony_cisk_sp<SkImageFilter> SkSVGFeGaussianBlur::onMakeImageFilter(const SkSVGRenderContext& ctx, 22cb93a386Sopenharmony_ci const SkSVGFilterContext& fctx) const { 23cb93a386Sopenharmony_ci const auto sigma = SkV2{fStdDeviation.fX, fStdDeviation.fY} 24cb93a386Sopenharmony_ci * ctx.transformForCurrentOBB(fctx.primitiveUnits()).scale; 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ci return SkImageFilters::Blur( 27cb93a386Sopenharmony_ci sigma.x, sigma.y, 28cb93a386Sopenharmony_ci fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)), 29cb93a386Sopenharmony_ci this->resolveFilterSubregion(ctx, fctx)); 30cb93a386Sopenharmony_ci} 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_citemplate <> 33cb93a386Sopenharmony_cibool SkSVGAttributeParser::parse<SkSVGFeGaussianBlur::StdDeviation>( 34cb93a386Sopenharmony_ci SkSVGFeGaussianBlur::StdDeviation* stdDeviation) { 35cb93a386Sopenharmony_ci std::vector<SkSVGNumberType> values; 36cb93a386Sopenharmony_ci if (!this->parse(&values)) { 37cb93a386Sopenharmony_ci return false; 38cb93a386Sopenharmony_ci } 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_ci stdDeviation->fX = values[0]; 41cb93a386Sopenharmony_ci stdDeviation->fY = values.size() > 1 ? values[1] : values[0]; 42cb93a386Sopenharmony_ci return true; 43cb93a386Sopenharmony_ci} 44