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