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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 | 219 |
220 void Manage() { | 220 void Manage() { |
221 ClientAssignmentCollector::ClearAllStats(); | 221 ClientAssignmentCollector::ClearAllStats(); |
222 memmgr_.Manage(); | 222 memmgr_.Manage(); |
223 } | 223 } |
224 | 224 |
225 uint64 CalcAvailableFromGpuTotal(uint64 bytes) { | 225 uint64 CalcAvailableFromGpuTotal(uint64 bytes) { |
226 return GpuMemoryManager::CalcAvailableFromGpuTotal(bytes); | 226 return GpuMemoryManager::CalcAvailableFromGpuTotal(bytes); |
227 } | 227 } |
228 | 228 |
229 uint64 CalcAvailableFromViewportArea(int viewport_area) { | |
230 return GpuMemoryManager::CalcAvailableFromViewportArea(viewport_area); | |
231 } | |
232 | |
233 uint64 CalcAvailableClamped(uint64 bytes) { | 229 uint64 CalcAvailableClamped(uint64 bytes) { |
234 bytes = std::max(bytes, memmgr_.GetDefaultAvailableGpuMemory()); | 230 bytes = std::max(bytes, memmgr_.GetDefaultAvailableGpuMemory()); |
235 bytes = std::min(bytes, memmgr_.GetMaximumTotalGpuMemory()); | 231 bytes = std::min(bytes, memmgr_.GetMaximumTotalGpuMemory()); |
236 return bytes; | 232 return bytes; |
237 } | 233 } |
238 | 234 |
239 uint64 GetAvailableGpuMemory() { | 235 uint64 GetAvailableGpuMemory() { |
240 return memmgr_.GetAvailableGpuMemory(); | 236 return memmgr_.GetAvailableGpuMemory(); |
241 } | 237 } |
242 | 238 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 delete stubs[i]; | 507 delete stubs[i]; |
512 } | 508 } |
513 } | 509 } |
514 | 510 |
515 // Test GpuMemoryManager::UpdateAvailableGpuMemory functionality | 511 // Test GpuMemoryManager::UpdateAvailableGpuMemory functionality |
516 TEST_F(GpuMemoryManagerTest, TestUpdateAvailableGpuMemory) { | 512 TEST_F(GpuMemoryManagerTest, TestUpdateAvailableGpuMemory) { |
517 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), | 513 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
518 stub2(&memmgr_, GenerateUniqueSurfaceId(), false), | 514 stub2(&memmgr_, GenerateUniqueSurfaceId(), false), |
519 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), | 515 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
520 stub4(&memmgr_, GenerateUniqueSurfaceId(), false); | 516 stub4(&memmgr_, GenerateUniqueSurfaceId(), false); |
521 | |
522 #if defined(OS_ANDROID) | |
523 // We use the largest visible surface size to calculate the limit | |
524 stub1.SetSurfaceSize(gfx::Size(1024, 512)); // Surface size | |
525 stub2.SetSurfaceSize(gfx::Size(2048, 512)); // Larger but not visible. | |
526 stub3.SetSurfaceSize(gfx::Size(512, 512)); // Visible but smaller. | |
527 stub4.SetSurfaceSize(gfx::Size(512, 512)); // Not visible and smaller. | |
528 Manage(); | |
529 uint64 bytes_expected = CalcAvailableFromViewportArea(1024*512); | |
530 #else | |
531 // We take the lowest GPU's total memory as the limit | |
jar (doing other things)
2013/02/14 01:48:41
nit: This comment probably should not be removed.
epenner
2013/02/14 04:18:36
Done.
| |
532 uint64 expected = 400 * 1024 * 1024; | 517 uint64 expected = 400 * 1024 * 1024; |
533 stub1.SetTotalGpuMemory(expected); // GPU Memory | 518 stub1.SetTotalGpuMemory(expected); // GPU Memory |
534 stub2.SetTotalGpuMemory(expected - 1024 * 1024); // Smaller but not visible. | 519 stub2.SetTotalGpuMemory(expected - 1024 * 1024); // Smaller but not visible. |
535 stub3.SetTotalGpuMemory(expected + 1024 * 1024); // Visible but larger. | 520 stub3.SetTotalGpuMemory(expected + 1024 * 1024); // Visible but larger. |
536 stub4.SetTotalGpuMemory(expected + 1024 * 1024); // Not visible and larger. | 521 stub4.SetTotalGpuMemory(expected + 1024 * 1024); // Not visible and larger. |
537 Manage(); | 522 Manage(); |
538 uint64 bytes_expected = CalcAvailableFromGpuTotal(expected); | 523 uint64 bytes_expected = CalcAvailableFromGpuTotal(expected); |
539 #endif | |
540 EXPECT_EQ(GetAvailableGpuMemory(), CalcAvailableClamped(bytes_expected)); | 524 EXPECT_EQ(GetAvailableGpuMemory(), CalcAvailableClamped(bytes_expected)); |
541 } | 525 } |
542 | 526 |
543 | 527 |
544 // Test GpuMemoryAllocation comparison operators: Iterate over all possible | 528 // Test GpuMemoryAllocation comparison operators: Iterate over all possible |
545 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and | 529 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and |
546 // suggest_have_frontbuffer, and make sure allocations with equal values test | 530 // suggest_have_frontbuffer, and make sure allocations with equal values test |
547 // equal and non equal values test not equal. | 531 // equal and non equal values test not equal. |
548 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { | 532 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { |
549 std::vector<int> gpu_resource_size_in_bytes_values; | 533 std::vector<int> gpu_resource_size_in_bytes_values; |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1043 | 1027 |
1044 // Expect that a client which has not sent stats receive the | 1028 // Expect that a client which has not sent stats receive the |
1045 // default allocation. | 1029 // default allocation. |
1046 Manage(); | 1030 Manage(); |
1047 EXPECT_EQ(stub1.BytesWhenVisible(), | 1031 EXPECT_EQ(stub1.BytesWhenVisible(), |
1048 memmgr_.GetDefaultClientAllocation()); | 1032 memmgr_.GetDefaultClientAllocation()); |
1049 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); | 1033 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); |
1050 } | 1034 } |
1051 | 1035 |
1052 } // namespace content | 1036 } // namespace content |
OLD | NEW |