Debian Codegraph @

include/gpu/graphite/precompile/PrecompileBase.h

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