Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSVGFeImage.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
15
16bool SkSVGFeImage::parseAndSetAttribute(const char* n, const char* v) {
18 this->setHref(SkSVGAttributeParser::parse<SkSVGIRI>("xlink:href", n, v)) ||
19 this->setPreserveAspectRatio(SkSVGAttributeParser::parse<SkSVGPreserveAspectRatio>(
20 "preserveAspectRatio", n, v));
21}
22
24 const SkSVGFilterContext& fctx) const {
25 // Load image and map viewbox (image bounds) to viewport (filter effects subregion).
26 const SkRect viewport = this->resolveFilterSubregion(ctx, fctx);
27 const auto imgInfo =
28 SkSVGImage::LoadImage(ctx.resourceProvider(), fHref, viewport, fPreserveAspectRatio);
29 if (!imgInfo.fImage) {
30 return nullptr;
31 }
32
33 // Create the image filter mapped according to aspect ratio
34 const SkRect srcRect = SkRect::Make(imgInfo.fImage->bounds());
35 const SkRect& dstRect = imgInfo.fDst;
36 // TODO: image-rendering property
37 auto imgfilt = SkImageFilters::Image(imgInfo.fImage, srcRect, dstRect,
40
41 // Aspect ratio mapping may end up drawing content outside of the filter effects region,
42 // so perform an explicit crop.
43 return SkImageFilters::Merge(&imgfilt, 1, fctx.filterEffectsRegion());
44}
static sk_sp< SkImageFilter > Merge(sk_sp< SkImageFilter > *const filters, int count, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
bool parseAndSetAttribute(const char *, const char *) override
sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const override
SkRect resolveFilterSubregion(const SkSVGRenderContext &, const SkSVGFilterContext &) const
Definition SkSVGFe.cpp:54
bool parseAndSetAttribute(const char *, const char *) override
Definition SkSVGFe.cpp:93
const SkRect & filterEffectsRegion() const
static ImageInfo LoadImage(const sk_sp< skresources::ResourceProvider > &, const SkSVGIRI &, const SkRect &, SkSVGPreserveAspectRatio)
const sk_sp< skresources::ResourceProvider > & resourceProvider() const
static SkRect Make(const SkISize &size)
Definition SkRect.h:669