Coverage Report

Created: 2024-05-20 07:14

/src/skia/modules/svg/src/SkSVGFeMorphology.cpp
Line
Count
Source (jump to first uncovered line)
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/SkSVGFeMorphology.h"
11
#include "modules/svg/include/SkSVGFilterContext.h"
12
#include "modules/svg/include/SkSVGRenderContext.h"
13
#include "modules/svg/include/SkSVGValue.h"
14
15
0
bool SkSVGFeMorphology::parseAndSetAttribute(const char* name, const char* value) {
16
0
    return INHERITED::parseAndSetAttribute(name, value) ||
17
0
           this->setOperator(SkSVGAttributeParser::parse<SkSVGFeMorphology::Operator>(
18
0
                   "operator", name, value)) ||
19
0
           this->setRadius(SkSVGAttributeParser::parse<SkSVGFeMorphology::Radius>(
20
0
                   "radius", name, value));
21
0
}
22
23
sk_sp<SkImageFilter> SkSVGFeMorphology::onMakeImageFilter(const SkSVGRenderContext& ctx,
24
0
                                                          const SkSVGFilterContext& fctx) const {
25
0
    const SkRect cropRect = this->resolveFilterSubregion(ctx, fctx);
26
0
    const SkSVGColorspace colorspace = this->resolveColorspace(ctx, fctx);
27
0
    sk_sp<SkImageFilter> input = fctx.resolveInput(ctx, this->getIn(), colorspace);
28
29
0
    const auto r = SkV2{fRadius.fX, fRadius.fY}
30
0
                 * ctx.transformForCurrentOBB(fctx.primitiveUnits()).scale;
31
0
    switch (fOperator) {
32
0
        case Operator::kErode:
33
0
            return SkImageFilters::Erode(r.x, r.y, input, cropRect);
34
0
        case Operator::kDilate:
35
0
            return SkImageFilters::Dilate(r.x, r.y, input, cropRect);
36
0
    }
37
38
0
    SkUNREACHABLE;
39
0
}
40
41
template <>
42
0
bool SkSVGAttributeParser::parse<SkSVGFeMorphology::Operator>(SkSVGFeMorphology::Operator* op) {
43
0
    static constexpr std::tuple<const char*, SkSVGFeMorphology::Operator> gMap[] = {
44
0
            { "dilate", SkSVGFeMorphology::Operator::kDilate },
45
0
            { "erode" , SkSVGFeMorphology::Operator::kErode  },
46
0
    };
47
48
0
    return this->parseEnumMap(gMap, op) && this->parseEOSToken();
49
0
}
50
51
template <>
52
0
bool SkSVGAttributeParser::parse<SkSVGFeMorphology::Radius>(SkSVGFeMorphology::Radius* radius) {
53
0
    std::vector<SkSVGNumberType> values;
54
0
    if (!this->parse(&values)) {
55
0
        return false;
56
0
    }
57
58
0
    radius->fX = values[0];
59
0
    radius->fY = values.size() > 1 ? values[1] : values[0];
60
0
    return true;
61
0
}