content/common/gpu/gpu_memory_manager_unittest.cc
// Test GpuMemoryManager's background MRU behavior
Test GpuMemoryManager's background MRU behavior
Test GpuMemoryManager ' s background MRU behavior
TEST_F(GpuMemoryManagerTest, TestBackgroundMru) {
  memmgr_.TestingSetAvailableGpuMemory(64);
  memmgr_.TestingSetBackgroundedAvailableGpuMemory(16);
  FakeClient stub1(memmgr_, GenerateUniqueSurfaceId(), true, older_);
  FakeClient stub2(memmgr_, GenerateUniqueSurfaceId(), true, older_);
  FakeClient stub3(memmgr_, GenerateUniqueSurfaceId(), true, older_);
  stub1.SetUsageStats(7, 24, 7);
  stub2.SetUsageStats(7, 24, 7);
  stub3.SetUsageStats(7, 24, 7);
  Manage();
  EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
            memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub1.BytesWhenNotVisible());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub2.BytesWhenNotVisible());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub3.BytesWhenNotVisible());
  stub2.SetVisible(false);
  memmgr_.TestingSetClientLastUsedTime(&stub2, older_);
  stub1.SetVisible(false);
  memmgr_.TestingSetClientLastUsedTime(&stub1, newer_);
  Manage();
  EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
            memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub1.BytesWhenNotVisible());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub2.BytesWhenNotVisible());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub3.BytesWhenNotVisible());
  stub3.SetVisible(false);
  memmgr_.TestingSetClientLastUsedTime(&stub3, newer_);
  Manage();
  EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
            memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub1.BytesWhenNotVisible());
  EXPECT_EQ(0ul,
            stub2.BytesWhenNotVisible());
  EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
            stub3.BytesWhenNotVisible());
}
TEST_F ( GpuMemoryManagerTest , TestBackgroundMru ) { memmgr_ . TestingSetAvailableGpuMemory ( 64 ) ; memmgr_ . TestingSetBackgroundedAvailableGpuMemory ( 16 ) ; FakeClient stub1 ( memmgr_ , GenerateUniqueSurfaceId ( ) , true , older_ ) ; FakeClient stub2 ( memmgr_ , GenerateUniqueSurfaceId ( ) , true , older_ ) ; FakeClient stub3 ( memmgr_ , GenerateUniqueSurfaceId ( ) , true , older_ ) ; stub1 . SetUsageStats ( 7 , 24 , 7 ) ; stub2 . SetUsageStats ( 7 , 24 , 7 ) ; stub3 . SetUsageStats ( 7 , 24 , 7 ) ; Manage ( ) ; EXPECT_EQ ( memmgr_ . bytes_backgrounded_available_gpu_memory_ , memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub1 . BytesWhenNotVisible ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub2 . BytesWhenNotVisible ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub3 . BytesWhenNotVisible ( ) ) ; stub2 . SetVisible ( false ) ; memmgr_ . TestingSetClientLastUsedTime ( & stub2 , older_ ) ; stub1 . SetVisible ( false ) ; memmgr_ . TestingSetClientLastUsedTime ( & stub1 , newer_ ) ; Manage ( ) ; EXPECT_EQ ( memmgr_ . bytes_backgrounded_available_gpu_memory_ , memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub1 . BytesWhenNotVisible ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub2 . BytesWhenNotVisible ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub3 . BytesWhenNotVisible ( ) ) ; stub3 . SetVisible ( false ) ; memmgr_ . TestingSetClientLastUsedTime ( & stub3 , newer_ ) ; Manage ( ) ; EXPECT_EQ ( memmgr_ . bytes_backgrounded_available_gpu_memory_ , memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub1 . BytesWhenNotVisible ( ) ) ; EXPECT_EQ ( 0ul , stub2 . BytesWhenNotVisible ( ) ) ; EXPECT_EQ ( memmgr_ . GetCurrentBackgroundedAvailableGpuMemory ( ) , stub3 . BytesWhenNotVisible ( ) ) ; }
Test GpuMemoryManager's background MRU behavior
Test GpuMemoryManager ' s background MRU behavior
// When all are visible, they should all be allowed to have memory // should they become backgrounded. // Background stubs 1 and 2, and they should fit // XXX - the MRU ordering is determined by taking the timestamp //       at which visibility changed. This does not have high //       enough resolution on all platforms to distinguish //       between the three SetVisible calls, so we have to //       explicitly set the timestamp. // Now background stub 3, and it should cause stub 2 to be // evicted because it was set non-visible first