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

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

Issue 10083056: GpuMemoryManager suggests values for renderer Contents Texture Managers' preferred memory limit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: On max 10.5, it fails to init command buffer, and my callback code didn't guard against that. Created 8 years, 7 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') | content/common/gpu/gpu_messages.h » ('j') | 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_command_buffer_stub.h" 5 #include "content/common/gpu/gpu_command_buffer_stub.h"
6 #include "content/common/gpu/gpu_memory_allocation.h" 6 #include "content/common/gpu/gpu_memory_allocation.h"
7 #include "content/common/gpu/gpu_memory_manager.h" 7 #include "content/common/gpu/gpu_memory_manager.h"
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 class FakeCommandBufferStub : public GpuCommandBufferStubBase { 11 class FakeCommandBufferStub : public GpuCommandBufferStubBase {
12 public: 12 public:
13 SurfaceState surface_state_; 13 SurfaceState surface_state_;
14 GpuMemoryAllocation allocation_; 14 GpuMemoryAllocation allocation_;
15 15
16 FakeCommandBufferStub() 16 FakeCommandBufferStub()
17 : surface_state_(0, false, base::TimeTicks()) { 17 : surface_state_(0, false, base::TimeTicks()) {
18 } 18 }
19 19
20 FakeCommandBufferStub(int32 surface_id, 20 FakeCommandBufferStub(int32 surface_id,
21 bool visible, 21 bool visible,
22 base::TimeTicks last_used_time) 22 base::TimeTicks last_used_time)
23 : surface_state_(surface_id, visible, last_used_time) { 23 : surface_state_(surface_id, visible, last_used_time) {
24 } 24 }
25 25
26 virtual bool client_has_memory_allocation_changed_callback() const {
27 return true;
28 }
26 virtual bool has_surface_state() const { 29 virtual bool has_surface_state() const {
27 return surface_state_.surface_id != 0; 30 return surface_state_.surface_id != 0;
28 } 31 }
29 virtual const SurfaceState& surface_state() const { 32 virtual const SurfaceState& surface_state() const {
30 return surface_state_; 33 return surface_state_;
31 } 34 }
32 35
33 virtual bool IsInSameContextShareGroup( 36 virtual bool IsInSameContextShareGroup(
34 const GpuCommandBufferStubBase& stub) const { 37 const GpuCommandBufferStubBase& stub) const {
35 return false; 38 return false;
36 } 39 }
37 virtual void SendMemoryAllocationToProxy(const GpuMemoryAllocation& alloc) { 40 virtual void SendMemoryAllocationToProxy(const GpuMemoryAllocation& alloc) {
38 } 41 }
39 virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) { 42 virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) {
40 allocation_ = alloc; 43 allocation_ = alloc;
41 } 44 }
42 }; 45 };
43 46
44 class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase { 47 class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase {
45 public: 48 public:
46 GpuMemoryAllocation allocation_; 49 GpuMemoryAllocation allocation_;
47 std::vector<GpuCommandBufferStubBase*> share_group_; 50 std::vector<GpuCommandBufferStubBase*> share_group_;
48 51
49 FakeCommandBufferStubWithoutSurface() { 52 FakeCommandBufferStubWithoutSurface() {
50 } 53 }
51 54
55 virtual bool client_has_memory_allocation_changed_callback() const {
56 return true;
57 }
52 virtual bool has_surface_state() const { 58 virtual bool has_surface_state() const {
53 return false; 59 return false;
54 } 60 }
55 virtual const SurfaceState& surface_state() const { 61 virtual const SurfaceState& surface_state() const {
56 NOTREACHED(); 62 NOTREACHED();
57 static SurfaceState* surface_state_; 63 static SurfaceState* surface_state_;
58 return *surface_state_; 64 return *surface_state_;
59 } 65 }
60 66
61 virtual bool IsInSameContextShareGroup( 67 virtual bool IsInSameContextShareGroup(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 older_ = base::TimeTicks::FromInternalValue(1); 99 older_ = base::TimeTicks::FromInternalValue(1);
94 newer_ = base::TimeTicks::FromInternalValue(2); 100 newer_ = base::TimeTicks::FromInternalValue(2);
95 newest_ = base::TimeTicks::FromInternalValue(3); 101 newest_ = base::TimeTicks::FromInternalValue(3);
96 } 102 }
97 103
98 static int32 GenerateUniqueSurfaceId() { 104 static int32 GenerateUniqueSurfaceId() {
99 static int32 surface_id_ = 1; 105 static int32 surface_id_ = 1;
100 return surface_id_++; 106 return surface_id_++;
101 } 107 }
102 108
103 static bool is_more_important(GpuCommandBufferStubBase* lhs, 109 static bool IsMoreImportant(GpuCommandBufferStubBase* lhs,
104 GpuCommandBufferStubBase* rhs) { 110 GpuCommandBufferStubBase* rhs) {
105 return GpuMemoryManager::StubWithSurfaceComparator()(lhs, rhs); 111 return GpuMemoryManager::StubWithSurfaceComparator()(lhs, rhs);
106 } 112 }
107 113
114 static bool IsAllocationForegroundForSurfaceYes(
115 const GpuMemoryAllocation& alloc) {
116 return alloc.suggest_have_frontbuffer &&
117 alloc.suggest_have_backbuffer &&
118 alloc.gpu_resource_size_in_bytes >=
119 GpuMemoryManager::kMinimumAllocationForTab;
120 }
121 static bool IsAllocationBackgroundForSurfaceYes(
122 const GpuMemoryAllocation& alloc) {
123 return alloc.suggest_have_frontbuffer &&
124 !alloc.suggest_have_backbuffer &&
125 alloc.gpu_resource_size_in_bytes == 0;
126 }
127 static bool IsAllocationHibernatedForSurfaceYes(
128 const GpuMemoryAllocation& alloc) {
129 return !alloc.suggest_have_frontbuffer &&
130 !alloc.suggest_have_backbuffer &&
131 alloc.gpu_resource_size_in_bytes == 0;
132 }
133 static bool IsAllocationForegroundForSurfaceNo(
134 const GpuMemoryAllocation& alloc) {
135 return !alloc.suggest_have_frontbuffer &&
136 !alloc.suggest_have_backbuffer &&
137 alloc.gpu_resource_size_in_bytes ==
138 GpuMemoryManager::kMinimumAllocationForTab;
139 }
140 static bool IsAllocationBackgroundForSurfaceNo(
141 const GpuMemoryAllocation& alloc) {
142 return !alloc.suggest_have_frontbuffer &&
143 !alloc.suggest_have_backbuffer &&
144 alloc.gpu_resource_size_in_bytes ==
145 GpuMemoryManager::kMinimumAllocationForTab;
146 }
147 static bool IsAllocationHibernatedForSurfaceNo(
148 const GpuMemoryAllocation& alloc) {
149 return !alloc.suggest_have_frontbuffer &&
150 !alloc.suggest_have_backbuffer &&
151 alloc.gpu_resource_size_in_bytes == 0;
152 }
153
108 void Manage() { 154 void Manage() {
109 memory_manager_.Manage(); 155 memory_manager_.Manage();
110 } 156 }
111 157
112 base::TimeTicks older_, newer_, newest_; 158 base::TimeTicks older_, newer_, newest_;
113 FakeClient client_; 159 FakeClient client_;
114 GpuMemoryManager memory_manager_; 160 GpuMemoryManager memory_manager_;
115 }; 161 };
116 162
117 // Create fake stubs with every combination of {visibilty,last_use_time} 163 // Create fake stubs with every combination of {visibilty,last_use_time}
118 // and make sure they compare correctly. Only compare stubs with surfaces. 164 // and make sure they compare correctly. Only compare stubs with surfaces.
119 // Expect {more visible, newer} surfaces to be more important, in that order. 165 // Expect {more visible, newer} surfaces to be more important, in that order.
120 TEST_F(GpuMemoryManagerTest, ComparatorTests) { 166 TEST_F(GpuMemoryManagerTest, ComparatorTests) {
121 FakeCommandBufferStub stub_true1(GenerateUniqueSurfaceId(), true, older_), 167 FakeCommandBufferStub stub_true1(GenerateUniqueSurfaceId(), true, older_),
122 stub_true2(GenerateUniqueSurfaceId(), true, newer_), 168 stub_true2(GenerateUniqueSurfaceId(), true, newer_),
123 stub_true3(GenerateUniqueSurfaceId(), true, newest_), 169 stub_true3(GenerateUniqueSurfaceId(), true, newest_),
124 stub_false1(GenerateUniqueSurfaceId(), false, older_), 170 stub_false1(GenerateUniqueSurfaceId(), false, older_),
125 stub_false2(GenerateUniqueSurfaceId(), false, newer_), 171 stub_false2(GenerateUniqueSurfaceId(), false, newer_),
126 stub_false3(GenerateUniqueSurfaceId(), false, newest_); 172 stub_false3(GenerateUniqueSurfaceId(), false, newest_);
127 173
128 // Should never be more important than self: 174 // Should never be more important than self:
129 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true1)); 175 EXPECT_FALSE(IsMoreImportant(&stub_true1, &stub_true1));
130 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true2)); 176 EXPECT_FALSE(IsMoreImportant(&stub_true2, &stub_true2));
131 EXPECT_FALSE(is_more_important(&stub_true3, &stub_true3)); 177 EXPECT_FALSE(IsMoreImportant(&stub_true3, &stub_true3));
132 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false1)); 178 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_false1));
133 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false2)); 179 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_false2));
134 EXPECT_FALSE(is_more_important(&stub_false3, &stub_false3)); 180 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_false3));
135 181
136 // Visible should always be more important than non visible: 182 // Visible should always be more important than non visible:
137 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false1)); 183 EXPECT_TRUE(IsMoreImportant(&stub_true1, &stub_false1));
138 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false2)); 184 EXPECT_TRUE(IsMoreImportant(&stub_true1, &stub_false2));
139 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false3)); 185 EXPECT_TRUE(IsMoreImportant(&stub_true1, &stub_false3));
140 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false1)); 186 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_false1));
141 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false2)); 187 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_false2));
142 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false3)); 188 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_false3));
143 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false1)); 189 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_false1));
144 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false2)); 190 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_false2));
145 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false3)); 191 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_false3));
146 192
147 // Not visible should never be more important than visible: 193 // Not visible should never be more important than visible:
148 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true1)); 194 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_true1));
149 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true2)); 195 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_true2));
150 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true3)); 196 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_true3));
151 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true1)); 197 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_true1));
152 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true2)); 198 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_true2));
153 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true3)); 199 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_true3));
154 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true1)); 200 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_true1));
155 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true2)); 201 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_true2));
156 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true3)); 202 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_true3));
157 203
158 // Newer should always be more important than older: 204 // Newer should always be more important than older:
159 EXPECT_TRUE(is_more_important(&stub_true2, &stub_true1)); 205 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_true1));
160 EXPECT_TRUE(is_more_important(&stub_true3, &stub_true1)); 206 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_true1));
161 EXPECT_TRUE(is_more_important(&stub_true3, &stub_true2)); 207 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_true2));
162 EXPECT_TRUE(is_more_important(&stub_false2, &stub_false1)); 208 EXPECT_TRUE(IsMoreImportant(&stub_false2, &stub_false1));
163 EXPECT_TRUE(is_more_important(&stub_false3, &stub_false1)); 209 EXPECT_TRUE(IsMoreImportant(&stub_false3, &stub_false1));
164 EXPECT_TRUE(is_more_important(&stub_false3, &stub_false2)); 210 EXPECT_TRUE(IsMoreImportant(&stub_false3, &stub_false2));
165 211
166 // Older should never be more important than newer: 212 // Older should never be more important than newer:
167 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true2)); 213 EXPECT_FALSE(IsMoreImportant(&stub_true1, &stub_true2));
168 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true3)); 214 EXPECT_FALSE(IsMoreImportant(&stub_true1, &stub_true3));
169 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true3)); 215 EXPECT_FALSE(IsMoreImportant(&stub_true2, &stub_true3));
170 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false2)); 216 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_false2));
171 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false3)); 217 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_false3));
172 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false3)); 218 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_false3));
173 } 219 }
174 220
175 // Test GpuMemoryManager::Manage basic functionality. 221 // Test GpuMemoryManager::Manage basic functionality.
176 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according 222 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according
177 // to visibility and last used time for stubs with surface. 223 // to visibility and last used time for stubs with surface.
178 // Expect memory allocation to be shared according to share groups for stubs 224 // Expect memory allocation to be shared according to share groups for stubs
179 // without a surface. 225 // without a surface.
180 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { 226 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) {
181 // Test stubs with surface. 227 // Test stubs with surface.
182 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), 228 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
183 stub2(GenerateUniqueSurfaceId(), false, older_); 229 stub2(GenerateUniqueSurfaceId(), false, older_);
184 client_.stubs_.push_back(&stub1); 230 client_.stubs_.push_back(&stub1);
185 client_.stubs_.push_back(&stub2); 231 client_.stubs_.push_back(&stub2);
186 232
187 Manage(); 233 Manage();
188 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 234 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
189 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); 235 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
190 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
191 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false);
192 236
193 // Test stubs without surface, with share group of 1 stub. 237 // Test stubs without surface, with share group of 1 stub.
194 FakeCommandBufferStubWithoutSurface stub3, stub4; 238 FakeCommandBufferStubWithoutSurface stub3, stub4;
195 stub3.share_group_.push_back(&stub1); 239 stub3.share_group_.push_back(&stub1);
196 stub4.share_group_.push_back(&stub2); 240 stub4.share_group_.push_back(&stub2);
197 client_.stubs_.push_back(&stub3); 241 client_.stubs_.push_back(&stub3);
198 client_.stubs_.push_back(&stub4); 242 client_.stubs_.push_back(&stub4);
199 243
200 Manage(); 244 Manage();
201 EXPECT_EQ(stub1.allocation_, stub3.allocation_); 245 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
202 EXPECT_EQ(stub2.allocation_, stub4.allocation_); 246 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
247 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
248 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
203 249
204 // Test stub without surface, with share group of multiple stubs. 250 // Test stub without surface, with share group of multiple stubs.
205 FakeCommandBufferStubWithoutSurface stub5; 251 FakeCommandBufferStubWithoutSurface stub5;
206 stub5.share_group_.push_back(&stub1); 252 stub5.share_group_.push_back(&stub1);
207 stub5.share_group_.push_back(&stub2); 253 stub5.share_group_.push_back(&stub2);
208 client_.stubs_.push_back(&stub5); 254 client_.stubs_.push_back(&stub5);
209 255
210 Manage(); 256 Manage();
211 EXPECT_EQ(stub1.allocation_, stub5.allocation_); 257 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
212 } 258 }
213 259
214 // Test GpuMemoryManager::Manage functionality: changing visibility. 260 // Test GpuMemoryManager::Manage functionality: changing visibility.
215 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according 261 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according
216 // to visibility and last used time for stubs with surface. 262 // to visibility and last used time for stubs with surface.
217 // Expect memory allocation to be shared according to share groups for stubs 263 // Expect memory allocation to be shared according to share groups for stubs
218 // without a surface. 264 // without a surface.
219 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { 265 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) {
220 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), 266 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
221 stub2(GenerateUniqueSurfaceId(), false, older_); 267 stub2(GenerateUniqueSurfaceId(), false, older_);
222 client_.stubs_.push_back(&stub1); 268 client_.stubs_.push_back(&stub1);
223 client_.stubs_.push_back(&stub2); 269 client_.stubs_.push_back(&stub2);
224 270
225 FakeCommandBufferStubWithoutSurface stub3, stub4; 271 FakeCommandBufferStubWithoutSurface stub3, stub4;
226 stub3.share_group_.push_back(&stub1); 272 stub3.share_group_.push_back(&stub1);
227 stub4.share_group_.push_back(&stub2); 273 stub4.share_group_.push_back(&stub2);
228 client_.stubs_.push_back(&stub3); 274 client_.stubs_.push_back(&stub3);
229 client_.stubs_.push_back(&stub4); 275 client_.stubs_.push_back(&stub4);
230 276
231 FakeCommandBufferStubWithoutSurface stub5; 277 FakeCommandBufferStubWithoutSurface stub5;
232 stub5.share_group_.push_back(&stub1); 278 stub5.share_group_.push_back(&stub1);
233 stub5.share_group_.push_back(&stub2); 279 stub5.share_group_.push_back(&stub2);
234 client_.stubs_.push_back(&stub5); 280 client_.stubs_.push_back(&stub5);
235 281
236 Manage(); 282 Manage();
237 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 283 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
238 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); 284 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
239 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 285 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
240 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 286 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
241 EXPECT_EQ(stub1.allocation_, stub3.allocation_); 287 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
242 EXPECT_EQ(stub2.allocation_, stub4.allocation_);
243 EXPECT_EQ(stub1.allocation_, stub5.allocation_);
244 288
245 stub1.surface_state_.visible = false; 289 stub1.surface_state_.visible = false;
246 stub2.surface_state_.visible = true; 290 stub2.surface_state_.visible = true;
247 291
248 Manage(); 292 Manage();
249 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 293 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
250 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 294 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
251 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 295 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
252 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 296 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
253 EXPECT_EQ(stub1.allocation_, stub3.allocation_); 297 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
254 EXPECT_EQ(stub2.allocation_, stub4.allocation_);
255 EXPECT_EQ(stub2.allocation_, stub5.allocation_);
256 } 298 }
257 299
258 // Test GpuMemoryManager::Manage functionality: Test more than threshold number 300 // Test GpuMemoryManager::Manage functionality: Test more than threshold number
259 // of visible stubs. 301 // of visible stubs.
260 // Expect all allocations to continue to have frontbuffer. 302 // Expect all allocations to continue to have frontbuffer.
261 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { 303 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) {
262 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), 304 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
263 stub2(GenerateUniqueSurfaceId(), true, older_), 305 stub2(GenerateUniqueSurfaceId(), true, older_),
264 stub3(GenerateUniqueSurfaceId(), true, older_), 306 stub3(GenerateUniqueSurfaceId(), true, older_),
265 stub4(GenerateUniqueSurfaceId(), true, older_); 307 stub4(GenerateUniqueSurfaceId(), true, older_);
266 client_.stubs_.push_back(&stub1); 308 client_.stubs_.push_back(&stub1);
267 client_.stubs_.push_back(&stub2); 309 client_.stubs_.push_back(&stub2);
268 client_.stubs_.push_back(&stub3); 310 client_.stubs_.push_back(&stub3);
269 client_.stubs_.push_back(&stub4); 311 client_.stubs_.push_back(&stub4);
270 312
271 FakeCommandBufferStubWithoutSurface stub5, stub6; 313 FakeCommandBufferStubWithoutSurface stub5, stub6;
272 stub5.share_group_.push_back(&stub1); 314 stub5.share_group_.push_back(&stub1);
273 stub6.share_group_.push_back(&stub2); 315 stub6.share_group_.push_back(&stub2);
274 client_.stubs_.push_back(&stub5); 316 client_.stubs_.push_back(&stub5);
275 client_.stubs_.push_back(&stub6); 317 client_.stubs_.push_back(&stub6);
276 318
277 FakeCommandBufferStubWithoutSurface stub7; 319 FakeCommandBufferStubWithoutSurface stub7;
278 stub7.share_group_.push_back(&stub1); 320 stub7.share_group_.push_back(&stub1);
279 stub7.share_group_.push_back(&stub2); 321 stub7.share_group_.push_back(&stub2);
280 client_.stubs_.push_back(&stub7); 322 client_.stubs_.push_back(&stub7);
281 323
282 Manage(); 324 Manage();
283 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 325 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
284 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); 326 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
285 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 327 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_));
286 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 328 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub4.allocation_));
287 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); 329 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
288 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, true); 330 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub6.allocation_));
289 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); 331 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub7.allocation_));
290 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, true);
291 EXPECT_EQ(stub5.allocation_, stub1.allocation_);
292 EXPECT_EQ(stub6.allocation_, stub2.allocation_);
293 EXPECT_EQ(stub7.allocation_, stub1.allocation_);
294 } 332 }
295 333
296 // Test GpuMemoryManager::Manage functionality: Test more than threshold number 334 // Test GpuMemoryManager::Manage functionality: Test more than threshold number
297 // of not visible stubs. 335 // of not visible stubs.
298 // Expect the stubs surpassing the threshold to not have a backbuffer. 336 // Expect the stubs surpassing the threshold to not have a backbuffer.
299 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { 337 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) {
300 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), 338 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_),
301 stub2(GenerateUniqueSurfaceId(), false, newer_), 339 stub2(GenerateUniqueSurfaceId(), false, newer_),
302 stub3(GenerateUniqueSurfaceId(), false, newer_), 340 stub3(GenerateUniqueSurfaceId(), false, newer_),
303 stub4(GenerateUniqueSurfaceId(), false, older_); 341 stub4(GenerateUniqueSurfaceId(), false, older_);
304 client_.stubs_.push_back(&stub1); 342 client_.stubs_.push_back(&stub1);
305 client_.stubs_.push_back(&stub2); 343 client_.stubs_.push_back(&stub2);
306 client_.stubs_.push_back(&stub3); 344 client_.stubs_.push_back(&stub3);
307 client_.stubs_.push_back(&stub4); 345 client_.stubs_.push_back(&stub4);
308 346
309 FakeCommandBufferStubWithoutSurface stub5, stub6; 347 FakeCommandBufferStubWithoutSurface stub5, stub6;
310 stub5.share_group_.push_back(&stub1); 348 stub5.share_group_.push_back(&stub1);
311 stub6.share_group_.push_back(&stub4); 349 stub6.share_group_.push_back(&stub4);
312 client_.stubs_.push_back(&stub5); 350 client_.stubs_.push_back(&stub5);
313 client_.stubs_.push_back(&stub6); 351 client_.stubs_.push_back(&stub6);
314 352
315 FakeCommandBufferStubWithoutSurface stub7; 353 FakeCommandBufferStubWithoutSurface stub7;
316 stub7.share_group_.push_back(&stub1); 354 stub7.share_group_.push_back(&stub1);
317 stub7.share_group_.push_back(&stub4); 355 stub7.share_group_.push_back(&stub4);
318 client_.stubs_.push_back(&stub7); 356 client_.stubs_.push_back(&stub7);
319 357
320 Manage(); 358 Manage();
321 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 359 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
322 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 360 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
323 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 361 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_));
324 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 362 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_));
325 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); 363 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_));
326 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); 364 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_));
327 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); 365 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
328 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false);
329 EXPECT_EQ(stub5.allocation_, stub1.allocation_);
330 EXPECT_EQ(stub6.allocation_, stub4.allocation_);
331 EXPECT_EQ(stub7.allocation_, stub1.allocation_);
332 } 366 }
333 367
334 // Test GpuMemoryManager::Manage functionality: Test changing the last used 368 // Test GpuMemoryManager::Manage functionality: Test changing the last used
335 // time of stubs when doing so causes change in which stubs surpass threshold. 369 // time of stubs when doing so causes change in which stubs surpass threshold.
336 // Expect frontbuffer to be dropped for the older stub. 370 // Expect frontbuffer to be dropped for the older stub.
337 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { 371 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) {
338 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), 372 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_),
339 stub2(GenerateUniqueSurfaceId(), false, newer_), 373 stub2(GenerateUniqueSurfaceId(), false, newer_),
340 stub3(GenerateUniqueSurfaceId(), false, newer_), 374 stub3(GenerateUniqueSurfaceId(), false, newer_),
341 stub4(GenerateUniqueSurfaceId(), false, older_); 375 stub4(GenerateUniqueSurfaceId(), false, older_);
342 client_.stubs_.push_back(&stub1); 376 client_.stubs_.push_back(&stub1);
343 client_.stubs_.push_back(&stub2); 377 client_.stubs_.push_back(&stub2);
344 client_.stubs_.push_back(&stub3); 378 client_.stubs_.push_back(&stub3);
345 client_.stubs_.push_back(&stub4); 379 client_.stubs_.push_back(&stub4);
346 380
347 FakeCommandBufferStubWithoutSurface stub5, stub6; 381 FakeCommandBufferStubWithoutSurface stub5, stub6;
348 stub5.share_group_.push_back(&stub3); 382 stub5.share_group_.push_back(&stub3);
349 stub6.share_group_.push_back(&stub4); 383 stub6.share_group_.push_back(&stub4);
350 client_.stubs_.push_back(&stub5); 384 client_.stubs_.push_back(&stub5);
351 client_.stubs_.push_back(&stub6); 385 client_.stubs_.push_back(&stub6);
352 386
353 FakeCommandBufferStubWithoutSurface stub7; 387 FakeCommandBufferStubWithoutSurface stub7;
354 stub7.share_group_.push_back(&stub3); 388 stub7.share_group_.push_back(&stub3);
355 stub7.share_group_.push_back(&stub4); 389 stub7.share_group_.push_back(&stub4);
356 client_.stubs_.push_back(&stub7); 390 client_.stubs_.push_back(&stub7);
357 391
358 Manage(); 392 Manage();
359 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); 393 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
360 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); 394 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
361 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); 395 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_));
362 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); 396 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_));
363 EXPECT_EQ(stub5.allocation_, stub3.allocation_); 397 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_));
364 EXPECT_EQ(stub6.allocation_, stub4.allocation_); 398 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_));
365 EXPECT_EQ(stub7.allocation_, stub3.allocation_); 399 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
366 400
367 stub3.surface_state_.last_used_time = older_; 401 stub3.surface_state_.last_used_time = older_;
368 stub4.surface_state_.last_used_time = newer_; 402 stub4.surface_state_.last_used_time = newer_;
369 403
370 Manage(); 404 Manage();
371 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, false); 405 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
372 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); 406 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
373 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); 407 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub3.allocation_));
374 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); 408 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_));
375 EXPECT_EQ(stub5.allocation_, stub3.allocation_); 409 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_));
376 EXPECT_EQ(stub6.allocation_, stub4.allocation_); 410 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_));
377 EXPECT_EQ(stub7.allocation_, stub4.allocation_); 411 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
378 } 412 }
379 413
380 // Test GpuMemoryManager::Manage functionality: Test changing importance of 414 // Test GpuMemoryManager::Manage functionality: Test changing importance of
381 // enough stubs so that every stub in share group crosses threshold. 415 // enough stubs so that every stub in share group crosses threshold.
382 // Expect memory allocation of the stubs without surface to share memory 416 // Expect memory allocation of the stubs without surface to share memory
383 // allocation with the most visible stub in share group. 417 // allocation with the most visible stub in share group.
384 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { 418 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) {
385 FakeCommandBufferStub stubA(GenerateUniqueSurfaceId(), true, newer_), 419 FakeCommandBufferStub stubIgnoreA(GenerateUniqueSurfaceId(), true, newer_),
386 stubB(GenerateUniqueSurfaceId(), false, newer_), 420 stubIgnoreB(GenerateUniqueSurfaceId(), false, newer_),
387 stubC(GenerateUniqueSurfaceId(), false, newer_); 421 stubIgnoreC(GenerateUniqueSurfaceId(), false, newer_);
388 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, newest_), 422 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, newest_),
389 stub2(GenerateUniqueSurfaceId(), true, newest_); 423 stub2(GenerateUniqueSurfaceId(), true, newest_);
390 client_.stubs_.push_back(&stubA); 424 client_.stubs_.push_back(&stubIgnoreA);
391 client_.stubs_.push_back(&stubB); 425 client_.stubs_.push_back(&stubIgnoreB);
392 client_.stubs_.push_back(&stubC); 426 client_.stubs_.push_back(&stubIgnoreC);
393 client_.stubs_.push_back(&stub1); 427 client_.stubs_.push_back(&stub1);
394 client_.stubs_.push_back(&stub2); 428 client_.stubs_.push_back(&stub2);
395 429
396 FakeCommandBufferStubWithoutSurface stub3, stub4; 430 FakeCommandBufferStubWithoutSurface stub3, stub4;
397 stub3.share_group_.push_back(&stub1); 431 stub3.share_group_.push_back(&stub1);
398 stub3.share_group_.push_back(&stub2); 432 stub3.share_group_.push_back(&stub2);
399 stub4.share_group_.push_back(&stub1); 433 stub4.share_group_.push_back(&stub1);
400 stub4.share_group_.push_back(&stub2); 434 stub4.share_group_.push_back(&stub2);
401 client_.stubs_.push_back(&stub3); 435 client_.stubs_.push_back(&stub3);
402 client_.stubs_.push_back(&stub4); 436 client_.stubs_.push_back(&stub4);
403 437
404 Manage(); 438 Manage();
405 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 439 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
406 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); 440 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
407 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 441 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
408 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 442 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
409 EXPECT_EQ(stub3.allocation_, stub1.allocation_);
410 EXPECT_EQ(stub3.allocation_, stub2.allocation_);
411 EXPECT_EQ(stub4.allocation_, stub1.allocation_);
412 EXPECT_EQ(stub4.allocation_, stub2.allocation_);
413 443
414 stub1.surface_state_.visible = false; 444 stub1.surface_state_.visible = false;
415 445
416 Manage(); 446 Manage();
417 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 447 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
418 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 448 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
419 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 449 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
420 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 450 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
421 EXPECT_NE(stub3.allocation_, stub1.allocation_);
422 EXPECT_EQ(stub3.allocation_, stub2.allocation_);
423 EXPECT_NE(stub4.allocation_, stub1.allocation_);
424 EXPECT_EQ(stub4.allocation_, stub2.allocation_);
425 451
426 stub2.surface_state_.visible = false; 452 stub2.surface_state_.visible = false;
427 453
428 Manage(); 454 Manage();
429 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 455 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
430 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 456 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
431 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 457 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
432 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 458 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
433 EXPECT_EQ(stub3.allocation_, stub1.allocation_);
434 EXPECT_EQ(stub3.allocation_, stub2.allocation_);
435 EXPECT_EQ(stub4.allocation_, stub1.allocation_);
436 EXPECT_EQ(stub4.allocation_, stub2.allocation_);
437 459
438 stub1.surface_state_.last_used_time = older_; 460 stub1.surface_state_.last_used_time = older_;
439 461
440 Manage(); 462 Manage();
441 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); 463 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_));
442 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 464 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
443 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 465 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
444 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 466 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
445 EXPECT_NE(stub3.allocation_, stub1.allocation_);
446 EXPECT_EQ(stub3.allocation_, stub2.allocation_);
447 EXPECT_NE(stub4.allocation_, stub1.allocation_);
448 EXPECT_EQ(stub4.allocation_, stub2.allocation_);
449 467
450 stub2.surface_state_.last_used_time = older_; 468 stub2.surface_state_.last_used_time = older_;
451 469
452 Manage(); 470 Manage();
453 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); 471 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_));
454 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 472 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_));
455 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, false); 473 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_));
456 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 474 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_));
457 EXPECT_EQ(stub3.allocation_, stub1.allocation_); 475 }
458 EXPECT_EQ(stub3.allocation_, stub2.allocation_); 476
459 EXPECT_EQ(stub4.allocation_, stub1.allocation_); 477 // Test GpuMemoryAllocation memory allocation bonuses:
460 EXPECT_EQ(stub4.allocation_, stub2.allocation_); 478 // When the number of visible tabs is small, each tab should get a
479 // gpu_resource_size_in_bytes allocation value that is greater than
480 // kMinimumAllocationForTab, and when the number of tabs is large, each should
481 // get exactly kMinimumAllocationForTab and not less.
482 TEST_F(GpuMemoryManagerTest, TestForegroundStubsGetBonusAllocation) {
483 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
484 stub2(GenerateUniqueSurfaceId(), true, older_),
485 stub3(GenerateUniqueSurfaceId(), true, older_);
486 client_.stubs_.push_back(&stub1);
487 client_.stubs_.push_back(&stub2);
488 client_.stubs_.push_back(&stub3);
489
490 Manage();
491 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
492 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
493 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_));
494 EXPECT_GT(stub1.allocation_.gpu_resource_size_in_bytes,
495 static_cast<size_t>(GpuMemoryManager::kMinimumAllocationForTab));
496 EXPECT_GT(stub2.allocation_.gpu_resource_size_in_bytes,
497 static_cast<size_t>(GpuMemoryManager::kMinimumAllocationForTab));
498 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes,
499 static_cast<size_t>(GpuMemoryManager::kMinimumAllocationForTab));
500
501 FakeCommandBufferStub stub4(GenerateUniqueSurfaceId(), true, older_),
502 stub5(GenerateUniqueSurfaceId(), true, older_),
503 stub6(GenerateUniqueSurfaceId(), true, older_),
504 stub7(GenerateUniqueSurfaceId(), true, older_),
505 stub8(GenerateUniqueSurfaceId(), true, older_),
506 stub9(GenerateUniqueSurfaceId(), true, older_);
507 client_.stubs_.push_back(&stub4);
508 client_.stubs_.push_back(&stub5);
509 client_.stubs_.push_back(&stub6);
510 client_.stubs_.push_back(&stub7);
511 client_.stubs_.push_back(&stub8);
512 client_.stubs_.push_back(&stub9);
513
514 Manage();
515 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
516 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
517 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_));
518 EXPECT_EQ(stub1.allocation_.gpu_resource_size_in_bytes,
519 GpuMemoryManager::kMinimumAllocationForTab);
520 EXPECT_EQ(stub2.allocation_.gpu_resource_size_in_bytes,
521 GpuMemoryManager::kMinimumAllocationForTab);
522 EXPECT_EQ(stub3.allocation_.gpu_resource_size_in_bytes,
523 GpuMemoryManager::kMinimumAllocationForTab);
461 } 524 }
462 525
463 // Test GpuMemoryAllocation comparison operators: Iterate over all possible 526 // Test GpuMemoryAllocation comparison operators: Iterate over all possible
464 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and 527 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and
465 // suggest_have_frontbuffer, and make sure allocations with equal values test 528 // suggest_have_frontbuffer, and make sure allocations with equal values test
466 // equal and non equal values test not equal. 529 // equal and non equal values test not equal.
467 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { 530 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) {
468 int gpu_resource_size_in_bytes_values[] = { 0, 1, 12345678 }; 531 std::vector<int> gpu_resource_size_in_bytes_values;
469 bool suggest_have_backbuffer_values[] = { false, true }; 532 gpu_resource_size_in_bytes_values.push_back(0);
470 bool suggest_have_frontbuffer_values[] = { false, true }; 533 gpu_resource_size_in_bytes_values.push_back(1);
534 gpu_resource_size_in_bytes_values.push_back(12345678);
471 535
472 for(int* sz = &gpu_resource_size_in_bytes_values[0]; 536 std::vector<int> suggested_buffer_allocation_values;
473 sz != &gpu_resource_size_in_bytes_values[3]; ++sz) { 537 suggested_buffer_allocation_values.push_back(
474 for(bool* shbb = &suggest_have_backbuffer_values[0]; 538 GpuMemoryAllocation::kHasFrontbuffer |
475 shbb != &suggest_have_backbuffer_values[2]; ++shbb) { 539 GpuMemoryAllocation::kHasBackbuffer);
476 for(bool* shfb = &suggest_have_frontbuffer_values[0]; 540 suggested_buffer_allocation_values.push_back(
477 shfb != &suggest_have_frontbuffer_values[2]; ++shfb) { 541 GpuMemoryAllocation::kHasFrontbuffer);
478 GpuMemoryAllocation allocation(*sz, *shbb, *shfb); 542 suggested_buffer_allocation_values.push_back(
479 EXPECT_EQ(allocation, GpuMemoryAllocation(*sz, *shbb, *shfb)); 543 GpuMemoryAllocation::kHasBackbuffer);
480 EXPECT_NE(allocation, GpuMemoryAllocation(*sz+1, *shbb, *shfb)); 544 suggested_buffer_allocation_values.push_back(
481 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, !*shbb, *shfb)); 545 GpuMemoryAllocation::kHasNoBuffers);
482 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, *shbb, !*shfb)); 546
547 for(size_t i = 0; i != gpu_resource_size_in_bytes_values.size(); ++i) {
548 for(size_t j = 0; j != suggested_buffer_allocation_values.size(); ++j) {
549 int sz = gpu_resource_size_in_bytes_values[i];
550 int buffer_allocation = suggested_buffer_allocation_values[j];
551 GpuMemoryAllocation allocation(sz, buffer_allocation);
552
553 EXPECT_EQ(allocation, GpuMemoryAllocation(sz, buffer_allocation));
554 EXPECT_NE(allocation, GpuMemoryAllocation(sz+1, buffer_allocation));
555
556 for(size_t k = 0; k != suggested_buffer_allocation_values.size(); ++k) {
557 int buffer_allocation_other = suggested_buffer_allocation_values[k];
558 if (buffer_allocation == buffer_allocation_other) continue;
559 EXPECT_NE(allocation, GpuMemoryAllocation(sz, buffer_allocation_other));
483 } 560 }
484 } 561 }
485 } 562 }
486 } 563 }
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_memory_manager.cc ('k') | content/common/gpu/gpu_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698