OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 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_SERVICE_DISCARDABLE_MANAGER_H_ | |
6 #define GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/containers/mru_cache.h" | |
11 #include "gpu/command_buffer/common/discardable_handle.h" | |
12 #include "gpu/command_buffer/service/context_group.h" | |
13 #include "gpu/command_buffer/service/texture_manager.h" | |
14 #include "gpu/gpu_export.h" | |
15 | |
16 namespace gpu { | |
17 class GPU_EXPORT ServiceDiscardableManager { | |
18 public: | |
19 ServiceDiscardableManager(); | |
20 ~ServiceDiscardableManager(); | |
21 | |
22 void InsertLockedTexture(uint32_t texture_id, | |
23 size_t texture_size, | |
24 gles2::TextureManager* texture_manager, | |
25 ServiceDiscardableHandle handle); | |
26 | |
27 // Unlocks the indicated texture. If *|texture_to_unbind| is not nullptr, | |
28 // ServiceDiscardableManager has taken ownership of the given texture, and | |
29 // it is the callers responsibility to unbind it from any other objects. | |
30 // Returns false if the given texture_id has not been initialized for use | |
31 // with discardable. | |
32 bool UnlockTexture(uint32_t texture_id, | |
33 gles2::TextureManager* texture_manager, | |
34 gles2::TextureRef** texture_to_unbind); | |
35 // Locks the indicated texture, allowing it to be used in future GL commands. | |
36 // Returns false if the given texture_id has not been initialized for use | |
37 // with discardable. | |
38 bool LockTexture(uint32_t texture_id, gles2::TextureManager* texture_manager); | |
39 | |
40 // Returns all unlocked texture refs to the texture_manager for deletion. | |
41 // After this point, this class will have no references to the given | |
42 // |texture_manager|. | |
43 void OnTextureManagerDestruction(gles2::TextureManager* texture_manager); | |
44 | |
45 // Called when a texture is deleted, to clean up state. | |
46 void OnTextureDeleted(uint32_t texture_id, | |
47 gles2::TextureManager* texture_manager); | |
48 | |
49 // Called by the TextureManager when a texture's size changes. | |
50 void OnTextureSizeChanged(uint32_t texture_id, | |
51 gles2::TextureManager* texture_manager, | |
52 size_t new_size); | |
53 | |
54 // Test only functions: | |
55 size_t NumCacheEntriesForTesting() const { return entries_.size(); } | |
56 bool IsEntryLockedForTesting(uint32_t texture_id, | |
57 gles2::TextureManager* texture_manager) const; | |
58 size_t TotalSizeForTesting() const { return total_size_; } | |
59 | |
60 private: | |
61 void EnforceLimits(); | |
62 | |
63 struct GpuDiscardableEntry { | |
64 public: | |
65 GpuDiscardableEntry(ServiceDiscardableHandle handle, size_t size); | |
66 GpuDiscardableEntry(const GpuDiscardableEntry& other); | |
67 GpuDiscardableEntry(GpuDiscardableEntry&& other); | |
68 ~GpuDiscardableEntry(); | |
69 | |
70 ServiceDiscardableHandle handle; | |
71 scoped_refptr<gles2::TextureRef> unlocked_texture_ref; | |
72 // The current ref count of this object with regards to command buffer | |
73 // execution. May be out of sync with the handle's refcount, as the handle | |
74 // can be locked out of band with the command buffer. | |
75 uint32_t service_ref_count_ = 1; | |
76 size_t size; | |
77 }; | |
78 struct GpuDiscardableEntryKey { | |
79 uint32_t texture_id; | |
80 gles2::TextureManager* texture_manager; | |
81 }; | |
82 struct GpuDiscardableEntryKeyCompare { | |
83 bool operator()(const GpuDiscardableEntryKey& lhs, | |
84 const GpuDiscardableEntryKey& rhs) const { | |
85 return lhs.texture_manager < rhs.texture_manager || | |
86 (lhs.texture_manager == rhs.texture_manager && | |
87 lhs.texture_id < rhs.texture_id); | |
piman
2017/05/10 22:13:59
nit: you can use std::tie for readability:
return
ericrk
2017/05/12 16:22:12
Done.
| |
88 } | |
89 }; | |
90 using EntryCache = base::MRUCache<GpuDiscardableEntryKey, | |
91 GpuDiscardableEntry, | |
92 GpuDiscardableEntryKeyCompare>; | |
93 EntryCache entries_; | |
94 | |
95 // Total size of all |entries_|. The same as summing | |
96 // GpuDiscardableEntry::size for each entry. | |
97 size_t total_size_ = 0; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(ServiceDiscardableManager); | |
100 }; | |
101 | |
102 } // namespace gpu | |
103 | |
104 #endif // GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ | |
OLD | NEW |