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

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

Issue 2814583002: Service/ClientDiscardableManager (Closed)
Patch Set: rebase Created 3 years, 7 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) 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/gpu_export.h"
14
15 namespace gpu {
16 namespace gles2 {
17 class TextureManager;
18 class TextureRef;
19 }
20
21 class GPU_EXPORT ServiceDiscardableManager {
22 public:
23 ServiceDiscardableManager();
24 ~ServiceDiscardableManager();
25
26 void InsertLockedTexture(uint32_t texture_id,
27 size_t texture_size,
28 gles2::TextureManager* texture_manager,
29 ServiceDiscardableHandle handle);
30
31 // Unlocks the indicated texture. If *|texture_to_unbind| is not nullptr,
32 // ServiceDiscardableManager has taken ownership of the given texture, and
33 // it is the callers responsibility to unbind it from any other objects.
34 // Returns false if the given texture_id has not been initialized for use
35 // with discardable.
36 bool UnlockTexture(uint32_t texture_id,
37 gles2::TextureManager* texture_manager,
38 gles2::TextureRef** texture_to_unbind);
39 // Locks the indicated texture, allowing it to be used in future GL commands.
40 // Returns false if the given texture_id has not been initialized for use
41 // with discardable.
42 bool LockTexture(uint32_t texture_id, gles2::TextureManager* texture_manager);
43
44 // Returns all unlocked texture refs to the texture_manager for deletion.
45 // After this point, this class will have no references to the given
46 // |texture_manager|.
47 void OnTextureManagerDestruction(gles2::TextureManager* texture_manager);
48
49 // Called when a texture is deleted, to clean up state.
50 void OnTextureDeleted(uint32_t texture_id,
51 gles2::TextureManager* texture_manager);
52
53 // Called by the TextureManager when a texture's size changes.
54 void OnTextureSizeChanged(uint32_t texture_id,
55 gles2::TextureManager* texture_manager,
56 size_t new_size);
57
58 // Test only functions:
59 size_t NumCacheEntriesForTesting() const { return entries_.size(); }
60 bool IsEntryLockedForTesting(uint32_t texture_id,
61 gles2::TextureManager* texture_manager) const;
62 size_t TotalSizeForTesting() const { return total_size_; }
63 gles2::TextureRef* UnlockedTextureRefForTesting(
64 uint32_t texture_id,
65 gles2::TextureManager* texture_manager) const;
66
67 // TODO(ericrk): Arbitrary limit, refine this once we actually use this class
68 // in production. crbug.com/706456
69 static const size_t kMaxSize = 256 * 1024 * 1024;
70
71 private:
72 void EnforceLimits();
73
74 struct GpuDiscardableEntry {
75 public:
76 GpuDiscardableEntry(ServiceDiscardableHandle handle, size_t size);
77 GpuDiscardableEntry(const GpuDiscardableEntry& other);
78 GpuDiscardableEntry(GpuDiscardableEntry&& other);
79 ~GpuDiscardableEntry();
80
81 ServiceDiscardableHandle handle;
82 scoped_refptr<gles2::TextureRef> unlocked_texture_ref;
83 // The current ref count of this object with regards to command buffer
84 // execution. May be out of sync with the handle's refcount, as the handle
85 // can be locked out of band with the command buffer.
86 uint32_t service_ref_count_ = 1;
87 size_t size;
88 };
89 struct GpuDiscardableEntryKey {
90 uint32_t texture_id;
91 gles2::TextureManager* texture_manager;
92 };
93 struct GpuDiscardableEntryKeyCompare {
94 bool operator()(const GpuDiscardableEntryKey& lhs,
95 const GpuDiscardableEntryKey& rhs) const {
96 return std::tie(lhs.texture_manager, lhs.texture_id) <
97 std::tie(rhs.texture_manager, rhs.texture_id);
98 }
99 };
100 using EntryCache = base::MRUCache<GpuDiscardableEntryKey,
101 GpuDiscardableEntry,
102 GpuDiscardableEntryKeyCompare>;
103 EntryCache entries_;
104
105 // Total size of all |entries_|. The same as summing
106 // GpuDiscardableEntry::size for each entry.
107 size_t total_size_ = 0;
108
109 DISALLOW_COPY_AND_ASSIGN(ServiceDiscardableManager);
110 };
111
112 } // namespace gpu
113
114 #endif // GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698