• 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 #ifndef skgpu_UniformCache_DEFINED
9 #define skgpu_UniformCache_DEFINED
10 
11 #include <unordered_set>
12 #include <vector>
13 #include "include/core/SkRefCnt.h"
14 
15 namespace skgpu {
16 
17 class UniformData;
18 
19 class UniformCache {
20 public:
21     UniformCache();
22 
23     sk_sp<UniformData> findOrCreate(sk_sp<UniformData>);
24 
25     sk_sp<UniformData> lookup(uint32_t uniqueID);
26 
27     // The number of unique uniformdata objects in the cache
count()28     size_t count() const {
29         SkASSERT(fUniformDataHash.size()+1 == fUniformDataVector.size());
30         return fUniformDataHash.size();
31     }
32 
33 private:
34     struct Hash {
35         size_t operator()(sk_sp<UniformData>) const;
36     };
37     struct Eq {
38         // This equality operator doesn't compare the UniformData's ids
39         bool operator()(sk_sp<UniformData>, sk_sp<UniformData>) const;
40     };
41 
42     std::unordered_set<sk_sp<UniformData>, Hash, Eq> fUniformDataHash;
43     std::vector<sk_sp<UniformData>> fUniformDataVector;
44     // The UniformData's unique ID is only unique w/in a Recorder _not_ globally
45     uint32_t fNextUniqueID = 1;
46 };
47 
48 } // namespace skgpu
49 
50 #endif // skgpu_UniformCache_DEFINED
51