• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PrecompileImageFilter;
22 class PrecompileMaskFilter;
23 class PrecompileShader;
24 
25 // All of these factory functions will be moved elsewhere once the pre-compile API becomes public
26 
27 namespace PrecompileShaders {
28     // ??
29     SK_API sk_sp<PrecompileShader> YUVImage();
30 
31 } // namespace PrecompileShaders
32 
33 // TODO: For all of the PrecompileImageFilter factories, should we have a CropRect parameter or
34 // have clients explicitly create a crop PrecompileImageFilter?
35 // Note: In order to make analysis more tractable we don't allow options for the internals of an
36 // ImageFilter nor in the structure of the DAG.
37 namespace PrecompileImageFilters {
38     // This is the Precompile correlate to SkImageFilters::Arithmetic
39     SK_API sk_sp<PrecompileImageFilter> Arithmetic(sk_sp<PrecompileImageFilter> background,
40                                                    sk_sp<PrecompileImageFilter> foreground);
41 
42     // This is the Precompile correlate to SkImageFilters::Blend(SkBlendMode, ...)
43     SK_API sk_sp<PrecompileImageFilter> Blend(SkBlendMode bm,
44                                               sk_sp<PrecompileImageFilter> background,
45                                               sk_sp<PrecompileImageFilter> foreground);
46 
47     // This is the Precompile correlate to SkImageFilters::Blend(sk_sp<SkBlender>, ...)
48     SK_API sk_sp<PrecompileImageFilter> Blend(sk_sp<PrecompileBlender> blender,
49                                               sk_sp<PrecompileImageFilter> background,
50                                               sk_sp<PrecompileImageFilter> foreground);
51 
52     // This is the Precompile correlate to the two SkImageFilters::Blur factories
53     SK_API sk_sp<PrecompileImageFilter> Blur(sk_sp<PrecompileImageFilter> input);
54 
55     // This is the Precompile correlate to SkImageFilters::ColorFilter.
56     SK_API sk_sp<PrecompileImageFilter> ColorFilter(sk_sp<PrecompileColorFilter> colorFilter,
57                                                     sk_sp<PrecompileImageFilter> input);
58 
59     // This is the Precompile correlate to SkImageFilters::DisplacementMap
60     SK_API sk_sp<PrecompileImageFilter> DisplacementMap(sk_sp<PrecompileImageFilter> input);
61 
62     // This is the Precompile correlate to all of SkImageFilters::
63     //      DistantLitDiffuse,  PointLitDiffuse,  SpotLitDiffuse
64     //      DistantLitSpecular, PointLitSpecular, SpotLitSpecular
65     SK_API sk_sp<PrecompileImageFilter> Lighting(sk_sp<PrecompileImageFilter> input);
66 
67     // This is the Precompile correlate to SkImageFilters::MatrixConvolution
68     SK_API sk_sp<PrecompileImageFilter> MatrixConvolution(sk_sp<PrecompileImageFilter> input);
69 
70     // This is the Precompile correlate to SkImageFilters::Erode and SkImageFilters::Dilate
71     SK_API sk_sp<PrecompileImageFilter> Morphology(sk_sp<PrecompileImageFilter> input);
72 
73 } // namespace PrecompileImageFilters
74 
75 //--------------------------------------------------------------------------------------------------
76 // Initially this will go next to SkMaskFilter in include/core/SkMaskFilter.h but the
77 // SkMaskFilter::MakeBlur factory should be split out or removed. This namespace will follow
78 // where ever that factory goes.
79 namespace PrecompileMaskFilters {
80     // TODO: change SkMaskFilter::MakeBlur to match this and SkImageFilters::Blur (skbug.com/13441)
81     SK_API sk_sp<PrecompileMaskFilter> Blur();
82 } // namespace PrecompileMaskFilters
83 
84 //--------------------------------------------------------------------------------------------------
85 // This will move to be beside SkColorFilters in include/core/SkColorFilter.h
86 namespace PrecompileColorFilters {
87     // -- The next 9 entries match those in include/core/SkColorFilter.h
88     SK_API sk_sp<PrecompileColorFilter> Compose(SkSpan<const sk_sp<PrecompileColorFilter>> outer,
89                                                 SkSpan<const sk_sp<PrecompileColorFilter>> inner);
90 
91     // This encompasses both variants of SkColorFilters::Blend
92     SK_API sk_sp<PrecompileColorFilter> Blend();
93 
94     // This encompasses both variants of SkColorFilters::Matrix
95     SK_API sk_sp<PrecompileColorFilter> Matrix();
96 
97     // This encompasses both variants of SkColorFilters::HSLAMatrix
98     SK_API sk_sp<PrecompileColorFilter> HSLAMatrix();
99 
100     SK_API sk_sp<PrecompileColorFilter> LinearToSRGBGamma();
101     SK_API sk_sp<PrecompileColorFilter> SRGBToLinearGamma();
102     SK_API sk_sp<PrecompileColorFilter> Lerp(SkSpan<const sk_sp<PrecompileColorFilter>> dstOptions,
103                                              SkSpan<const sk_sp<PrecompileColorFilter>> srcOptions);
104 
105     // This encompases both variants of SkColorFilters::Table and TableARGB
106     SK_API sk_sp<PrecompileColorFilter> Table();
107 
108     SK_API sk_sp<PrecompileColorFilter> Lighting();
109 
110     // This matches the main API's factory in include/effects/SkHighContrastFilter.h
111     SK_API sk_sp<PrecompileColorFilter> HighContrast();
112 
113     // This matches the main API's factory in include/effects/SkLumaColorFilter.h
114     SK_API sk_sp<PrecompileColorFilter> Luma();
115 
116     // This matches the main API's factory in include/effects/SkOverdrawColorFilter.h
117     SK_API sk_sp<PrecompileColorFilter> Overdraw();
118 
119 } // namespace PrecompileColorFilters
120 
121 //--------------------------------------------------------------------------------------------------
122 // Object that allows passing a SkPrecompileShader, SkPrecompileColorFilter or
123 // SkPrecompileBlender as a child
124 //
125 // This will moved to be on SkRuntimeEffect
126 class PrecompileChildPtr {
127 public:
128     PrecompileChildPtr() = default;
129     PrecompileChildPtr(sk_sp<PrecompileShader>);
130     PrecompileChildPtr(sk_sp<PrecompileColorFilter>);
131     PrecompileChildPtr(sk_sp<PrecompileBlender>);
132 
133     // Asserts that the SkPrecompileBase is either null, or one of the legal derived types
134     PrecompileChildPtr(sk_sp<PrecompileBase>);
135 
136     std::optional<SkRuntimeEffect::ChildType> type() const;
137 
138     PrecompileShader* shader() const;
139     PrecompileColorFilter* colorFilter() const;
140     PrecompileBlender* blender() const;
base()141     PrecompileBase* base() const { return fChild.get(); }
142 
143 private:
144     sk_sp<PrecompileBase> fChild;
145 };
146 
147 using PrecompileChildOptions = SkSpan<const PrecompileChildPtr>;
148 
149 // TODO: the precompile RuntimeEffects are handling their child options different from the
150 // rest of the precompile system!
151 
152 // These will move to be on SkRuntimeEffect to parallel makeShader, makeColorFilter and
153 // makeBlender
154 sk_sp<PrecompileShader> MakePrecompileShader(
155         sk_sp<SkRuntimeEffect> effect,
156         SkSpan<const PrecompileChildOptions> childOptions = {});
157 
158 sk_sp<PrecompileColorFilter> MakePrecompileColorFilter(
159         sk_sp<SkRuntimeEffect> effect,
160         SkSpan<const PrecompileChildOptions> childOptions = {});
161 
162 sk_sp<PrecompileBlender> MakePrecompileBlender(
163         sk_sp<SkRuntimeEffect> effect,
164         SkSpan<const PrecompileChildOptions> childOptions = {});
165 
166 } // namespace skgpu::graphite
167 
168 #endif // skgpu_graphite_FactoryFunctions_DEFINED
169