blob: 78ed49f9f5b08de0d14934a49cbb74ebf915d6b7 [file] [log] [blame]
Tyler Dennistondf208a32020-10-30 16:01:54 -04001/*
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 Dennistonb25caae2020-11-09 12:46:02 -05009#include "modules/svg/include/SkSVGAttributeParser.h"
Tyler Dennistondf208a32020-10-30 16:01:54 -040010#include "modules/svg/include/SkSVGFe.h"
Tyler Dennistondf208a32020-10-30 16:01:54 -040011
12sk_sp<SkImageFilter> SkSVGFe::makeImageFilter(const SkSVGRenderContext& ctx,
Tyler Dennistonb25caae2020-11-09 12:46:02 -050013 const SkSVGFilterContext& fctx) const {
14 return this->onMakeImageFilter(ctx, fctx);
15}
16
17bool SkSVGFe::parseAndSetAttribute(const char* name, const char* value) {
18 return INHERITED::parseAndSetAttribute(name, value) ||
19 this->setIn(SkSVGAttributeParser::parse<SkSVGFeInputType>("in", name, value)) ||
20 this->setResult(SkSVGAttributeParser::parse<SkSVGStringType>("result", name, value));
21}
22
23template <> bool SkSVGAttributeParser::parse(SkSVGFeInputType* type) {
24 static constexpr std::tuple<const char*, SkSVGFeInputType::Type> gTypeMap[] = {
25 {"SourceGraphic", SkSVGFeInputType::Type::kSourceGraphic},
26 {"SourceAlpha", SkSVGFeInputType::Type::kSourceAlpha},
27 {"BackgroundImage", SkSVGFeInputType::Type::kBackgroundImage},
28 {"BackgroundAlpha", SkSVGFeInputType::Type::kBackgroundAlpha},
29 {"FillPaint", SkSVGFeInputType::Type::kFillPaint},
30 {"StrokePaint", SkSVGFeInputType::Type::kStrokePaint},
31 };
32
33 SkSVGStringType resultId;
34 SkSVGFeInputType::Type t;
35 bool parsedValue = false;
36 if (this->parseEnumMap(gTypeMap, &t)) {
37 *type = SkSVGFeInputType(t);
38 parsedValue = true;
39 } else if (parse(&resultId)) {
40 *type = SkSVGFeInputType(resultId);
41 parsedValue = true;
42 }
43
44 return parsedValue && this->parseEOSToken();
Tyler Dennistondf208a32020-10-30 16:01:54 -040045}