Flutter Engine
The Flutter Engine
CoverBoundsRenderStep.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 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
10#include "src/base/SkVx.h"
14
15namespace skgpu::graphite {
16
18 : RenderStep("CoverBoundsRenderStep",
19 inverseFill ? "inverse" : "regular",
20 Flags::kPerformsShading,
21 /*uniforms=*/{},
24 /*vertexAttrs=*/{{"position",
27 /*instanceAttrs=*/{{"bounds", VertexAttribType::kFloat4, SkSLType::kFloat4},
33 , fInverseFill(inverseFill) {}
34
36
38 // Returns the body of a vertex function, which must define a float4 devPosition variable and
39 // must write to an already-defined float2 stepLocalCoords variable.
40 return "float4 devPosition = cover_bounds_vertex_fn("
41 "float2(sk_VertexID / 2, sk_VertexID % 2), "
42 "bounds, depth, float3x3(mat0, mat1, mat2), "
43 "stepLocalCoords);\n";
44}
45
47 const DrawParams& params,
48 skvx::ushort2 ssboIndices) const {
49 // Each instance is 4 vertices, forming 2 triangles from a single triangle strip, so no indices
50 // are needed. sk_VertexID is used to place vertex positions, so no vertex buffer is needed.
51 DrawWriter::Instances instances{*writer, {}, {}, 4};
52
54 const SkM44* m;
55 if (fInverseFill) {
56 // Normally all bounding boxes are sorted such that l<r and t<b. We upload an inverted
57 // rectangle [r,b,l,t] when it's an inverse fill to encode that the bounds are already in
58 // device space and then use the inverse of the transform to compute local coordinates.
59 bounds = skvx::shuffle</*R*/2, /*B*/3, /*L*/0, /*T*/1>(
60 skvx::cast<float>(skvx::int4::Load(&params.clip().scissor())));
61 m = &params.transform().inverse();
62 } else {
63 bounds = params.geometry().bounds().ltrb();
64 m = &params.transform().matrix();
65 }
66
67 // Since the local coords always have Z=0, we can discard the 3rd row and column of the matrix.
68 instances.append(1) << bounds << params.order().depthAsFloat() << ssboIndices
69 << m->rc(0,0) << m->rc(1,0) << m->rc(3,0)
70 << m->rc(0,1) << m->rc(1,1) << m->rc(3,1)
71 << m->rc(0,3) << m->rc(1,3) << m->rc(3,3);
72}
73
75 PipelineDataGatherer*) const {
76 // All data is uploaded as instance attributes, so no uniforms are needed.
77}
78
79} // namespace skgpu::graphite
Definition: SkM44.h:150
void writeVertices(DrawWriter *, const DrawParams &, skvx::ushort2 ssboIndices) const override
void writeUniformsAndTextures(const DrawParams &, PipelineDataGatherer *) const override
const EmbeddedViewParams * params
Optional< SkRect > bounds
Definition: SkRecords.h:189
constexpr DepthStencilSettings kRegularCoverPass
constexpr DepthStencilSettings kInverseCoverPass
SI Vec< sizeof...(Ix), T > shuffle(const Vec< N, T > &)
Definition: SkVx.h:667
Definition: SkVx.h:83
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109