Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: content/common/gpu/gpu_memory_manager_unittest.cc

Issue 11677008: Account for unmanaged (e.g, WebGL) use in memory manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate review feedback Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/gpu/gpu_memory_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; } 138 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; }
139 139
140 void SetVisible(bool visible) { 140 void SetVisible(bool visible) {
141 client_state_->SetVisible(visible); 141 client_state_->SetVisible(visible);
142 } 142 }
143 143
144 void SetManagedMemoryStats(const GpuManagedMemoryStats& stats) { 144 void SetManagedMemoryStats(const GpuManagedMemoryStats& stats) {
145 client_state_->SetManagedMemoryStats(stats); 145 client_state_->SetManagedMemoryStats(stats);
146 } 146 }
147 147
148 size_t BytesWhenVisible() const {
149 return allocation_.renderer_allocation.bytes_limit_when_visible;
150 }
151
148 size_t BytesWhenNotVisible() const { 152 size_t BytesWhenNotVisible() const {
149 return allocation_.renderer_allocation.bytes_limit_when_not_visible; 153 return allocation_.renderer_allocation.bytes_limit_when_not_visible;
150 } 154 }
151 }; 155 };
152 156
153 class GpuMemoryManagerTest : public testing::Test { 157 class GpuMemoryManagerTest : public testing::Test {
154 protected: 158 protected:
155 static const size_t kFrontbufferLimitForTest = 3; 159 static const size_t kFrontbufferLimitForTest = 3;
156 160
157 GpuMemoryManagerTest() 161 GpuMemoryManagerTest()
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_, 808 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
805 memmgr_.GetCurrentBackgroundedAvailableGpuMemory()); 809 memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
806 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), 810 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
807 stub1.BytesWhenNotVisible()); 811 stub1.BytesWhenNotVisible());
808 EXPECT_EQ(0ul, 812 EXPECT_EQ(0ul,
809 stub2.BytesWhenNotVisible()); 813 stub2.BytesWhenNotVisible());
810 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(), 814 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
811 stub3.BytesWhenNotVisible()); 815 stub3.BytesWhenNotVisible());
812 } 816 }
813 817
818 // Test GpuMemoryManager's tracking of unmanaged (e.g, WebGL) memory.
819 TEST_F(GpuMemoryManagerTest, TestUnmanagedTracking) {
820 memmgr_.TestingSetAvailableGpuMemory(64);
821 memmgr_.TestingSetBackgroundedAvailableGpuMemory(16);
822 memmgr_.TestingSetUnmanagedLimitStep(16);
823 memmgr_.TestingSetMinimumClientAllocation(8);
824
825 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true);
826
827 // Expect that the one stub get the maximum tab allocation.
828 Manage();
829 EXPECT_EQ(memmgr_.GetMaximumTabAllocation(),
830 stub1.BytesWhenVisible());
831
832 // Now allocate some unmanaged memory and make sure the amount
833 // goes down.
834 memmgr_.TrackMemoryAllocatedChange(
835 stub1.tracking_group_.get(),
836 0,
837 48,
838 gpu::gles2::MemoryTracker::kUnmanaged);
839 Manage();
840 EXPECT_GT(memmgr_.GetMaximumTabAllocation(),
841 stub1.BytesWhenVisible());
842
843 // Now allocate the entire FB worth of unmanaged memory, and
844 // make sure that we stay stuck at the minimum tab allocation.
845 memmgr_.TrackMemoryAllocatedChange(
846 stub1.tracking_group_.get(),
847 48,
848 64,
849 gpu::gles2::MemoryTracker::kUnmanaged);
850 Manage();
851 EXPECT_EQ(memmgr_.GetMinimumTabAllocation(),
852 stub1.BytesWhenVisible());
853
854 // Far-oversubscribe the entire FB, and make sure we stay at
855 // the minimum allocation, and don't blow up.
856 memmgr_.TrackMemoryAllocatedChange(
857 stub1.tracking_group_.get(),
858 64,
859 999,
860 gpu::gles2::MemoryTracker::kUnmanaged);
861 Manage();
862 EXPECT_EQ(memmgr_.GetMinimumTabAllocation(),
863 stub1.BytesWhenVisible());
864
865 // Delete all tracked memory so we don't hit leak checks.
866 memmgr_.TrackMemoryAllocatedChange(
867 stub1.tracking_group_.get(),
868 999,
869 0,
870 gpu::gles2::MemoryTracker::kUnmanaged);
871 }
872
814 } // namespace content 873 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_memory_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698