xref: /aosp_15_r20/external/skia/src/gpu/graphite/SharedContext.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #include "src/gpu/graphite/SharedContext.h"
9 
10 #include "include/gpu/graphite/BackendTexture.h"
11 #include "include/gpu/graphite/TextureInfo.h"
12 #include "src/gpu/graphite/Caps.h"
13 #include "src/gpu/graphite/CommandBuffer.h"
14 #include "src/gpu/graphite/GpuWorkSubmission.h"
15 #include "src/gpu/graphite/RendererProvider.h"
16 #include "src/gpu/graphite/ResourceProvider.h"
17 
18 namespace skgpu::graphite {
19 
get_binding_layout(const Caps * caps)20 static Layout get_binding_layout(const Caps* caps) {
21     ResourceBindingRequirements reqs = caps->resourceBindingRequirements();
22     return caps->storageBufferSupport() ? reqs.fStorageBufferLayout : reqs.fUniformBufferLayout;
23 }
24 
SharedContext(std::unique_ptr<const Caps> caps,BackendApi backend)25 SharedContext::SharedContext(std::unique_ptr<const Caps> caps, BackendApi backend)
26     : fCaps(std::move(caps))
27     , fBackend(backend)
28     , fGlobalCache()
29     , fShaderDictionary(get_binding_layout(fCaps.get())) {}
30 
~SharedContext()31 SharedContext::~SharedContext() {
32     // TODO: add disconnect?
33 
34     // TODO: destroyResources instead?
35 }
36 
isProtected() const37 Protected SharedContext::isProtected() const { return Protected(fCaps->protectedSupport()); }
38 
setRendererProvider(std::unique_ptr<RendererProvider> rendererProvider)39 void SharedContext::setRendererProvider(std::unique_ptr<RendererProvider> rendererProvider) {
40     // Should only be called once and be non-null
41     SkASSERT(rendererProvider && !fRendererProvider);
42     fRendererProvider = std::move(rendererProvider);
43 }
44 
45 } // namespace skgpu::graphite
46