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