Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrBlurUtils.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 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
8#ifndef GrBlurUtils_DEFINED
9#define GrBlurUtils_DEFINED
10
14
15#include <memory>
16
17class GrClip;
18class GrPaint;
20class GrStyledShape;
22class SkColorSpace;
23class SkMaskFilter;
24class SkMatrix;
25class SkPaint;
26class SkRRect;
27enum SkAlphaType : int;
28enum class GrColorType;
29enum class SkTileMode;
30namespace skgpu { namespace ganesh { class SurfaceDrawContext; } }
31struct SkIRect;
32struct SkISize;
33
34/**
35 * Blur utilities.
36 */
37namespace GrBlurUtils {
38
39static constexpr int kBlurRRectMaxDivisions = 6;
40
41/**
42 * This method computes all the parameters for drawing a partially occluded nine-patched
43 * blurred rrect mask:
44 * rrectToDraw - the integerized rrect to draw in the mask
45 * widthHeight - how large to make the mask (rrectToDraw will be centered in this coord system).
46 * rectXs, rectYs - the x & y coordinates of the covering geometry lattice
47 * texXs, texYs - the texture coordinate at each point in rectXs & rectYs
48 * It returns true if 'devRRect' is nine-patchable
49 */
50bool ComputeBlurredRRectParams(const SkRRect& srcRRect,
51 const SkRRect& devRRect,
52 SkScalar sigma,
53 SkScalar xformedSigma,
54 SkRRect* rrectToDraw,
55 SkISize* widthHeight,
60
61/**
62 * Draw a shape handling the mask filter if present.
63 */
66 const GrClip*,
67 const SkPaint&,
68 const SkMatrix&,
69 const GrStyledShape&);
70
71/**
72 * Draw a shape handling the mask filter. The mask filter is not optional.
73 * The GrPaint will be modified after return.
74 */
77 const GrClip*,
78 const GrStyledShape&,
79 GrPaint&&,
80 const SkMatrix& viewMatrix,
81 const SkMaskFilter*);
82
83/**
84 * Applies a 2D Gaussian blur to a given texture. The blurred result is returned
85 * as a surfaceDrawContext in case the caller wishes to draw into the result.
86 * The GrSurfaceOrigin of the result will watch the GrSurfaceOrigin of srcView. The output
87 * color type, color space, and alpha type will be the same as the src.
88 *
89 * Note: one of sigmaX and sigmaY should be non-zero!
90 * @param context The GPU context
91 * @param srcView The source to be blurred.
92 * @param srcColorType The colorType of srcProxy
93 * @param srcAlphaType The alphaType of srcProxy
94 * @param srcColorSpace Color space of the source.
95 * @param dstBounds The destination bounds, relative to the source texture.
96 * @param srcBounds The source bounds, relative to the source texture's offset. No pixels
97 * will be sampled outside of this rectangle.
98 * @param sigmaX The blur's standard deviation in X.
99 * @param sigmaY The blur's standard deviation in Y.
100 * @param tileMode The mode to handle samples outside bounds.
101 * @param fit backing fit for the returned render target context
102 * @return The surfaceDrawContext containing the blurred result.
103 */
104std::unique_ptr<skgpu::ganesh::SurfaceDrawContext> GaussianBlur(
106 GrSurfaceProxyView srcView,
107 GrColorType srcColorType,
108 SkAlphaType srcAlphaType,
109 sk_sp<SkColorSpace> srcColorSpace,
110 SkIRect dstBounds,
111 SkIRect srcBounds,
112 float sigmaX,
113 float sigmaY,
114 SkTileMode mode,
116
117} // namespace GrBlurUtils
118
119#endif
GrColorType
SkAlphaType
Definition SkAlphaType.h:26
SkBackingFit
SkTileMode
Definition SkTileMode.h:13
Type::kYUV Type::kRGBA() int(0.7 *637)
float SkScalar
Definition extension.cpp:12
static constexpr int kBlurRRectMaxDivisions
Definition GrBlurUtils.h:39
bool ComputeBlurredRRectParams(const SkRRect &srcRRect, const SkRRect &devRRect, SkScalar sigma, SkScalar xformedSigma, SkRRect *rrectToDraw, SkISize *widthHeight, SkScalar rectXs[kBlurRRectMaxDivisions], SkScalar rectYs[kBlurRRectMaxDivisions], SkScalar texXs[kBlurRRectMaxDivisions], SkScalar texYs[kBlurRRectMaxDivisions])
void DrawShapeWithMaskFilter(GrRecordingContext *rContext, skgpu::ganesh::SurfaceDrawContext *sdc, const GrClip *clip, const GrStyledShape &shape, GrPaint &&paint, const SkMatrix &viewMatrix, const SkMaskFilter *mf)
std::unique_ptr< skgpu::ganesh::SurfaceDrawContext > GaussianBlur(GrRecordingContext *rContext, GrSurfaceProxyView srcView, GrColorType srcColorType, SkAlphaType srcAlphaType, sk_sp< SkColorSpace > colorSpace, SkIRect dstBounds, SkIRect srcBounds, float sigmaX, float sigmaY, SkTileMode mode, SkBackingFit fit)