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 #include "gpu/command_buffer/service/service_discardable_manager.h" | |
6 | |
7 #include "base/memory/singleton.h" | |
8 #include "gpu/command_buffer/service/texture_manager.h" | |
9 | |
10 namespace gpu { | |
11 namespace { | |
12 // TODO(ericrk): Arbitrary limit, refine this once we actually use this class in | |
13 // production. crbug.com/706456 | |
14 const size_t kMaxSize = 256 * 1024 * 1024; | |
15 } | |
16 | |
17 ServiceDiscardableManager::ServiceDiscardableManager() | |
18 : entries_(EntryCache::NO_AUTO_EVICT) {} | |
19 ServiceDiscardableManager::~ServiceDiscardableManager() = default; | |
20 | |
21 void ServiceDiscardableManager::InsertLockedTexture( | |
22 uint32_t texture_id, | |
23 size_t texture_size, | |
24 gles2::ContextGroup* context_group, | |
25 ServiceDiscardableHandle handle) { | |
26 total_size_ += texture_size; | |
27 entries_.Put({texture_id, context_group}, | |
28 GpuDiscardableEntry{handle, texture_size}); | |
29 EnforceLimits(); | |
30 } | |
31 | |
32 bool ServiceDiscardableManager::UnlockTexture( | |
33 uint32_t texture_id, | |
34 const gles2::ContextGroup* context_group) { | |
35 auto found = entries_.Get({texture_id, context_group}); | |
36 if (found == entries_.end()) | |
37 return false; | |
38 | |
39 found->second.handle.Unlock(); | |
40 EnforceLimits(); | |
41 return true; | |
42 } | |
43 | |
44 void ServiceDiscardableManager::OnTextureDeleted( | |
45 uint32_t texture_id, | |
46 const gles2::ContextGroup* context_group) { | |
piman
2017/05/02 22:21:03
You probably also need a call when the whole conte
ericrk
2017/05/10 21:36:03
Updated to handle this in TextureManager.
| |
47 auto found = entries_.Get({texture_id, context_group}); | |
48 if (found == entries_.end()) | |
49 return; | |
50 | |
51 found->second.handle.ForceDelete(); | |
52 total_size_ -= found->second.size; | |
53 entries_.Erase(found); | |
54 } | |
55 | |
56 void ServiceDiscardableManager::EnforceLimits() { | |
57 for (auto it = entries_.rbegin(); it != entries_.rend();) { | |
58 if (total_size_ <= kMaxSize) { | |
59 return; | |
60 } | |
61 if (!it->second.handle.Delete()) { | |
62 ++it; | |
63 continue; | |
64 } | |
65 | |
66 total_size_ -= it->second.size; | |
67 it->first.context_group->texture_manager()->RemoveTexture( | |
68 it->first.texture_id); | |
piman
2017/05/02 22:21:03
I think that for consistency, we should do somethi
ericrk
2017/05/10 21:36:02
Makes perfect sense. I *think* I have achieved thi
| |
69 it = entries_.Erase(it); | |
70 } | |
71 } | |
72 | |
73 bool ServiceDiscardableManager::IsEntryLockedForTesting( | |
74 uint32_t texture_id, | |
75 const gles2::ContextGroup* context_group) const { | |
76 auto found = entries_.Peek({texture_id, context_group}); | |
77 DCHECK(found != entries_.end()); | |
78 | |
79 return found->second.handle.IsLockedForTesting(); | |
80 } | |
81 | |
82 } // namespace gpu | |
OLD | NEW |