• 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 #include "src/core/SkOpts.h"
9 #include "src/gpu/ResourceKey.h"
10 
11 namespace skgpu {
12 
GenerateResourceType()13 ScratchKey::ResourceType ScratchKey::GenerateResourceType() {
14     static std::atomic<int32_t> nextType{ResourceKey::kInvalidDomain + 1};
15 
16     int32_t type = nextType.fetch_add(1, std::memory_order_relaxed);
17     if (type > SkTo<int32_t>(UINT16_MAX)) {
18         SK_ABORT("Too many Resource Types");
19     }
20 
21     return static_cast<ResourceType>(type);
22 }
23 
GenerateDomain()24 UniqueKey::Domain UniqueKey::GenerateDomain() {
25     static std::atomic<int32_t> nextDomain{ResourceKey::kInvalidDomain + 1};
26 
27     int32_t domain = nextDomain.fetch_add(1, std::memory_order_relaxed);
28     if (domain > SkTo<int32_t>(UINT16_MAX)) {
29         SK_ABORT("Too many skgpu::UniqueKey Domains");
30     }
31 
32     return static_cast<Domain>(domain);
33 }
34 
ResourceKeyHash(const uint32_t * data,size_t size)35 uint32_t ResourceKeyHash(const uint32_t* data, size_t size) {
36     return SkOpts::hash(data, size);
37 }
38 
39 } // namespace skgpu
40 
41