Debian Codegraph @

src/gpu/ResourceKey.cpp

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