xref: /aosp_15_r20/external/skia/include/gpu/graphite/precompile/PrecompileImageFilter.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 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_precompile_PrecompileImageFilter_DEFINED
9 #define skgpu_graphite_precompile_PrecompileImageFilter_DEFINED
10 
11 #include "include/gpu/graphite/precompile/PrecompileBase.h"
12 
13 #include "include/core/SkBlendMode.h"
14 #include "include/gpu/graphite/precompile/PaintOptions.h"
15 #include "include/private/base/SkTemplates.h"
16 
17 namespace skgpu::graphite {
18 
19 class PrecompileBlender;
20 class PrecompileColorFilter;
21 class PrecompileImageFilterPriv;
22 
23 /** \class PrecompileImageFilter
24     This class corresponds to the SkImageFilter class in the main API.
25 */
26 class SK_API PrecompileImageFilter : public PrecompileBase {
27 public:
28     ~PrecompileImageFilter() override;
29 
30     // Provides access to functions that aren't part of the public API.
31     PrecompileImageFilterPriv priv();
32     const PrecompileImageFilterPriv priv() const;  // NOLINT(readability-const-return-type)
33 
34 protected:
35     PrecompileImageFilter(SkSpan<sk_sp<PrecompileImageFilter>> inputs);
36 
37 private:
38     friend class PaintOptions;  // for createPipelines() access
39     friend class PrecompileImageFilterPriv;
40 
countInputs()41     int countInputs() const { return fInputs.count(); }
42 
getInput(int index)43     const PrecompileImageFilter* getInput(int index) const {
44         SkASSERT(index < this->countInputs());
45         return fInputs[index].get();
46     }
47 
isColorFilterNode()48     virtual sk_sp<PrecompileColorFilter> isColorFilterNode() const { return nullptr; }
49 
50     sk_sp<PrecompileColorFilter> asAColorFilter() const;
51 
52     // The PrecompileImageFilter classes do not use the PrecompileBase::addToKey virtual since
53     // they, in general, do not themselves contribute to a given SkPaint/Pipeline but, rather,
54     // create separate SkPaints/Pipelines from whole cloth (in onCreatePipelines).
addToKey(const KeyContext &,PaintParamsKeyBuilder *,PipelineDataGatherer *,int)55     void addToKey(const KeyContext& /* keyContext */,
56                   PaintParamsKeyBuilder* /* builder */,
57                   PipelineDataGatherer* /* gatherer */,
58                   int /* desiredCombination */) const final {
59         SkASSERT(false);
60     }
61 
62     virtual void onCreatePipelines(const KeyContext&,
63                                    PipelineDataGatherer*,
64                                    const RenderPassDesc&,
65                                    const PaintOptions::ProcessCombination&) const = 0;
66 
67     void createPipelines(const KeyContext&,
68                          PipelineDataGatherer*,
69                          const RenderPassDesc&,
70                          const PaintOptions::ProcessCombination&);
71 
72     skia_private::AutoSTArray<2, sk_sp<PrecompileImageFilter>> fInputs;
73 };
74 
75 //--------------------------------------------------------------------------------------------------
76 // This is the Precompile correlate to the SkImageFilters class' factories in the main API
77 //
78 // Note: In order to make precompilation analysis more tractable we don't allow options for the
79 // internals of an PrecompileImageFilter nor in the structure of the DAG.
80 namespace PrecompileImageFilters {
81 
82     // This is the Precompile correlate to SkImageFilters::Arithmetic
83     SK_API sk_sp<PrecompileImageFilter> Arithmetic(sk_sp<PrecompileImageFilter> background,
84                                                    sk_sp<PrecompileImageFilter> foreground);
85 
86     // This is the Precompile correlate to SkImageFilters::Blend(SkBlendMode, ...)
87     SK_API sk_sp<PrecompileImageFilter> Blend(SkBlendMode bm,
88                                               sk_sp<PrecompileImageFilter> background,
89                                               sk_sp<PrecompileImageFilter> foreground);
90 
91     // This is the Precompile correlate to SkImageFilters::Blend(sk_sp<SkBlender>, ...)
92     SK_API sk_sp<PrecompileImageFilter> Blend(sk_sp<PrecompileBlender> blender,
93                                               sk_sp<PrecompileImageFilter> background,
94                                               sk_sp<PrecompileImageFilter> foreground);
95 
96     // This is the Precompile correlate to the two SkImageFilters::Blur factories
97     SK_API sk_sp<PrecompileImageFilter> Blur(sk_sp<PrecompileImageFilter> input);
98 
99     // This is the Precompile correlate to SkImageFilters::ColorFilter.
100     SK_API sk_sp<PrecompileImageFilter> ColorFilter(sk_sp<PrecompileColorFilter> colorFilter,
101                                                     sk_sp<PrecompileImageFilter> input);
102 
103     // This is the Precompile correlate to SkImageFilters::DisplacementMap
104     SK_API sk_sp<PrecompileImageFilter> DisplacementMap(sk_sp<PrecompileImageFilter> input);
105 
106     // This is the Precompile correlate to all of SkImageFilters::
107     //      DistantLitDiffuse,  PointLitDiffuse,  SpotLitDiffuse
108     //      DistantLitSpecular, PointLitSpecular, SpotLitSpecular
109     SK_API sk_sp<PrecompileImageFilter> Lighting(sk_sp<PrecompileImageFilter> input);
110 
111     // This is the Precompile correlate to SkImageFilters::MatrixConvolution
112     SK_API sk_sp<PrecompileImageFilter> MatrixConvolution(sk_sp<PrecompileImageFilter> input);
113 
114     // This is the Precompile correlate to SkImageFilters::Erode and SkImageFilters::Dilate
115     SK_API sk_sp<PrecompileImageFilter> Morphology(sk_sp<PrecompileImageFilter> input);
116 
117 } // namespace PrecompileImageFilters
118 
119 } // namespace skgpu::graphite
120 
121 #endif // skgpu_graphite_precompile_PrecompileImageFilter_DEFINED
122