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 #include "content/common/gpu/gpu_memory_manager.h" | 5 #include "content/common/gpu/gpu_memory_manager.h" |
6 | 6 |
7 #include "content/common/gpu/gpu_memory_manager_client.h" | 7 #include "content/common/gpu/gpu_memory_manager_client.h" |
8 #include "content/common/gpu/gpu_memory_tracking.h" | 8 #include "content/common/gpu/gpu_memory_tracking.h" |
9 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 9 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 client_state_.reset( | 100 client_state_.reset( |
101 memmgr_->CreateClientState(this, surface_id != 0, visible)); | 101 memmgr_->CreateClientState(this, surface_id != 0, visible)); |
102 } | 102 } |
103 | 103 |
104 ~FakeClient() override { | 104 ~FakeClient() override { |
105 client_state_.reset(); | 105 client_state_.reset(); |
106 tracking_group_.reset(); | 106 tracking_group_.reset(); |
107 memory_tracker_ = NULL; | 107 memory_tracker_ = NULL; |
108 } | 108 } |
109 | 109 |
110 void SetMemoryAllocation(const MemoryAllocation& alloc) override { | |
111 allocation_ = alloc; | |
112 ClientAssignmentCollector::AddClientStat(this, alloc); | |
113 } | |
114 | |
115 void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override { | 110 void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override { |
116 suggest_have_frontbuffer_ = suggest_have_frontbuffer; | 111 suggest_have_frontbuffer_ = suggest_have_frontbuffer; |
117 } | 112 } |
118 | 113 |
119 bool GetTotalGpuMemory(uint64* bytes) override { | 114 bool GetTotalGpuMemory(uint64* bytes) override { |
120 if (total_gpu_memory_) { | 115 if (total_gpu_memory_) { |
121 *bytes = total_gpu_memory_; | 116 *bytes = total_gpu_memory_; |
122 return true; | 117 return true; |
123 } | 118 } |
124 return false; | 119 return false; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 } | 180 } |
186 | 181 |
187 void Manage() { | 182 void Manage() { |
188 ClientAssignmentCollector::ClearAllStats(); | 183 ClientAssignmentCollector::ClearAllStats(); |
189 memmgr_.Manage(); | 184 memmgr_.Manage(); |
190 } | 185 } |
191 | 186 |
192 GpuMemoryManager memmgr_; | 187 GpuMemoryManager memmgr_; |
193 }; | 188 }; |
194 | 189 |
190 // Disabled, as gpumemorymanager doesnt do much work now. | |
191 // TODO(sohanjg): Clean up as part of crbug.com/537563. | |
piman
2015/09/30 19:04:33
Just delete all of them instead? They don't provid
sohanjg
2015/10/01 07:14:13
Done.
| |
192 | |
195 // Test GpuMemoryManager::Manage basic functionality. | 193 // Test GpuMemoryManager::Manage basic functionality. |
196 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer | 194 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer |
197 // according to visibility and last used time for stubs with surface. | 195 // according to visibility and last used time for stubs with surface. |
198 // Expect memory allocation to be shared according to share groups for stubs | 196 // Expect memory allocation to be shared according to share groups for stubs |
199 // without a surface. | 197 // without a surface. |
200 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { | 198 TEST_F(GpuMemoryManagerTest, DISABLED_TestManageBasicFunctionality) { |
201 // Test stubs with surface. | 199 // Test stubs with surface. |
202 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 200 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
203 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); | 201 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); |
204 | 202 |
205 Manage(); | 203 Manage(); |
206 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 204 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
207 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 205 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
208 | 206 |
209 // Test stubs without surface, with share group of 1 stub. | 207 // Test stubs without surface, with share group of 1 stub. |
210 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); | 208 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); |
211 | 209 |
212 Manage(); | 210 Manage(); |
213 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 211 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
214 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 212 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
215 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | 213 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); |
216 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | 214 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); |
217 | 215 |
218 // Test stub without surface, with share group of multiple stubs. | 216 // Test stub without surface, with share group of multiple stubs. |
219 FakeClient stub5(&memmgr_ , &stub2); | 217 FakeClient stub5(&memmgr_ , &stub2); |
220 | 218 |
221 Manage(); | 219 Manage(); |
222 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | 220 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); |
223 } | 221 } |
224 | 222 |
225 // Test GpuMemoryManager::Manage functionality: changing visibility. | 223 // Test GpuMemoryManager::Manage functionality: changing visibility. |
226 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer | 224 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer |
227 // according to visibility and last used time for stubs with surface. | 225 // according to visibility and last used time for stubs with surface. |
228 // Expect memory allocation to be shared according to share groups for stubs | 226 // Expect memory allocation to be shared according to share groups for stubs |
229 // without a surface. | 227 // without a surface. |
230 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { | 228 TEST_F(GpuMemoryManagerTest, DISABLED_TestManageChangingVisibility) { |
231 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 229 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
232 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); | 230 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); |
233 | 231 |
234 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); | 232 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); |
235 FakeClient stub5(&memmgr_ , &stub2); | 233 FakeClient stub5(&memmgr_ , &stub2); |
236 | 234 |
237 Manage(); | 235 Manage(); |
238 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 236 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
239 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 237 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
240 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | 238 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); |
241 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | 239 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); |
242 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | 240 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); |
243 | 241 |
244 stub1.SetVisible(false); | 242 stub1.SetVisible(false); |
245 stub2.SetVisible(true); | 243 stub2.SetVisible(true); |
246 | 244 |
247 Manage(); | 245 Manage(); |
248 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 246 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
249 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | 247 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); |
250 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | 248 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); |
251 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | 249 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); |
252 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | 250 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); |
253 } | 251 } |
254 | 252 |
255 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | 253 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
256 // of visible stubs. | 254 // of visible stubs. |
257 // Expect all allocations to continue to have frontbuffer. | 255 // Expect all allocations to continue to have frontbuffer. |
258 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { | 256 TEST_F(GpuMemoryManagerTest, DISABLED_TestManageManyVisibleStubs) { |
259 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 257 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
260 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), | 258 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), |
261 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | 259 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
262 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); | 260 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); |
263 | 261 |
264 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub2); | 262 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub2); |
265 FakeClient stub7(&memmgr_ , &stub2); | 263 FakeClient stub7(&memmgr_ , &stub2); |
266 | 264 |
267 Manage(); | 265 Manage(); |
268 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 266 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
269 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | 267 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); |
270 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_)); | 268 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_)); |
271 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub4.allocation_)); | 269 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub4.allocation_)); |
272 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | 270 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); |
273 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub6.allocation_)); | 271 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub6.allocation_)); |
274 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub7.allocation_)); | 272 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub7.allocation_)); |
275 } | 273 } |
276 | 274 |
277 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | 275 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
278 // of not visible stubs. | 276 // of not visible stubs. |
279 // Expect the stubs surpassing the threshold to not have a backbuffer. | 277 // Expect the stubs surpassing the threshold to not have a backbuffer. |
280 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { | 278 TEST_F(GpuMemoryManagerTest, DISABLED_TestManageManyNotVisibleStubs) { |
281 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 279 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
282 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), | 280 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), |
283 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | 281 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
284 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); | 282 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); |
285 stub4.SetVisible(false); | 283 stub4.SetVisible(false); |
286 stub3.SetVisible(false); | 284 stub3.SetVisible(false); |
287 stub2.SetVisible(false); | 285 stub2.SetVisible(false); |
288 stub1.SetVisible(false); | 286 stub1.SetVisible(false); |
289 | 287 |
290 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub4); | 288 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub4); |
291 FakeClient stub7(&memmgr_ , &stub1); | 289 FakeClient stub7(&memmgr_ , &stub1); |
292 | 290 |
293 Manage(); | 291 Manage(); |
294 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 292 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
295 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 293 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
296 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); | 294 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); |
297 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); | 295 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); |
298 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); | 296 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); |
299 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); | 297 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); |
300 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); | 298 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); |
301 } | 299 } |
302 | 300 |
303 // Test GpuMemoryManager::Manage functionality: Test changing the last used | 301 // Test GpuMemoryManager::Manage functionality: Test changing the last used |
304 // time of stubs when doing so causes change in which stubs surpass threshold. | 302 // time of stubs when doing so causes change in which stubs surpass threshold. |
305 // Expect frontbuffer to be dropped for the older stub. | 303 // Expect frontbuffer to be dropped for the older stub. |
306 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { | 304 TEST_F(GpuMemoryManagerTest, DISABLED_TestManageChangingLastUsedTime) { |
307 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 305 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
308 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), | 306 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), |
309 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | 307 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
310 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); | 308 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); |
311 | 309 |
312 FakeClient stub5(&memmgr_ , &stub3), stub6(&memmgr_ , &stub4); | 310 FakeClient stub5(&memmgr_ , &stub3), stub6(&memmgr_ , &stub4); |
313 FakeClient stub7(&memmgr_ , &stub3); | 311 FakeClient stub7(&memmgr_ , &stub3); |
314 | 312 |
315 // Make stub4 be the least-recently-used client | 313 // Make stub4 be the least-recently-used client |
316 stub4.SetVisible(false); | 314 stub4.SetVisible(false); |
(...skipping 23 matching lines...) Expand all Loading... | |
340 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_)); | 338 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_)); |
341 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_)); | 339 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_)); |
342 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_)); | 340 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_)); |
343 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub7.allocation_)); | 341 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub7.allocation_)); |
344 } | 342 } |
345 | 343 |
346 // Test GpuMemoryManager::Manage functionality: Test changing importance of | 344 // Test GpuMemoryManager::Manage functionality: Test changing importance of |
347 // enough stubs so that every stub in share group crosses threshold. | 345 // enough stubs so that every stub in share group crosses threshold. |
348 // Expect memory allocation of the stubs without surface to share memory | 346 // Expect memory allocation of the stubs without surface to share memory |
349 // allocation with the most visible stub in share group. | 347 // allocation with the most visible stub in share group. |
350 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { | 348 TEST_F(GpuMemoryManagerTest, DISABLED_TestManageChangingImportanceShareGroup) { |
351 FakeClient stub_ignore_a(&memmgr_, GenerateUniqueSurfaceId(), true), | 349 FakeClient stub_ignore_a(&memmgr_, GenerateUniqueSurfaceId(), true), |
352 stub_ignore_b(&memmgr_, GenerateUniqueSurfaceId(), false), | 350 stub_ignore_b(&memmgr_, GenerateUniqueSurfaceId(), false), |
353 stub_ignore_c(&memmgr_, GenerateUniqueSurfaceId(), false); | 351 stub_ignore_c(&memmgr_, GenerateUniqueSurfaceId(), false); |
354 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), false), | 352 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), false), |
355 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); | 353 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); |
356 | 354 |
357 FakeClient stub3(&memmgr_, &stub2), stub4(&memmgr_, &stub2); | 355 FakeClient stub3(&memmgr_, &stub2), stub4(&memmgr_, &stub2); |
358 | 356 |
359 // stub1 and stub2 keep their non-hibernated state because they're | 357 // stub1 and stub2 keep their non-hibernated state because they're |
360 // either visible or the 2 most recently used clients (through the | 358 // either visible or the 2 most recently used clients (through the |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 stub_ignore_c.SetVisible(true); | 396 stub_ignore_c.SetVisible(true); |
399 stub_ignore_c.SetVisible(false); | 397 stub_ignore_c.SetVisible(false); |
400 Manage(); | 398 Manage(); |
401 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | 399 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); |
402 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); | 400 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); |
403 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); | 401 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); |
404 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); | 402 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); |
405 } | 403 } |
406 | 404 |
407 } // namespace content | 405 } // namespace content |
OLD | NEW |