OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
6 #define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 6 #define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
7 | 7 |
8 #if defined(ENABLE_GPU) | 8 #if defined(ENABLE_GPU) |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 96 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
97 TestForegroundStubsGetBonusAllocation); | 97 TestForegroundStubsGetBonusAllocation); |
98 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 98 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
99 TestUpdateAvailableGpuMemory); | 99 TestUpdateAvailableGpuMemory); |
100 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 100 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
101 GpuMemoryAllocationCompareTests); | 101 GpuMemoryAllocationCompareTests); |
102 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 102 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
103 StubMemoryStatsForLastManageTests); | 103 StubMemoryStatsForLastManageTests); |
104 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 104 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
105 TestManagedUsageTracking); | 105 TestManagedUsageTracking); |
| 106 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
| 107 TestBackgroundCutoff); |
| 108 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
| 109 TestBackgroundMru); |
106 | 110 |
107 struct ClientState { | 111 struct ClientState { |
108 ClientState(GpuMemoryManagerClient* client, | 112 ClientState(GpuMemoryManagerClient* client, |
109 bool has_surface, | 113 bool has_surface, |
110 bool visible, | 114 bool visible, |
111 base::TimeTicks last_used_time); | 115 base::TimeTicks last_used_time); |
112 // The client to send allocations to. | 116 // The client to send allocations to. |
113 GpuMemoryManagerClient* client; | 117 GpuMemoryManagerClient* client; |
114 | 118 |
115 // Offscreen commandbuffers will not have a surface. | 119 // Offscreen commandbuffers will not have a surface. |
(...skipping 18 matching lines...) Expand all Loading... |
134 ClientState* rhs); | 138 ClientState* rhs); |
135 }; | 139 }; |
136 | 140 |
137 typedef std::map<GpuMemoryManagerClient*, ClientState*> ClientMap; | 141 typedef std::map<GpuMemoryManagerClient*, ClientState*> ClientMap; |
138 | 142 |
139 typedef std::vector<ClientState*> ClientStateVector; | 143 typedef std::vector<ClientState*> ClientStateVector; |
140 | 144 |
141 void Manage(); | 145 void Manage(); |
142 void SetClientsHibernatedState(const ClientStateVector& clients) const; | 146 void SetClientsHibernatedState(const ClientStateVector& clients) const; |
143 size_t GetVisibleClientAllocation(const ClientStateVector& clients) const; | 147 size_t GetVisibleClientAllocation(const ClientStateVector& clients) const; |
| 148 size_t GetCurrentBackgroundedAvailableGpuMemory() const; |
144 | 149 |
145 // Update the amount of GPU memory we think we have in the system, based | 150 // Update the amount of GPU memory we think we have in the system, based |
146 // on what the stubs' contexts report. | 151 // on what the stubs' contexts report. |
147 void UpdateAvailableGpuMemory(const ClientStateVector& clients); | 152 void UpdateAvailableGpuMemory(const ClientStateVector& clients); |
| 153 void UpdateBackgroundedAvailableGpuMemory(); |
148 | 154 |
149 // The amount of video memory which is available for allocation. | 155 // The amount of video memory which is available for allocation. |
150 size_t GetAvailableGpuMemory() const; | 156 size_t GetAvailableGpuMemory() const; |
151 | 157 |
152 // Default per-OS value for the amount of available GPU memory, used | 158 // Minimum value of available GPU memory, no matter how little the GPU |
153 // if we can't query the driver for an exact value. | 159 // reports. This is the default value. |
154 size_t GetDefaultAvailableGpuMemory() const; | 160 size_t GetDefaultAvailableGpuMemory() const; |
155 | 161 |
156 // Maximum cap on total GPU memory, no matter how much the GPU reports. | 162 // Maximum cap on total GPU memory, no matter how much the GPU reports. |
157 size_t GetMaximumTotalGpuMemory() const; | 163 size_t GetMaximumTotalGpuMemory() const; |
158 | 164 |
159 // The maximum and minimum amount of memory that a tab may be assigned. | 165 // The maximum and minimum amount of memory that a tab may be assigned. |
160 size_t GetMaximumTabAllocation() const; | 166 size_t GetMaximumTabAllocation() const; |
161 size_t GetMinimumTabAllocation() const; | 167 size_t GetMinimumTabAllocation() const; |
162 | 168 |
163 // Get a reasonable memory limit from a viewport's surface area. | 169 // Get a reasonable memory limit from a viewport's surface area. |
164 static size_t CalcAvailableFromViewportArea(int viewport_area); | 170 static size_t CalcAvailableFromViewportArea(int viewport_area); |
165 static size_t CalcAvailableFromGpuTotal(size_t total_gpu_memory); | 171 static size_t CalcAvailableFromGpuTotal(size_t total_gpu_memory); |
166 | 172 |
167 // Interfaces for testing | 173 // Interfaces for testing |
168 void TestingSetClientVisible(GpuMemoryManagerClient* client, bool visible); | 174 void TestingSetClientVisible(GpuMemoryManagerClient* client, bool visible); |
169 void TestingSetClientLastUsedTime(GpuMemoryManagerClient* client, | 175 void TestingSetClientLastUsedTime(GpuMemoryManagerClient* client, |
170 base::TimeTicks last_used_time); | 176 base::TimeTicks last_used_time); |
171 void TestingSetClientHasSurface(GpuMemoryManagerClient* client, | 177 void TestingSetClientHasSurface(GpuMemoryManagerClient* client, |
172 bool has_surface); | 178 bool has_surface); |
173 bool TestingCompareClients(GpuMemoryManagerClient* lhs, | 179 bool TestingCompareClients(GpuMemoryManagerClient* lhs, |
174 GpuMemoryManagerClient* rhs) const; | 180 GpuMemoryManagerClient* rhs) const; |
175 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; } | 181 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; } |
| 182 void TestingSetAvailableGpuMemory(size_t bytes) { |
| 183 bytes_available_gpu_memory_ = bytes; |
| 184 bytes_available_gpu_memory_overridden_ = true; |
| 185 } |
| 186 |
| 187 void TestingSetBackgroundedAvailableGpuMemory(size_t bytes) { |
| 188 bytes_backgrounded_available_gpu_memory_ = bytes; |
| 189 } |
176 | 190 |
177 // All clients of this memory manager which have callbacks we | 191 // All clients of this memory manager which have callbacks we |
178 // can use to adjust memory usage | 192 // can use to adjust memory usage |
179 ClientMap clients_; | 193 ClientMap clients_; |
180 | 194 |
181 // All context groups' tracking structures | 195 // All context groups' tracking structures |
182 std::set<GpuMemoryTrackingGroup*> tracking_groups_; | 196 std::set<GpuMemoryTrackingGroup*> tracking_groups_; |
183 | 197 |
184 base::CancelableClosure delayed_manage_callback_; | 198 base::CancelableClosure delayed_manage_callback_; |
185 bool manage_immediate_scheduled_; | 199 bool manage_immediate_scheduled_; |
186 | 200 |
187 size_t max_surfaces_with_frontbuffer_soft_limit_; | 201 size_t max_surfaces_with_frontbuffer_soft_limit_; |
188 | 202 |
189 // The maximum amount of memory that may be allocated for GPU resources | 203 // The maximum amount of memory that may be allocated for GPU resources |
190 size_t bytes_available_gpu_memory_; | 204 size_t bytes_available_gpu_memory_; |
191 bool bytes_available_gpu_memory_overridden_; | 205 bool bytes_available_gpu_memory_overridden_; |
192 | 206 |
| 207 // The maximum amount of memory that can be allocated for GPU resources |
| 208 // in backgrounded renderers. |
| 209 size_t bytes_backgrounded_available_gpu_memory_; |
| 210 |
193 // The current total memory usage, and historical maximum memory usage | 211 // The current total memory usage, and historical maximum memory usage |
194 size_t bytes_allocated_current_; | 212 size_t bytes_allocated_current_; |
195 size_t bytes_allocated_managed_visible_; | 213 size_t bytes_allocated_managed_visible_; |
196 size_t bytes_allocated_managed_backgrounded_; | 214 size_t bytes_allocated_managed_backgrounded_; |
197 | 215 |
198 // The number of browser windows that exist. If we ever receive a | 216 // The number of browser windows that exist. If we ever receive a |
199 // GpuMsg_SetVideoMemoryWindowCount, then we use this to compute memory | 217 // GpuMsg_SetVideoMemoryWindowCount, then we use this to compute memory |
200 // budgets, instead of doing more complicated stub-based calculations. | 218 // budgets, instead of doing more complicated stub-based calculations. |
201 bool window_count_has_been_received_; | 219 bool window_count_has_been_received_; |
202 uint32 window_count_; | 220 uint32 window_count_; |
(...skipping 22 matching lines...) Expand all Loading... |
225 // context is currently rendering on. Returns false if no extension exists | 243 // context is currently rendering on. Returns false if no extension exists |
226 // to get the exact amount of GPU memory. | 244 // to get the exact amount of GPU memory. |
227 virtual bool GetTotalGpuMemory(size_t* bytes) = 0; | 245 virtual bool GetTotalGpuMemory(size_t* bytes) = 0; |
228 }; | 246 }; |
229 | 247 |
230 } // namespace content | 248 } // namespace content |
231 | 249 |
232 #endif | 250 #endif |
233 | 251 |
234 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 252 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
OLD | NEW |