blob: a936ef156e778fee2ef69ad2ea6988d9ca2455f5 [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 Denniston62a683e2020-12-11 11:47:55 -050011#include "modules/svg/include/SkSVGFilterContext.h"
Tyler Dennistondf208a32020-10-30 16:01:54 -040012
13sk_sp<SkImageFilter> SkSVGFe::makeImageFilter(const SkSVGRenderContext& ctx,
Tyler Dennistonb25caae2020-11-09 12:46:02 -050014 const SkSVGFilterContext& fctx) const {
15 return this->onMakeImageFilter(ctx, fctx);
16}
17
Tyler Denniston62a683e2020-12-11 11:47:55 -050018SkRect SkSVGFe::resolveFilterSubregion(const SkSVGRenderContext& ctx,
19 const SkSVGFilterContext& fctx) const {
20 // TODO: calculate primitive subregion
21 return fctx.filterEffectsRegion();
22}
23
Tyler Dennistonb25caae2020-11-09 12:46:02 -050024bool SkSVGFe::parseAndSetAttribute(const char* name, const char* value) {
25 return INHERITED::parseAndSetAttribute(name, value) ||
26 this->setIn(SkSVGAttributeParser::parse<SkSVGFeInputType>("in", name, value)) ||
Tyler Denniston62a683e2020-12-11 11:47:55 -050027 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 Dennistonb25caae2020-11-09 12:46:02 -050032}
33
34template <> 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 Dennistondf208a32020-10-30 16:01:54 -040056}