Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skgpu::graphite::SDFTextLCDRenderStep Class Referencefinal

#include <SDFTextLCDRenderStep.h>

Inheritance diagram for skgpu::graphite::SDFTextLCDRenderStep:
skgpu::graphite::RenderStep

Public Member Functions

 SDFTextLCDRenderStep ()
 
 ~SDFTextLCDRenderStep () override
 
std::string vertexSkSL () const override
 
std::string texturesAndSamplersSkSL (const ResourceBindingRequirements &, int *nextBindingIndex) const override
 
const char * fragmentCoverageSkSL () const override
 
void writeVertices (DrawWriter *, const DrawParams &, skvx::ushort2 ssboIndices) const override
 
void writeUniformsAndTextures (const DrawParams &, PipelineDataGatherer *) const override
 
- Public Member Functions inherited from skgpu::graphite::RenderStep
virtual ~RenderStep ()=default
 
virtual void writeVertices (DrawWriter *, const DrawParams &, skvx::ushort2 ssboIndices) const =0
 
virtual void writeUniformsAndTextures (const DrawParams &, PipelineDataGatherer *) const =0
 
virtual std::string vertexSkSL () const =0
 
virtual std::string texturesAndSamplersSkSL (const ResourceBindingRequirements &, int *nextBindingIndex) const
 
virtual const char * fragmentCoverageSkSL () const
 
virtual const char * fragmentColorSkSL () const
 
uint32_t uniqueID () const
 
const char * name () const
 
bool requiresMSAA () const
 
bool performsShading () const
 
bool hasTextures () const
 
bool emitsPrimitiveColor () const
 
bool outsetBoundsForAA () const
 
Coverage coverage () const
 
PrimitiveType primitiveType () const
 
size_t vertexStride () const
 
size_t instanceStride () const
 
size_t numUniforms () const
 
size_t numVertexAttributes () const
 
size_t numInstanceAttributes () const
 
SkSpan< const Uniformuniforms () const
 
SkSpan< const AttributevertexAttributes () const
 
SkSpan< const AttributeinstanceAttributes () const
 
SkSpan< const Varyingvaryings () const
 
const DepthStencilSettingsdepthStencilSettings () const
 
SkEnumBitMask< DepthStencilFlagsdepthStencilFlags () const
 

Additional Inherited Members

- Static Public Member Functions inherited from skgpu::graphite::RenderStep
static const char * ssboIndicesAttribute ()
 
static const char * ssboIndicesVarying ()
 
- Protected Types inherited from skgpu::graphite::RenderStep
enum class  Flags : unsigned {
  kNone = 0b0000000 , kRequiresMSAA = 0b0000001 , kPerformsShading = 0b0000010 , kHasTextures = 0b0000100 ,
  kEmitsCoverage = 0b0001000 , kLCDCoverage = 0b0010000 , kEmitsPrimitiveColor = 0b0100000 , kOutsetBoundsForAA = 0b1000000
}
 
- Protected Member Functions inherited from skgpu::graphite::RenderStep
 RenderStep (std::string_view className, std::string_view variantName, SkEnumBitMask< Flags > flags, std::initializer_list< Uniform > uniforms, PrimitiveType primitiveType, DepthStencilSettings depthStencilSettings, SkSpan< const Attribute > vertexAttrs, SkSpan< const Attribute > instanceAttrs, SkSpan< const Varying > varyings={})
 

Detailed Description

Definition at line 17 of file SDFTextLCDRenderStep.h.

Constructor & Destructor Documentation

◆ SDFTextLCDRenderStep()

skgpu::graphite::SDFTextLCDRenderStep::SDFTextLCDRenderStep ( )

Definition at line 36 of file SDFTextLCDRenderStep.cpp.

37 : RenderStep("SDFTextLCDRenderStep",
38 "",
41 /*uniforms=*/{{"subRunDeviceMatrix", SkSLType::kFloat4x4},
42 {"deviceToLocal", SkSLType::kFloat4x4},
43 {"atlasSizeInv", SkSLType::kFloat2},
44 {"pixelGeometryDelta", SkSLType::kHalf2},
45 {"gammaParams", SkSLType::kHalf4}},
48 /*vertexAttrs=*/ {},
49 /*instanceAttrs=*/
54 {"strikeToSourceScale", VertexAttribType::kFloat, SkSLType::kFloat},
57 /*varyings=*/
58 {{"unormTexCoords", SkSLType::kFloat2},
59 {"textureCoords", SkSLType::kFloat2},
60 {"texIndex", SkSLType::kFloat}}) {}
RenderStep(std::string_view className, std::string_view variantName, SkEnumBitMask< Flags > flags, std::initializer_list< Uniform > uniforms, PrimitiveType primitiveType, DepthStencilSettings depthStencilSettings, SkSpan< const Attribute > vertexAttrs, SkSpan< const Attribute > instanceAttrs, SkSpan< const Varying > varyings={})
Definition: Renderer.cpp:19
static constexpr DepthStencilSettings kDirectDepthGEqualPass

