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

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

Issue 11293194: ui: Prefer +/- operators to apply offsets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: floats Created 8 years, 1 month 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
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_tracking.h" 7 #include "content/common/gpu/gpu_memory_tracking.h"
8 #include "ui/gfx/size_conversions.h" 8 #include "ui/gfx/size_conversions.h"
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 void SetInSameShareGroup(GpuMemoryManagerClient* stub) { 106 void SetInSameShareGroup(GpuMemoryManagerClient* stub) {
107 overridden_memory_tracker_ = stub->GetMemoryTracker(); 107 overridden_memory_tracker_ = stub->GetMemoryTracker();
108 } 108 }
109 109
110 gfx::Size GetSurfaceSize() const { 110 gfx::Size GetSurfaceSize() const {
111 return surface_size_; 111 return surface_size_;
112 } 112 }
113 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; } 113 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; }
114 114
115 void SetVisible(bool visible) {
116 memmgr_.SetClientVisible(this, visible);
117 }
118
119 void SetUsageStats(size_t bytes_required,
120 size_t bytes_nice_to_have,
121 size_t bytes_allocated) {
122 memmgr_.SetClientManagedMemoryStats(
123 this,
124 GpuManagedMemoryStats(bytes_required,
125 bytes_nice_to_have,
126 bytes_allocated,
127 false));
128 }
129
130 size_t BytesWhenNotVisible() const {
131 return allocation_.renderer_allocation.bytes_limit_when_not_visible;
132 }
115 }; 133 };
116 134
117 class GpuMemoryManagerTest : public testing::Test { 135 class GpuMemoryManagerTest : public testing::Test {
118 protected: 136 protected:
119 static const size_t kFrontbufferLimitForTest = 3; 137 static const size_t kFrontbufferLimitForTest = 3;
120 138
121 GpuMemoryManagerTest() 139 GpuMemoryManagerTest()
122 : memmgr_(kFrontbufferLimitForTest) { 140 : memmgr_(kFrontbufferLimitForTest) {
123 memmgr_.TestingDisableScheduleManage(); 141 memmgr_.TestingDisableScheduleManage();
124 } 142 }
(...skipping 13 matching lines...) Expand all
138 const GpuMemoryAllocation& alloc) { 156 const GpuMemoryAllocation& alloc) {
139 return alloc.browser_allocation.suggest_have_frontbuffer && 157 return alloc.browser_allocation.suggest_have_frontbuffer &&
140 !alloc.renderer_allocation.have_backbuffer_when_not_visible && 158 !alloc.renderer_allocation.have_backbuffer_when_not_visible &&
141 alloc.renderer_allocation.bytes_limit_when_visible >= 159 alloc.renderer_allocation.bytes_limit_when_visible >=
142 GetMinimumTabAllocation(); 160 GetMinimumTabAllocation();
143 } 161 }
144 bool IsAllocationBackgroundForSurfaceYes( 162 bool IsAllocationBackgroundForSurfaceYes(
145 const GpuMemoryAllocation& alloc) { 163 const GpuMemoryAllocation& alloc) {
146 return alloc.browser_allocation.suggest_have_frontbuffer && 164 return alloc.browser_allocation.suggest_have_frontbuffer &&
147 !alloc.renderer_allocation.have_backbuffer_when_not_visible && 165 !alloc.renderer_allocation.have_backbuffer_when_not_visible &&
148 alloc.renderer_allocation.bytes_limit_when_not_visible == 0; 166 alloc.renderer_allocation.bytes_limit_when_not_visible <=
167 memmgr_.GetCurrentBackgroundedAvailableGpuMemory();
149 } 168 }
150 bool IsAllocationHibernatedForSurfaceYes( 169 bool IsAllocationHibernatedForSurfaceYes(
151 const GpuMemoryAllocation& alloc) { 170 const GpuMemoryAllocation& alloc) {
152 return !alloc.browser_allocation.suggest_have_frontbuffer && 171 return !alloc.browser_allocation.suggest_have_frontbuffer &&
153 !alloc.renderer_allocation.have_backbuffer_when_not_visible && 172 !alloc.renderer_allocation.have_backbuffer_when_not_visible &&
154 alloc.renderer_allocation.bytes_limit_when_not_visible == 0; 173 alloc.renderer_allocation.bytes_limit_when_not_visible <=
174 memmgr_.GetCurrentBackgroundedAvailableGpuMemory();
155 } 175 }
156 bool IsAllocationForegroundForSurfaceNo( 176 bool IsAllocationForegroundForSurfaceNo(
157 const GpuMemoryAllocation& alloc) { 177 const GpuMemoryAllocation& alloc) {
158 return !alloc.browser_allocation.suggest_have_frontbuffer && 178 return !alloc.browser_allocation.suggest_have_frontbuffer &&
159 !alloc.renderer_allocation.have_backbuffer_when_not_visible && 179 !alloc.renderer_allocation.have_backbuffer_when_not_visible &&
160 alloc.renderer_allocation.bytes_limit_when_visible == 180 alloc.renderer_allocation.bytes_limit_when_visible ==
161 GetMinimumTabAllocation(); 181 GetMinimumTabAllocation();
162 } 182 }
163 bool IsAllocationBackgroundForSurfaceNo( 183 bool IsAllocationBackgroundForSurfaceNo(
164 const GpuMemoryAllocation& alloc) { 184 const GpuMemoryAllocation& alloc) {
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 771
752 // Decrease allocation amounts. 772 // Decrease allocation amounts.
753 memmgr_.SetClientManagedMemoryStats( 773 memmgr_.SetClientManagedMemoryStats(
754 &stub1, GpuManagedMemoryStats(0, 0, 4, false)); 774 &stub1, GpuManagedMemoryStats(0, 0, 4, false));
755 memmgr_.SetClientManagedMemoryStats( 775 memmgr_.SetClientManagedMemoryStats(
756 &stub2, GpuManagedMemoryStats(0, 0, 6, false)); 776 &stub2, GpuManagedMemoryStats(0, 0, 6, false));
757 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_); 777 EXPECT_EQ(6ul, memmgr_.bytes_allocated_managed_visible_);
758 EXPECT_EQ(4ul, memmgr_.bytes_allocated_managed_backgrounded_); 778 EXPECT_EQ(4ul, memmgr_.bytes_allocated_managed_backgrounded_);
759 } 779 }
760 780
781 // Test GpuMemoryManager's background cutoff threshoulds
782 TEST_F(GpuMemoryManagerTest, TestBackgroundCutoff) {
783 memmgr_.TestingSetAvailableGpuMemory(64);
784 memmgr_.TestingSetBackgroundedAvailableGpuMemory(16);
785
786 FakeClient stub1(memmgr_, GenerateUniqueSurfaceId(), true, older_);
787
788 // stub1's requirements are not <16, so it should just dump
789 // everything when it goes invisible.
790 stub1.SetUsageStats(16, 24, 18);
791 Manage();
792 EXPECT_EQ(0ul, stub1.BytesWhenNotVisible());
793
794 // stub1 now fits, so it should have a full budget.
795 stub1.SetUsageStats(15, 24, 18);
796 Manage();
797 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
798 memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
799 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
800 stub1.BytesWhenNotVisible());
801
802 // background stub1
803 stub1.SetUsageStats(15, 24, 15);
804 stub1.SetVisible(false);
805
806 // Add stub2 that uses almost enough memory to evict
807 // stub1, but not quite
808 FakeClient stub2(memmgr_, GenerateUniqueSurfaceId(), true, older_);
809 stub2.SetUsageStats(15, 50, 48);
810 Manage();
811 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
812 memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
813 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
814 stub1.BytesWhenNotVisible());
815 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
816 stub2.BytesWhenNotVisible());
817
818 // Increase stub2 to break evict stub1
819 stub2.SetUsageStats(15, 50, 49);
820 Manage();
821 EXPECT_EQ(0ul,
822 stub1.BytesWhenNotVisible());
823 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
824 stub2.BytesWhenNotVisible());
825 }
826
827 // Test GpuMemoryManager's background MRU behavior
828 TEST_F(GpuMemoryManagerTest, TestBackgroundMru) {
829 memmgr_.TestingSetAvailableGpuMemory(64);
830 memmgr_.TestingSetBackgroundedAvailableGpuMemory(16);
831
832 FakeClient stub1(memmgr_, GenerateUniqueSurfaceId(), true, older_);
833 FakeClient stub2(memmgr_, GenerateUniqueSurfaceId(), true, older_);
834 FakeClient stub3(memmgr_, GenerateUniqueSurfaceId(), true, older_);
835
836 // When all are visible, they should all be allowed to have memory
837 // should they become backgrounded.
838 stub1.SetUsageStats(7, 24, 7);
839 stub2.SetUsageStats(7, 24, 7);
840 stub3.SetUsageStats(7, 24, 7);
841 Manage();
842 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
843 memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
844 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
845 stub1.BytesWhenNotVisible());
846 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
847 stub2.BytesWhenNotVisible());
848 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
849 stub3.BytesWhenNotVisible());
850
851
852 // Background stubs 1 and 2, and they should fit
853 stub2.SetVisible(false);
854 // XXX - the MRU ordering is determined by taking the timestamp
855 // at which visibility changed. This does not have high
856 // enough resolution on all platforms to distinguish
857 // between the three SetVisible calls, so we have to
858 // explicitly set the timestamp.
859 memmgr_.TestingSetClientLastUsedTime(&stub2, older_);
860 stub1.SetVisible(false);
861 memmgr_.TestingSetClientLastUsedTime(&stub1, newer_);
862 Manage();
863 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
864 memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
865 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
866 stub1.BytesWhenNotVisible());
867 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
868 stub2.BytesWhenNotVisible());
869 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
870 stub3.BytesWhenNotVisible());
871
872 // Now background stub 3, and it should cause stub 2 to be
873 // evicted because it was set non-visible first
874 stub3.SetVisible(false);
875 memmgr_.TestingSetClientLastUsedTime(&stub3, newer_);
876 Manage();
877 EXPECT_EQ(memmgr_.bytes_backgrounded_available_gpu_memory_,
878 memmgr_.GetCurrentBackgroundedAvailableGpuMemory());
879 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
880 stub1.BytesWhenNotVisible());
881 EXPECT_EQ(0ul,
882 stub2.BytesWhenNotVisible());
883 EXPECT_EQ(memmgr_.GetCurrentBackgroundedAvailableGpuMemory(),
884 stub3.BytesWhenNotVisible());
885 }
886
761 } // namespace content 887 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698