Flutter Engine
The Flutter Engine
SharedContext.h
Go to the documentation of this file.
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>
13#include "include/core/SkSize.h"
14
18
19namespace skgpu {
20class SingleOwner;
21}
22
23namespace skgpu::graphite {
24
25class BackendTexture;
26class Caps;
27class CommandBuffer;
28class RendererProvider;
30class TextureInfo;
31
32class SharedContext : public SkRefCnt {
33public:
34 ~SharedContext() override;
35
36 /**
37 * Gets the capabilities of the draw target.
38 */
39 const Caps* caps() const { return fCaps.get(); }
40
41 BackendApi backend() const { return fBackend; }
42 Protected isProtected() const;
43
44 GlobalCache* globalCache() { return &fGlobalCache; }
45 const GlobalCache* globalCache() const { return &fGlobalCache; }
46
47 const RendererProvider* rendererProvider() const { return fRendererProvider.get(); }
48
49 ShaderCodeDictionary* shaderCodeDictionary() { return &fShaderDictionary; }
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.
58 virtual bool isDeviceLost() const { return false; }
59
60protected:
61 SharedContext(std::unique_ptr<const Caps>, BackendApi);
62
63private:
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
const Caps * caps() const
Definition: SharedContext.h:39
SharedContext(std::unique_ptr< const Caps >, BackendApi)
ShaderCodeDictionary * shaderCodeDictionary()
Definition: SharedContext.h:49
virtual bool isDeviceLost() const
Definition: SharedContext.h:58
const ShaderCodeDictionary * shaderCodeDictionary() const
Definition: SharedContext.h:50
BackendApi backend() const
Definition: SharedContext.h:41
const RendererProvider * rendererProvider() const
Definition: SharedContext.h:47
const GlobalCache * globalCache() const
Definition: SharedContext.h:45
virtual std::unique_ptr< ResourceProvider > makeResourceProvider(SingleOwner *, uint32_t recorderID, size_t resourceBudget)=0
Definition: GpuTools.h:21
BackendApi
Definition: GpuTypes.h:22
Protected
Definition: GpuTypes.h:61