xref: /aosp_15_r20/external/skia/src/gpu/graphite/PrecompileContext.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 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 "include/gpu/graphite/PrecompileContext.h"
9 
10 #include "src/gpu/graphite/ResourceProvider.h"
11 #include "src/gpu/graphite/SharedContext.h"
12 
13 namespace skgpu::graphite {
14 
15 #define ASSERT_SINGLE_OWNER SKGPU_ASSERT_SINGLE_OWNER(&fSingleOwner)
16 
~PrecompileContext()17 PrecompileContext::~PrecompileContext() {
18     ASSERT_SINGLE_OWNER
19 }
20 
PrecompileContext(sk_sp<SharedContext> sharedContext)21 PrecompileContext::PrecompileContext(sk_sp<SharedContext> sharedContext)
22     : fSharedContext(sharedContext) {
23 
24     // ResourceProviders are not thread-safe. Here we create a ResourceProvider
25     // specifically for the thread on which precompilation will occur.
26     static constexpr size_t kEmptyBudget = 0;
27     fResourceProvider = fSharedContext->makeResourceProvider(
28             &fSingleOwner,
29             SK_InvalidGenID,
30             kEmptyBudget,
31             /* avoidBufferAlloc= */ true);
32 }
33 
34 } // namespace skgpu::graphite
35