Flutter Engine
The Flutter Engine
third_party
skia
src
gpu
ganesh
effects
GrModulateAtlasCoverageEffect.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2021 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
8
#include "
src/gpu/ganesh/effects/GrModulateAtlasCoverageEffect.h
"
9
10
#include "
include/core/SkAlphaType.h
"
11
#include "
include/core/SkSamplingOptions.h
"
12
#include "
include/core/SkString.h
"
13
#include "
include/private/SkSLSampleUsage.h
"
14
#include "
include/private/gpu/ganesh/GrTypesPriv.h
"
15
#include "
src/core/SkSLTypeShared.h
"
16
#include "
src/gpu/KeyBuilder.h
"
17
#include "
src/gpu/ganesh/GrSamplerState.h
"
18
#include "
src/gpu/ganesh/GrSurfaceProxyView.h
"
19
#include "
src/gpu/ganesh/effects/GrTextureEffect.h
"
20
#include "
src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h
"
21
#include "
src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h
"
22
#include "
src/gpu/ganesh/glsl/GrGLSLUniformHandler.h
"
23
24
#include <utility>
25
26
class
SkMatrix
;
27
struct
GrShaderCaps
;
28
29
GrModulateAtlasCoverageEffect::GrModulateAtlasCoverageEffect
(
30
Flags
flags
,
31
std::unique_ptr<GrFragmentProcessor> inputFP,
32
GrSurfaceProxyView
atlasView,
33
const
SkMatrix
& devToAtlasMatrix,
34
const
SkIRect
& devIBounds)
35
:
GrFragmentProcessor
(kTessellate_GrModulateAtlasCoverageEffect_ClassID,
36
kCompatibleWithCoverageAsAlpha_OptimizationFlag)
37
,
fFlags
(
flags
)
38
,
fBounds
((
fFlags
&
Flags
::kCheckBounds) ? devIBounds :
SkIRect
{0,0,0,0}) {
39
this->
registerChild
(std::move(inputFP));
40
this->
registerChild
(
GrTextureEffect::Make
(std::move(atlasView),
kUnknown_SkAlphaType
,
41
devToAtlasMatrix,
GrSamplerState::Filter::kNearest
),
42
SkSL::SampleUsage::Explicit
());
43
}
44
45
GrModulateAtlasCoverageEffect::GrModulateAtlasCoverageEffect
(
46
const
GrModulateAtlasCoverageEffect
& that)
47
:
GrFragmentProcessor
(that)
48
,
fFlags
(that.
fFlags
)
49
,
fBounds
(that.
fBounds
) {}
50
51
void
GrModulateAtlasCoverageEffect::onAddToKey(
const
GrShaderCaps
&,
52
skgpu::KeyBuilder
*
b
)
const
{
53
b
->add32(
fFlags
&
Flags::kCheckBounds
);
54
}
55
56
std::unique_ptr<GrFragmentProcessor::ProgramImpl>
57
GrModulateAtlasCoverageEffect::onMakeProgramImpl()
const
{
58
class
Impl :
public
ProgramImpl
{
59
void
emitCode(EmitArgs&
args
)
override
{
60
auto
fp
=
args
.fFp.cast<
GrModulateAtlasCoverageEffect
>();
61
auto
f
=
args
.fFragBuilder;
62
auto
uniHandler =
args
.fUniformHandler;
63
SkString
inputColor = this->invokeChild(0,
args
);
64
f
->codeAppend(
"half coverage = 0;"
);
65
if
(
fp
.fFlags &
Flags::kCheckBounds
) {
66
const
char
* boundsName;
67
fBoundsUniform = uniHandler->addUniform(&
fp
,
kFragment_GrShaderFlag
,
68
SkSLType::kFloat4
,
"bounds"
, &boundsName);
69
// Are we inside the path's valid atlas bounds?
70
f
->codeAppendf(
"if (all(greaterThan(sk_FragCoord.xy, %s.xy)) && "
71
"all(lessThan(sk_FragCoord.xy, %s.zw))) "
,
72
boundsName, boundsName);
73
}
74
f
->codeAppendf(
"{"
);
75
SkString
atlasCoverage = this->invokeChild(1,
args
,
"sk_FragCoord.xy"
);
76
f
->codeAppendf(
"coverage = %s.a;"
, atlasCoverage.
c_str
());
77
f
->codeAppendf(
"}"
);
78
const
char
* coverageMaybeInvertName;
79
fCoverageMaybeInvertUniform = uniHandler->addUniform(&
fp
,
kFragment_GrShaderFlag
,
80
SkSLType::kHalf2
,
"coverageInvert"
,
81
&coverageMaybeInvertName);
82
// Invert coverage, if needed.
83
f
->codeAppendf(
"coverage = coverage * %s.x + %s.y;"
,
84
coverageMaybeInvertName, coverageMaybeInvertName);
85
f
->codeAppendf(
"return %s * coverage;"
, inputColor.
c_str
());
86
}
87
88
private
:
89
void
onSetData(
const
GrGLSLProgramDataManager
& pdman,
90
const
GrFragmentProcessor
& processor)
override
{
91
const
auto
&
fp
= processor.
cast
<
GrModulateAtlasCoverageEffect
>();
92
if
(
fp
.fFlags &
Flags::kCheckBounds
) {
93
pdman.
set4fv
(fBoundsUniform, 1,
SkRect::Make
(
fp
.fBounds).
asScalars
());
94
}
95
if
(
fp
.fFlags &
Flags::kInvertCoverage
) {
96
pdman.
set2f
(fCoverageMaybeInvertUniform, -1, 1);
// -1*coverage + 1 = 1 - coverage.
97
}
else
{
98
pdman.
set2f
(fCoverageMaybeInvertUniform, 1, 0);
// 1*coverage + 0 = coverage.
99
}
100
}
101
UniformHandle fBoundsUniform;
102
UniformHandle fCoverageMaybeInvertUniform;
103
};
104
105
return
std::make_unique<Impl>();
106
}
GrGLSLFragmentShaderBuilder.h
GrGLSLProgramDataManager.h
GrGLSLUniformHandler.h
GrModulateAtlasCoverageEffect.h
GrSamplerState.h
GrSurfaceProxyView.h
GrTextureEffect.h
GrTypesPriv.h
kFragment_GrShaderFlag
@ kFragment_GrShaderFlag
Definition:
GrTypesPriv.h:287
KeyBuilder.h
fBounds
const SkRect fBounds
Definition:
ParsePathTest.cpp:38
fFlags
uint16_t fFlags
Definition:
ShapeLayer.cpp:106
SkAlphaType.h
kUnknown_SkAlphaType
@ kUnknown_SkAlphaType
uninitialized
Definition:
SkAlphaType.h:27
SkSLSampleUsage.h
SkSLTypeShared.h
SkSLType::kFloat4
@ kFloat4
SkSLType::kHalf2
@ kHalf2
SkSamplingOptions.h
SkFilterMode::kNearest
@ kNearest
SkString.h
GrFragmentProcessor::ProgramImpl
Definition:
GrFragmentProcessor.h:472
GrFragmentProcessor
Definition:
GrFragmentProcessor.h:45
GrFragmentProcessor::registerChild
void registerChild(std::unique_ptr< GrFragmentProcessor > child, SkSL::SampleUsage sampleUsage=SkSL::SampleUsage::PassThrough())
Definition:
GrFragmentProcessor.cpp:146
GrGLSLProgramDataManager
Definition:
GrGLSLProgramDataManager.h:26
GrGLSLProgramDataManager::set4fv
virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const =0
GrGLSLProgramDataManager::set2f
virtual void set2f(UniformHandle, float, float) const =0
GrModulateAtlasCoverageEffect
Definition:
GrModulateAtlasCoverageEffect.h:23
GrModulateAtlasCoverageEffect::Flags
Flags
Definition:
GrModulateAtlasCoverageEffect.h:25
GrModulateAtlasCoverageEffect::Flags::kInvertCoverage
@ kInvertCoverage
GrModulateAtlasCoverageEffect::Flags::kCheckBounds
@ kCheckBounds
GrModulateAtlasCoverageEffect::GrModulateAtlasCoverageEffect
GrModulateAtlasCoverageEffect(Flags flags, std::unique_ptr< GrFragmentProcessor > inputFP, GrSurfaceProxyView atlasView, const SkMatrix &devToAtlasMatrix, const SkIRect &devIBounds)
Definition:
GrModulateAtlasCoverageEffect.cpp:29
GrProcessor::cast
const T & cast() const
Definition:
GrProcessor.h:127
GrSurfaceProxyView
Definition:
GrSurfaceProxyView.h:34
GrTextureEffect::Make
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
Definition:
GrTextureEffect.cpp:217
SkMatrix
Definition:
SkMatrix.h:54
SkSL::SampleUsage::Explicit
static SampleUsage Explicit()
Definition:
SkSLSampleUsage.h:47
SkString
Definition:
SkString.h:118
SkString::c_str
const char * c_str() const
Definition:
SkString.h:133
skgpu::KeyBuilder
Definition:
KeyBuilder.h:20
b
static bool b
Definition:
ffi_native_test_module.c:74
flags
FlutterSemanticsFlag flags
Definition:
fl_accessible_node.cc:106
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition:
fl_event_channel.h:89
dart::fp
const uint32_t fp
Definition:
method_recognizer.cc:121
skcms_private::f
float f
Definition:
skcms_Transform.h:121
GrShaderCaps
Definition:
GrShaderCaps.h:17
SkIRect
Definition:
SkRect.h:32
SkRect::Make
static SkRect Make(const SkISize &size)
Definition:
SkRect.h:669
SkRect::asScalars
const float * asScalars() const
Definition:
SkRect.h:1340
Generated on Sun Jun 23 2024 21:56:18 for Flutter Engine by
1.9.4