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_command_buffer_stub.h" | 5 #include "content/common/gpu/gpu_command_buffer_stub.h" |
6 #include "content/common/gpu/gpu_memory_allocation.h" | 6 #include "content/common/gpu/gpu_memory_allocation.h" |
7 #include "content/common/gpu/gpu_memory_manager.h" | 7 #include "content/common/gpu/gpu_memory_manager.h" |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 152 } |
153 | 153 |
154 void Manage() { | 154 void Manage() { |
155 memory_manager_.Manage(); | 155 memory_manager_.Manage(); |
156 } | 156 } |
157 | 157 |
158 size_t GetAvailableGpuMemory() { | 158 size_t GetAvailableGpuMemory() { |
159 return memory_manager_.GetAvailableGpuMemory(); | 159 return memory_manager_.GetAvailableGpuMemory(); |
160 } | 160 } |
161 | 161 |
| 162 size_t GetMaximumTabAllocation() { |
| 163 return memory_manager_.GetMaximumTabAllocation(); |
| 164 } |
| 165 |
162 size_t GetMinimumTabAllocation() { | 166 size_t GetMinimumTabAllocation() { |
163 return memory_manager_.GetMinimumTabAllocation(); | 167 return memory_manager_.GetMinimumTabAllocation(); |
164 } | 168 } |
165 | 169 |
166 base::TimeTicks older_, newer_, newest_; | 170 base::TimeTicks older_, newer_, newest_; |
167 FakeClient client_; | 171 FakeClient client_; |
168 GpuMemoryManager memory_manager_; | 172 GpuMemoryManager memory_manager_; |
169 }; | 173 }; |
170 | 174 |
171 // Create fake stubs with every combination of {visibilty,last_use_time} | 175 // Create fake stubs with every combination of {visibilty,last_use_time} |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 Manage(); | 636 Manage(); |
633 stats = memory_manager_.stub_memory_stats_for_last_manage(); | 637 stats = memory_manager_.stub_memory_stats_for_last_manage(); |
634 size_t stub1allocation2 = stats[&stub1].allocation.gpu_resource_size_in_bytes; | 638 size_t stub1allocation2 = stats[&stub1].allocation.gpu_resource_size_in_bytes; |
635 size_t stub2allocation2 = stats[&stub2].allocation.gpu_resource_size_in_bytes; | 639 size_t stub2allocation2 = stats[&stub2].allocation.gpu_resource_size_in_bytes; |
636 | 640 |
637 EXPECT_EQ(stats.size(), 2ul); | 641 EXPECT_EQ(stats.size(), 2ul); |
638 EXPECT_TRUE(stats[&stub1].visible); | 642 EXPECT_TRUE(stats[&stub1].visible); |
639 EXPECT_TRUE(stats[&stub2].visible); | 643 EXPECT_TRUE(stats[&stub2].visible); |
640 EXPECT_GT(stub1allocation2, 0ul); | 644 EXPECT_GT(stub1allocation2, 0ul); |
641 EXPECT_GT(stub2allocation2, 0ul); | 645 EXPECT_GT(stub2allocation2, 0ul); |
642 if (compositors_get_bonus_allocation) | 646 if (compositors_get_bonus_allocation && |
| 647 stub1allocation2 != GetMaximumTabAllocation()) |
643 EXPECT_LT(stub1allocation2, stub1allocation1); | 648 EXPECT_LT(stub1allocation2, stub1allocation1); |
644 | 649 |
645 FakeCommandBufferStub stub3(GenerateUniqueSurfaceId(), true, older_); | 650 FakeCommandBufferStub stub3(GenerateUniqueSurfaceId(), true, older_); |
646 client_.stubs_.push_back(&stub3); | 651 client_.stubs_.push_back(&stub3); |
647 Manage(); | 652 Manage(); |
648 stats = memory_manager_.stub_memory_stats_for_last_manage(); | 653 stats = memory_manager_.stub_memory_stats_for_last_manage(); |
649 size_t stub1allocation3 = stats[&stub1].allocation.gpu_resource_size_in_bytes; | 654 size_t stub1allocation3 = stats[&stub1].allocation.gpu_resource_size_in_bytes; |
650 size_t stub2allocation3 = stats[&stub1].allocation.gpu_resource_size_in_bytes; | 655 size_t stub2allocation3 = stats[&stub2].allocation.gpu_resource_size_in_bytes; |
651 size_t stub3allocation3 = stats[&stub3].allocation.gpu_resource_size_in_bytes; | 656 size_t stub3allocation3 = stats[&stub3].allocation.gpu_resource_size_in_bytes; |
652 | 657 |
653 EXPECT_EQ(stats.size(), 3ul); | 658 EXPECT_EQ(stats.size(), 3ul); |
654 EXPECT_TRUE(stats[&stub1].visible); | 659 EXPECT_TRUE(stats[&stub1].visible); |
655 EXPECT_TRUE(stats[&stub2].visible); | 660 EXPECT_TRUE(stats[&stub2].visible); |
656 EXPECT_TRUE(stats[&stub3].visible); | 661 EXPECT_TRUE(stats[&stub3].visible); |
657 EXPECT_GT(stub1allocation3, 0ul); | 662 EXPECT_GT(stub1allocation3, 0ul); |
658 EXPECT_GT(stub2allocation3, 0ul); | 663 EXPECT_GT(stub2allocation3, 0ul); |
659 EXPECT_GT(stub3allocation3, 0ul); | 664 EXPECT_GT(stub3allocation3, 0ul); |
660 if (compositors_get_bonus_allocation) | 665 if (compositors_get_bonus_allocation && |
| 666 stub1allocation3 != GetMaximumTabAllocation()) |
661 EXPECT_LT(stub1allocation3, stub1allocation2); | 667 EXPECT_LT(stub1allocation3, stub1allocation2); |
662 | 668 |
663 stub1.surface_state_.visible = false; | 669 stub1.surface_state_.visible = false; |
664 Manage(); | 670 Manage(); |
665 stats = memory_manager_.stub_memory_stats_for_last_manage(); | 671 stats = memory_manager_.stub_memory_stats_for_last_manage(); |
666 size_t stub1allocation4 = stats[&stub1].allocation.gpu_resource_size_in_bytes; | 672 size_t stub1allocation4 = stats[&stub1].allocation.gpu_resource_size_in_bytes; |
667 size_t stub2allocation4 = stats[&stub2].allocation.gpu_resource_size_in_bytes; | 673 size_t stub2allocation4 = stats[&stub2].allocation.gpu_resource_size_in_bytes; |
668 size_t stub3allocation4 = stats[&stub3].allocation.gpu_resource_size_in_bytes; | 674 size_t stub3allocation4 = stats[&stub3].allocation.gpu_resource_size_in_bytes; |
669 | 675 |
670 EXPECT_EQ(stats.size(), 3ul); | 676 EXPECT_EQ(stats.size(), 3ul); |
671 EXPECT_FALSE(stats[&stub1].visible); | 677 EXPECT_FALSE(stats[&stub1].visible); |
672 EXPECT_FALSE(stats[&stub2].visible); | 678 EXPECT_FALSE(stats[&stub2].visible); |
673 EXPECT_TRUE(stats[&stub3].visible); | 679 EXPECT_TRUE(stats[&stub3].visible); |
674 EXPECT_EQ(stub1allocation4, 0ul); | 680 EXPECT_EQ(stub1allocation4, 0ul); |
675 EXPECT_GE(stub2allocation4, 0ul); | 681 EXPECT_GE(stub2allocation4, 0ul); |
676 EXPECT_GT(stub3allocation4, 0ul); | 682 EXPECT_GT(stub3allocation4, 0ul); |
677 if (compositors_get_bonus_allocation) | 683 if (compositors_get_bonus_allocation && |
| 684 stub3allocation3 != GetMaximumTabAllocation()) |
678 EXPECT_GT(stub3allocation4, stub3allocation3); | 685 EXPECT_GT(stub3allocation4, stub3allocation3); |
679 } | 686 } |
OLD | NEW |