1 /* 2 * Copyright 2021 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_SharedContext_DEFINED 9 #define skgpu_graphite_SharedContext_DEFINED 10 11 #include <memory> 12 #include "include/core/SkRefCnt.h" 13 #include "include/core/SkSize.h" 14 15 #include "include/gpu/graphite/GraphiteTypes.h" 16 #include "src/gpu/graphite/GlobalCache.h" 17 #include "src/gpu/graphite/ShaderCodeDictionary.h" 18 19 namespace skgpu { 20 class SingleOwner; 21 } 22 23 namespace skgpu::graphite { 24 25 class BackendTexture; 26 class Caps; 27 class CommandBuffer; 28 class RendererProvider; 29 class ResourceProvider; 30 class TextureInfo; 31 32 class SharedContext : public SkRefCnt { 33 public: 34 ~SharedContext() override; 35 36 /** 37 * Gets the capabilities of the draw target. 38 */ caps()39 const Caps* caps() const { return fCaps.get(); } 40 backend()41 BackendApi backend() const { return fBackend; } isProtected()42 Protected isProtected() const { return fProtected; } 43 globalCache()44 GlobalCache* globalCache() { return &fGlobalCache; } globalCache()45 const GlobalCache* globalCache() const { return &fGlobalCache; } 46 rendererProvider()47 const RendererProvider* rendererProvider() const { return fRendererProvider.get(); } 48 shaderCodeDictionary()49 ShaderCodeDictionary* shaderCodeDictionary() { return &fShaderDictionary; } shaderCodeDictionary()50 const ShaderCodeDictionary* shaderCodeDictionary() const { return &fShaderDictionary; } 51 52 virtual std::unique_ptr<ResourceProvider> makeResourceProvider(SingleOwner*) = 0; 53 54 protected: 55 SharedContext(std::unique_ptr<const Caps>, BackendApi); 56 57 private: 58 friend class Context; // for setRendererProvider() 59 60 // Must be created out-of-band to allow RenderSteps to use a QueueManager. 61 void setRendererProvider(std::unique_ptr<RendererProvider> rendererProvider); 62 63 std::unique_ptr<const Caps> fCaps; // Provided by backend subclass 64 65 BackendApi fBackend; 66 Protected fProtected; 67 GlobalCache fGlobalCache; 68 std::unique_ptr<RendererProvider> fRendererProvider; 69 ShaderCodeDictionary fShaderDictionary; 70 }; 71 72 } // namespace skgpu::graphite 73 74 #endif // skgpu_graphite_SharedContext_DEFINED 75