/* * Copyright 2021 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "src/gpu/ResourceKey.h" #include "src/core/SkChecksum.h" #include namespace skgpu { ScratchKey::ResourceType ScratchKey::GenerateResourceType() { static std::atomic nextType{ResourceKey::kInvalidDomain + 1}; int32_t type = nextType.fetch_add(1, std::memory_order_relaxed); if (type > SkTo(UINT16_MAX)) { SK_ABORT("Too many Resource Types"); } return static_cast(type); } UniqueKey::Domain UniqueKey::GenerateDomain() { static std::atomic nextDomain{ResourceKey::kInvalidDomain + 1}; int32_t domain = nextDomain.fetch_add(1, std::memory_order_relaxed); if (domain > SkTo(UINT16_MAX)) { SK_ABORT("Too many skgpu::UniqueKey Domains"); } return static_cast(domain); } uint32_t ResourceKeyHash(const uint32_t* data, size_t size) { return SkChecksum::Hash32(data, size); } } // namespace skgpu