Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(793)

Side by Side Diff: gpu/command_buffer/service/program_cache_lru_helper.h

Issue 10534173: GPU Program Caching (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: memory limit + lru Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 201 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_LRU_HELPER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_LRU_HELPER_H_
7
8 #include "base/basictypes.h"
9 #include "base/hash_tables.h"
10 #include "gpu/gpu_export.h"
11 #include "net/disk_cache/hash.h"
12
13 #include <list>
14
15 namespace gpu {
16 namespace gles2 {
17
18 // LRU helper for the program cache, operates in O(1) time.
19 // This class uses a linked list with a hash map. Both copy their string keys,
20 // so be mindful that keys you insert will be stored again twice in memory.
21 class GPU_EXPORT ProgramCacheLruHelper {
22 public:
23 ProgramCacheLruHelper() {}
24 // clears the lru queue
25 void Clear();
26 // returns true if the lru queue is empty
27 bool IsEmpty();
28 // inserts or refreshes a key in the queue
29 void KeyUsed(const std::string& key);
30 // removes + returns the lru key from the queue.
31 // If the queue is empty, "" is returned (you should use isEmpty())
32 std::string EvictKey();
33
34 private:
35 struct FastHash {
greggman 2012/06/25 18:53:03 do you really need FastHash?
dmurph 2012/06/26 02:32:56 Hell yeah! http://www.azillionmonkeys.com/qed/hash
36 const inline uint32 operator()(const std::string& key) const {
37 if (key.empty())
38 return 0;
39 return disk_cache::SuperFastHash(key.data(),
40 static_cast<int>(key.size()));
41 }
42 };
43 typedef std::list<std::string> StringList;
44 typedef base::hash_map<std::string,
45 StringList::iterator,
46 FastHash> IteratorMap;
47 StringList queue;
48 IteratorMap location_map;
49
50 DISALLOW_COPY_AND_ASSIGN(ProgramCacheLruHelper);
51 };
52
53 } // namespace gles2
54 } // namespace gpu
55
56 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_LRU_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698