/src/skia/include/gpu/graphite/precompile/PrecompileBase.h
Line | Count | Source (jump to first uncovered line) |
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_PrecompileBase_DEFINED |
9 | | #define skgpu_graphite_precompile_PrecompileBase_DEFINED |
10 | | |
11 | | #include "include/core/SkRefCnt.h" |
12 | | #include "include/core/SkSpan.h" |
13 | | |
14 | | namespace skgpu::graphite { |
15 | | |
16 | | class KeyContext; |
17 | | class PaintParamsKeyBuilder; |
18 | | class PipelineDataGatherer; |
19 | | class PrecompileBasePriv; |
20 | | |
21 | | /** \class PrecompileBase |
22 | | This is the base class for all the objects that can be attached to PaintOptions. |
23 | | */ |
24 | | class SK_API PrecompileBase : public SkRefCnt { |
25 | | public: |
26 | | enum class Type { |
27 | | kBlender, |
28 | | kColorFilter, |
29 | | kImageFilter, |
30 | | kMaskFilter, |
31 | | kShader, |
32 | | }; |
33 | | |
34 | 0 | Type type() const { return fType; } |
35 | | |
36 | | // Provides access to functions that aren't part of the public API. |
37 | | PrecompileBasePriv priv(); |
38 | | const PrecompileBasePriv priv() const; // NOLINT(readability-const-return-type) |
39 | | |
40 | | protected: |
41 | 0 | PrecompileBase(Type type) : fType(type) {} |
42 | | |
43 | 0 | virtual int numIntrinsicCombinations() const { return 1; } |
44 | 0 | virtual int numChildCombinations() const { return 1; } |
45 | | |
46 | | /** This call returns the number of combinations generated from this object and its childen. |
47 | | |
48 | | @return number of precompilation combinations generated by this object |
49 | | */ |
50 | 0 | int numCombinations() const { |
51 | 0 | return this->numIntrinsicCombinations() * this->numChildCombinations(); |
52 | 0 | } |
53 | | |
54 | | virtual void addToKey(const KeyContext&, |
55 | | PaintParamsKeyBuilder*, |
56 | | PipelineDataGatherer*, |
57 | | int desiredCombination) const = 0; |
58 | | |
59 | | // This returns the desired option along with the child options. |
60 | | template<typename T> |
61 | | static std::pair<sk_sp<T>, int> SelectOption(SkSpan<const sk_sp<T>> options, |
62 | | int desiredOption); |
63 | | |
64 | | // In general, derived classes should use AddToKey to select the desired child option from |
65 | | // a span and then have it added to the key with its reduced/nested child option. |
66 | | template<typename T> |
67 | | static void AddToKey(const KeyContext&, |
68 | | PaintParamsKeyBuilder*, |
69 | | PipelineDataGatherer*, |
70 | | SkSpan<const sk_sp<T>> options, |
71 | | int desiredOption); |
72 | | |
73 | | private: |
74 | | friend class PrecompileBasePriv; |
75 | | |
76 | | friend class PaintOptions; // for access to SelectOption |
77 | | friend class PrecompileBlenderList; // "" |
78 | | |
79 | | Type fType; |
80 | | }; |
81 | | |
82 | | } // namespace skgpu::graphite |
83 | | |
84 | | #endif // skgpu_graphite_precompile_PrecompileBase_DEFINED |