Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSVGFeBlend.cpp
Go to the documentation of this file.
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
15
16bool SkSVGFeBlend::parseAndSetAttribute(const char* name, const char* value) {
18 this->setIn2(SkSVGAttributeParser::parse<SkSVGFeInputType>("in2", name, value)) ||
19 this->setMode(SkSVGAttributeParser::parse<SkSVGFeBlend::Mode>("mode", name, value));
20}
21
38
40 const SkSVGFilterContext& fctx) const {
41 const SkRect cropRect = this->resolveFilterSubregion(ctx, fctx);
42 const SkBlendMode blendMode = GetBlendMode(this->getMode());
43 const SkSVGColorspace colorspace = this->resolveColorspace(ctx, fctx);
44 const sk_sp<SkImageFilter> background = fctx.resolveInput(ctx, fIn2, colorspace);
45 const sk_sp<SkImageFilter> foreground = fctx.resolveInput(ctx, this->getIn(), colorspace);
46 return SkImageFilters::Blend(blendMode, background, foreground, cropRect);
47}
48
49template <>
50bool SkSVGAttributeParser::parse<SkSVGFeBlend::Mode>(
51 SkSVGFeBlend::Mode* mode) {
52 static constexpr std::tuple<const char*, SkSVGFeBlend::Mode> gMap[] = {
53 { "normal" , SkSVGFeBlend::Mode::kNormal },
54 { "multiply", SkSVGFeBlend::Mode::kMultiply },
55 { "screen" , SkSVGFeBlend::Mode::kScreen },
56 { "darken" , SkSVGFeBlend::Mode::kDarken },
57 { "lighten" , SkSVGFeBlend::Mode::kLighten },
58 };
59
60 return this->parseEnumMap(gMap, mode) && this->parseEOSToken();
61}
#define SkUNREACHABLE
Definition SkAssert.h:135
SkBlendMode
Definition SkBlendMode.h:38
@ kLighten
rc = s + d - min(s*da, d*sa), ra = kSrcOver
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kScreen
r = s + d - s*d
@ kSrcOver
r = s + (1-sa)*d
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
static SkBlendMode GetBlendMode(SkSVGFeBlend::Mode mode)
SkSVGColorspace
Definition SkSVGTypes.h:719
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})
sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const override
bool parseAndSetAttribute(const char *, const char *) override
SkRect resolveFilterSubregion(const SkSVGRenderContext &, const SkSVGFilterContext &) const
Definition SkSVGFe.cpp:54
bool parseAndSetAttribute(const char *, const char *) override
Definition SkSVGFe.cpp:93
virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext &, const SkSVGFilterContext &) const
Definition SkSVGFe.cpp:84
sk_sp< SkImageFilter > resolveInput(const SkSVGRenderContext &, const SkSVGFeInputType &) const
uint8_t value
const char * name
Definition fuchsia.cc:50