Flutter Engine
The Flutter Engine
third_party
skia
src
gpu
ganesh
effects
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
8
#include "
src/gpu/ganesh/effects/GrShadowGeoProc.h
"
9
10
#include "
include/core/SkSamplingOptions.h
"
11
#include "
include/private/base/SkAssert.h
"
12
#include "
include/private/gpu/ganesh/GrTypesPriv.h
"
13
#include "
src/core/SkSLTypeShared.h
"
14
#include "
src/gpu/ganesh/GrSamplerState.h
"
15
#include "
src/gpu/ganesh/GrSurfaceProxy.h
"
16
#include "
src/gpu/ganesh/GrSurfaceProxyView.h
"
17
#include "
src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h
"
18
#include "
src/gpu/ganesh/glsl/GrGLSLVarying.h
"
19
20
class
GrGLSLProgramDataManager
;
21
class
GrGLSLVertexBuilder
;
22
struct
GrShaderCaps
;
23
24
class
GrRRectShadowGeoProc::Impl
:
public
ProgramImpl
{
25
public
:
26
void
setData
(
const
GrGLSLProgramDataManager
&,
27
const
GrShaderCaps
&,
28
const
GrGeometryProcessor
&)
override
{}
29
30
private
:
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
62
GrRRectShadowGeoProc::GrRRectShadowGeoProc(
const
GrSurfaceProxyView
& lutView)
63
:
INHERITED
(kGrRRectShadowGeoProc_ClassID) {
64
fInPosition = {
"inPosition"
,
kFloat2_GrVertexAttribType
,
SkSLType::kFloat2
};
65
fInColor = {
"inColor"
,
kUByte4_norm_GrVertexAttribType
,
SkSLType::kHalf4
};
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
75
std::unique_ptr<GrGeometryProcessor::ProgramImpl>
GrRRectShadowGeoProc::makeProgramImpl
(
76
const
GrShaderCaps
&)
const
{
77
return
std::make_unique<Impl>();
78
}
79
80
///////////////////////////////////////////////////////////////////////////////
81
82
GR_DEFINE_GEOMETRY_PROCESSOR_TEST
(
GrRRectShadowGeoProc
)
83
84
#if defined(GR_TEST_UTILS)
85
GrGeometryProcessor
* GrRRectShadowGeoProc::TestCreate(GrProcessorTestData*
d
) {
86
auto
[view, ct, at] =
d
->randomAlphaOnlyView();
87
88
return
GrRRectShadowGeoProc::Make
(
d
->allocator(), view);
89
}
90
#endif
GrGLSLFragmentShaderBuilder.h
GrGLSLVarying.h
GR_DEFINE_GEOMETRY_PROCESSOR_TEST
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...)
Definition:
GrProcessorUnitTest.h:191
GrSamplerState.h
GrShadowGeoProc.h
GrSurfaceProxyView.h
GrSurfaceProxy.h
GrTypesPriv.h
kFloat2_GrVertexAttribType
@ kFloat2_GrVertexAttribType
Definition:
GrTypesPriv.h:314
kUByte4_norm_GrVertexAttribType
@ kUByte4_norm_GrVertexAttribType
Definition:
GrTypesPriv.h:334
kFloat3_GrVertexAttribType
@ kFloat3_GrVertexAttribType
Definition:
GrTypesPriv.h:315
SkAssert.h
SkASSERT
#define SkASSERT(cond)
Definition:
SkAssert.h:116
INHERITED
#define INHERITED(method,...)
Definition:
SkRecorder.cpp:128
SkSLTypeShared.h
SkSLType::kHalf4
@ kHalf4
SkSLType::kFloat2
@ kFloat2
SkSLType::kHalf3
@ kHalf3
SkSamplingOptions.h
SkFilterMode::kLinear
@ kLinear
GrGLSLFPFragmentBuilder
Definition:
GrGLSLFragmentShaderBuilder.h:24
GrGLSLProgramDataManager
Definition:
GrGLSLProgramDataManager.h:26
GrGLSLShaderBuilder::codeAppend
void codeAppend(const char *str)
Definition:
GrGLSLShaderBuilder.h:120
GrGLSLShaderBuilder::appendTextureLookup
void appendTextureLookup(SkString *out, SamplerHandle, const char *coordName) const
Definition:
GrGLSLShaderBuilder.cpp:101
GrGLSLShaderBuilder::codeAppendf
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
GrGLSLVaryingHandler
Definition:
GrGLSLVarying.h:91
GrGLSLVaryingHandler::emitAttributes
void emitAttributes(const GrGeometryProcessor &)
Definition:
GrGLSLVarying.cpp:64
GrGLSLVaryingHandler::addPassThroughAttribute
void addPassThroughAttribute(const GrShaderVar &vsVar, const char *output, Interpolation=Interpolation::kInterpolated)
Definition:
GrGLSLVarying.cpp:17
GrGLSLVertexBuilder
Definition:
GrGLSLVertexGeoBuilder.h:49
GrGeometryProcessor::Attribute::asShaderVar
GrShaderVar asShaderVar() const
Definition:
GrGeometryProcessor.h:116
GrGeometryProcessor::Attribute::name
constexpr const char * name() const
Definition:
GrGeometryProcessor.h:98
GrGeometryProcessor::ProgramImpl
Definition:
GrGeometryProcessor.h:261
GrGeometryProcessor::ProgramImpl::WriteOutputPosition
static void WriteOutputPosition(GrGLSLVertexBuilder *, GrGPArgs *, const char *posName)
GrGeometryProcessor
Definition:
GrGeometryProcessor.h:53
GrGeometryProcessor::setTextureSamplerCnt
void setTextureSamplerCnt(int cnt)
Definition:
GrGeometryProcessor.h:244
GrGeometryProcessor::setVertexAttributesWithImplicitOffsets
void setVertexAttributesWithImplicitOffsets(const Attribute *attrs, int attrCount)
Definition:
GrGeometryProcessor.h:237
GrRRectShadowGeoProc::Impl
Definition:
GrShadowGeoProc.cpp:24
GrRRectShadowGeoProc::Impl::setData
void setData(const GrGLSLProgramDataManager &, const GrShaderCaps &, const GrGeometryProcessor &) override
Definition:
GrShadowGeoProc.cpp:26
GrRRectShadowGeoProc
Definition:
GrShadowGeoProc.h:26
GrRRectShadowGeoProc::inShadowParams
const Attribute & inShadowParams() const
Definition:
GrShadowGeoProc.h:38
GrRRectShadowGeoProc::Make
static GrGeometryProcessor * Make(SkArenaAlloc *arena, const GrSurfaceProxyView &lutView)
Definition:
GrShadowGeoProc.h:28
GrRRectShadowGeoProc::inColor
const Attribute & inColor() const
Definition:
GrShadowGeoProc.h:37
GrRRectShadowGeoProc::makeProgramImpl
std::unique_ptr< ProgramImpl > makeProgramImpl(const GrShaderCaps &) const override
Definition:
GrShadowGeoProc.cpp:75
GrRRectShadowGeoProc::inPosition
const Attribute & inPosition() const
Definition:
GrShadowGeoProc.h:36
GrSurfaceProxyView
Definition:
GrSurfaceProxyView.h:34
GrSurfaceProxyView::swizzle
skgpu::Swizzle swizzle() const
Definition:
GrSurfaceProxyView.h:72
GrSurfaceProxyView::proxy
GrSurfaceProxy * proxy() const
Definition:
GrSurfaceProxyView.h:62
GrSurfaceProxy::backendFormat
const GrBackendFormat & backendFormat() const
Definition:
GrSurfaceProxy.h:173
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition:
fl_event_channel.h:89
GrShaderCaps
Definition:
GrShaderCaps.h:17
Generated on Sun Jun 23 2024 21:56:18 for Flutter Engine by
1.9.4