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_PrecompileContextPriv_DEFINED 9 #define skgpu_graphite_PrecompileContextPriv_DEFINED 10 11 #include "include/gpu/graphite/PrecompileContext.h" 12 13 class Caps; 14 15 namespace skgpu::graphite { 16 17 /** 18 * Class that adds methods to PrecompileContext that are only intended for use internal to Skia. 19 * This class is purely a privileged window into PrecompileContext. It should never have additional 20 * data members or virtual methods. 21 */ 22 class PrecompileContextPriv { 23 public: caps()24 const Caps* caps() const { return fPrecompileContext->fSharedContext->caps(); } shaderCodeDictionary()25 const ShaderCodeDictionary* shaderCodeDictionary() const { 26 return fPrecompileContext->fSharedContext->shaderCodeDictionary(); 27 } shaderCodeDictionary()28 ShaderCodeDictionary* shaderCodeDictionary() { 29 return fPrecompileContext->fSharedContext->shaderCodeDictionary(); 30 } rendererProvider()31 const RendererProvider* rendererProvider() const { 32 return fPrecompileContext->fSharedContext->rendererProvider(); 33 } sharedContext()34 SharedContext* sharedContext() { 35 return fPrecompileContext->fSharedContext.get(); 36 } resourceProvider()37 ResourceProvider* resourceProvider() { 38 return fPrecompileContext->fResourceProvider.get(); 39 } 40 #if defined(GPU_TEST_UTILS) globalCache()41 GlobalCache* globalCache() { 42 return fPrecompileContext->fSharedContext->globalCache(); 43 } 44 #endif 45 46 private: 47 friend class PrecompileContext; // to construct/copy this type. 48 PrecompileContextPriv(PrecompileContext * precompileContext)49 explicit PrecompileContextPriv(PrecompileContext* precompileContext) 50 : fPrecompileContext(precompileContext) {} 51 52 PrecompileContextPriv& operator=(const PrecompileContextPriv&) = delete; 53 54 // No taking addresses of this type. 55 const PrecompileContextPriv* operator&() const; 56 PrecompileContextPriv *operator&(); 57 58 PrecompileContext* fPrecompileContext; 59 }; 60 priv()61inline PrecompileContextPriv PrecompileContext::priv() { return PrecompileContextPriv(this); } 62 63 // NOLINTNEXTLINE(readability-const-return-type) priv()64inline const PrecompileContextPriv PrecompileContext::priv() const { 65 return PrecompileContextPriv(const_cast<PrecompileContext *>(this)); 66 } 67 68 } // namespace skgpu::graphite 69 70 #endif // skgpu_graphite_PrecompileContextPriv_DEFINED 71