diff options
author | ccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 12:14:03 +0000 |
---|---|---|
committer | ccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 12:14:03 +0000 |
commit | 26d01364394b7f3e1cc1a48dee00761ad95a4bf8 (patch) | |
tree | 012622bbac5fd70cddb51a9f5be4114efec45345 /content/common/gpu/gpu_memory_manager_unittest.cc | |
parent | ba3d09a1464372826de29fea84f8d7c1605ebd11 (diff) | |
download | chromium_src-26d01364394b7f3e1cc1a48dee00761ad95a4bf8.zip chromium_src-26d01364394b7f3e1cc1a48dee00761ad95a4bf8.tar.gz chromium_src-26d01364394b7f3e1cc1a48dee00761ad95a4bf8.tar.bz2 |
Track the total amount of managed memory allocated by all clients.
Remove tracking of the historical maximum, since it wasn't used.
Also move the ifdef-heavy const function out of the header and into
the source file.
BUG=134750
Review URL: https://chromiumcodereview.appspot.com/11366082
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common/gpu/gpu_memory_manager_unittest.cc')
-rw-r--r-- | content/common/gpu/gpu_memory_manager_unittest.cc | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/content/common/gpu/gpu_memory_manager_unittest.cc b/content/common/gpu/gpu_memory_manager_unittest.cc index a63a218..a26dd3d 100644 --- a/content/common/gpu/gpu_memory_manager_unittest.cc +++ b/content/common/gpu/gpu_memory_manager_unittest.cc @@ -662,4 +662,100 @@ TEST_F(GpuMemoryManagerTest, StubMemoryStatsForLastManageTests) { EXPECT_GT(stub3allocation4, stub3allocation3); } +// Test GpuMemoryManager's managed memory tracking +TEST_F(GpuMemoryManagerTest, TestManagedUsageTracking) { + FakeClient stub1(memmgr_, GenerateUniqueSurfaceId(), true, older_), + stub2(memmgr_, GenerateUniqueSurfaceId(), false, older_); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Set memory allocations and verify the results are reflected. + memmgr_.SetClientManagedMemoryStats( + &stub1, GpuManagedMemoryStats(0, 0, 5, false)); + memmgr_.SetClientManagedMemoryStats( + &stub2, GpuManagedMemoryStats(0, 0, 7, false)); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Redundantly add a client and make sure nothing changes + memmgr_.AddClient(&stub1, true, true, older_); + memmgr_.AddClient(&stub2, true, true, older_); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Remove a visible client + memmgr_.RemoveClient(&stub1); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + memmgr_.SetClientManagedMemoryStats( + &stub1, GpuManagedMemoryStats(0, 0, 99, false)); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + memmgr_.AddClient(&stub1, true, true, older_); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + memmgr_.SetClientManagedMemoryStats( + &stub1, GpuManagedMemoryStats(0, 0, 5, false)); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Remove a backgrounded client + memmgr_.RemoveClient(&stub2); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); + memmgr_.SetClientManagedMemoryStats( + &stub2, GpuManagedMemoryStats(0, 0, 99, false)); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); + memmgr_.AddClient(&stub2, true, false, older_); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(0ul, memmgr_.bytes_allocated_managed_backgrounded_); + memmgr_.SetClientManagedMemoryStats( + &stub2, GpuManagedMemoryStats(0, 0, 7, false)); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Create and then destroy some stubs, and verify their allocations go away. + { + FakeClient stub3(memmgr_, GenerateUniqueSurfaceId(), true, older_), + stub4(memmgr_, GenerateUniqueSurfaceId(), false, older_); + memmgr_.SetClientManagedMemoryStats( + &stub3, GpuManagedMemoryStats(0, 0, 1, false)); + memmgr_.SetClientManagedMemoryStats( + &stub4, GpuManagedMemoryStats(0, 0, 2, false)); + EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(9ul, memmgr_.bytes_allocated_managed_backgrounded_); + } + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Do no-op changes to stubs' visibility and make sure nothing chnages. + memmgr_.SetClientVisible(&stub1, true); + memmgr_.SetClientVisible(&stub2, false); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Change visbility state. + memmgr_.SetClientVisible(&stub1, false); + memmgr_.SetClientVisible(&stub2, true); + EXPECT_EQ(7ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(5ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Increase allocation amounts. + memmgr_.SetClientManagedMemoryStats( + &stub1, GpuManagedMemoryStats(0, 0, 6, false)); + memmgr_.SetClientManagedMemoryStats( + &stub2, GpuManagedMemoryStats(0, 0, 8, false)); + EXPECT_EQ(8ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_backgrounded_); + + // Decrease allocation amounts. + memmgr_.SetClientManagedMemoryStats( + &stub1, GpuManagedMemoryStats(0, 0, 4, false)); + memmgr_.SetClientManagedMemoryStats( + &stub2, GpuManagedMemoryStats(0, 0, 6, false)); + EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_); + EXPECT_EQ(4ul, memmgr_.bytes_allocated_managed_backgrounded_); +} + } // namespace content |