Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
13#include "include/core/SkSpan.h"
15
16namespace skgpu::graphite {
17
18class PrecompileBase;
19class PrecompileBlender;
20class PrecompileColorFilter;
21class PrecompileMaskFilter;
22class PrecompileShader;
23
24// All of these factory functions will be moved elsewhere once the pre-compile API becomes public
25
26//--------------------------------------------------------------------------------------------------
27namespace PrecompileBlenders {
28
29 // --- This call matches the SkBlenders factory in include/effects/SkBlenders.h
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//--------------------------------------------------------------------------------------------------
42namespace PrecompileShaders {
43 // --- This block of six matches the SkShaders factories in include/core/SkShader.h
54
55 // --- This block of two matches the SkShaders factories in include/effects/SkPerlinNoiseShader.h
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.
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.
68
69 // ??
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
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.
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.
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.
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.
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.
124public:
125 // TODO: change SkMaskFilter::MakeBlur to match this and SkImageFilters::Blur (skbug.com/13441)
127
128private:
129 PrecompileMaskFilters() = delete;
130};
131
132//--------------------------------------------------------------------------------------------------
133// This will move to be beside SkColorFilters in include/core/SkColorFilter.h
134namespace PrecompileColorFilters {
135 // -- The next 8 entries match those in include/core/SkColorFilter.h
138
139 // This encompasses both variants of SkColorFilters::Blend
141
142 // This encompasses both variants of SkColorFilters::Matrix
144
145 // This encompasses both variants of SkColorFilters::HSLAMatrix
147
148 SK_API sk_sp<PrecompileColorFilter> LinearToSRGBGamma();
149 SK_API sk_sp<PrecompileColorFilter> SRGBToLinearGamma();
151 SkSpan<const sk_sp<PrecompileColorFilter>> srcOptions);
152
153 // This matches the main API's factory in include/effects/SkLumaColorFilter.h
155
156 // This encompases both variants of SkColorFilters::Table and TableARGB
158
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
169public:
174
175 // Asserts that the SkPrecompileBase is either null, or one of the legal derived types
177
178 std::optional<SkRuntimeEffect::ChildType> type() const;
179
180 PrecompileShader* shader() const;
182 PrecompileBlender* blender() const;
183 PrecompileBase* base() const { return fChild.get(); }
184
185private:
187};
188
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
198 SkSpan<const PrecompileChildOptions> childOptions = {});
199
202 SkSpan<const PrecompileChildOptions> childOptions = {});
203
206 SkSpan<const PrecompileChildOptions> childOptions = {});
207
208} // namespace skgpu::graphite
209
210#endif // skgpu_graphite_FactoryFunctions_DEFINED
static const char * srcs[2]
#define SK_API
Definition SkAPI.h:35
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
PrecompileBlender * blender() const
std::optional< SkRuntimeEffect::ChildType > type() const
PrecompileColorFilter * colorFilter() const
static sk_sp< PrecompileMaskFilter > Blur()
SK_API sk_sp< PrecompileBlender > Arithmetic()
SK_API sk_sp< PrecompileShader > ColorFilter(SkSpan< const sk_sp< PrecompileShader > > shaders, SkSpan< const sk_sp< PrecompileColorFilter > > colorFilters)
SK_API sk_sp< PrecompileShader > WorkingColorSpace(SkSpan< const sk_sp< PrecompileShader > > shaders, SkSpan< const sk_sp< SkColorSpace > > colorSpaces)
SK_API sk_sp< PrecompileShader > LinearGradient()
SK_API sk_sp< PrecompileShader > RadialGradient()
SK_API sk_sp< PrecompileShader > Picture()
SK_API sk_sp< PrecompileShader > CoordClamp(SkSpan< const sk_sp< PrecompileShader > >)
SK_API sk_sp< PrecompileShader > MakeTurbulence()
SK_API sk_sp< PrecompileShader > Image()
SK_API sk_sp< PrecompileShader > Empty()
SK_API sk_sp< PrecompileShader > Blend(SkSpan< SkBlendMode > blendModes, SkSpan< const sk_sp< PrecompileShader > > dsts, SkSpan< const sk_sp< PrecompileShader > > srcs)
SK_API sk_sp< PrecompileShader > MakeFractalNoise()
SK_API sk_sp< PrecompileShader > YUVImage()
SK_API sk_sp< PrecompileShader > SweepGradient()
SK_API sk_sp< PrecompileShader > RawImage()
SK_API sk_sp< PrecompileShader > Color()
SK_API sk_sp< PrecompileShader > TwoPointConicalGradient()
sk_sp< PrecompileBlender > MakePrecompileBlender(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)
sk_sp< PrecompileShader > MakePrecompileShader(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)
sk_sp< PrecompileColorFilter > MakePrecompileColorFilter(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)