Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ResourceKey.cpp
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
9
10#include "src/core/SkChecksum.h"
11
12#include <atomic>
13
14namespace skgpu {
15
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
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
38uint32_t ResourceKeyHash(const uint32_t* data, size_t size) {
39 return SkChecksum::Hash32(data, size);
40}
41
42} // namespace skgpu
43
#define SK_ABORT(message,...)
Definition SkAssert.h:70
static const uint32_t kInvalidDomain
Definition ResourceKey.h:95
uint32_t domain() const
static ResourceType GenerateResourceType()
uint32_t ResourceType
static Domain GenerateDomain()
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
uint32_t ResourceKeyHash(const uint32_t *data, size_t size)