◆ ~SDFTextLCDRenderStep()

skgpu::graphite::SDFTextLCDRenderStep::~SDFTextLCDRenderStep ( )
override

Definition at line 62 of file SDFTextLCDRenderStep.cpp.

62{}

Member Function Documentation

◆ fragmentCoverageSkSL()

const char * skgpu::graphite::SDFTextLCDRenderStep::fragmentCoverageSkSL ( ) const
overridevirtual

Reimplemented from skgpu::graphite::RenderStep.

Definition at line 94 of file SDFTextLCDRenderStep.cpp.

94 {
95 // The returned SkSL must write its coverage into a 'half4 outputCoverage' variable (defined in
96 // the calling code) with the actual coverage splatted out into all four channels.
97
98 // TODO: To minimize the number of shaders generated this is the full affine shader.
99 // For best performance it may be worth creating the uniform scale shader as well,
100 // as that's the most common case.
101 // TODO: Need to add 565 support.
102 // TODO: Need aliased and possibly sRGB support.
103 static_assert(kNumSDFAtlasTextures == 4);
104 return "outputCoverage = sdf_text_lcd_coverage_fn(textureCoords, "
105 "pixelGeometryDelta, "
106 "gammaParams, "
107 "unormTexCoords, "
108 "texIndex, "
109 "sdf_atlas_0, "
110 "sdf_atlas_1, "
111 "sdf_atlas_2, "
112 "sdf_atlas_3);";
113}

◆ texturesAndSamplersSkSL()

std::string skgpu::graphite::SDFTextLCDRenderStep::texturesAndSamplersSkSL ( const ResourceBindingRequirements bindingReqs,
int nextBindingIndex 
) const
overridevirtual

Reimplemented from skgpu::graphite::RenderStep.

Definition at line 82 of file SDFTextLCDRenderStep.cpp.

