Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 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" |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 9 | #include "modules/svg/include/SkSVGAttributeParser.h" |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 10 | #include "modules/svg/include/SkSVGFe.h" |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame^] | 11 | #include "modules/svg/include/SkSVGFilterContext.h" |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 12 | |
| 13 | sk_sp<SkImageFilter> SkSVGFe::makeImageFilter(const SkSVGRenderContext& ctx, |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 14 | const SkSVGFilterContext& fctx) const { |
| 15 | return this->onMakeImageFilter(ctx, fctx); |
| 16 | } |
| 17 | |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame^] | 18 | SkRect SkSVGFe::resolveFilterSubregion(const SkSVGRenderContext& ctx, |
| 19 | const SkSVGFilterContext& fctx) const { |
| 20 | // TODO: calculate primitive subregion |
| 21 | return fctx.filterEffectsRegion(); |
| 22 | } |
| 23 | |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 24 | bool SkSVGFe::parseAndSetAttribute(const char* name, const char* value) { |
| 25 | return INHERITED::parseAndSetAttribute(name, value) || |
| 26 | this->setIn(SkSVGAttributeParser::parse<SkSVGFeInputType>("in", name, value)) || |
Tyler Denniston | 62a683e | 2020-12-11 11:47:55 -0500 | [diff] [blame^] | 27 | this->setResult(SkSVGAttributeParser::parse<SkSVGStringType>("result", name, value)) || |
| 28 | this->setX(SkSVGAttributeParser::parse<SkSVGLength>("x", name, value)) || |
| 29 | this->setY(SkSVGAttributeParser::parse<SkSVGLength>("y", name, value)) || |
| 30 | this->setWidth(SkSVGAttributeParser::parse<SkSVGLength>("width", name, value)) || |
| 31 | this->setHeight(SkSVGAttributeParser::parse<SkSVGLength>("height", name, value)); |
Tyler Denniston | b25caae | 2020-11-09 12:46:02 -0500 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | template <> bool SkSVGAttributeParser::parse(SkSVGFeInputType* type) { |
| 35 | static constexpr std::tuple<const char*, SkSVGFeInputType::Type> gTypeMap[] = { |
| 36 | {"SourceGraphic", SkSVGFeInputType::Type::kSourceGraphic}, |
| 37 | {"SourceAlpha", SkSVGFeInputType::Type::kSourceAlpha}, |
| 38 | {"BackgroundImage", SkSVGFeInputType::Type::kBackgroundImage}, |
| 39 | {"BackgroundAlpha", SkSVGFeInputType::Type::kBackgroundAlpha}, |
| 40 | {"FillPaint", SkSVGFeInputType::Type::kFillPaint}, |
| 41 | {"StrokePaint", SkSVGFeInputType::Type::kStrokePaint}, |
| 42 | }; |
| 43 | |
| 44 | SkSVGStringType resultId; |
| 45 | SkSVGFeInputType::Type t; |
| 46 | bool parsedValue = false; |
| 47 | if (this->parseEnumMap(gTypeMap, &t)) { |
| 48 | *type = SkSVGFeInputType(t); |
| 49 | parsedValue = true; |
| 50 | } else if (parse(&resultId)) { |
| 51 | *type = SkSVGFeInputType(resultId); |
| 52 | parsedValue = true; |
| 53 | } |
| 54 | |
| 55 | return parsedValue && this->parseEOSToken(); |
Tyler Denniston | df208a3 | 2020-10-30 16:01:54 -0400 | [diff] [blame] | 56 | } |