Flutter Engine
The Flutter Engine
GrShadowGeoProc.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
9
19
22struct GrShaderCaps;
23
25public:
27 const GrShaderCaps&,
28 const GrGeometryProcessor&) override {}
29
30private:
31 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
32 const GrRRectShadowGeoProc& rsgp = args.fGeomProc.cast<GrRRectShadowGeoProc>();
33 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
34 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
35 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
36
37 // emit attributes
38 varyingHandler->emitAttributes(rsgp);
39 fragBuilder->codeAppend("half3 shadowParams;");
40 varyingHandler->addPassThroughAttribute(rsgp.inShadowParams().asShaderVar(),
41 "shadowParams");
42
43 // setup pass through color
44 fragBuilder->codeAppendf("half4 %s;", args.fOutputColor);
45 varyingHandler->addPassThroughAttribute(rsgp.inColor().asShaderVar(), args.fOutputColor);
46
47 // Setup position
48 WriteOutputPosition(vertBuilder, gpArgs, rsgp.inPosition().name());
49 // No need for local coordinates, this GP does not combine with fragment processors
50
51 fragBuilder->codeAppend("half d = length(shadowParams.xy);");
52 fragBuilder->codeAppend("float2 uv = float2(shadowParams.z * (1.0 - d), 0.5);");
53 fragBuilder->codeAppend("half factor = ");
54 fragBuilder->appendTextureLookup(args.fTexSamplers[0], "uv");
55 fragBuilder->codeAppend(".a;");
56 fragBuilder->codeAppendf("half4 %s = half4(factor);", args.fOutputCoverage);
57 }
58};
59
60///////////////////////////////////////////////////////////////////////////////
61
62GrRRectShadowGeoProc::GrRRectShadowGeoProc(const GrSurfaceProxyView& lutView)
63 : INHERITED(kGrRRectShadowGeoProc_ClassID) {
64 fInPosition = {"inPosition", kFloat2_GrVertexAttribType, SkSLType::kFloat2};
66 fInShadowParams = {"inShadowParams", kFloat3_GrVertexAttribType, SkSLType::kHalf3};
67 this->setVertexAttributesWithImplicitOffsets(&fInPosition, 3);
68
69 SkASSERT(lutView.proxy());
70 fLUTTextureSampler.reset(GrSamplerState::Filter::kLinear, lutView.proxy()->backendFormat(),
71 lutView.swizzle());
72 this->setTextureSamplerCnt(1);
73}
74
75std::unique_ptr<GrGeometryProcessor::ProgramImpl> GrRRectShadowGeoProc::makeProgramImpl(
76 const GrShaderCaps&) const {
77 return std::make_unique<Impl>();
78}
79
80///////////////////////////////////////////////////////////////////////////////
81
83
84#if defined(GR_TEST_UTILS)
85GrGeometryProcessor* GrRRectShadowGeoProc::TestCreate(GrProcessorTestData* d) {
86 auto [view, ct, at] = d->randomAlphaOnlyView();
87
88 return GrRRectShadowGeoProc::Make(d->allocator(), view);
89}
90#endif
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...)
@ kFloat2_GrVertexAttribType
Definition: GrTypesPriv.h:314
@ kUByte4_norm_GrVertexAttribType
Definition: GrTypesPriv.h:334
@ kFloat3_GrVertexAttribType
Definition: GrTypesPriv.h:315
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
void codeAppend(const char *str)
void appendTextureLookup(SkString *out, SamplerHandle, const char *coordName) const
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
void emitAttributes(const GrGeometryProcessor &)
void addPassThroughAttribute(const GrShaderVar &vsVar, const char *output, Interpolation=Interpolation::kInterpolated)
constexpr const char * name() const
static void WriteOutputPosition(GrGLSLVertexBuilder *, GrGPArgs *, const char *posName)
void setTextureSamplerCnt(int cnt)
void setVertexAttributesWithImplicitOffsets(const Attribute *attrs, int attrCount)
void setData(const GrGLSLProgramDataManager &, const GrShaderCaps &, const GrGeometryProcessor &) override
const Attribute & inShadowParams() const
static GrGeometryProcessor * Make(SkArenaAlloc *arena, const GrSurfaceProxyView &lutView)
const Attribute & inColor() const
std::unique_ptr< ProgramImpl > makeProgramImpl(const GrShaderCaps &) const override
const Attribute & inPosition() const
skgpu::Swizzle swizzle() const
GrSurfaceProxy * proxy() const
const GrBackendFormat & backendFormat() const
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args