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

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: Fixing issue with every proxy registering a callback, even when it is null. Created 8 years, 8 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
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 handles_memory_allocations() 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;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 194 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false);
192 195
193 // Test stubs without surface, with share group of 1 stub. 196 // Test stubs without surface, with share group of 1 stub.
194 FakeCommandBufferStubWithoutSurface stub3, stub4; 197 FakeCommandBufferStubWithoutSurface stub3, stub4;
195 stub3.share_group_.push_back(&stub1); 198 stub3.share_group_.push_back(&stub1);
196 stub4.share_group_.push_back(&stub2); 199 stub4.share_group_.push_back(&stub2);
197 client_.stubs_.push_back(&stub3); 200 client_.stubs_.push_back(&stub3);
198 client_.stubs_.push_back(&stub4); 201 client_.stubs_.push_back(&stub4);
199 202
200 Manage(); 203 Manage();
201 EXPECT_EQ(stub1.allocation_, stub3.allocation_); 204 EXPECT_GT(stub1.allocation_.gpu_resource_size_in_bytes, 1ul);
202 EXPECT_EQ(stub2.allocation_, stub4.allocation_); 205 EXPECT_EQ(stub2.allocation_.gpu_resource_size_in_bytes, 0ul);
206 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, 1ul);
207 EXPECT_GT(stub4.allocation_.gpu_resource_size_in_bytes, 1ul);
203 208
204 // Test stub without surface, with share group of multiple stubs. 209 // Test stub without surface, with share group of multiple stubs.
205 FakeCommandBufferStubWithoutSurface stub5; 210 FakeCommandBufferStubWithoutSurface stub5;
206 stub5.share_group_.push_back(&stub1); 211 stub5.share_group_.push_back(&stub1);
207 stub5.share_group_.push_back(&stub2); 212 stub5.share_group_.push_back(&stub2);
208 client_.stubs_.push_back(&stub5); 213 client_.stubs_.push_back(&stub5);
209 214
210 Manage(); 215 Manage();
211 EXPECT_EQ(stub1.allocation_, stub5.allocation_); 216 EXPECT_GT(stub5.allocation_.gpu_resource_size_in_bytes, 1ul);
212 } 217 }
213 218
214 // Test GpuMemoryManager::Manage functionality: changing visibility. 219 // Test GpuMemoryManager::Manage functionality: changing visibility.
215 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according 220 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according
216 // to visibility and last used time for stubs with surface. 221 // to visibility and last used time for stubs with surface.
217 // Expect memory allocation to be shared according to share groups for stubs 222 // Expect memory allocation to be shared according to share groups for stubs
218 // without a surface. 223 // without a surface.
219 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { 224 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) {
220 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), 225 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
221 stub2(GenerateUniqueSurfaceId(), false, older_); 226 stub2(GenerateUniqueSurfaceId(), false, older_);
222 client_.stubs_.push_back(&stub1); 227 client_.stubs_.push_back(&stub1);
223 client_.stubs_.push_back(&stub2); 228 client_.stubs_.push_back(&stub2);
224 229
225 FakeCommandBufferStubWithoutSurface stub3, stub4; 230 FakeCommandBufferStubWithoutSurface stub3, stub4;
226 stub3.share_group_.push_back(&stub1); 231 stub3.share_group_.push_back(&stub1);
227 stub4.share_group_.push_back(&stub2); 232 stub4.share_group_.push_back(&stub2);
228 client_.stubs_.push_back(&stub3); 233 client_.stubs_.push_back(&stub3);
229 client_.stubs_.push_back(&stub4); 234 client_.stubs_.push_back(&stub4);
230 235
231 FakeCommandBufferStubWithoutSurface stub5; 236 FakeCommandBufferStubWithoutSurface stub5;
232 stub5.share_group_.push_back(&stub1); 237 stub5.share_group_.push_back(&stub1);
233 stub5.share_group_.push_back(&stub2); 238 stub5.share_group_.push_back(&stub2);
234 client_.stubs_.push_back(&stub5); 239 client_.stubs_.push_back(&stub5);
235 240
236 Manage(); 241 Manage();
237 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 242 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true);
238 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); 243 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true);
239 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 244 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
240 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 245 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false);
241 EXPECT_EQ(stub1.allocation_, stub3.allocation_); 246 EXPECT_GT(stub1.allocation_.gpu_resource_size_in_bytes, 1ul);
242 EXPECT_EQ(stub2.allocation_, stub4.allocation_); 247 EXPECT_EQ(stub2.allocation_.gpu_resource_size_in_bytes, 0ul);
243 EXPECT_EQ(stub1.allocation_, stub5.allocation_); 248 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, 1ul);
249 EXPECT_GT(stub4.allocation_.gpu_resource_size_in_bytes, 1ul);
250 EXPECT_GT(stub5.allocation_.gpu_resource_size_in_bytes, 1ul);
244 251
245 stub1.surface_state_.visible = false; 252 stub1.surface_state_.visible = false;
246 stub2.surface_state_.visible = true; 253 stub2.surface_state_.visible = true;
247 254
248 Manage(); 255 Manage();
249 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 256 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true);
250 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 257 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false);
251 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 258 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
252 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 259 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true);
253 EXPECT_EQ(stub1.allocation_, stub3.allocation_); 260 EXPECT_EQ(stub1.allocation_.gpu_resource_size_in_bytes, 0ul);
254 EXPECT_EQ(stub2.allocation_, stub4.allocation_); 261 EXPECT_GT(stub2.allocation_.gpu_resource_size_in_bytes, 1ul);
255 EXPECT_EQ(stub2.allocation_, stub5.allocation_); 262 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, 1ul);
263 EXPECT_GT(stub4.allocation_.gpu_resource_size_in_bytes, 1ul);
264 EXPECT_GT(stub5.allocation_.gpu_resource_size_in_bytes, 1ul);
256 } 265 }
257 266
258 // Test GpuMemoryManager::Manage functionality: Test more than threshold number 267 // Test GpuMemoryManager::Manage functionality: Test more than threshold number
259 // of visible stubs. 268 // of visible stubs.
260 // Expect all allocations to continue to have frontbuffer. 269 // Expect all allocations to continue to have frontbuffer.
261 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { 270 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) {
262 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), 271 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
263 stub2(GenerateUniqueSurfaceId(), true, older_), 272 stub2(GenerateUniqueSurfaceId(), true, older_),
264 stub3(GenerateUniqueSurfaceId(), true, older_), 273 stub3(GenerateUniqueSurfaceId(), true, older_),
265 stub4(GenerateUniqueSurfaceId(), true, older_); 274 stub4(GenerateUniqueSurfaceId(), true, older_);
(...skipping 15 matching lines...) Expand all
281 290
282 Manage(); 291 Manage();
283 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 292 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true);
284 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); 293 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true);
285 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 294 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
286 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 295 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true);
287 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); 296 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true);
288 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, true); 297 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, true);
289 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); 298 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true);
290 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, true); 299 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, true);
291 EXPECT_EQ(stub5.allocation_, stub1.allocation_); 300 EXPECT_GT(stub5.allocation_.gpu_resource_size_in_bytes, 1ul);
292 EXPECT_EQ(stub6.allocation_, stub2.allocation_); 301 EXPECT_GT(stub6.allocation_.gpu_resource_size_in_bytes, 1ul);
293 EXPECT_EQ(stub7.allocation_, stub1.allocation_); 302 EXPECT_GT(stub7.allocation_.gpu_resource_size_in_bytes, 1ul);
294 } 303 }
295 304
296 // Test GpuMemoryManager::Manage functionality: Test more than threshold number 305 // Test GpuMemoryManager::Manage functionality: Test more than threshold number
297 // of not visible stubs. 306 // of not visible stubs.
298 // Expect the stubs surpassing the threshold to not have a backbuffer. 307 // Expect the stubs surpassing the threshold to not have a backbuffer.
299 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { 308 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) {
300 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), 309 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_),
301 stub2(GenerateUniqueSurfaceId(), false, newer_), 310 stub2(GenerateUniqueSurfaceId(), false, newer_),
302 stub3(GenerateUniqueSurfaceId(), false, newer_), 311 stub3(GenerateUniqueSurfaceId(), false, newer_),
303 stub4(GenerateUniqueSurfaceId(), false, older_); 312 stub4(GenerateUniqueSurfaceId(), false, older_);
(...skipping 15 matching lines...) Expand all
319 328
320 Manage(); 329 Manage();
321 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 330 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true);
322 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 331 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false);
323 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 332 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
324 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 333 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false);
325 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); 334 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true);
326 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); 335 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false);
327 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); 336 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false);
328 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); 337 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false);
329 EXPECT_EQ(stub5.allocation_, stub1.allocation_); 338 EXPECT_GT(stub5.allocation_.gpu_resource_size_in_bytes, 1ul);
330 EXPECT_EQ(stub6.allocation_, stub4.allocation_); 339 EXPECT_EQ(stub6.allocation_.gpu_resource_size_in_bytes, 0ul);
331 EXPECT_EQ(stub7.allocation_, stub1.allocation_); 340 EXPECT_GT(stub7.allocation_.gpu_resource_size_in_bytes, 1ul);
332 } 341 }
333 342
334 // Test GpuMemoryManager::Manage functionality: Test changing the last used 343 // Test GpuMemoryManager::Manage functionality: Test changing the last used
335 // time of stubs when doing so causes change in which stubs surpass threshold. 344 // time of stubs when doing so causes change in which stubs surpass threshold.
336 // Expect frontbuffer to be dropped for the older stub. 345 // Expect frontbuffer to be dropped for the older stub.
337 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { 346 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) {
338 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), 347 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_),
339 stub2(GenerateUniqueSurfaceId(), false, newer_), 348 stub2(GenerateUniqueSurfaceId(), false, newer_),
340 stub3(GenerateUniqueSurfaceId(), false, newer_), 349 stub3(GenerateUniqueSurfaceId(), false, newer_),
341 stub4(GenerateUniqueSurfaceId(), false, older_); 350 stub4(GenerateUniqueSurfaceId(), false, older_);
(...skipping 11 matching lines...) Expand all
353 FakeCommandBufferStubWithoutSurface stub7; 362 FakeCommandBufferStubWithoutSurface stub7;
354 stub7.share_group_.push_back(&stub3); 363 stub7.share_group_.push_back(&stub3);
355 stub7.share_group_.push_back(&stub4); 364 stub7.share_group_.push_back(&stub4);
356 client_.stubs_.push_back(&stub7); 365 client_.stubs_.push_back(&stub7);
357 366
358 Manage(); 367 Manage();
359 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); 368 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true);
360 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); 369 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false);
361 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); 370 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false);
362 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); 371 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false);
363 EXPECT_EQ(stub5.allocation_, stub3.allocation_); 372 EXPECT_GT(stub5.allocation_.gpu_resource_size_in_bytes, 1ul);
364 EXPECT_EQ(stub6.allocation_, stub4.allocation_); 373 EXPECT_EQ(stub6.allocation_.gpu_resource_size_in_bytes, 0ul);
365 EXPECT_EQ(stub7.allocation_, stub3.allocation_); 374 EXPECT_GT(stub7.allocation_.gpu_resource_size_in_bytes, 1ul);
366 375
367 stub3.surface_state_.last_used_time = older_; 376 stub3.surface_state_.last_used_time = older_;
368 stub4.surface_state_.last_used_time = newer_; 377 stub4.surface_state_.last_used_time = newer_;
369 378
370 Manage(); 379 Manage();
371 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, false); 380 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, false);
372 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); 381 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false);
373 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); 382 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true);
374 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); 383 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false);
375 EXPECT_EQ(stub5.allocation_, stub3.allocation_); 384 EXPECT_EQ(stub5.allocation_.gpu_resource_size_in_bytes, 0ul);
376 EXPECT_EQ(stub6.allocation_, stub4.allocation_); 385 EXPECT_GT(stub6.allocation_.gpu_resource_size_in_bytes, 1ul);
377 EXPECT_EQ(stub7.allocation_, stub4.allocation_); 386 EXPECT_GT(stub7.allocation_.gpu_resource_size_in_bytes, 1ul);
378 } 387 }
379 388
380 // Test GpuMemoryManager::Manage functionality: Test changing importance of 389 // Test GpuMemoryManager::Manage functionality: Test changing importance of
381 // enough stubs so that every stub in share group crosses threshold. 390 // enough stubs so that every stub in share group crosses threshold.
382 // Expect memory allocation of the stubs without surface to share memory 391 // Expect memory allocation of the stubs without surface to share memory
383 // allocation with the most visible stub in share group. 392 // allocation with the most visible stub in share group.
384 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { 393 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) {
385 FakeCommandBufferStub stubA(GenerateUniqueSurfaceId(), true, newer_), 394 FakeCommandBufferStub stubA(GenerateUniqueSurfaceId(), true, newer_),
386 stubB(GenerateUniqueSurfaceId(), false, newer_), 395 stubB(GenerateUniqueSurfaceId(), false, newer_),
387 stubC(GenerateUniqueSurfaceId(), false, newer_); 396 stubC(GenerateUniqueSurfaceId(), false, newer_);
(...skipping 11 matching lines...) Expand all
399 stub4.share_group_.push_back(&stub1); 408 stub4.share_group_.push_back(&stub1);
400 stub4.share_group_.push_back(&stub2); 409 stub4.share_group_.push_back(&stub2);
401 client_.stubs_.push_back(&stub3); 410 client_.stubs_.push_back(&stub3);
402 client_.stubs_.push_back(&stub4); 411 client_.stubs_.push_back(&stub4);
403 412
404 Manage(); 413 Manage();
405 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 414 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true);
406 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); 415 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true);
407 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 416 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
408 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 417 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true);
409 EXPECT_EQ(stub3.allocation_, stub1.allocation_); 418 EXPECT_GT(stub1.allocation_.gpu_resource_size_in_bytes, 1ul);
410 EXPECT_EQ(stub3.allocation_, stub2.allocation_); 419 EXPECT_GT(stub2.allocation_.gpu_resource_size_in_bytes, 1ul);
411 EXPECT_EQ(stub4.allocation_, stub1.allocation_); 420 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, 1ul);
412 EXPECT_EQ(stub4.allocation_, stub2.allocation_); 421 EXPECT_GT(stub4.allocation_.gpu_resource_size_in_bytes, 1ul);
413 422
414 stub1.surface_state_.visible = false; 423 stub1.surface_state_.visible = false;
415 424
416 Manage(); 425 Manage();
417 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 426 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true);
418 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 427 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false);
419 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 428 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
420 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); 429 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true);
421 EXPECT_NE(stub3.allocation_, stub1.allocation_); 430 EXPECT_EQ(stub1.allocation_.gpu_resource_size_in_bytes, 0ul);
422 EXPECT_EQ(stub3.allocation_, stub2.allocation_); 431 EXPECT_GT(stub2.allocation_.gpu_resource_size_in_bytes, 1ul);
423 EXPECT_NE(stub4.allocation_, stub1.allocation_); 432 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, 1ul);
424 EXPECT_EQ(stub4.allocation_, stub2.allocation_); 433 EXPECT_GT(stub4.allocation_.gpu_resource_size_in_bytes, 1ul);
425 434
426 stub2.surface_state_.visible = false; 435 stub2.surface_state_.visible = false;
427 436
428 Manage(); 437 Manage();
429 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); 438 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true);
430 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 439 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false);
431 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 440 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
432 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 441 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false);
433 EXPECT_EQ(stub3.allocation_, stub1.allocation_); 442 EXPECT_EQ(stub1.allocation_.gpu_resource_size_in_bytes, 0ul);
434 EXPECT_EQ(stub3.allocation_, stub2.allocation_); 443 EXPECT_EQ(stub2.allocation_.gpu_resource_size_in_bytes, 0ul);
435 EXPECT_EQ(stub4.allocation_, stub1.allocation_); 444 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, 1ul);
436 EXPECT_EQ(stub4.allocation_, stub2.allocation_); 445 EXPECT_GT(stub4.allocation_.gpu_resource_size_in_bytes, 1ul);
437 446
438 stub1.surface_state_.last_used_time = older_; 447 stub1.surface_state_.last_used_time = older_;
439 448
440 Manage(); 449 Manage();
441 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); 450 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false);
442 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 451 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false);
443 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); 452 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true);
444 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 453 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false);
445 EXPECT_NE(stub3.allocation_, stub1.allocation_); 454 EXPECT_EQ(stub1.allocation_.gpu_resource_size_in_bytes, 0ul);
446 EXPECT_EQ(stub3.allocation_, stub2.allocation_); 455 EXPECT_EQ(stub2.allocation_.gpu_resource_size_in_bytes, 0ul);
447 EXPECT_NE(stub4.allocation_, stub1.allocation_); 456 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, 1ul);
448 EXPECT_EQ(stub4.allocation_, stub2.allocation_); 457 EXPECT_GT(stub4.allocation_.gpu_resource_size_in_bytes, 1ul);
449 458
450 stub2.surface_state_.last_used_time = older_; 459 stub2.surface_state_.last_used_time = older_;
451 460
452 Manage(); 461 Manage();
453 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); 462 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false);
454 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); 463 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false);
455 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, false); 464 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, false);
456 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); 465 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false);
457 EXPECT_EQ(stub3.allocation_, stub1.allocation_); 466 EXPECT_EQ(stub1.allocation_.gpu_resource_size_in_bytes, 0ul);
458 EXPECT_EQ(stub3.allocation_, stub2.allocation_); 467 EXPECT_EQ(stub2.allocation_.gpu_resource_size_in_bytes, 0ul);
459 EXPECT_EQ(stub4.allocation_, stub1.allocation_); 468 EXPECT_EQ(stub3.allocation_.gpu_resource_size_in_bytes, 0ul);
460 EXPECT_EQ(stub4.allocation_, stub2.allocation_); 469 EXPECT_EQ(stub4.allocation_.gpu_resource_size_in_bytes, 0ul);
461 } 470 }
462 471
463 // Test GpuMemoryAllocation comparison operators: Iterate over all possible 472 // Test GpuMemoryAllocation comparison operators: Iterate over all possible
464 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and 473 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and
465 // suggest_have_frontbuffer, and make sure allocations with equal values test 474 // suggest_have_frontbuffer, and make sure allocations with equal values test
466 // equal and non equal values test not equal. 475 // equal and non equal values test not equal.
467 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { 476 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) {
468 int gpu_resource_size_in_bytes_values[] = { 0, 1, 12345678 }; 477 int gpu_resource_size_in_bytes_values[] = { 0, 1, 12345678 };
469 bool suggest_have_backbuffer_values[] = { false, true }; 478 bool suggest_have_backbuffer_values[] = { false, true };
470 bool suggest_have_frontbuffer_values[] = { false, true }; 479 bool suggest_have_frontbuffer_values[] = { false, true };
471 480
472 for(int* sz = &gpu_resource_size_in_bytes_values[0]; 481 for(int* sz = &gpu_resource_size_in_bytes_values[0];
473 sz != &gpu_resource_size_in_bytes_values[3]; ++sz) { 482 sz != &gpu_resource_size_in_bytes_values[3]; ++sz) {
474 for(bool* shbb = &suggest_have_backbuffer_values[0]; 483 for(bool* shbb = &suggest_have_backbuffer_values[0];
475 shbb != &suggest_have_backbuffer_values[2]; ++shbb) { 484 shbb != &suggest_have_backbuffer_values[2]; ++shbb) {
476 for(bool* shfb = &suggest_have_frontbuffer_values[0]; 485 for(bool* shfb = &suggest_have_frontbuffer_values[0];
477 shfb != &suggest_have_frontbuffer_values[2]; ++shfb) { 486 shfb != &suggest_have_frontbuffer_values[2]; ++shfb) {
478 GpuMemoryAllocation allocation(*sz, *shbb, *shfb); 487 GpuMemoryAllocation allocation(*sz, *shbb, *shfb);
479 EXPECT_EQ(allocation, GpuMemoryAllocation(*sz, *shbb, *shfb)); 488 EXPECT_EQ(allocation, GpuMemoryAllocation(*sz, *shbb, *shfb));
480 EXPECT_NE(allocation, GpuMemoryAllocation(*sz+1, *shbb, *shfb)); 489 EXPECT_NE(allocation, GpuMemoryAllocation(*sz+1, *shbb, *shfb));
481 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, !*shbb, *shfb)); 490 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, !*shbb, *shfb));
482 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, *shbb, !*shfb)); 491 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, *shbb, !*shfb));
483 } 492 }
484 } 493 }
485 } 494 }
486 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698