Flutter Engine
The Flutter Engine
BlurUtils.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 skgpu_BlurUtils_DEFINED
9#define skgpu_BlurUtils_DEFINED
10
11#include "include/core/SkSize.h"
12#include "include/core/SkSpan.h"
14
15#include <array>
16
17class SkBitmap;
18class SkRRect;
19class SkRuntimeEffect;
20struct SkV4;
21
22namespace skgpu {
23
24// TODO: Remove functions that just wrap SkBlurEngine utilities once calling code is updated to
25// use SkBlurEngine directly or is deleted entirely in favor of SkShaderBlurAlgorithm.
26constexpr int BlurKernelWidth(int radius) { return SkShaderBlurAlgorithm::KernelWidth(radius); }
27constexpr int BlurLinearKernelWidth(int radius) {
29}
30constexpr bool BlurIsEffectivelyIdentity(float sigma) {
32}
33inline int BlurSigmaRadius(float sigma) { return SkBlurEngine::SigmaToRadius(sigma); }
34
37
38inline const SkRuntimeEffect* GetBlur2DEffect(const SkISize& radii) {
40}
41
42inline const SkRuntimeEffect* GetLinearBlur1DEffect(int radius) {
44}
45
46inline void Compute2DBlurKernel(SkSize sigma, SkISize radius, SkSpan<float> kernel) {
47 SkShaderBlurAlgorithm::Compute2DBlurKernel(sigma, radius, kernel);
48}
49
50inline void Compute2DBlurKernel(SkSize sigma,
51 SkISize radius,
52 std::array<SkV4, kMaxBlurSamples/4>& kernel) {
53 SkShaderBlurAlgorithm::Compute2DBlurKernel(sigma, radius, kernel);
54}
55
56inline void Compute1DBlurKernel(float sigma, int radius, SkSpan<float> kernel) {
57 SkShaderBlurAlgorithm::Compute1DBlurKernel(sigma, radius, kernel);
58}
59
60inline void Compute2DBlurOffsets(SkISize radius, std::array<SkV4, kMaxBlurSamples/2>& offsets) {
62}
63
64inline void Compute1DBlurLinearKernel(float sigma,
65 int radius,
66 std::array<SkV4, kMaxBlurSamples/2>& offsetsAndKernel) {
67 SkShaderBlurAlgorithm::Compute1DBlurLinearKernel(sigma, radius, offsetsAndKernel);
68}
69
70///////////////////////////////////////////////////////////////////////////////////////////////////
71
72// Calculates the integral table for an analytic rectangle blur. The integral values are stored in
73// the red channel of the provided bitmap, which will be 1D with a 1-pixel height.
75
76// Returns the width of an integral table we will create for the given 6*sigma.
77int ComputeIntegralTableWidth(float sixSigma);
78
79// Creates a profile of a blurred circle.
80SkBitmap CreateCircleProfile(float sigma, float radius, int profileWidth);
81
82// Creates a half plane approximation profile of a blurred circle.
83SkBitmap CreateHalfPlaneProfile(int profileWidth);
84
85// Creates a blurred rounded rectangle mask. 'rrectToDraw' is the original rrect centered within
86// bounds defined by 'dimensions', which encompass the entire blurred rrect.
87SkBitmap CreateRRectBlurMask(const SkRRect& rrectToDraw, const SkISize& dimensions, float sigma);
88
89} // namespace skgpu
90
91#endif // skgpu_BlurUtils_DEFINED
static int SigmaToRadius(float sigma)
Definition: SkBlurEngine.h:67
static constexpr bool IsEffectivelyIdentity(float sigma)
Definition: SkBlurEngine.h:63
static constexpr int kMaxSamples
Definition: SkBlurEngine.h:166
static void Compute1DBlurKernel(float sigma, int radius, SkSpan< float > kernel)
Definition: SkBlurEngine.h:235
static void Compute1DBlurLinearKernel(float sigma, int radius, std::array< SkV4, kMaxSamples/2 > &offsetsAndKernel)
static constexpr float kMaxLinearSigma
Definition: SkBlurEngine.h:172
static void Compute2DBlurOffsets(SkISize radius, std::array< SkV4, kMaxSamples/2 > &offsets)
static constexpr int LinearKernelWidth(int radius)
Definition: SkBlurEngine.h:158
static const SkRuntimeEffect * GetBlur2DEffect(const SkISize &radii)
static constexpr int KernelWidth(int radius)
Definition: SkBlurEngine.h:154
static const SkRuntimeEffect * GetLinearBlur1DEffect(int radius)
static void Compute2DBlurKernel(SkSize sigma, SkISize radius, SkSpan< float > kernel)
list offsets
Definition: mskp_parser.py:37
Definition: GpuTools.h:21
constexpr bool BlurIsEffectivelyIdentity(float sigma)
Definition: BlurUtils.h:30
SkBitmap CreateRRectBlurMask(const SkRRect &rrectToDraw, const SkISize &dimensions, float sigma)
Definition: BlurUtils.cpp:316
static constexpr int kMaxBlurSamples
Definition: BlurUtils.h:35
int ComputeIntegralTableWidth(float sixSigma)
Definition: BlurUtils.cpp:62
static constexpr float kMaxLinearBlurSigma
Definition: BlurUtils.h:36
void Compute1DBlurKernel(float sigma, int radius, SkSpan< float > kernel)
Definition: BlurUtils.h:56
void Compute2DBlurOffsets(SkISize radius, std::array< SkV4, kMaxBlurSamples/2 > &offsets)
Definition: BlurUtils.h:60
SkBitmap CreateCircleProfile(float sigma, float radius, int profileWidth)
Definition: BlurUtils.cpp:188
const SkRuntimeEffect * GetLinearBlur1DEffect(int radius)
Definition: BlurUtils.h:42
int BlurSigmaRadius(float sigma)
Definition: BlurUtils.h:33
constexpr int BlurKernelWidth(int radius)
Definition: BlurUtils.h:26
void Compute2DBlurKernel(SkSize sigma, SkISize radius, SkSpan< float > kernel)
Definition: BlurUtils.h:46
constexpr int BlurLinearKernelWidth(int radius)
Definition: BlurUtils.h:27
SkBitmap CreateHalfPlaneProfile(int profileWidth)
Definition: BlurUtils.cpp:226
SkBitmap CreateIntegralTable(int width)
Definition: BlurUtils.cpp:38
const SkRuntimeEffect * GetBlur2DEffect(const SkISize &radii)
Definition: BlurUtils.h:38
void Compute1DBlurLinearKernel(float sigma, int radius, std::array< SkV4, kMaxBlurSamples/2 > &offsetsAndKernel)
Definition: BlurUtils.h:64
int32_t width
Definition: SkSize.h:16
Definition: SkSize.h:52
Definition: SkM44.h:98