| 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 | 517 // On Android the dalvik heap size is used instead. |
| 522 #if defined(OS_ANDROID) | 518 // TODO(epenner): We should avoid #ifdefs in this test and use |
| 523 // We use the largest visible surface size to calculate the limit | 519 // a setting instead, so we can test all platform behavior. |
| 524 stub1.SetSurfaceSize(gfx::Size(1024, 512)); // Surface size | 520 #if !defined(OS_ANDROID) |
| 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 | |
| 532 uint64 expected = 400 * 1024 * 1024; | 521 uint64 expected = 400 * 1024 * 1024; |
| 533 stub1.SetTotalGpuMemory(expected); // GPU Memory | 522 stub1.SetTotalGpuMemory(expected); // GPU Memory |
| 534 stub2.SetTotalGpuMemory(expected - 1024 * 1024); // Smaller but not visible. | 523 stub2.SetTotalGpuMemory(expected - 1024 * 1024); // Smaller but not visible. |
| 535 stub3.SetTotalGpuMemory(expected + 1024 * 1024); // Visible but larger. | 524 stub3.SetTotalGpuMemory(expected + 1024 * 1024); // Visible but larger. |
| 536 stub4.SetTotalGpuMemory(expected + 1024 * 1024); // Not visible and larger. | 525 stub4.SetTotalGpuMemory(expected + 1024 * 1024); // Not visible and larger. |
| 537 Manage(); | 526 Manage(); |
| 538 uint64 bytes_expected = CalcAvailableFromGpuTotal(expected); | 527 uint64 bytes_expected = CalcAvailableFromGpuTotal(expected); |
| 528 EXPECT_EQ(GetAvailableGpuMemory(), CalcAvailableClamped(bytes_expected)); |
| 539 #endif | 529 #endif |
| 540 EXPECT_EQ(GetAvailableGpuMemory(), CalcAvailableClamped(bytes_expected)); | |
| 541 } | 530 } |
| 542 | 531 |
| 543 | 532 |
| 544 // Test GpuMemoryAllocation comparison operators: Iterate over all possible | 533 // Test GpuMemoryAllocation comparison operators: Iterate over all possible |
| 545 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and | 534 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and |
| 546 // suggest_have_frontbuffer, and make sure allocations with equal values test | 535 // suggest_have_frontbuffer, and make sure allocations with equal values test |
| 547 // equal and non equal values test not equal. | 536 // equal and non equal values test not equal. |
| 548 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { | 537 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { |
| 549 std::vector<int> gpu_resource_size_in_bytes_values; | 538 std::vector<int> gpu_resource_size_in_bytes_values; |
| 550 gpu_resource_size_in_bytes_values.push_back(0); | 539 gpu_resource_size_in_bytes_values.push_back(0); |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 | 1032 |
| 1044 // Expect that a client which has not sent stats receive the | 1033 // Expect that a client which has not sent stats receive the |
| 1045 // default allocation. | 1034 // default allocation. |
| 1046 Manage(); | 1035 Manage(); |
| 1047 EXPECT_EQ(stub1.BytesWhenVisible(), | 1036 EXPECT_EQ(stub1.BytesWhenVisible(), |
| 1048 memmgr_.GetDefaultClientAllocation()); | 1037 memmgr_.GetDefaultClientAllocation()); |
| 1049 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); | 1038 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); |
| 1050 } | 1039 } |
| 1051 | 1040 |
| 1052 } // namespace content | 1041 } // namespace content |
| OLD | NEW |