| 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 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkScalar.h" |
| 13 |
#include "src/gpu/SkBackingFit.h" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
#include <optional> |
| 17 |
|
| 18 |
class GrClip; |
| 19 |
class GrFragmentProcessor; |
| 20 |
class GrPaint; |
| 21 |
class GrRecordingContext; |
| 22 |
class GrStyledShape; |
| 23 |
class GrSurfaceProxyView; |
| 24 |
class SkColorSpace; |
| 25 |
class SkMaskFilter; |
| 26 |
class SkMatrix; |
| 27 |
class SkPaint; |
| 28 |
class SkRRect; |
| 29 |
enum SkAlphaType : int; |
| 30 |
enum class GrColorType; |
| 31 |
enum class SkTileMode; |
| 32 |
namespace skgpu { namespace ganesh { class SurfaceDrawContext; } } |
| 33 |
struct GrShaderCaps; |
| 34 |
struct SkIRect; |
| 35 |
struct SkISize; |
| 36 |
struct SkRect; |
| 37 |
|
| 38 |
/** |
| 39 |
* Blur utilities. |
| 40 |
*/ |
| 41 |
namespace GrBlurUtils { |
| 42 |
|
| 43 |
static constexpr int kBlurRRectMaxDivisions = 6; |
| 44 |
|
| 45 |
/** |
| 46 |
* This method computes all the parameters for drawing a partially occluded nine-patched |
| 47 |
* blurred rrect mask: |
| 48 |
* rrectToDraw - the integerized rrect to draw in the mask |
| 49 |
* widthHeight - how large to make the mask (rrectToDraw will be centered in this coord system). |
| 50 |
* rectXs, rectYs - the x & y coordinates of the covering geometry lattice |
| 51 |
* texXs, texYs - the texture coordinate at each point in rectXs & rectYs |
| 52 |
* It returns true if 'devRRect' is nine-patchable |
| 53 |
*/ |
| 54 |
bool ComputeBlurredRRectParams(const SkRRect& srcRRect, |
| 55 |
const SkRRect& devRRect, |
| 56 |
SkScalar sigma, |
| 57 |
SkScalar xformedSigma, |
| 58 |
SkRRect* rrectToDraw, |
| 59 |
SkISize* widthHeight, |
| 60 |
SkScalar rectXs[kBlurRRectMaxDivisions], |
| 61 |
SkScalar rectYs[kBlurRRectMaxDivisions], |
| 62 |
SkScalar texXs[kBlurRRectMaxDivisions], |
| 63 |
SkScalar texYs[kBlurRRectMaxDivisions]); |
| 64 |
|
| 65 |
/** |
| 66 |
* Draw a shape handling the mask filter if present. |
| 67 |
*/ |
| 68 |
void DrawShapeWithMaskFilter(GrRecordingContext*, |
| 69 |
skgpu::ganesh::SurfaceDrawContext*, |
| 70 |
const GrClip*, |
| 71 |
const SkPaint&, |
| 72 |
const SkMatrix&, |
| 73 |
const GrStyledShape&); |
| 74 |
|
| 75 |
/** |
| 76 |
* Draw a shape handling the mask filter. The mask filter is not optional. |
| 77 |
* The GrPaint will be modified after return. |
| 78 |
*/ |
| 79 |
void DrawShapeWithMaskFilter(GrRecordingContext*, |
| 80 |
skgpu::ganesh::SurfaceDrawContext*, |
| 81 |
const GrClip*, |
| 82 |
const GrStyledShape&, |
| 83 |
GrPaint&&, |
| 84 |
const SkMatrix& viewMatrix, |
| 85 |
const SkMaskFilter*); |
| 86 |
|
| 87 |
/** |
| 88 |
* Applies a 2D Gaussian blur to a given texture. The blurred result is returned |
| 89 |
* as a surfaceDrawContext in case the caller wishes to draw into the result. |
| 90 |
* The GrSurfaceOrigin of the result will watch the GrSurfaceOrigin of srcView. The output |
| 91 |
* color type, color space, and alpha type will be the same as the src. |
| 92 |
* |
| 93 |
* Note: one of sigmaX and sigmaY should be non-zero! |
| 94 |
* @param context The GPU context |
| 95 |
* @param srcView The source to be blurred. |
| 96 |
* @param srcColorType The colorType of srcProxy |
| 97 |
* @param srcAlphaType The alphaType of srcProxy |
| 98 |
* @param srcColorSpace Color space of the source. |
| 99 |
* @param dstBounds The destination bounds, relative to the source texture. |
| 100 |
* @param srcBounds The source bounds, relative to the source texture's offset. No pixels |
| 101 |
* will be sampled outside of this rectangle. |
| 102 |
* @param sigmaX The blur's standard deviation in X. |
| 103 |
* @param sigmaY The blur's standard deviation in Y. |
| 104 |
* @param tileMode The mode to handle samples outside bounds. |
| 105 |
* @param fit backing fit for the returned render target context |
| 106 |
* @return The surfaceDrawContext containing the blurred result. |
| 107 |
*/ |
| 108 |
std::unique_ptr<skgpu::ganesh::SurfaceDrawContext> GaussianBlur( |
| 109 |
GrRecordingContext*, |
| 110 |
GrSurfaceProxyView srcView, |
| 111 |
GrColorType srcColorType, |
| 112 |
SkAlphaType srcAlphaType, |
| 113 |
sk_sp<SkColorSpace> srcColorSpace, |
| 114 |
SkIRect dstBounds, |
| 115 |
SkIRect srcBounds, |
| 116 |
float sigmaX, |
| 117 |
float sigmaY, |
| 118 |
SkTileMode mode, |
| 119 |
SkBackingFit fit = SkBackingFit::kApprox); |
| 120 |
|
| 121 |
std::unique_ptr<GrFragmentProcessor> MakeCircleBlur(GrRecordingContext* context, |
| 122 |
const SkRect& circle, |
| 123 |
float sigma); |
| 124 |
|
| 125 |
std::unique_ptr<GrFragmentProcessor> MakeRectBlur(GrRecordingContext* context, |
| 126 |
const GrShaderCaps& caps, |
| 127 |
const SkRect& srcRect, |
| 128 |
const std::optional<SkRect>& devRect, |
| 129 |
const SkMatrix& viewMatrix, |
| 130 |
float transformedSigma); |
| 131 |
|
| 132 |
std::unique_ptr<GrFragmentProcessor> MakeRRectBlur(GrRecordingContext* context, |
| 133 |
float sigma, |
| 134 |
float xformedSigma, |
| 135 |
const SkRRect& srcRRect, |
| 136 |
const SkRRect& devRRect); |
| 137 |
|
| 138 |
} // namespace GrBlurUtils |
| 139 |
|
| 140 |
#endif |