Debian Codegraph @

src/gpu/graphite/precompile/PrecompileBlenderPriv.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_PrecompileBlenderPriv_DEFINED
9 #define skgpu_graphite_PrecompileBlenderPriv_DEFINED
10
11 #include "include/gpu/graphite/precompile/PrecompileBlender.h"
12
13 #include <vector>
14
15 namespace skgpu::graphite {
16
17 /** Class that exposes methods in PrecompileBlender that are only intended for use internal to Skia.
18 This class is purely a privileged window into PrecompileBlender. It should never have additional
19 data members or virtual methods. */
20 class PrecompileBlenderPriv {
21 public:
22 std::optional<SkBlendMode> asBlendMode() const { return fPrecompileBlender->asBlendMode(); }
23
24 // The remaining methods make this a viable standin for PrecompileBasePriv
25 int numChildCombinations() const { return fPrecompileBlender->numChildCombinations(); }
26
27 int numCombinations() const { return fPrecompileBlender->numCombinations(); }
28
29 void addToKey(const KeyContext& keyContext, int desiredCombination) const {
30 fPrecompileBlender->addToKey(keyContext, desiredCombination);
31 }
32
33 private:
34 friend class PrecompileBlender; // to construct/copy this type.
35
36 explicit PrecompileBlenderPriv(PrecompileBlender* precompileBlender)
37 : fPrecompileBlender(precompileBlender) {}
38
39 PrecompileBlenderPriv& operator=(const PrecompileBlenderPriv&) = delete;
40
41 // No taking addresses of this type.
42 const PrecompileBlenderPriv* operator&() const;
43 PrecompileBlenderPriv *operator&();
44
45 PrecompileBlender* fPrecompileBlender;
46 };
47
48 inline PrecompileBlenderPriv PrecompileBlender::priv() { return PrecompileBlenderPriv(this); }
49
50 // NOLINTNEXTLINE(readability-const-return-type)
51 inline const PrecompileBlenderPriv PrecompileBlender::priv() const {
52 return PrecompileBlenderPriv(const_cast<PrecompileBlender *>(this));
53 }
54
55 class PrecompileBlenderList {
56 public:
57 PrecompileBlenderList(SkSpan<const sk_sp<PrecompileBlender>> blenders);
58 PrecompileBlenderList(SkSpan<const SkBlendMode> blendModes);
59
60 int numCombinations() const { return fNumCombos; }
61
62 // For options that use a consolidated blend function, a representative blend mode is returned.
63 // Blend modes passed directly to the list's constructor will be re-wrapped in a
64 // PrecompileBlender that returns the correct value from asBlendMode().
65 //
66 // The representative blend mode is consistent with the block selection logic in AddBlendMode().
67 std::pair<sk_sp<PrecompileBlender>, int> selectOption(int desiredCombination) const;
68
69 private:
70 // Porter Duff and HSLC blend modes are removed, but any remaining SkBlendModes that do not
71 // have a consolidated function must be fixed in the PaintParamsKey just like runtime blenders.
72 std::vector<sk_sp<PrecompileBlender>> fFixedBlenderEffects;
73 bool fHasPorterDuffBlender = false;
74 bool fHasHSLCBlender = false;
75
76 int fNumCombos = 0;
77 };
78
79 } // namespace skgpu::graphite
80
81 #endif // skgpu_graphite_PrecompileBlenderPriv_DEFINED