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 Context; 29 class RendererProvider; 30 class ResourceProvider; 31 class TextureInfo; 32 33 class SharedContext : public SkRefCnt { 34 public: 35 ~SharedContext() override; 36 37 /** 38 * Gets the capabilities of the draw target. 39 */ caps()40 const Caps* caps() const { return fCaps.get(); } 41 backend()42 BackendApi backend() const { return fBackend; } 43 Protected isProtected() const; 44 globalCache()45 GlobalCache* globalCache() { return &fGlobalCache; } globalCache()46 const GlobalCache* globalCache() const { return &fGlobalCache; } 47 rendererProvider()48 const RendererProvider* rendererProvider() const { return fRendererProvider.get(); } 49 shaderCodeDictionary()50 ShaderCodeDictionary* shaderCodeDictionary() { return &fShaderDictionary; } shaderCodeDictionary()51 const ShaderCodeDictionary* shaderCodeDictionary() const { return &fShaderDictionary; } 52 53 virtual std::unique_ptr<ResourceProvider> makeResourceProvider(SingleOwner*, 54 uint32_t recorderID, 55 size_t resourceBudget) = 0; 56 57 // Called by Context::isContextLost(). Returns true if the backend-specific SharedContext has 58 // gotten into an unrecoverable, lost state. isDeviceLost()59 virtual bool isDeviceLost() const { return false; } 60 deviceTick(Context *)61 virtual void deviceTick(Context*) {} 62 63 protected: 64 SharedContext(std::unique_ptr<const Caps>, 65 BackendApi, 66 SkSpan<sk_sp<SkRuntimeEffect>> userDefinedKnownRuntimeEffects); 67 68 private: 69 friend class Context; // for setRendererProvider() 70 71 // Must be created out-of-band to allow RenderSteps to use a QueueManager. 72 void setRendererProvider(std::unique_ptr<RendererProvider> rendererProvider); 73 74 std::unique_ptr<const Caps> fCaps; // Provided by backend subclass 75 76 BackendApi fBackend; 77 GlobalCache fGlobalCache; 78 std::unique_ptr<RendererProvider> fRendererProvider; 79 ShaderCodeDictionary fShaderDictionary; 80 }; 81 82 } // namespace skgpu::graphite 83 84 #endif // skgpu_graphite_SharedContext_DEFINED 85