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 |
195 // Test GpuMemoryManager::Manage basic functionality. | |
196 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer | |
197 // according to visibility and last used time for stubs with surface. | |
198 // Expect memory allocation to be shared according to share groups for stubs | |
199 // without a surface. | |
200 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { | |
201 // Test stubs with surface. | |
202 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | |
203 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); | |
204 | |
205 Manage(); | |
206 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | |
207 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
208 | |
209 // Test stubs without surface, with share group of 1 stub. | |
210 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); | |
211 | |
212 Manage(); | |
213 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | |
214 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
215 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | |
216 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | |
217 | |
218 // Test stub without surface, with share group of multiple stubs. | |
219 FakeClient stub5(&memmgr_ , &stub2); | |
220 | |
221 Manage(); | |
222 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | |
223 } | |
224 | |
225 // Test GpuMemoryManager::Manage functionality: changing visibility. | |
226 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer | |
227 // according to visibility and last used time for stubs with surface. | |
228 // Expect memory allocation to be shared according to share groups for stubs | |
229 // without a surface. | |
230 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { | |
231 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | |
232 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); | |
233 | |
234 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); | |
235 FakeClient stub5(&memmgr_ , &stub2); | |
236 | |
237 Manage(); | |
238 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | |
239 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
240 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | |
241 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | |
242 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | |
243 | |
244 stub1.SetVisible(false); | |
245 stub2.SetVisible(true); | |
246 | |
247 Manage(); | |
248 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | |
249 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | |
250 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | |
251 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | |
252 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | |
253 } | |
254 | |
255 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | |
256 // of visible stubs. | |
257 // Expect all allocations to continue to have frontbuffer. | |
258 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { | |
259 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | |
260 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), | |
261 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | |
262 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); | |
263 | |
264 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub2); | |
265 FakeClient stub7(&memmgr_ , &stub2); | |
266 | |
267 Manage(); | |
268 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | |
269 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | |
270 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_)); | |
271 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub4.allocation_)); | |
272 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | |
273 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub6.allocation_)); | |
274 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub7.allocation_)); | |
275 } | |
276 | |
277 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | |
278 // of not visible stubs. | |
279 // Expect the stubs surpassing the threshold to not have a backbuffer. | |
280 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { | |
281 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | |
282 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), | |
283 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | |
284 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); | |
285 stub4.SetVisible(false); | |
286 stub3.SetVisible(false); | |
287 stub2.SetVisible(false); | |
288 stub1.SetVisible(false); | |
289 | |
290 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub4); | |
291 FakeClient stub7(&memmgr_ , &stub1); | |
292 | |
293 Manage(); | |
294 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | |
295 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
296 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); | |
297 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); | |
298 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); | |
299 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); | |
300 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); | |
301 } | |
302 | |
303 // Test GpuMemoryManager::Manage functionality: Test changing the last used | |
304 // time of stubs when doing so causes change in which stubs surpass threshold. | |
305 // Expect frontbuffer to be dropped for the older stub. | |
306 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { | |
307 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | |
308 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), | |
309 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | |
310 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); | |
311 | |
312 FakeClient stub5(&memmgr_ , &stub3), stub6(&memmgr_ , &stub4); | |
313 FakeClient stub7(&memmgr_ , &stub3); | |
314 | |
315 // Make stub4 be the least-recently-used client | |
316 stub4.SetVisible(false); | |
317 stub3.SetVisible(false); | |
318 stub2.SetVisible(false); | |
319 stub1.SetVisible(false); | |
320 | |
321 Manage(); | |
322 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | |
323 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
324 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); | |
325 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); | |
326 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); | |
327 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); | |
328 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); | |
329 | |
330 // Make stub3 become the least-recently-used client. | |
331 stub2.SetVisible(true); | |
332 stub2.SetVisible(false); | |
333 stub4.SetVisible(true); | |
334 stub4.SetVisible(false); | |
335 | |
336 Manage(); | |
337 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | |
338 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
339 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub3.allocation_)); | |
340 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_)); | |
341 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_)); | |
342 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_)); | |
343 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub7.allocation_)); | |
344 } | |
345 | |
346 // Test GpuMemoryManager::Manage functionality: Test changing importance of | |
347 // enough stubs so that every stub in share group crosses threshold. | |
348 // Expect memory allocation of the stubs without surface to share memory | |
349 // allocation with the most visible stub in share group. | |
350 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { | |
351 FakeClient stub_ignore_a(&memmgr_, GenerateUniqueSurfaceId(), true), | |
352 stub_ignore_b(&memmgr_, GenerateUniqueSurfaceId(), false), | |
353 stub_ignore_c(&memmgr_, GenerateUniqueSurfaceId(), false); | |
354 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), false), | |
355 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); | |
356 | |
357 FakeClient stub3(&memmgr_, &stub2), stub4(&memmgr_, &stub2); | |
358 | |
359 // stub1 and stub2 keep their non-hibernated state because they're | |
360 // either visible or the 2 most recently used clients (through the | |
361 // first three checks). | |
362 stub1.SetVisible(true); | |
363 stub2.SetVisible(true); | |
364 Manage(); | |
365 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | |
366 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | |
367 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | |
368 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | |
369 | |
370 stub1.SetVisible(false); | |
371 Manage(); | |
372 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | |
373 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | |
374 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | |
375 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | |
376 | |
377 stub2.SetVisible(false); | |
378 Manage(); | |
379 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | |
380 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
381 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | |
382 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | |
383 | |
384 // stub_ignore_b will cause stub1 to become hibernated (because | |
385 // stub_ignore_a, stub_ignore_b, and stub2 are all non-hibernated and more | |
386 // important). | |
387 stub_ignore_b.SetVisible(true); | |
388 stub_ignore_b.SetVisible(false); | |
389 Manage(); | |
390 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | |
391 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | |
392 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | |
393 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | |
394 | |
395 // stub_ignore_c will cause stub2 to become hibernated (because | |
396 // stub_ignore_a, stub_ignore_b, and stub_ignore_c are all non-hibernated | |
397 // and more important). | |
398 stub_ignore_c.SetVisible(true); | |
399 stub_ignore_c.SetVisible(false); | |
400 Manage(); | |
401 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | |
402 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); | |
403 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); | |
404 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); | |
405 } | |
406 | |
407 } // namespace content | 190 } // namespace content |
OLD | NEW |