83 {
84 std::string result;
85
86 for (unsigned int i = 0; i < kNumSDFAtlasTextures; ++i) {
87 result += EmitSamplerLayout(bindingReqs, nextBindingIndex);
88 SkSL::String::appendf(&result, " sampler2D sdf_atlas_%u;\n", i);
89 }
90
91 return result;
92}
GAsyncResult * result
std::string void appendf(std::string *str, const char *fmt,...) SK_PRINTF_LIKE(2
Definition: SkSLString.cpp:92
std::string EmitSamplerLayout(const ResourceBindingRequirements &bindingReqs, int *binding)

◆ vertexSkSL()

std::string skgpu::graphite::SDFTextLCDRenderStep::vertexSkSL ( ) const
overridevirtual

Implements skgpu::graphite::RenderStep.

Definition at line 64 of file SDFTextLCDRenderStep.cpp.

64 {
65 // Returns the body of a vertex function, which must define a float4 devPosition variable and
66 // must write to an already-defined float2 stepLocalCoords variable.
67 return "texIndex = half(indexAndFlags.x);"
68 "float4 devPosition = text_vertex_fn(float2(sk_VertexID >> 1, sk_VertexID & 1), "
69 "subRunDeviceMatrix, "
70 "deviceToLocal, "
71 "atlasSizeInv, "
72 "float2(size), "
73 "float2(uvPos), "
74 "xyPos, "
75 "strikeToSourceScale, "
76 "depth, "
77 "textureCoords, "
78 "unormTexCoords, "
79 "stepLocalCoords);";
80}

◆ writeUniformsAndTextures()

void skgpu::graphite::SDFTextLCDRenderStep::writeUniformsAndTextures ( const DrawParams params,
PipelineDataGatherer gatherer 
) const
overridevirtual

Implements skgpu::graphite::RenderStep.

Definition at line 128 of file SDFTextLCDRenderStep.cpp.

129 {
130 SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, this->uniforms());)
131
132 const SubRunData& subRunData = params.geometry().subRunData();
133 unsigned int numProxies;
134 Recorder* recorder = subRunData.recorder();
135 const sk_sp<TextureProxy>* proxies =
137 subRunData.subRun()->maskFormat(), &numProxies);
138 SkASSERT(proxies && numProxies > 0);
139
140 // write uniforms
141 gatherer->write(params.transform().matrix()); // subRunDeviceMatrix
142 gatherer->write(subRunData.deviceToLocal());
143 SkV2 atlasDimensionsInverse = {1.f/proxies[0]->dimensions().width(),
144 1.f/proxies[0]->dimensions().height()};
145 gatherer->write(atlasDimensionsInverse);
146
147 // compute and write pixelGeometry vector
148 SkV2 pixelGeometryDelta = {0, 0};
149 if (SkPixelGeometryIsH(subRunData.pixelGeometry())) {
150 pixelGeometryDelta = {1.f/(3*proxies[0]->dimensions().width()), 0};
151 } else if (SkPixelGeometryIsV(subRunData.pixelGeometry())) {
152 pixelGeometryDelta = {0, 1.f/(3*proxies[0]->dimensions().height())};
153 }
154 if (SkPixelGeometryIsBGR(subRunData.pixelGeometry())) {
155 pixelGeometryDelta = -pixelGeometryDelta;
156 }
157 gatherer->writeHalf(pixelGeometryDelta);
158
159 // compute and write gamma adjustment
160 auto dfAdjustTable = sktext::gpu::DistanceFieldAdjustTable::Get();
161 float redCorrection = dfAdjustTable->getAdjustment(SkColorGetR(subRunData.luminanceColor()),
162 subRunData.useGammaCorrectDistanceTable());
163 float greenCorrection = dfAdjustTable->getAdjustment(SkColorGetG(subRunData.luminanceColor()),
164 subRunData.useGammaCorrectDistanceTable());
165 float blueCorrection = dfAdjustTable->getAdjustment(SkColorGetB(subRunData.luminanceColor()),
166 subRunData.useGammaCorrectDistanceTable());
167 SkV4 gammaParams = {redCorrection, greenCorrection, blueCorrection,
168 subRunData.useGammaCorrectDistanceTable() ? 1.f : 0.f};
169 gatherer->writeHalf(gammaParams);
170
171 // write textures and samplers
172 const SkSamplingOptions kSamplingOptions(SkFilterMode::kLinear);
173 constexpr SkTileMode kTileModes[2] = { SkTileMode::kClamp, SkTileMode::kClamp };
174 for (unsigned int i = 0; i < numProxies; ++i) {
175 gatherer->add(proxies[i], {kSamplingOptions, kTileModes});
176 }
177 // If the atlas has less than 4 active proxies we still need to set up samplers for the shader.
178 for (unsigned int i = numProxies; i < kNumSDFAtlasTextures; ++i) {
179 gatherer->add(proxies[0], {kSamplingOptions, kTileModes});
180 }
181}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorGetB(color)
Definition: SkColor.h:73
static bool SkPixelGeometryIsH(SkPixelGeometry geo)
static bool SkPixelGeometryIsBGR(SkPixelGeometry geo)
static bool SkPixelGeometryIsV(SkPixelGeometry geo)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
SkTileMode
Definition: SkTileMode.h:13
TextAtlasManager * textAtlasManager() const
Definition: AtlasProvider.h:53
AtlasProvider * atlasProvider()
Definition: RecorderPriv.h:61
SkSpan< const Uniform > uniforms() const
Definition: Renderer.h:143
const sk_sp< TextureProxy > * getProxies(MaskFormat format, unsigned int *numActiveProxies)
static const DistanceFieldAdjustTable * Get()
const EmbeddedViewParams * params
Definition: SkM44.h:19
Definition: SkM44.h:98

◆ writeVertices()

void skgpu::graphite::SDFTextLCDRenderStep::writeVertices ( DrawWriter dw,
const DrawParams params,
skvx::ushort2  ssboIndices 
) const
overridevirtual

Implements skgpu::graphite::RenderStep.

Definition at line 115 of file SDFTextLCDRenderStep.cpp.

117 {
118 const SubRunData& subRunData = params.geometry().subRunData();
119 subRunData.subRun()->vertexFiller().fillInstanceData(dw,
120 subRunData.startGlyphIndex(),
121 subRunData.glyphCount(),
122 subRunData.subRun()->instanceFlags(),
123 ssboIndices,
124 subRunData.subRun()->glyphs(),
125 params.order().depthAsFloat());
126}

The documentation for this class was generated from the following files: