Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
AnalyticBlurRenderStep.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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
9
15
16namespace skgpu::graphite {
17
19 : RenderStep("AnalyticBlurRenderStep",
20 "",
21 Flags::kPerformsShading | Flags::kHasTextures | Flags::kEmitsCoverage,
22 /*uniforms=*/
23 {{"localToDevice", SkSLType::kFloat4x4},
24 {"deviceToScaledShape", SkSLType::kFloat3x3},
25 {"shapeData", SkSLType::kFloat4},
26 {"depth", SkSLType::kFloat},
27 {"shapeType", SkSLType::kInt},
28 {"isFast", SkSLType::kInt},
29 {"invSixSigma", SkSLType::kHalf}},
32 /*vertexAttrs=*/
35 /*instanceAttrs=*/{},
36 /*varyings=*/
37 // scaledShapeCoords are the fragment coordinates in local shape space, where
38 // the shape has been scaled to device space but not translated or rotated.
39 {{"scaledShapeCoords", SkSLType::kFloat2}}) {}
40
42 return R"(
43 float4 devPosition = localToDevice * float4(position, depth, 1.0);
44 stepLocalCoords = position;
45 scaledShapeCoords = (deviceToScaledShape * devPosition.xy1).xy;
46 )";
47}
48
50 const ResourceBindingRequirements& bindingReqs, int* nextBindingIndex) const {
51 return EmitSamplerLayout(bindingReqs, nextBindingIndex) + " sampler2D s;";
52}
53
55 return "outputCoverage = blur_coverage_fn(scaledShapeCoords, "
56 "shapeData, "
57 "shapeType, "
58 "isFast, "
59 "invSixSigma, "
60 "s);";
61}
62
64 const DrawParams& params,
65 skvx::ushort2 ssboIndices) const {
66 const Rect& r = params.geometry().analyticBlurMask().drawBounds();
67 DrawWriter::Vertices verts{*writer};
68 verts.append(4) << skvx::float2(r.left(), r.top()) << ssboIndices
69 << skvx::float2(r.right(), r.top()) << ssboIndices
70 << skvx::float2(r.left(), r.bot()) << ssboIndices
71 << skvx::float2(r.right(), r.bot()) << ssboIndices;
72}
73
75 PipelineDataGatherer* gatherer) const {
76 SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, this->uniforms());)
77
78 gatherer->write(params.transform().matrix());
79
80 const AnalyticBlurMask& blur = params.geometry().analyticBlurMask();
81 gatherer->write(blur.deviceToScaledShape().asM33());
82 gatherer->write(blur.shapeData().asSkRect());
83 gatherer->write(params.order().depthAsFloat());
84 gatherer->write(static_cast<int>(blur.shapeType()));
85 gatherer->write(blur.isFast());
86 gatherer->writeHalf(blur.invSixSigma());
87
91 constexpr SkTileMode kTileModes[2] = {SkTileMode::kClamp, SkTileMode::kClamp};
92 gatherer->add(samplingOptions, kTileModes, blur.refProxy());
93}
94
95} // namespace skgpu::graphite
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
SkTileMode
Definition SkTileMode.h:13
SkMatrix asM33() const
Definition SkM44.h:409
const SkM44 & deviceToScaledShape() const
sk_sp< TextureProxy > refProxy() const
std::string texturesAndSamplersSkSL(const ResourceBindingRequirements &, int *nextBindingIndex) const override
void writeVertices(DrawWriter *, const DrawParams &, skvx::ushort2 ssboIndices) const override
void writeUniformsAndTextures(const DrawParams &, PipelineDataGatherer *) const override
const char * fragmentCoverageSkSL() const override
AI float bot() const
Definition Rect.h:79
AI float top() const
Definition Rect.h:77
AI float left() const
Definition Rect.h:76
AI SkRect asSkRect() const
Definition Rect.h:91
AI float right() const
Definition Rect.h:78
SkSpan< const Uniform > uniforms() const
Definition Renderer.h:143
const EmbeddedViewParams * params
static constexpr DepthStencilSettings kDirectDepthGreaterPass
std::string EmitSamplerLayout(const ResourceBindingRequirements &bindingReqs, int *binding)
Vec< 2, float > float2
Definition SkVx.h:1145