Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkBlurEngine.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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#ifndef SkBlurEngine_DEFINED
9#define SkBlurEngine_DEFINED
10
12
13class SkSpecialImage;
14struct SkIRect;
15struct SkSize;
16enum class SkTileMode;
17enum SkColorType : int;
18
19/**
20 * SkBlurEngine is a backend-agnostic provider of blur algorithms. Each Skia backend defines a blur
21 * engine with a set of supported algorithms and/or implementations. A given implementation may be
22 * optimized for a particular color type, sigma range, or available hardware. Each engine and its
23 * algorithms are assumed to operate only on SkImages corresponding to its Skia backend, and will
24 * produce output SkImages of the same type.
25 *
26 * Algorithms are allowed to specify a maximum supported sigma. If the desired sigma is higher than
27 * this, the input image and output region must be downscaled by the caller before invoking the
28 * algorithm. This is to provide the most flexibility for input representation (e.g. directly
29 * rasterize at half resolution or apply deferred filter effects during the first downsample pass).
30 *
31 * skif::FilterResult::Builder::blur() is a convenient wrapper around the blur engine and
32 * automatically handles resizing.
33*/
35public:
36 class Algorithm;
37
38 virtual ~SkBlurEngine() = default;
39
40 // Returns an Algorithm ideal for the requested 'sigma' that will support sampling an image of
41 // the given 'colorType'. If the engine does not support the requested configuration, it returns
42 // null. The engine maintains the lifetime of its algorithms, so the returned non-null
43 // Algorithms live as long as the engine does.
44 virtual const Algorithm* findAlgorithm(SkSize sigma,
45 SkColorType colorType) const = 0;
46
47 // TODO: Consolidate common utility functions from SkBlurMask.h, skgpu::BlurUtils, and
48 // skgpu::ganesh::GrBlurUtils into this header.
49
50};
51
53public:
54 virtual ~Algorithm() = default;
55
56 // The maximum sigma that can be passed to blur() in the X and/or Y sigma values. Larger
57 // requested sigmas must manually downscale the input image and upscale the output image.
58 virtual float maxSigma() const = 0;
59
60 // Whether or not the SkTileMode can be passed to blur() must be SkTileMode::kDecal, or if any
61 // tile mode is supported. If only kDecal is supported, then callers must manually apply the
62 // tilemode and account for that in the src and dst bounds passed into blur(). If this returns
63 // false, then the algorithm supports all SkTileModes.
64 // TODO: Once CPU blurs support all tile modes, this API can go away.
65 virtual bool supportsOnlyDecalTiling() const = 0;
66
67 // Produce a blurred image that fills 'dstRect' (their dimensions will match). 'dstRect's top
68 // left corner defines the output's location relative to the 'src' image. 'srcRect' restricts
69 // the pixels that are included in the blur and is also relative to 'src'. The 'tileMode'
70 // applies to the boundary of 'srcRect', which must be contained within 'src's dimensions.
71 //
72 // 'srcRect' and 'dstRect' may be different sizes and even be disjoint.
73 //
74 // The returned SkImage will have the same color type and colorspace as the input image. It will
75 // be an SkImage type matching the underlying Skia backend. If the 'src' SkImage is not a
76 // compatible SkImage type, null is returned.
77 // TODO(b/299474380): This only takes SkSpecialImage to work with skif::FilterResult and
78 // SkDevice::snapSpecial(); SkImage would be ideal.
81 const SkIRect& srcRect,
82 SkTileMode tileMode,
83 const SkIRect& dstRect) const = 0;
84};
85
86#endif // SkBlurEngine_DEFINED
SkColorType
Definition SkColorType.h:19
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkTileMode
Definition SkTileMode.h:13
Type::kYUV Type::kRGBA() int(0.7 *637)
virtual ~Algorithm()=default
virtual float maxSigma() const =0
virtual bool supportsOnlyDecalTiling() const =0
virtual sk_sp< SkSpecialImage > blur(SkSize sigma, sk_sp< SkSpecialImage > src, const SkIRect &srcRect, SkTileMode tileMode, const SkIRect &dstRect) const =0
virtual ~SkBlurEngine()=default
virtual const Algorithm * findAlgorithm(SkSize sigma, SkColorType colorType) const =0