Flutter Engine
The Flutter Engine
SkSVGMask.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
9
14
15bool SkSVGMask::parseAndSetAttribute(const char* n, const char* v) {
17 this->setX(SkSVGAttributeParser::parse<SkSVGLength>("x", n, v)) ||
18 this->setY(SkSVGAttributeParser::parse<SkSVGLength>("y", n, v)) ||
19 this->setWidth(SkSVGAttributeParser::parse<SkSVGLength>("width", n, v)) ||
20 this->setHeight(SkSVGAttributeParser::parse<SkSVGLength>("height", n, v)) ||
21 this->setMaskUnits(
22 SkSVGAttributeParser::parse<SkSVGObjectBoundingBoxUnits>("maskUnits", n, v)) ||
23 this->setMaskContentUnits(
24 SkSVGAttributeParser::parse<SkSVGObjectBoundingBoxUnits>("maskContentUnits", n, v));
25}
26
28 return ctx.resolveOBBRect(fX, fY, fWidth, fHeight, fMaskUnits);
29}
30
32 // https://www.w3.org/TR/SVG11/masking.html#Masking
33
34 // Propagate any inherited properties that may impact mask effect behavior (e.g.
35 // color-interpolation). We call this explicitly here because the SkSVGMask
36 // nodes do not participate in the normal onRender path, which is when property
37 // propagation currently occurs.
38 // The local context also restores the filter layer created below on scope exit.
39 SkSVGRenderContext lctx(ctx);
40 this->onPrepareToRender(&lctx);
41
43 auto ci_filter = (ci == SkSVGColorspace::kLinearRGB)
45 : nullptr;
46
48 mask_filter.setColorFilter(
49 SkColorFilters::Compose(SkLumaColorFilter::Make(), std::move(ci_filter)));
50
51 // Mask color filter layer.
52 // Note: We could avoid this extra layer if we invert the stacking order
53 // (mask/content -> content/mask, kSrcIn -> kDstIn) and apply the filter
54 // via the top (mask) layer paint. That requires deferring mask rendering
55 // until after node content, which introduces extra state/complexity.
56 // Something to consider if masking performance ever becomes an issue.
57 lctx.canvas()->saveLayer(nullptr, &mask_filter);
58
59 const auto obbt = ctx.transformForCurrentOBB(fMaskContentUnits);
60 lctx.canvas()->translate(obbt.offset.x, obbt.offset.y);
61 lctx.canvas()->scale(obbt.scale.x, obbt.scale.y);
62
63 for (const auto& child : fChildren) {
64 child->render(lctx);
65 }
66}
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
static sk_sp< SkColorFilter > Compose(const sk_sp< SkColorFilter > &outer, sk_sp< SkColorFilter > inner)
Definition: SkColorFilter.h:92
static sk_sp< SkColorFilter > SRGBToLinearGamma()
skia_private::STArray< 1, sk_sp< SkSVGNode >, true > fChildren
void renderMask(const SkSVGRenderContext &) const
Definition: SkSVGMask.cpp:31
SkRect bounds(const SkSVGRenderContext &) const
Definition: SkSVGMask.cpp:27
bool parseAndSetAttribute(const char *, const char *) override
Definition: SkSVGMask.cpp:15
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition: SkSVGNode.cpp:90
SkRect resolveOBBRect(const SkSVGLength &x, const SkSVGLength &y, const SkSVGLength &w, const SkSVGLength &h, SkSVGObjectBoundingBoxUnits) const
OBBTransform transformForCurrentOBB(SkSVGObjectBoundingBoxUnits) const
const SkSVGPresentationContext & presentationContext() const
SkCanvas * canvas() const
bool onPrepareToRender(SkSVGRenderContext *) const override
std::shared_ptr< DlMaskFilter > mask_filter
static sk_sp< SkColorFilter > Make()
SkSVGProperty< SkSVGColorspace, true > fColorInterpolation
SkSVGPresentationAttributes fInherited