/* * Copyright 2021 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef skgpu_UniformCache_DEFINED #define skgpu_UniformCache_DEFINED #include #include #include "include/core/SkRefCnt.h" namespace skgpu { class UniformData; class UniformCache { public: UniformCache(); sk_sp findOrCreate(sk_sp); sk_sp lookup(uint32_t uniqueID); // The number of unique uniformdata objects in the cache size_t count() const { SkASSERT(fUniformDataHash.size()+1 == fUniformDataVector.size()); return fUniformDataHash.size(); } private: struct Hash { size_t operator()(sk_sp) const; }; struct Eq { // This equality operator doesn't compare the UniformData's ids bool operator()(sk_sp, sk_sp) const; }; std::unordered_set, Hash, Eq> fUniformDataHash; std::vector> fUniformDataVector; // The UniformData's unique ID is only unique w/in a Recorder _not_ globally uint32_t fNextUniqueID = 1; }; } // namespace skgpu #endif // skgpu_UniformCache_DEFINED