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_allocation.h" | 5 #include "content/common/gpu/gpu_memory_allocation.h" |
6 #include "content/common/gpu/gpu_memory_manager.h" | 6 #include "content/common/gpu/gpu_memory_manager.h" |
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 "ui/gfx/size_conversions.h" | 9 #include "ui/gfx/size_conversions.h" |
10 | 10 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 static int32 GenerateUniqueSurfaceId() { | 169 static int32 GenerateUniqueSurfaceId() { |
170 static int32 surface_id_ = 1; | 170 static int32 surface_id_ = 1; |
171 return surface_id_++; | 171 return surface_id_++; |
172 } | 172 } |
173 | 173 |
174 bool IsAllocationForegroundForSurfaceYes( | 174 bool IsAllocationForegroundForSurfaceYes( |
175 const GpuMemoryAllocation& alloc) { | 175 const GpuMemoryAllocation& alloc) { |
176 return alloc.browser_allocation.suggest_have_frontbuffer && | 176 return alloc.browser_allocation.suggest_have_frontbuffer && |
177 !alloc.renderer_allocation.have_backbuffer_when_not_visible && | 177 !alloc.renderer_allocation.have_backbuffer_when_not_visible && |
178 alloc.renderer_allocation.bytes_limit_when_visible >= | 178 alloc.renderer_allocation.bytes_limit_when_visible >= |
179 GetMinimumTabAllocation(); | 179 GetMinimumClientAllocation(); |
180 } | 180 } |
181 bool IsAllocationBackgroundForSurfaceYes( | 181 bool IsAllocationBackgroundForSurfaceYes( |
182 const GpuMemoryAllocation& alloc) { | 182 const GpuMemoryAllocation& alloc) { |
183 return alloc.browser_allocation.suggest_have_frontbuffer && | 183 return alloc.browser_allocation.suggest_have_frontbuffer && |
184 !alloc.renderer_allocation.have_backbuffer_when_not_visible && | 184 !alloc.renderer_allocation.have_backbuffer_when_not_visible && |
185 alloc.renderer_allocation.bytes_limit_when_not_visible <= | 185 alloc.renderer_allocation.bytes_limit_when_not_visible <= |
186 memmgr_.GetCurrentBackgroundedAvailableGpuMemory(); | 186 memmgr_.GetCurrentNonvisibleAvailableGpuMemory(); |
187 } | 187 } |
188 bool IsAllocationHibernatedForSurfaceYes( | 188 bool IsAllocationHibernatedForSurfaceYes( |
189 const GpuMemoryAllocation& alloc) { | 189 const GpuMemoryAllocation& alloc) { |
190 return !alloc.browser_allocation.suggest_have_frontbuffer && | 190 return !alloc.browser_allocation.suggest_have_frontbuffer && |
191 !alloc.renderer_allocation.have_backbuffer_when_not_visible && | 191 !alloc.renderer_allocation.have_backbuffer_when_not_visible && |
192 alloc.renderer_allocation.bytes_limit_when_not_visible <= | 192 alloc.renderer_allocation.bytes_limit_when_not_visible <= |
193 memmgr_.GetCurrentBackgroundedAvailableGpuMemory(); | 193 memmgr_.GetCurrentNonvisibleAvailableGpuMemory(); |
194 } | 194 } |
195 bool IsAllocationForegroundForSurfaceNo( | 195 bool IsAllocationForegroundForSurfaceNo( |
196 const GpuMemoryAllocation& alloc) { | 196 const GpuMemoryAllocation& alloc) { |
197 return !alloc.browser_allocation.suggest_have_frontbuffer && | 197 return !alloc.browser_allocation.suggest_have_frontbuffer && |
198 !alloc.renderer_allocation.have_backbuffer_when_not_visible && | 198 !alloc.renderer_allocation.have_backbuffer_when_not_visible && |
199 alloc.renderer_allocation.bytes_limit_when_visible == | 199 alloc.renderer_allocation.bytes_limit_when_visible == |
200 GetMinimumTabAllocation(); | 200 GetMinimumClientAllocation(); |
201 } | 201 } |
202 bool IsAllocationBackgroundForSurfaceNo( | 202 bool IsAllocationBackgroundForSurfaceNo( |
203 const GpuMemoryAllocation& alloc) { | 203 const GpuMemoryAllocation& alloc) { |
204 return !alloc.browser_allocation.suggest_have_frontbuffer && | 204 return !alloc.browser_allocation.suggest_have_frontbuffer && |
205 !alloc.renderer_allocation.have_backbuffer_when_not_visible && | 205 !alloc.renderer_allocation.have_backbuffer_when_not_visible && |
206 alloc.renderer_allocation.bytes_limit_when_visible == | 206 alloc.renderer_allocation.bytes_limit_when_visible == |
207 GetMinimumTabAllocation(); | 207 GetMinimumClientAllocation(); |
208 } | 208 } |
209 bool IsAllocationHibernatedForSurfaceNo( | 209 bool IsAllocationHibernatedForSurfaceNo( |
210 const GpuMemoryAllocation& alloc) { | 210 const GpuMemoryAllocation& alloc) { |
211 return !alloc.browser_allocation.suggest_have_frontbuffer && | 211 return !alloc.browser_allocation.suggest_have_frontbuffer && |
212 !alloc.renderer_allocation.have_backbuffer_when_not_visible && | 212 !alloc.renderer_allocation.have_backbuffer_when_not_visible && |
213 alloc.renderer_allocation.bytes_limit_when_visible == 0; | 213 alloc.renderer_allocation.bytes_limit_when_visible == 0; |
214 } | 214 } |
215 | 215 |
216 void Manage() { | 216 void Manage() { |
217 ClientAssignmentCollector::ClearAllStats(); | 217 ClientAssignmentCollector::ClearAllStats(); |
(...skipping 11 matching lines...) Expand all Loading... |
229 size_t CalcAvailableClamped(size_t bytes) { | 229 size_t CalcAvailableClamped(size_t bytes) { |
230 bytes = std::max(bytes, memmgr_.GetDefaultAvailableGpuMemory()); | 230 bytes = std::max(bytes, memmgr_.GetDefaultAvailableGpuMemory()); |
231 bytes = std::min(bytes, memmgr_.GetMaximumTotalGpuMemory()); | 231 bytes = std::min(bytes, memmgr_.GetMaximumTotalGpuMemory()); |
232 return bytes; | 232 return bytes; |
233 } | 233 } |
234 | 234 |
235 size_t GetAvailableGpuMemory() { | 235 size_t GetAvailableGpuMemory() { |
236 return memmgr_.GetAvailableGpuMemory(); | 236 return memmgr_.GetAvailableGpuMemory(); |
237 } | 237 } |
238 | 238 |
239 size_t GetMaximumTabAllocation() { | 239 size_t GetMaximumClientAllocation() { |
240 return memmgr_.GetMaximumTabAllocation(); | 240 return memmgr_.GetMaximumClientAllocation(); |
241 } | 241 } |
242 | 242 |
243 size_t GetMinimumTabAllocation() { | 243 size_t GetMinimumClientAllocation() { |
244 return memmgr_.GetMinimumTabAllocation(); | 244 return memmgr_.GetMinimumClientAllocation(); |
245 } | 245 } |
246 | 246 |
247 GpuMemoryManager memmgr_; | 247 GpuMemoryManager memmgr_; |
248 }; | 248 }; |
249 | 249 |
250 // Test GpuMemoryManager::Manage basic functionality. | 250 // Test GpuMemoryManager::Manage basic functionality. |
251 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer | 251 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer |
252 // according to visibility and last used time for stubs with surface. | 252 // according to visibility and last used time for stubs with surface. |
253 // Expect memory allocation to be shared according to share groups for stubs | 253 // Expect memory allocation to be shared according to share groups for stubs |
254 // without a surface. | 254 // without a surface. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 Manage(); | 455 Manage(); |
456 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | 456 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); |
457 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); | 457 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); |
458 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); | 458 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); |
459 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); | 459 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); |
460 } | 460 } |
461 | 461 |
462 // Test GpuMemoryAllocation memory allocation bonuses: | 462 // Test GpuMemoryAllocation memory allocation bonuses: |
463 // When the number of visible tabs is small, each tab should get a | 463 // When the number of visible tabs is small, each tab should get a |
464 // gpu_resource_size_in_bytes allocation value that is greater than | 464 // gpu_resource_size_in_bytes allocation value that is greater than |
465 // GetMinimumTabAllocation(), and when the number of tabs is large, each should | 465 // GetMinimumClientAllocation(), and when the number of tabs is large, |
466 // get exactly GetMinimumTabAllocation() and not less. | 466 // each should get exactly GetMinimumClientAllocation() and not less. |
467 TEST_F(GpuMemoryManagerTest, TestForegroundStubsGetBonusAllocation) { | 467 TEST_F(GpuMemoryManagerTest, TestForegroundStubsGetBonusAllocation) { |
468 size_t max_stubs_before_no_bonus = | 468 size_t max_stubs_before_no_bonus = |
469 GetAvailableGpuMemory() / (GetMinimumTabAllocation() + 1); | 469 GetAvailableGpuMemory() / (GetMinimumClientAllocation() + 1); |
470 | 470 |
471 std::vector<FakeClient*> stubs; | 471 std::vector<FakeClient*> stubs; |
472 for (size_t i = 0; i < max_stubs_before_no_bonus; ++i) { | 472 for (size_t i = 0; i < max_stubs_before_no_bonus; ++i) { |
473 stubs.push_back( | 473 stubs.push_back( |
474 new FakeClient(&memmgr_, GenerateUniqueSurfaceId(), true)); | 474 new FakeClient(&memmgr_, GenerateUniqueSurfaceId(), true)); |
475 } | 475 } |
476 | 476 |
477 Manage(); | 477 Manage(); |
478 for (size_t i = 0; i < stubs.size(); ++i) { | 478 for (size_t i = 0; i < stubs.size(); ++i) { |
479 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stubs[i]->allocation_)); | 479 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stubs[i]->allocation_)); |
480 EXPECT_GT( | 480 EXPECT_GT( |
481 stubs[i]->allocation_.renderer_allocation.bytes_limit_when_visible, | 481 stubs[i]->allocation_.renderer_allocation.bytes_limit_when_visible, |
482 static_cast<size_t>(GetMinimumTabAllocation())); | 482 static_cast<size_t>(GetMinimumClientAllocation())); |
483 } | 483 } |
484 | 484 |
485 FakeClient extra_stub(&memmgr_, GenerateUniqueSurfaceId(), true); | 485 FakeClient extra_stub(&memmgr_, GenerateUniqueSurfaceId(), true); |
486 | 486 |
487 Manage(); | 487 Manage(); |
488 for (size_t i = 0; i < stubs.size(); ++i) { | 488 for (size_t i = 0; i < stubs.size(); ++i) { |
489 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stubs[i]->allocation_)); | 489 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stubs[i]->allocation_)); |
490 EXPECT_EQ( | 490 EXPECT_EQ( |
491 stubs[i]->allocation_.renderer_allocation.bytes_limit_when_visible, | 491 stubs[i]->allocation_.renderer_allocation.bytes_limit_when_visible, |
492 GetMinimumTabAllocation()); | 492 GetMinimumClientAllocation()); |
493 } | 493 } |
494 | 494 |
495 for (size_t i = 0; i < max_stubs_before_no_bonus; ++i) { | 495 for (size_t i = 0; i < max_stubs_before_no_bonus; ++i) { |
496 delete stubs[i]; | 496 delete stubs[i]; |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
500 // Test GpuMemoryManager::UpdateAvailableGpuMemory functionality | 500 // Test GpuMemoryManager::UpdateAvailableGpuMemory functionality |
501 TEST_F(GpuMemoryManagerTest, TestUpdateAvailableGpuMemory) { | 501 TEST_F(GpuMemoryManagerTest, TestUpdateAvailableGpuMemory) { |
502 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 502 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 EXPECT_EQ(stats.count(&stub1), 1ul); | 595 EXPECT_EQ(stats.count(&stub1), 1ul); |
596 size_t stub1allocation2 = | 596 size_t stub1allocation2 = |
597 stats[&stub1].allocation.renderer_allocation.bytes_limit_when_visible; | 597 stats[&stub1].allocation.renderer_allocation.bytes_limit_when_visible; |
598 EXPECT_EQ(stats.count(&stub2), 1ul); | 598 EXPECT_EQ(stats.count(&stub2), 1ul); |
599 size_t stub2allocation2 = | 599 size_t stub2allocation2 = |
600 stats[&stub2].allocation.renderer_allocation.bytes_limit_when_visible; | 600 stats[&stub2].allocation.renderer_allocation.bytes_limit_when_visible; |
601 | 601 |
602 EXPECT_EQ(stats.size(), 2ul); | 602 EXPECT_EQ(stats.size(), 2ul); |
603 EXPECT_GT(stub1allocation2, 0ul); | 603 EXPECT_GT(stub1allocation2, 0ul); |
604 EXPECT_GT(stub2allocation2, 0ul); | 604 EXPECT_GT(stub2allocation2, 0ul); |
605 if (stub1allocation2 != GetMaximumTabAllocation()) | 605 if (stub1allocation2 != GetMaximumClientAllocation()) |
606 EXPECT_LT(stub1allocation2, stub1allocation1); | 606 EXPECT_LT(stub1allocation2, stub1allocation1); |
607 | 607 |
608 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); | 608 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); |
609 Manage(); | 609 Manage(); |
610 stats = ClientAssignmentCollector::GetClientStatsForLastManage(); | 610 stats = ClientAssignmentCollector::GetClientStatsForLastManage(); |
611 size_t stub1allocation3 = | 611 size_t stub1allocation3 = |
612 stats[&stub1].allocation.renderer_allocation.bytes_limit_when_visible; | 612 stats[&stub1].allocation.renderer_allocation.bytes_limit_when_visible; |
613 size_t stub2allocation3 = | 613 size_t stub2allocation3 = |
614 stats[&stub2].allocation.renderer_allocation.bytes_limit_when_visible; | 614 stats[&stub2].allocation.renderer_allocation.bytes_limit_when_visible; |
615 size_t stub3allocation3 = | 615 size_t stub3allocation3 = |
616 stats[&stub3].allocation.renderer_allocation.bytes_limit_when_visible; | 616 stats[&stub3].allocation.renderer_allocation.bytes_limit_when_visible; |
617 | 617 |
618 EXPECT_EQ(stats.size(), 3ul); | 618 EXPECT_EQ(stats.size(), 3ul); |
619 EXPECT_GT(stub1allocation3, 0ul); | 619 EXPECT_GT(stub1allocation3, 0ul); |
620 EXPECT_GT(stub2allocation3, 0ul); | 620 EXPECT_GT(stub2allocation3, 0ul); |
621 EXPECT_GT(stub3allocation3, 0ul); | 621 EXPECT_GT(stub3allocation3, 0ul); |
622 if (stub1allocation3 != GetMaximumTabAllocation()) | 622 if (stub1allocation3 != GetMaximumClientAllocation()) |
623 EXPECT_LT(stub1allocation3, stub1allocation2); | 623 EXPECT_LT(stub1allocation3, stub1allocation2); |
624 | 624 |
625 stub1.SetVisible(false); | 625 stub1.SetVisible(false); |
626 | 626 |
627 Manage(); | 627 Manage(); |
628 stats = ClientAssignmentCollector::GetClientStatsForLastManage(); | 628 stats = ClientAssignmentCollector::GetClientStatsForLastManage(); |
629 size_t stub1allocation4 = | 629 size_t stub1allocation4 = |
630 stats[&stub1].allocation.renderer_allocation.bytes_limit_when_visible; | 630 stats[&stub1].allocation.renderer_allocation.bytes_limit_when_visible; |
631 size_t stub2allocation4 = | 631 size_t stub2allocation4 = |
632 stats[&stub2].allocation.renderer_allocation.bytes_limit_when_visible; | 632 stats[&stub2].allocation.renderer_allocation.bytes_limit_when_visible; |
633 size_t stub3allocation4 = | 633 size_t stub3allocation4 = |
634 stats[&stub3].allocation.renderer_allocation.bytes_limit_when_visible; | 634 stats[&stub3].allocation.renderer_allocation.bytes_limit_when_visible; |
635 | 635 |
636 EXPECT_EQ(stats.size(), 3ul); | 636 EXPECT_EQ(stats.size(), 3ul); |
637 EXPECT_GT(stub1allocation4, 0ul); | 637 EXPECT_GT(stub1allocation4, 0ul); |
638 EXPECT_GE(stub2allocation4, 0ul); | 638 EXPECT_GE(stub2allocation4, 0ul); |
639 EXPECT_GT(stub3allocation4, 0ul); | 639 EXPECT_GT(stub3allocation4, 0ul); |
640 if (stub3allocation3 != GetMaximumTabAllocation()) | 640 if (stub3allocation3 != GetMaximumClientAllocation()) |
641 EXPECT_GT(stub3allocation4, stub3allocation3); | 641 EXPECT_GT(stub3allocation4, stub3allocation3); |
642 } | 642 } |
643 | 643 |
644 // Test GpuMemoryManager's managed memory tracking | 644 // Test GpuMemoryManager's managed memory tracking |
645 TEST_F(GpuMemoryManagerTest, TestManagedUsageTracking) { | 645 TEST_F(GpuMemoryManagerTest, TestManagedUsageTracking) { |
646 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 646 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
647 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); | 647 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); |
648 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); | 648 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); |
649 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); | 649 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_nonvisible_); |
650 | 650 |
651 // Set memory allocations and verify the results are reflected. | 651 // Set memory allocations and verify the results are reflected. |
652 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 5, false)); | 652 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 5, false)); |
653 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 7, false)); | 653 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 7, false)); |
654 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 654 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
655 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 655 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
656 | 656 |
657 // Remove a visible client | 657 // Remove a visible client |
658 stub1.client_state_.reset(); | 658 stub1.client_state_.reset(); |
659 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); | 659 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); |
660 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 660 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
661 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); | 661 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); |
662 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 662 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
663 stub1.client_state_.reset(memmgr_.CreateClientState(&stub1, true, true)); | 663 stub1.client_state_.reset(memmgr_.CreateClientState(&stub1, true, true)); |
664 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); | 664 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); |
665 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 665 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
666 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 5, false)); | 666 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 5, false)); |
667 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 667 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
668 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 668 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
669 | 669 |
670 // Remove a backgrounded client | 670 // Remove a nonvisible client |
671 stub2.client_state_.reset(); | 671 stub2.client_state_.reset(); |
672 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 672 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
673 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); | 673 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_nonvisible_); |
674 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 674 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
675 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); | 675 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_nonvisible_); |
676 stub2.client_state_.reset(memmgr_.CreateClientState(&stub2, true, false)); | 676 stub2.client_state_.reset(memmgr_.CreateClientState(&stub2, true, false)); |
677 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 677 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
678 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); | 678 EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_nonvisible_); |
679 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 7, false)); | 679 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 7, false)); |
680 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 680 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
681 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 681 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
682 | 682 |
683 // Create and then destroy some stubs, and verify their allocations go away. | 683 // Create and then destroy some stubs, and verify their allocations go away. |
684 { | 684 { |
685 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | 685 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
686 stub4(&memmgr_, GenerateUniqueSurfaceId(), false); | 686 stub4(&memmgr_, GenerateUniqueSurfaceId(), false); |
687 stub3.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 1, false)); | 687 stub3.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 1, false)); |
688 stub4.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 2, false)); | 688 stub4.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 2, false)); |
689 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_); | 689 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_); |
690 EXPECT_EQ(9ul, memmgr_.bytes_allocated_managed_backgrounded_); | 690 EXPECT_EQ(9ul, memmgr_.bytes_allocated_managed_nonvisible_); |
691 } | 691 } |
692 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 692 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
693 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 693 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
694 | 694 |
695 // Do no-op changes to stubs' visibility and make sure nothing chnages. | 695 // Do no-op changes to stubs' visibility and make sure nothing chnages. |
696 stub1.SetVisible(true); | 696 stub1.SetVisible(true); |
697 stub2.SetVisible(false); | 697 stub2.SetVisible(false); |
698 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); | 698 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); |
699 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); | 699 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_nonvisible_); |
700 | 700 |
701 // Change visbility state. | 701 // Change visbility state. |
702 stub1.SetVisible(false); | 702 stub1.SetVisible(false); |
703 stub2.SetVisible(true); | 703 stub2.SetVisible(true); |
704 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_visible_); | 704 EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_visible_); |
705 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_backgrounded_); | 705 EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_nonvisible_); |
706 | 706 |
707 // Increase allocation amounts. | 707 // Increase allocation amounts. |
708 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 6, false)); | 708 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 6, false)); |
709 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 8, false)); | 709 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 8, false)); |
710 EXPECT_EQ(8ul, memmgr_.bytes_allocated_managed_visible_); | 710 EXPECT_EQ(8ul, memmgr_.bytes_allocated_managed_visible_); |
711 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_backgrounded_); | 711 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_nonvisible_); |
712 | 712 |
713 // Decrease allocation amounts. | 713 // Decrease allocation amounts. |
714 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 4, false)); | 714 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 4, false)); |
715 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 6, false)); | 715 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(0, 0, 6, false)); |
716 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_); | 716 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_); |
717 EXPECT_EQ(4ul, memmgr_.bytes_allocated_managed_backgrounded_); | 717 EXPECT_EQ(4ul, memmgr_.bytes_allocated_managed_nonvisible_); |
718 } | 718 } |
719 | 719 |
720 // Test GpuMemoryManager's background cutoff threshoulds | 720 // Test GpuMemoryManager's background cutoff threshoulds |
721 TEST_F(GpuMemoryManagerTest, TestBackgroundCutoff) { | 721 TEST_F(GpuMemoryManagerTest, TestBackgroundCutoff) { |
722 memmgr_.TestingSetAvailableGpuMemory(64); | 722 memmgr_.TestingSetAvailableGpuMemory(64); |
723 memmgr_.TestingSetBackgroundedAvailableGpuMemory(16); | 723 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
724 | 724 |
725 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 725 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
726 | 726 |
727 // stub1's requirements are not <=16, so it should just dump | 727 // stub1's requirements are not <=16, so it should just dump |
728 // everything when it goes invisible. | 728 // everything when it goes invisible. |
729 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(17, 24, 18, false)); | 729 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(17, 24, 18, false)); |
730 Manage(); | 730 Manage(); |
731 EXPECT_EQ(0ul, stub1.BytesWhenNotVisible()); | 731 EXPECT_EQ(0ul, stub1.BytesWhenNotVisible()); |
732 | 732 |
733 // stub1 now fits, so it should have a full budget. | 733 // stub1 now fits, so it should have a full budget. |
734 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(16, 24, 18, false)); | 734 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(16, 24, 18, false)); |
735 Manage(); | 735 Manage(); |
736 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_, | 736 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
737 memmgr_.GetCurrentBackgroundedAvailableGpuMemory()); | 737 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); |
738 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 738 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
739 stub1.BytesWhenNotVisible()); | 739 stub1.BytesWhenNotVisible()); |
740 | 740 |
741 // Background stub1. | 741 // Background stub1. |
742 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(16, 24, 16, false)); | 742 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(16, 24, 16, false)); |
743 stub1.SetVisible(false); | 743 stub1.SetVisible(false); |
744 | 744 |
745 // Add stub2 that uses almost enough memory to evict | 745 // Add stub2 that uses almost enough memory to evict |
746 // stub1, but not quite. | 746 // stub1, but not quite. |
747 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); | 747 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); |
748 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(16, 50, 48, false)); | 748 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(16, 50, 48, false)); |
749 Manage(); | 749 Manage(); |
750 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_, | 750 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
751 memmgr_.GetCurrentBackgroundedAvailableGpuMemory()); | 751 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); |
752 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 752 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
753 stub1.BytesWhenNotVisible()); | 753 stub1.BytesWhenNotVisible()); |
754 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 754 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
755 stub2.BytesWhenNotVisible()); | 755 stub2.BytesWhenNotVisible()); |
756 | 756 |
757 // Increase stub2 to force stub1 to be evicted. | 757 // Increase stub2 to force stub1 to be evicted. |
758 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(16, 50, 49, false)); | 758 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(16, 50, 49, false)); |
759 Manage(); | 759 Manage(); |
760 EXPECT_EQ(0ul, | 760 EXPECT_EQ(0ul, |
761 stub1.BytesWhenNotVisible()); | 761 stub1.BytesWhenNotVisible()); |
762 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 762 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
763 stub2.BytesWhenNotVisible()); | 763 stub2.BytesWhenNotVisible()); |
764 } | 764 } |
765 | 765 |
766 // Test GpuMemoryManager's background MRU behavior | 766 // Test GpuMemoryManager's background MRU behavior |
767 TEST_F(GpuMemoryManagerTest, TestBackgroundMru) { | 767 TEST_F(GpuMemoryManagerTest, TestBackgroundMru) { |
768 memmgr_.TestingSetAvailableGpuMemory(64); | 768 memmgr_.TestingSetAvailableGpuMemory(64); |
769 memmgr_.TestingSetBackgroundedAvailableGpuMemory(16); | 769 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
770 | 770 |
771 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 771 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
772 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); | 772 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); |
773 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); | 773 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); |
774 | 774 |
775 // When all are visible, they should all be allowed to have memory | 775 // When all are visible, they should all be allowed to have memory |
776 // should they become backgrounded. | 776 // should they become nonvisible. |
777 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); | 777 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); |
778 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); | 778 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); |
779 stub3.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); | 779 stub3.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); |
780 Manage(); | 780 Manage(); |
781 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_, | 781 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
782 memmgr_.GetCurrentBackgroundedAvailableGpuMemory()); | 782 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); |
783 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 783 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
784 stub1.BytesWhenNotVisible()); | 784 stub1.BytesWhenNotVisible()); |
785 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 785 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
786 stub2.BytesWhenNotVisible()); | 786 stub2.BytesWhenNotVisible()); |
787 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 787 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
788 stub3.BytesWhenNotVisible()); | 788 stub3.BytesWhenNotVisible()); |
789 | 789 |
790 | 790 |
791 // Background stubs 1 and 2, and they should fit | 791 // Background stubs 1 and 2, and they should fit |
792 stub2.SetVisible(false); | 792 stub2.SetVisible(false); |
793 stub1.SetVisible(false); | 793 stub1.SetVisible(false); |
794 Manage(); | 794 Manage(); |
795 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_, | 795 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
796 memmgr_.GetCurrentBackgroundedAvailableGpuMemory()); | 796 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); |
797 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 797 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
798 stub1.BytesWhenNotVisible()); | 798 stub1.BytesWhenNotVisible()); |
799 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 799 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
800 stub2.BytesWhenNotVisible()); | 800 stub2.BytesWhenNotVisible()); |
801 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 801 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
802 stub3.BytesWhenNotVisible()); | 802 stub3.BytesWhenNotVisible()); |
803 | 803 |
804 // Now background stub 3, and it should cause stub 2 to be | 804 // Now background stub 3, and it should cause stub 2 to be |
805 // evicted because it was set non-visible first | 805 // evicted because it was set non-visible first |
806 stub3.SetVisible(false); | 806 stub3.SetVisible(false); |
807 Manage(); | 807 Manage(); |
808 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_, | 808 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
809 memmgr_.GetCurrentBackgroundedAvailableGpuMemory()); | 809 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); |
810 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 810 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
811 stub1.BytesWhenNotVisible()); | 811 stub1.BytesWhenNotVisible()); |
812 EXPECT_EQ(0ul, | 812 EXPECT_EQ(0ul, |
813 stub2.BytesWhenNotVisible()); | 813 stub2.BytesWhenNotVisible()); |
814 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), | 814 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
815 stub3.BytesWhenNotVisible()); | 815 stub3.BytesWhenNotVisible()); |
816 } | 816 } |
817 | 817 |
818 // Test GpuMemoryManager's tracking of unmanaged (e.g, WebGL) memory. | 818 // Test GpuMemoryManager's tracking of unmanaged (e.g, WebGL) memory. |
819 TEST_F(GpuMemoryManagerTest, TestUnmanagedTracking) { | 819 TEST_F(GpuMemoryManagerTest, TestUnmanagedTracking) { |
820 memmgr_.TestingSetAvailableGpuMemory(64); | 820 memmgr_.TestingSetAvailableGpuMemory(64); |
821 memmgr_.TestingSetBackgroundedAvailableGpuMemory(16); | 821 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
822 memmgr_.TestingSetUnmanagedLimitStep(16); | 822 memmgr_.TestingSetUnmanagedLimitStep(16); |
823 memmgr_.TestingSetMinimumClientAllocation(8); | 823 memmgr_.TestingSetMinimumClientAllocation(8); |
824 | 824 |
825 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 825 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
826 | 826 |
827 // Expect that the one stub get the maximum tab allocation. | 827 // Expect that the one stub get the maximum tab allocation. |
828 Manage(); | 828 Manage(); |
829 EXPECT_EQ(memmgr_.GetMaximumTabAllocation(), | 829 EXPECT_EQ(memmgr_.GetMaximumClientAllocation(), |
830 stub1.BytesWhenVisible()); | 830 stub1.BytesWhenVisible()); |
831 | 831 |
832 // Now allocate some unmanaged memory and make sure the amount | 832 // Now allocate some unmanaged memory and make sure the amount |
833 // goes down. | 833 // goes down. |
834 memmgr_.TrackMemoryAllocatedChange( | 834 memmgr_.TrackMemoryAllocatedChange( |
835 stub1.tracking_group_.get(), | 835 stub1.tracking_group_.get(), |
836 0, | 836 0, |
837 48, | 837 48, |
838 gpu::gles2::MemoryTracker::kUnmanaged); | 838 gpu::gles2::MemoryTracker::kUnmanaged); |
839 Manage(); | 839 Manage(); |
840 EXPECT_GT(memmgr_.GetMaximumTabAllocation(), | 840 EXPECT_GT(memmgr_.GetMaximumClientAllocation(), |
841 stub1.BytesWhenVisible()); | 841 stub1.BytesWhenVisible()); |
842 | 842 |
843 // Now allocate the entire FB worth of unmanaged memory, and | 843 // Now allocate the entire FB worth of unmanaged memory, and |
844 // make sure that we stay stuck at the minimum tab allocation. | 844 // make sure that we stay stuck at the minimum tab allocation. |
845 memmgr_.TrackMemoryAllocatedChange( | 845 memmgr_.TrackMemoryAllocatedChange( |
846 stub1.tracking_group_.get(), | 846 stub1.tracking_group_.get(), |
847 48, | 847 48, |
848 64, | 848 64, |
849 gpu::gles2::MemoryTracker::kUnmanaged); | 849 gpu::gles2::MemoryTracker::kUnmanaged); |
850 Manage(); | 850 Manage(); |
851 EXPECT_EQ(memmgr_.GetMinimumTabAllocation(), | 851 EXPECT_EQ(memmgr_.GetMinimumClientAllocation(), |
852 stub1.BytesWhenVisible()); | 852 stub1.BytesWhenVisible()); |
853 | 853 |
854 // Far-oversubscribe the entire FB, and make sure we stay at | 854 // Far-oversubscribe the entire FB, and make sure we stay at |
855 // the minimum allocation, and don't blow up. | 855 // the minimum allocation, and don't blow up. |
856 memmgr_.TrackMemoryAllocatedChange( | 856 memmgr_.TrackMemoryAllocatedChange( |
857 stub1.tracking_group_.get(), | 857 stub1.tracking_group_.get(), |
858 64, | 858 64, |
859 999, | 859 999, |
860 gpu::gles2::MemoryTracker::kUnmanaged); | 860 gpu::gles2::MemoryTracker::kUnmanaged); |
861 Manage(); | 861 Manage(); |
862 EXPECT_EQ(memmgr_.GetMinimumTabAllocation(), | 862 EXPECT_EQ(memmgr_.GetMinimumClientAllocation(), |
863 stub1.BytesWhenVisible()); | 863 stub1.BytesWhenVisible()); |
864 | 864 |
865 // Delete all tracked memory so we don't hit leak checks. | 865 // Delete all tracked memory so we don't hit leak checks. |
866 memmgr_.TrackMemoryAllocatedChange( | 866 memmgr_.TrackMemoryAllocatedChange( |
867 stub1.tracking_group_.get(), | 867 stub1.tracking_group_.get(), |
868 999, | 868 999, |
869 0, | 869 0, |
870 gpu::gles2::MemoryTracker::kUnmanaged); | 870 gpu::gles2::MemoryTracker::kUnmanaged); |
871 } | 871 } |
872 | 872 |
873 } // namespace content | 873 } // namespace content |
OLD | NEW |