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, 56 bool avoidBufferAlloc) = 0; 57 58 // Called by Context::isContextLost(). Returns true if the backend-specific SharedContext has 59 // gotten into an unrecoverable, lost state. isDeviceLost()60 virtual bool isDeviceLost() const { return false; } 61 deviceTick(Context *)62 virtual void deviceTick(Context*) {} 63 64 protected: 65 SharedContext(std::unique_ptr<const Caps>, BackendApi); 66 67 private: 68 friend class Context; // for setRendererProvider() 69 70 // Must be created out-of-band to allow RenderSteps to use a QueueManager. 71 void setRendererProvider(std::unique_ptr<RendererProvider> rendererProvider); 72 73 std::unique_ptr<const Caps> fCaps; // Provided by backend subclass 74 75 BackendApi fBackend; 76 GlobalCache fGlobalCache; 77 std::unique_ptr<RendererProvider> fRendererProvider; 78 ShaderCodeDictionary fShaderDictionary; 79 }; 80 81 } // namespace skgpu::graphite 82 83 #endif // skgpu_graphite_SharedContext_DEFINED 84