xref: /aosp_15_r20/external/skia/src/gpu/graphite/precompile/PrecompileShaderPriv.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_PrecompileShaderPriv_DEFINED
9 #define skgpu_graphite_PrecompileShaderPriv_DEFINED
10 
11 #include "include/gpu/graphite/precompile/PrecompileShader.h"
12 
13 namespace skgpu::graphite {
14 
15 /** Class that exposes methods in PrecompileShader that are only intended for use internal to Skia.
16     This class is purely a privileged window into PrecompileShader. It should never have additional
17     data members or virtual methods. */
18 class PrecompileShaderPriv {
19 public:
isConstant(int desiredCombination)20     bool isConstant(int desiredCombination) const {
21         return fPrecompileShader->isConstant(desiredCombination);
22     }
23 
isALocalMatrixShader()24     bool isALocalMatrixShader() const {
25         return fPrecompileShader->isALocalMatrixShader();
26     }
27 
28     // The remaining methods make this a viable standin for PrecompileBasePriv
numChildCombinations()29     int numChildCombinations() const { return fPrecompileShader->numChildCombinations(); }
30 
numCombinations()31     int numCombinations() const { return fPrecompileShader->numCombinations(); }
32 
addToKey(const KeyContext & keyContext,PaintParamsKeyBuilder * builder,PipelineDataGatherer * gatherer,int desiredCombination)33     void addToKey(const KeyContext& keyContext,
34                   PaintParamsKeyBuilder* builder,
35                   PipelineDataGatherer* gatherer,
36                   int desiredCombination) const {
37         fPrecompileShader->addToKey(keyContext, builder, gatherer, desiredCombination);
38     }
39 
40 private:
41     friend class PrecompileShader; // to construct/copy this type.
42 
PrecompileShaderPriv(PrecompileShader * precompileShader)43     explicit PrecompileShaderPriv(PrecompileShader* precompileShader)
44             : fPrecompileShader(precompileShader) {}
45 
46     PrecompileShaderPriv& operator=(const PrecompileShaderPriv&) = delete;
47 
48     // No taking addresses of this type.
49     const PrecompileShaderPriv* operator&() const;
50     PrecompileShaderPriv *operator&();
51 
52     PrecompileShader* fPrecompileShader;
53 };
54 
priv()55 inline PrecompileShaderPriv PrecompileShader::priv() { return PrecompileShaderPriv(this); }
56 
57 // NOLINTNEXTLINE(readability-const-return-type)
priv()58 inline const PrecompileShaderPriv PrecompileShader::priv() const {
59     return PrecompileShaderPriv(const_cast<PrecompileShader *>(this));
60 }
61 
62 } // namespace skgpu::graphite
63 
64 #endif // skgpu_graphite_PrecompileShaderPriv_DEFINED
65