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

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

Issue 11187010: Rename SurfaceState to MemoryManagerState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trybot warnings Created 8 years, 2 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_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 #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"
11 11
12 class FakeCommandBufferStub : public GpuCommandBufferStubBase { 12 class FakeCommandBufferStub : public GpuCommandBufferStubBase {
13 public: 13 public:
14 SurfaceState surface_state_; 14 MemoryManagerState memory_manager_state_;
15 GpuMemoryAllocation allocation_; 15 GpuMemoryAllocation allocation_;
16 gfx::Size size_; 16 gfx::Size size_;
17 17
18 FakeCommandBufferStub() 18 FakeCommandBufferStub()
19 : surface_state_(0, false, base::TimeTicks()) { 19 : memory_manager_state_(0, false, base::TimeTicks()) {
20 memory_manager_state_.client_has_memory_allocation_changed_callback = true;
20 } 21 }
21 22
22 FakeCommandBufferStub(int32 surface_id, 23 FakeCommandBufferStub(int32 surface_id,
23 bool visible, 24 bool visible,
24 base::TimeTicks last_used_time) 25 base::TimeTicks last_used_time)
25 : surface_state_(surface_id, visible, last_used_time) { 26 : memory_manager_state_(surface_id != 0, visible, last_used_time) {
27 memory_manager_state_.client_has_memory_allocation_changed_callback = true;
26 } 28 }
27 29
28 virtual bool client_has_memory_allocation_changed_callback() const { 30 virtual const MemoryManagerState& memory_manager_state() const {
29 return true; 31 return memory_manager_state_;
30 }
31 virtual bool has_surface_state() const {
32 return surface_state_.surface_id != 0;
33 }
34 virtual const SurfaceState& surface_state() const {
35 return surface_state_;
36 } 32 }
37 33
38 virtual gfx::Size GetSurfaceSize() const { 34 virtual gfx::Size GetSurfaceSize() const {
39 return size_; 35 return size_;
40 } 36 }
41 virtual bool IsInSameContextShareGroup( 37 virtual bool IsInSameContextShareGroup(
42 const GpuCommandBufferStubBase& stub) const { 38 const GpuCommandBufferStubBase& stub) const {
43 return false; 39 return false;
44 } 40 }
45 virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) { 41 virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) {
46 allocation_ = alloc; 42 allocation_ = alloc;
47 } 43 }
48 virtual bool GetTotalGpuMemory(size_t* bytes) { 44 virtual bool GetTotalGpuMemory(size_t* bytes) {
49 return false; 45 return false;
50 } 46 }
51 }; 47 };
52 48
53 class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase { 49 class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase {
54 public: 50 public:
51 MemoryManagerState memory_manager_state_;
55 GpuMemoryAllocation allocation_; 52 GpuMemoryAllocation allocation_;
56 std::vector<GpuCommandBufferStubBase*> share_group_; 53 std::vector<GpuCommandBufferStubBase*> share_group_;
57 54
58 FakeCommandBufferStubWithoutSurface() { 55 FakeCommandBufferStubWithoutSurface()
56 : memory_manager_state_(false, true, base::TimeTicks()) {
57 memory_manager_state_.client_has_memory_allocation_changed_callback = true;
59 } 58 }
60 59
61 virtual bool client_has_memory_allocation_changed_callback() const { 60 virtual const MemoryManagerState& memory_manager_state() const {
62 return true; 61 return memory_manager_state_;
63 }
64 virtual bool has_surface_state() const {
65 return false;
66 }
67 virtual const SurfaceState& surface_state() const {
68 NOTREACHED();
69 static SurfaceState* surface_state_;
70 return *surface_state_;
71 } 62 }
72 63
73 virtual gfx::Size GetSurfaceSize() const { 64 virtual gfx::Size GetSurfaceSize() const {
74 return gfx::Size(); 65 return gfx::Size();
75 } 66 }
76 virtual bool IsInSameContextShareGroup( 67 virtual bool IsInSameContextShareGroup(
77 const GpuCommandBufferStubBase& stub) const { 68 const GpuCommandBufferStubBase& stub) const {
78 return std::find(share_group_.begin(), 69 return std::find(share_group_.begin(),
79 share_group_.end(), 70 share_group_.end(),
80 &stub) != share_group_.end(); 71 &stub) != share_group_.end();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 stub5.share_group_.push_back(&stub2); 289 stub5.share_group_.push_back(&stub2);
299 client_.stubs_.push_back(&stub5); 290 client_.stubs_.push_back(&stub5);
300 291
301 Manage(); 292 Manage();
302 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); 293 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
303 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); 294 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
304 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); 295 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
305 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); 296 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
306 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); 297 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
307 298
308 stub1.surface_state_.visible = false; 299 stub1.memory_manager_state_.visible = false;
309 stub2.surface_state_.visible = true; 300 stub2.memory_manager_state_.visible = true;
310 301
311 Manage(); 302 Manage();
312 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); 303 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
313 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); 304 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
314 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); 305 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
315 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); 306 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
316 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); 307 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
317 } 308 }
318 309
319 // Test GpuMemoryManager::Manage functionality: Test more than threshold number 310 // Test GpuMemoryManager::Manage functionality: Test more than threshold number
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 401
411 Manage(); 402 Manage();
412 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); 403 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
413 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); 404 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
414 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); 405 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_));
415 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); 406 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_));
416 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); 407 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_));
417 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); 408 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_));
418 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); 409 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
419 410
420 stub3.surface_state_.last_used_time = older_; 411 stub3.memory_manager_state_.last_used_time = older_;
421 stub4.surface_state_.last_used_time = newer_; 412 stub4.memory_manager_state_.last_used_time = newer_;
422 413
423 Manage(); 414 Manage();
424 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); 415 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
425 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); 416 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
426 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub3.allocation_)); 417 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub3.allocation_));
427 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_)); 418 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_));
428 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_)); 419 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_));
429 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_)); 420 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_));
430 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); 421 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
431 } 422 }
(...skipping 21 matching lines...) Expand all
453 stub4.share_group_.push_back(&stub2); 444 stub4.share_group_.push_back(&stub2);
454 client_.stubs_.push_back(&stub3); 445 client_.stubs_.push_back(&stub3);
455 client_.stubs_.push_back(&stub4); 446 client_.stubs_.push_back(&stub4);
456 447
457 Manage(); 448 Manage();
458 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); 449 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
459 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); 450 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
460 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); 451 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
461 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); 452 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
462 453
463 stub1.surface_state_.visible = false; 454 stub1.memory_manager_state_.visible = false;
464 455
465 Manage(); 456 Manage();
466 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); 457 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
467 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); 458 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
468 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); 459 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
469 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); 460 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
470 461
471 stub2.surface_state_.visible = false; 462 stub2.memory_manager_state_.visible = false;
472 463
473 Manage(); 464 Manage();
474 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); 465 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
475 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); 466 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
476 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); 467 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
477 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); 468 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
478 469
479 stub1.surface_state_.last_used_time = older_; 470 stub1.memory_manager_state_.last_used_time = older_;
480 471
481 Manage(); 472 Manage();
482 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); 473 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_));
483 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); 474 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
484 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); 475 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
485 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); 476 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
486 477
487 stub2.surface_state_.last_used_time = older_; 478 stub2.memory_manager_state_.last_used_time = older_;
488 479
489 Manage(); 480 Manage();
490 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); 481 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_));
491 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); 482 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_));
492 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); 483 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_));
493 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); 484 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_));
494 } 485 }
495 486
496 #if !defined(OS_ANDROID) 487 #if !defined(OS_ANDROID)
497 // Test GpuMemoryAllocation memory allocation bonuses: 488 // Test GpuMemoryAllocation memory allocation bonuses:
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 EXPECT_TRUE(stats[&stub1].visible); 657 EXPECT_TRUE(stats[&stub1].visible);
667 EXPECT_TRUE(stats[&stub2].visible); 658 EXPECT_TRUE(stats[&stub2].visible);
668 EXPECT_TRUE(stats[&stub3].visible); 659 EXPECT_TRUE(stats[&stub3].visible);
669 EXPECT_GT(stub1allocation3, 0ul); 660 EXPECT_GT(stub1allocation3, 0ul);
670 EXPECT_GT(stub2allocation3, 0ul); 661 EXPECT_GT(stub2allocation3, 0ul);
671 EXPECT_GT(stub3allocation3, 0ul); 662 EXPECT_GT(stub3allocation3, 0ul);
672 if (compositors_get_bonus_allocation && 663 if (compositors_get_bonus_allocation &&
673 stub1allocation3 != GetMaximumTabAllocation()) 664 stub1allocation3 != GetMaximumTabAllocation())
674 EXPECT_LT(stub1allocation3, stub1allocation2); 665 EXPECT_LT(stub1allocation3, stub1allocation2);
675 666
676 stub1.surface_state_.visible = false; 667 stub1.memory_manager_state_.visible = false;
677 Manage(); 668 Manage();
678 stats = memory_manager_.stub_memory_stats_for_last_manage(); 669 stats = memory_manager_.stub_memory_stats_for_last_manage();
679 size_t stub1allocation4 = stats[&stub1].allocation.gpu_resource_size_in_bytes; 670 size_t stub1allocation4 = stats[&stub1].allocation.gpu_resource_size_in_bytes;
680 size_t stub2allocation4 = stats[&stub2].allocation.gpu_resource_size_in_bytes; 671 size_t stub2allocation4 = stats[&stub2].allocation.gpu_resource_size_in_bytes;
681 size_t stub3allocation4 = stats[&stub3].allocation.gpu_resource_size_in_bytes; 672 size_t stub3allocation4 = stats[&stub3].allocation.gpu_resource_size_in_bytes;
682 673
683 EXPECT_EQ(stats.size(), 3ul); 674 EXPECT_EQ(stats.size(), 3ul);
684 EXPECT_FALSE(stats[&stub1].visible); 675 EXPECT_FALSE(stats[&stub1].visible);
685 EXPECT_FALSE(stats[&stub2].visible); 676 EXPECT_FALSE(stats[&stub2].visible);
686 EXPECT_TRUE(stats[&stub3].visible); 677 EXPECT_TRUE(stats[&stub3].visible);
687 EXPECT_EQ(stub1allocation4, 0ul); 678 EXPECT_EQ(stub1allocation4, 0ul);
688 EXPECT_GE(stub2allocation4, 0ul); 679 EXPECT_GE(stub2allocation4, 0ul);
689 EXPECT_GT(stub3allocation4, 0ul); 680 EXPECT_GT(stub3allocation4, 0ul);
690 if (compositors_get_bonus_allocation && 681 if (compositors_get_bonus_allocation &&
691 stub3allocation3 != GetMaximumTabAllocation()) 682 stub3allocation3 != GetMaximumTabAllocation())
692 EXPECT_GT(stub3allocation4, stub3allocation3); 683 EXPECT_GT(stub3allocation4, stub3allocation3);
693 } 684 }
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