Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
src
gpu
graphite
FactoryFunctions.h
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
8
#ifndef skgpu_graphite_FactoryFunctions_DEFINED
9
#define skgpu_graphite_FactoryFunctions_DEFINED
10
11
#include "
include/core/SkBlendMode.h
"
12
#include "
include/core/SkRefCnt.h
"
13
#include "
include/core/SkSpan.h
"
14
#include "
include/effects/SkRuntimeEffect.h
"
15
16
namespace
skgpu::graphite
{
17
18
class
PrecompileBase;
19
class
PrecompileBlender;
20
class
PrecompileColorFilter;
21
class
PrecompileMaskFilter;
22
class
PrecompileShader;
23
24
// All of these factory functions will be moved elsewhere once the pre-compile API becomes public
25
26
//--------------------------------------------------------------------------------------------------
27
namespace
PrecompileBlenders {
28
29
// --- This call matches the SkBlenders factory in include/effects/SkBlenders.h
30
SK_API
sk_sp<PrecompileBlender>
Arithmetic
();
31
32
// Note: the other main API SkBlender factories are:
33
// SkBlender::Mode in include/core/SkBlender.h
34
// SkRuntimeEffect::makeBlender in include/effects/SkRuntimeEffect.h
35
// Their precompilation correlates are:
36
// PrecompileBlender::Mode(bm) in src/gpu/graphite/Precompile.h
37
// MakePrecompileBlender() in src/gpu/graphite/FactoryFunctions.h
38
39
}
// namespace PrecompileBlenders
40
41
//--------------------------------------------------------------------------------------------------
42
namespace
PrecompileShaders {
43
// --- This block of six matches the SkShaders factories in include/core/SkShader.h
44
SK_API
sk_sp<PrecompileShader>
Empty
();
45
SK_API
sk_sp<PrecompileShader>
Color
();
46
SK_API
sk_sp<PrecompileShader>
Color
(
sk_sp<SkColorSpace>
);
47
SK_API
sk_sp<PrecompileShader>
Blend
(
SkSpan<SkBlendMode>
blendModes,
48
SkSpan
<
const
sk_sp<PrecompileShader>
> dsts,
49
SkSpan
<
const
sk_sp<PrecompileShader>
>
srcs
);
50
SK_API
sk_sp<PrecompileShader>
Blend
(
SkSpan
<
const
sk_sp<PrecompileBlender>
> blenders,
51
SkSpan
<
const
sk_sp<PrecompileShader>
> dsts,
52
SkSpan
<
const
sk_sp<PrecompileShader>
>
srcs
);
53
SK_API
sk_sp<PrecompileShader>
CoordClamp
(
SkSpan
<
const
sk_sp<PrecompileShader>
>);
54
55
// --- This block of two matches the SkShaders factories in include/effects/SkPerlinNoiseShader.h
56
SK_API
sk_sp<PrecompileShader>
MakeFractalNoise
();
57
SK_API
sk_sp<PrecompileShader>
MakeTurbulence
();
58
59
// --- This block of two matches the SkShaders factories in include/core/SkImage.h
60
// In the normal Skia API ImageShaders are usually created via a SkImage::makeShader call.
61
// Since the SkImage used to create the ImageShader is unlikely to be present at precompilation
62
// time this entry point allows the equivalent precompilation program structure to be created.
63
SK_API
sk_sp<PrecompileShader>
Image
();
64
// As with the above Image call, raw ImageShaders are usually created via an
65
// SkImage::makeRawShader call. The RawImage call allows the equivalent precompilation
66
// program structure to be created without needing the SkImage.
67
SK_API
sk_sp<PrecompileShader>
RawImage
();
68
69
// ??
70
SK_API
sk_sp<PrecompileShader>
YUVImage
();
71
72
// TODO: make SkGradientShader match this convention (skbug.com/13438)
73
// This block of four matches all the entry points in include/effects/SkGradientShader.h
74
SK_API
sk_sp<PrecompileShader>
LinearGradient
();
75
SK_API
sk_sp<PrecompileShader>
RadialGradient
();
76
SK_API
sk_sp<PrecompileShader>
TwoPointConicalGradient
();
77
SK_API
sk_sp<PrecompileShader>
SweepGradient
();
78
79
// Normally, SkPicture shaders are only created via SkPicture::makeShader. Since the
80
// SkPicture to be drawn, most likely, won't be available at precompilation time, this
81
// entry point can be used to create a precompilation equivalent.
82
// Note: this will precompile the program that draws the SkPicture. It, obviously, won't
83
// precompile any SkPaints within the SkPicture.
84
//
85
// API Note: At the end of the day this turns into a LMShader wrapping an image shader. The
86
// LMShader has logic to elide itself if the LM is missing or the Identity. Combinatorially,
87
// this yields 6 combinations: 2 from the LM x 3 from the ImageShader. We could try to reduce
88
// that by adding a "passing-non-null-non-Identity-LM-to-SkPicture::makeShader" flag here
89
// in which case we would either add or skip the LMShader. That would be a pretty obscure API
90
// though.
91
SK_API
sk_sp<PrecompileShader>
Picture
();
92
93
// Normally, LocalMatrixShaders are only created via SkShader::makeWithLocalMatrix.
94
// However, in the combination API, clients may want to create a set of precompile
95
// LocalMatrixShaders (i.e., pass an SkSpan to the factory function vs just creating a
96
// single option). This entry point allows that use case.
97
// Note: PrecompileShader::makeWithLocalMatrix() can still be used and works as expected.
98
SK_API
sk_sp<PrecompileShader>
LocalMatrix(
SkSpan
<
const
sk_sp<PrecompileShader>
>
wrapped
);
99
100
// Normally, ColorFilterShaders are only created via SkShader::makeWithColorFilter.
101
// However, in the combination API, clients may want to create a set of precompile
102
// ColorFilterShaders (i.e., pass SkSpans to the factory function vs just creating a
103
// single option). This entry point allows that use case.
104
// Note: PrecompileShader::makeWithColorFilter can still be used and works as expected.
105
SK_API
sk_sp<PrecompileShader>
ColorFilter
(
106
SkSpan
<
const
sk_sp<PrecompileShader>
> shaders,
107
SkSpan
<
const
sk_sp<PrecompileColorFilter>
> colorFilters);
108
109
// Normally, WorkingColorSpaceShaders are only created via SkShader::makeWithWorkingColorSpace.
110
// However, in the combination API, clients may want to create a set of precompile
111
// WorkingColorSpaceShaders (i.e., pass SkSpans to the factory function vs just creating a
112
// single option). This entry point allows that use case.
113
// Note: PrecompileShader::makeWithWorkingColorSpace can still be used and works as expected.
114
SK_API
sk_sp<PrecompileShader>
WorkingColorSpace
(
SkSpan
<
const
sk_sp<PrecompileShader>
> shaders,
115
SkSpan
<
const
sk_sp<SkColorSpace>
> colorSpaces);
116
117
}
// namespace PrecompileShaders
118
119
//--------------------------------------------------------------------------------------------------
120
// Initially this will go next to SkMaskFilter in include/core/SkMaskFilter.h but the
121
// SkMaskFilter::MakeBlur factory should be split out or removed. This namespace will follow
122
// where ever that factory goes.
123
class
PrecompileMaskFilters
{
124
public
:
125
// TODO: change SkMaskFilter::MakeBlur to match this and SkImageFilters::Blur (skbug.com/13441)
126
static
sk_sp<PrecompileMaskFilter>
Blur
();
127
128
private
:
129
PrecompileMaskFilters
() =
delete
;
130
};
131
132
//--------------------------------------------------------------------------------------------------
133
// This will move to be beside SkColorFilters in include/core/SkColorFilter.h
134
namespace
PrecompileColorFilters {
135
// -- The next 8 entries match those in include/core/SkColorFilter.h
136
SK_API
sk_sp<PrecompileColorFilter>
Compose(
SkSpan
<
const
sk_sp<PrecompileColorFilter>
> outer,
137
SkSpan
<
const
sk_sp<PrecompileColorFilter>
> inner);
138
139
// This encompasses both variants of SkColorFilters::Blend
140
SK_API
sk_sp<PrecompileColorFilter>
Blend();
141
142
// This encompasses both variants of SkColorFilters::Matrix
143
SK_API
sk_sp<PrecompileColorFilter>
Matrix();
144
145
// This encompasses both variants of SkColorFilters::HSLAMatrix
146
SK_API
sk_sp<PrecompileColorFilter>
HSLAMatrix();
147
148
SK_API
sk_sp<PrecompileColorFilter>
LinearToSRGBGamma();
149
SK_API
sk_sp<PrecompileColorFilter>
SRGBToLinearGamma();
150
SK_API
sk_sp<PrecompileColorFilter>
Lerp(
SkSpan
<
const
sk_sp<PrecompileColorFilter>
> dstOptions,
151
SkSpan
<
const
sk_sp<PrecompileColorFilter>
> srcOptions);
152
153
// This matches the main API's factory in include/effects/SkLumaColorFilter.h
154
SK_API
sk_sp<PrecompileColorFilter>
Luma();
155
156
// This encompases both variants of SkColorFilters::Table and TableARGB
157
SK_API
sk_sp<PrecompileColorFilter>
Table();
158
159
SK_API
sk_sp<PrecompileColorFilter>
Lighting();
160
161
}
// namespace PrecompileColorFilters
162
163
//--------------------------------------------------------------------------------------------------
164
// Object that allows passing a SkPrecompileShader, SkPrecompileColorFilter or
165
// SkPrecompileBlender as a child
166
//
167
// This will moved to be on SkRuntimeEffect
168
class
PrecompileChildPtr
{
169
public
:
170
PrecompileChildPtr
() =
default
;
171
PrecompileChildPtr
(
sk_sp<PrecompileShader>
);
172
PrecompileChildPtr
(
sk_sp<PrecompileColorFilter>
);
173
PrecompileChildPtr
(
sk_sp<PrecompileBlender>
);
174
175
// Asserts that the SkPrecompileBase is either null, or one of the legal derived types
176
PrecompileChildPtr
(
sk_sp<PrecompileBase>
);
177
178
std::optional<SkRuntimeEffect::ChildType>
type
()
const
;
179
180
PrecompileShader
*
shader
()
const
;
181
PrecompileColorFilter
*
colorFilter
()
const
;
182
PrecompileBlender
*
blender
()
const
;
183
PrecompileBase
*
base
()
const
{
return
fChild.get(); }
184
185
private
:
186
sk_sp<PrecompileBase>
fChild;
187
};
188
189
using
PrecompileChildOptions
=
SkSpan<const PrecompileChildPtr>
;
190
191
// TODO: the precompile RuntimeEffects are handling their child options different from the
192
// rest of the precompile system!
193
194
// These will move to be on SkRuntimeEffect to parallel makeShader, makeColorFilter and
195
// makeBlender
196
sk_sp<PrecompileShader>
MakePrecompileShader
(
197
sk_sp<SkRuntimeEffect>
effect,
198
SkSpan<const PrecompileChildOptions>
childOptions = {});
199
200
sk_sp<PrecompileColorFilter>
MakePrecompileColorFilter
(
201
sk_sp<SkRuntimeEffect>
effect,
202
SkSpan<const PrecompileChildOptions>
childOptions = {});
203
204
sk_sp<PrecompileBlender>
MakePrecompileBlender
(
205
sk_sp<SkRuntimeEffect>
effect,
206
SkSpan<const PrecompileChildOptions>
childOptions = {});
207
208
}
// namespace skgpu::graphite
209
210
#endif
// skgpu_graphite_FactoryFunctions_DEFINED
srcs
static const char * srcs[2]
Definition
EncodeBench.cpp:88
SK_API
#define SK_API
Definition
SkAPI.h:35
SkBlendMode.h
SkRefCnt.h
SkRuntimeEffect.h
SkSpan.h
wrapped
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
Definition
TextureProxyTest.cpp:112
SkSpan
Definition
SkSpan_impl.h:65
sk_sp
Definition
SkRefCnt.h:220
skgpu::graphite::PrecompileBase
Definition
Precompile.h:40
skgpu::graphite::PrecompileBlender
Definition
Precompile.h:152
skgpu::graphite::PrecompileChildPtr
Definition
FactoryFunctions.h:168
skgpu::graphite::PrecompileChildPtr::shader
PrecompileShader * shader() const
Definition
FactoryFunctions.cpp:1328
skgpu::graphite::PrecompileChildPtr::blender
PrecompileBlender * blender() const
Definition
FactoryFunctions.cpp:1340
skgpu::graphite::PrecompileChildPtr::type
std::optional< SkRuntimeEffect::ChildType > type() const
Definition
FactoryFunctions.cpp:1312
skgpu::graphite::PrecompileChildPtr::base
PrecompileBase * base() const
Definition
FactoryFunctions.h:183
skgpu::graphite::PrecompileChildPtr::colorFilter
PrecompileColorFilter * colorFilter() const
Definition
FactoryFunctions.cpp:1334
skgpu::graphite::PrecompileChildPtr::PrecompileChildPtr
PrecompileChildPtr()=default
skgpu::graphite::PrecompileColorFilter
Definition
Precompile.h:145
skgpu::graphite::PrecompileMaskFilters
Definition
FactoryFunctions.h:123
skgpu::graphite::PrecompileMaskFilters::Blur
static sk_sp< PrecompileMaskFilter > Blur()
Definition
FactoryFunctions.cpp:1002
skgpu::graphite::PrecompileShader
Definition
Precompile.h:125
skgpu::graphite::PrecompileBlenders::Arithmetic
SK_API sk_sp< PrecompileBlender > Arithmetic()
Definition
FactoryFunctions.cpp:89
skgpu::graphite::PrecompileShaders::ColorFilter
SK_API sk_sp< PrecompileShader > ColorFilter(SkSpan< const sk_sp< PrecompileShader > > shaders, SkSpan< const sk_sp< PrecompileColorFilter > > colorFilters)
Definition
FactoryFunctions.cpp:816
skgpu::graphite::PrecompileShaders::WorkingColorSpace
SK_API sk_sp< PrecompileShader > WorkingColorSpace(SkSpan< const sk_sp< PrecompileShader > > shaders, SkSpan< const sk_sp< SkColorSpace > > colorSpaces)
Definition
FactoryFunctions.cpp:876
skgpu::graphite::PrecompileShaders::LinearGradient
SK_API sk_sp< PrecompileShader > LinearGradient()
Definition
FactoryFunctions.cpp:605
skgpu::graphite::PrecompileShaders::RadialGradient
SK_API sk_sp< PrecompileShader > RadialGradient()
Definition
FactoryFunctions.cpp:620
skgpu::graphite::PrecompileShaders::Picture
SK_API sk_sp< PrecompileShader > Picture()
Definition
FactoryFunctions.cpp:548
skgpu::graphite::PrecompileShaders::CoordClamp
SK_API sk_sp< PrecompileShader > CoordClamp(SkSpan< const sk_sp< PrecompileShader > >)
Definition
FactoryFunctions.cpp:401
skgpu::graphite::PrecompileShaders::MakeTurbulence
SK_API sk_sp< PrecompileShader > MakeTurbulence()
Definition
FactoryFunctions.cpp:144
skgpu::graphite::PrecompileShaders::Image
SK_API sk_sp< PrecompileShader > Image()
Definition
raw_object.h:2021
skgpu::graphite::PrecompileShaders::Empty
SK_API sk_sp< PrecompileShader > Empty()
Definition
FactoryFunctions.cpp:114
skgpu::graphite::PrecompileShaders::Blend
SK_API sk_sp< PrecompileShader > Blend(SkSpan< SkBlendMode > blendModes, SkSpan< const sk_sp< PrecompileShader > > dsts, SkSpan< const sk_sp< PrecompileShader > > srcs)
Definition
FactoryFunctions.cpp:339
skgpu::graphite::PrecompileShaders::MakeFractalNoise
SK_API sk_sp< PrecompileShader > MakeFractalNoise()
Definition
FactoryFunctions.cpp:140
skgpu::graphite::PrecompileShaders::YUVImage
SK_API sk_sp< PrecompileShader > YUVImage()
Definition
FactoryFunctions.cpp:539
skgpu::graphite::PrecompileShaders::SweepGradient
SK_API sk_sp< PrecompileShader > SweepGradient()
Definition
FactoryFunctions.cpp:635
skgpu::graphite::PrecompileShaders::RawImage
SK_API sk_sp< PrecompileShader > RawImage()
Definition
FactoryFunctions.cpp:498
skgpu::graphite::PrecompileShaders::Color
SK_API sk_sp< PrecompileShader > Color()
Definition
FactoryFunctions.cpp:171
skgpu::graphite::PrecompileShaders::TwoPointConicalGradient
SK_API sk_sp< PrecompileShader > TwoPointConicalGradient()
Definition
FactoryFunctions.cpp:650
skgpu::graphite
Definition
BoundsManagerBench.cpp:27
skgpu::graphite::MakePrecompileBlender
sk_sp< PrecompileBlender > MakePrecompileBlender(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)
Definition
FactoryFunctions.cpp:1488
skgpu::graphite::MakePrecompileShader
sk_sp< PrecompileShader > MakePrecompileShader(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)
Definition
FactoryFunctions.cpp:1470
skgpu::graphite::MakePrecompileColorFilter
sk_sp< PrecompileColorFilter > MakePrecompileColorFilter(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)
Definition
FactoryFunctions.cpp:1479
Generated on Fri Apr 26 2024 06:17:17 for Flutter Engine by
1.9.8