Flutter Engine
The Flutter Engine
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 {"blurData", SkSLType::kHalf2},
27 {"shapeType", SkSLType::kInt},
28 {"depth", SkSLType::kFloat}},
31 /*vertexAttrs=*/
34 /*instanceAttrs=*/{},
35 /*varyings=*/
36 // scaledShapeCoords are the fragment coordinates in local shape space, where
37 // the shape has been scaled to device space but not translated or rotated.
38 {{"scaledShapeCoords", SkSLType::kFloat2}}) {}
39
41 return R"(
42 float4 devPosition = localToDevice * float4(position, depth, 1.0);
43 stepLocalCoords = position;
44 scaledShapeCoords = (deviceToScaledShape * devPosition.xy1).xy;
45 )";
46}
47
49 const ResourceBindingRequirements& bindingReqs, int* nextBindingIndex) const {
50 return EmitSamplerLayout(bindingReqs, nextBindingIndex) + " sampler2D s;";
51}
52
54 return "outputCoverage = blur_coverage_fn(scaledShapeCoords, "
55 "shapeData, "
56 "blurData, "
57 "shapeType, "
58 "s);";
59}
60
62 const DrawParams& params,
63 skvx::ushort2 ssboIndices) const {
64 const Rect& r = params.geometry().analyticBlurMask().drawBounds();
65 DrawWriter::Vertices verts{*writer};
66 verts.append(6) << skvx::float2(r.left(), r.top()) << ssboIndices
67 << skvx::float2(r.right(), r.top()) << ssboIndices
68 << skvx::float2(r.left(), r.bot()) << ssboIndices
69 << skvx::float2(r.right(), r.top()) << ssboIndices
70 << skvx::float2(r.right(), r.bot()) << ssboIndices
71 << skvx::float2(r.left(), 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->writeHalf(blur.blurData());
84 gatherer->write(static_cast<int>(blur.shapeType()));
85 gatherer->write(params.order().depthAsFloat());
86
90 constexpr SkTileMode kTileModes[2] = {SkTileMode::kClamp, SkTileMode::kClamp};
91 gatherer->add(blur.refProxy(), {samplingOptions, kTileModes});
92}
93
94} // namespace skgpu::graphite
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
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
Definition: SkVx.h:83