OLD | NEW |
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_manager.h" | 5 #include "content/common/gpu/gpu_memory_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 uint64 max_surfaces_with_frontbuffer_soft_limit) | 52 uint64 max_surfaces_with_frontbuffer_soft_limit) |
53 : channel_manager_(channel_manager), | 53 : channel_manager_(channel_manager), |
54 manage_immediate_scheduled_(false), | 54 manage_immediate_scheduled_(false), |
55 max_surfaces_with_frontbuffer_soft_limit_( | 55 max_surfaces_with_frontbuffer_soft_limit_( |
56 max_surfaces_with_frontbuffer_soft_limit), | 56 max_surfaces_with_frontbuffer_soft_limit), |
57 bytes_available_gpu_memory_(0), | 57 bytes_available_gpu_memory_(0), |
58 bytes_available_gpu_memory_overridden_(false), | 58 bytes_available_gpu_memory_overridden_(false), |
59 bytes_minimum_per_client_(0), | 59 bytes_minimum_per_client_(0), |
60 bytes_default_per_client_(0), | 60 bytes_default_per_client_(0), |
61 bytes_allocated_managed_current_(0), | 61 bytes_allocated_managed_current_(0), |
62 bytes_allocated_managed_visible_(0), | |
63 bytes_allocated_managed_nonvisible_(0), | |
64 bytes_allocated_unmanaged_current_(0), | 62 bytes_allocated_unmanaged_current_(0), |
65 bytes_allocated_historical_max_(0), | 63 bytes_allocated_historical_max_(0), |
66 bytes_allocated_unmanaged_high_(0), | 64 bytes_allocated_unmanaged_high_(0), |
67 bytes_allocated_unmanaged_low_(0), | 65 bytes_allocated_unmanaged_low_(0), |
68 bytes_unmanaged_limit_step_(kBytesAllocatedUnmanagedStep), | 66 bytes_unmanaged_limit_step_(kBytesAllocatedUnmanagedStep), |
69 disable_schedule_manage_(false) | 67 disable_schedule_manage_(false) |
70 { | 68 { |
71 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 69 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
72 | 70 |
73 #if defined(OS_ANDROID) | 71 #if defined(OS_ANDROID) |
74 bytes_default_per_client_ = 8 * 1024 * 1024; | 72 bytes_default_per_client_ = 8 * 1024 * 1024; |
75 bytes_minimum_per_client_ = 8 * 1024 * 1024; | 73 bytes_minimum_per_client_ = 8 * 1024 * 1024; |
76 #elif defined(OS_CHROMEOS) | 74 #elif defined(OS_CHROMEOS) |
77 bytes_default_per_client_ = 64 * 1024 * 1024; | 75 bytes_default_per_client_ = 64 * 1024 * 1024; |
78 bytes_minimum_per_client_ = 4 * 1024 * 1024; | 76 bytes_minimum_per_client_ = 4 * 1024 * 1024; |
79 #else | 77 #else |
80 bytes_default_per_client_ = 64 * 1024 * 1024; | 78 bytes_default_per_client_ = 64 * 1024 * 1024; |
81 bytes_minimum_per_client_ = 64 * 1024 * 1024; | 79 bytes_minimum_per_client_ = 64 * 1024 * 1024; |
82 #endif | 80 #endif |
83 | 81 |
84 // On Android, always discard everything that is nonvisible. | |
85 // On Linux and Mac, use as little memory as possible to avoid stability | |
86 // issues. | |
87 // http://crbug.com/145600 (Linux) | |
88 // http://crbug.com/141377 (Mac) | |
89 #if defined(OS_ANDROID) || defined(OS_MACOSX) || \ | |
90 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | |
91 allow_nonvisible_memory_ = false; | |
92 #else | |
93 allow_nonvisible_memory_ = true; | |
94 #endif | |
95 | |
96 if (command_line->HasSwitch(switches::kForceGpuMemAvailableMb)) { | 82 if (command_line->HasSwitch(switches::kForceGpuMemAvailableMb)) { |
97 base::StringToUint64( | 83 base::StringToUint64( |
98 command_line->GetSwitchValueASCII(switches::kForceGpuMemAvailableMb), | 84 command_line->GetSwitchValueASCII(switches::kForceGpuMemAvailableMb), |
99 &bytes_available_gpu_memory_); | 85 &bytes_available_gpu_memory_); |
100 bytes_available_gpu_memory_ *= 1024 * 1024; | 86 bytes_available_gpu_memory_ *= 1024 * 1024; |
101 bytes_available_gpu_memory_overridden_ = true; | 87 bytes_available_gpu_memory_overridden_ = true; |
102 } else | 88 } else |
103 bytes_available_gpu_memory_ = GetDefaultAvailableGpuMemory(); | 89 bytes_available_gpu_memory_ = GetDefaultAvailableGpuMemory(); |
104 } | 90 } |
105 | 91 |
106 GpuMemoryManager::~GpuMemoryManager() { | 92 GpuMemoryManager::~GpuMemoryManager() { |
107 DCHECK(tracking_groups_.empty()); | 93 DCHECK(tracking_groups_.empty()); |
108 DCHECK(clients_visible_mru_.empty()); | 94 DCHECK(clients_visible_mru_.empty()); |
109 DCHECK(clients_nonvisible_mru_.empty()); | 95 DCHECK(clients_nonvisible_mru_.empty()); |
110 DCHECK(clients_nonsurface_.empty()); | 96 DCHECK(clients_nonsurface_.empty()); |
111 DCHECK(!bytes_allocated_managed_current_); | 97 DCHECK(!bytes_allocated_managed_current_); |
112 DCHECK(!bytes_allocated_unmanaged_current_); | 98 DCHECK(!bytes_allocated_unmanaged_current_); |
113 DCHECK(!bytes_allocated_managed_visible_); | |
114 DCHECK(!bytes_allocated_managed_nonvisible_); | |
115 } | 99 } |
116 | 100 |
117 uint64 GpuMemoryManager::GetAvailableGpuMemory() const { | 101 uint64 GpuMemoryManager::GetAvailableGpuMemory() const { |
118 // Allow unmanaged allocations to over-subscribe by at most (high_ - low_) | 102 // Allow unmanaged allocations to over-subscribe by at most (high_ - low_) |
119 // before restricting managed (compositor) memory based on unmanaged usage. | 103 // before restricting managed (compositor) memory based on unmanaged usage. |
120 if (bytes_allocated_unmanaged_low_ > bytes_available_gpu_memory_) | 104 if (bytes_allocated_unmanaged_low_ > bytes_available_gpu_memory_) |
121 return 0; | 105 return 0; |
122 return bytes_available_gpu_memory_ - bytes_allocated_unmanaged_low_; | 106 return bytes_available_gpu_memory_ - bytes_allocated_unmanaged_low_; |
123 } | 107 } |
124 | 108 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 GpuMemoryManagerClient* client, | 275 GpuMemoryManagerClient* client, |
292 bool has_surface, | 276 bool has_surface, |
293 bool visible) { | 277 bool visible) { |
294 TrackingGroupMap::iterator tracking_group_it = | 278 TrackingGroupMap::iterator tracking_group_it = |
295 tracking_groups_.find(client->GetMemoryTracker()); | 279 tracking_groups_.find(client->GetMemoryTracker()); |
296 DCHECK(tracking_group_it != tracking_groups_.end()); | 280 DCHECK(tracking_group_it != tracking_groups_.end()); |
297 GpuMemoryTrackingGroup* tracking_group = tracking_group_it->second; | 281 GpuMemoryTrackingGroup* tracking_group = tracking_group_it->second; |
298 | 282 |
299 GpuMemoryManagerClientState* client_state = new GpuMemoryManagerClientState( | 283 GpuMemoryManagerClientState* client_state = new GpuMemoryManagerClientState( |
300 this, client, tracking_group, has_surface, visible); | 284 this, client, tracking_group, has_surface, visible); |
301 TrackValueChanged(0, client_state->managed_memory_stats_.bytes_allocated, | |
302 client_state->visible_ ? | |
303 &bytes_allocated_managed_visible_ : | |
304 &bytes_allocated_managed_nonvisible_); | |
305 AddClientToList(client_state); | 285 AddClientToList(client_state); |
306 ScheduleManage(kScheduleManageNow); | 286 ScheduleManage(kScheduleManageNow); |
307 return client_state; | 287 return client_state; |
308 } | 288 } |
309 | 289 |
310 void GpuMemoryManager::OnDestroyClientState( | 290 void GpuMemoryManager::OnDestroyClientState( |
311 GpuMemoryManagerClientState* client_state) { | 291 GpuMemoryManagerClientState* client_state) { |
312 RemoveClientFromList(client_state); | 292 RemoveClientFromList(client_state); |
313 TrackValueChanged(client_state->managed_memory_stats_.bytes_allocated, 0, | |
314 client_state->visible_ ? | |
315 &bytes_allocated_managed_visible_ : | |
316 &bytes_allocated_managed_nonvisible_); | |
317 ScheduleManage(kScheduleManageLater); | 293 ScheduleManage(kScheduleManageLater); |
318 } | 294 } |
319 | 295 |
320 void GpuMemoryManager::SetClientStateVisible( | 296 void GpuMemoryManager::SetClientStateVisible( |
321 GpuMemoryManagerClientState* client_state, bool visible) { | 297 GpuMemoryManagerClientState* client_state, bool visible) { |
322 DCHECK(client_state->has_surface_); | 298 DCHECK(client_state->has_surface_); |
323 if (client_state->visible_ == visible) | 299 if (client_state->visible_ == visible) |
324 return; | 300 return; |
325 | 301 |
326 RemoveClientFromList(client_state); | 302 RemoveClientFromList(client_state); |
327 client_state->visible_ = visible; | 303 client_state->visible_ = visible; |
328 AddClientToList(client_state); | 304 AddClientToList(client_state); |
329 | |
330 TrackValueChanged(client_state->managed_memory_stats_.bytes_allocated, 0, | |
331 client_state->visible_ ? | |
332 &bytes_allocated_managed_nonvisible_ : | |
333 &bytes_allocated_managed_visible_); | |
334 TrackValueChanged(0, client_state->managed_memory_stats_.bytes_allocated, | |
335 client_state->visible_ ? | |
336 &bytes_allocated_managed_visible_ : | |
337 &bytes_allocated_managed_nonvisible_); | |
338 ScheduleManage(visible ? kScheduleManageNow : kScheduleManageLater); | 305 ScheduleManage(visible ? kScheduleManageNow : kScheduleManageLater); |
339 } | 306 } |
340 | 307 |
341 void GpuMemoryManager::SetClientStateManagedMemoryStats( | 308 void GpuMemoryManager::SetClientStateManagedMemoryStats( |
342 GpuMemoryManagerClientState* client_state, | 309 GpuMemoryManagerClientState* client_state, |
343 const ManagedMemoryStats& stats) | 310 const ManagedMemoryStats& stats) |
344 { | 311 { |
345 TrackValueChanged(client_state->managed_memory_stats_.bytes_allocated, | |
346 stats.bytes_allocated, | |
347 client_state->visible_ ? | |
348 &bytes_allocated_managed_visible_ : | |
349 &bytes_allocated_managed_nonvisible_); | |
350 client_state->managed_memory_stats_ = stats; | 312 client_state->managed_memory_stats_ = stats; |
351 | 313 |
352 // If this is the first time that stats have been received for this | 314 // If this is the first time that stats have been received for this |
353 // client, use them immediately. | 315 // client, use them immediately. |
354 if (!client_state->managed_memory_stats_received_) { | 316 if (!client_state->managed_memory_stats_received_) { |
355 client_state->managed_memory_stats_received_ = true; | 317 client_state->managed_memory_stats_received_ = true; |
356 ScheduleManage(kScheduleManageNow); | 318 ScheduleManage(kScheduleManageNow); |
357 return; | 319 return; |
358 } | 320 } |
359 | 321 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 uint64 allocation = GetMinimumClientAllocation(); | 456 uint64 allocation = GetMinimumClientAllocation(); |
495 allocation += std::min(bytes_required - GetMinimumClientAllocation(), | 457 allocation += std::min(bytes_required - GetMinimumClientAllocation(), |
496 bytes_above_minimum_cap); | 458 bytes_above_minimum_cap); |
497 allocation += std::min(bytes_nicetohave - bytes_required, | 459 allocation += std::min(bytes_nicetohave - bytes_required, |
498 bytes_above_required_cap); | 460 bytes_above_required_cap); |
499 allocation = std::min(allocation, | 461 allocation = std::min(allocation, |
500 bytes_overall_cap); | 462 bytes_overall_cap); |
501 return allocation; | 463 return allocation; |
502 } | 464 } |
503 | 465 |
504 uint64 GpuMemoryManager::ComputeClientAllocationWhenNonvisible( | |
505 GpuMemoryManagerClientState* client_state) { | |
506 if (!client_state->managed_memory_stats_received_) | |
507 return 0; | |
508 | |
509 if (!allow_nonvisible_memory_) | |
510 return 0; | |
511 | |
512 return 9 * client_state->managed_memory_stats_.bytes_required / 8; | |
513 } | |
514 | |
515 void GpuMemoryManager::ComputeVisibleSurfacesAllocations() { | 466 void GpuMemoryManager::ComputeVisibleSurfacesAllocations() { |
516 uint64 bytes_available_total = GetAvailableGpuMemory(); | 467 uint64 bytes_available_total = GetAvailableGpuMemory(); |
517 uint64 bytes_above_required_cap = std::numeric_limits<uint64>::max(); | 468 uint64 bytes_above_required_cap = std::numeric_limits<uint64>::max(); |
518 uint64 bytes_above_minimum_cap = std::numeric_limits<uint64>::max(); | 469 uint64 bytes_above_minimum_cap = std::numeric_limits<uint64>::max(); |
519 uint64 bytes_overall_cap_visible = GetMaximumClientAllocation(); | 470 uint64 bytes_overall_cap_visible = GetMaximumClientAllocation(); |
520 | 471 |
521 // Compute memory usage at three levels | 472 // Compute memory usage at three levels |
522 // - painting everything that is nicetohave for visible clients | 473 // - painting everything that is nicetohave for visible clients |
523 // - painting only what that is visible | 474 // - painting only what that is visible |
524 // - giving every client the minimum allocation | 475 // - giving every client the minimum allocation |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 bytes_above_required_cap, | 554 bytes_above_required_cap, |
604 bytes_above_minimum_cap, | 555 bytes_above_minimum_cap, |
605 bytes_overall_cap_visible); | 556 bytes_overall_cap_visible); |
606 bytes_allocated_visible += client_state->bytes_allocation_when_visible_; | 557 bytes_allocated_visible += client_state->bytes_allocation_when_visible_; |
607 bytes_allocated_max_client_allocation = std::max( | 558 bytes_allocated_max_client_allocation = std::max( |
608 bytes_allocated_max_client_allocation, | 559 bytes_allocated_max_client_allocation, |
609 client_state->bytes_allocation_when_visible_); | 560 client_state->bytes_allocation_when_visible_); |
610 } | 561 } |
611 | 562 |
612 // Set the limit for nonvisible clients for when they become visible. | 563 // Set the limit for nonvisible clients for when they become visible. |
613 // Use the same formula, with a lowered overall cap to in case any of the | 564 // Use the same formula, with a lowered overall cap in case any of the |
614 // currently-nonvisible clients are much more resource-intensive than any | 565 // currently-nonvisible clients are much more resource-intensive than any |
615 // of the existing clients. | 566 // of the existing clients. |
616 uint64 bytes_overall_cap_nonvisible = bytes_allocated_max_client_allocation; | 567 uint64 bytes_overall_cap_nonvisible = bytes_allocated_max_client_allocation; |
617 if (bytes_available_total > bytes_allocated_visible) { | 568 if (bytes_available_total > bytes_allocated_visible) { |
618 bytes_overall_cap_nonvisible += | 569 bytes_overall_cap_nonvisible += |
619 bytes_available_total - bytes_allocated_visible; | 570 bytes_available_total - bytes_allocated_visible; |
620 } | 571 } |
621 bytes_overall_cap_nonvisible = std::min(bytes_overall_cap_nonvisible, | 572 bytes_overall_cap_nonvisible = std::min(bytes_overall_cap_nonvisible, |
622 GetMaximumClientAllocation()); | 573 GetMaximumClientAllocation()); |
623 for (ClientStateList::const_iterator it = clients_nonvisible_mru_.begin(); | 574 for (ClientStateList::const_iterator it = clients_nonvisible_mru_.begin(); |
624 it != clients_nonvisible_mru_.end(); | 575 it != clients_nonvisible_mru_.end(); |
625 ++it) { | 576 ++it) { |
626 GpuMemoryManagerClientState* client_state = *it; | 577 GpuMemoryManagerClientState* client_state = *it; |
627 client_state->bytes_allocation_when_visible_ = | 578 client_state->bytes_allocation_when_visible_ = |
628 ComputeClientAllocationWhenVisible( | 579 ComputeClientAllocationWhenVisible( |
629 client_state, | 580 client_state, |
630 bytes_above_required_cap, | 581 bytes_above_required_cap, |
631 bytes_above_minimum_cap, | 582 bytes_above_minimum_cap, |
632 bytes_overall_cap_nonvisible); | 583 bytes_overall_cap_nonvisible); |
633 } | 584 } |
634 } | 585 } |
635 | 586 |
636 void GpuMemoryManager::ComputeNonvisibleSurfacesAllocations() { | |
637 uint64 bytes_allocated_visible = 0; | |
638 for (ClientStateList::const_iterator it = clients_visible_mru_.begin(); | |
639 it != clients_visible_mru_.end(); | |
640 ++it) { | |
641 GpuMemoryManagerClientState* client_state = *it; | |
642 bytes_allocated_visible += client_state->bytes_allocation_when_visible_; | |
643 } | |
644 | |
645 // Allow up to 1/4 of the memory that was available for visible clients to | |
646 // go to nonvisible clients. | |
647 uint64 bytes_available_total = GetAvailableGpuMemory(); | |
648 uint64 bytes_available_nonvisible = 0; | |
649 uint64 bytes_allocated_nonvisible = 0; | |
650 if (bytes_available_total > bytes_allocated_visible) { | |
651 bytes_available_nonvisible = std::min( | |
652 bytes_available_total / 4, | |
653 bytes_available_total - bytes_allocated_visible); | |
654 } | |
655 | |
656 // Determine which now-visible clients should keep their contents when | |
657 // they are made nonvisible. | |
658 for (ClientStateList::const_iterator it = clients_visible_mru_.begin(); | |
659 it != clients_visible_mru_.end(); | |
660 ++it) { | |
661 GpuMemoryManagerClientState* client_state = *it; | |
662 | |
663 // Compute the amount of space available have for this renderer when it is | |
664 // nonvisible. Do not count this client's allocation while visible against | |
665 // the nonvisible clients' allocation total. | |
666 uint64 bytes_available_nonvisible_adjusted = std::min( | |
667 bytes_available_nonvisible + | |
668 client_state->bytes_allocation_when_visible_ / 4, | |
669 bytes_available_total / 4); | |
670 | |
671 // Allow this client to keep its contents if they fit in the allocation. | |
672 client_state->bytes_allocation_when_nonvisible_ = | |
673 ComputeClientAllocationWhenNonvisible(client_state); | |
674 if (client_state->bytes_allocation_when_nonvisible_ > | |
675 bytes_available_nonvisible_adjusted) | |
676 client_state->bytes_allocation_when_nonvisible_ = 0; | |
677 } | |
678 | |
679 // Compute which currently nonvisible clients should keep their contents. | |
680 for (ClientStateList::const_iterator it = clients_nonvisible_mru_.begin(); | |
681 it != clients_nonvisible_mru_.end(); | |
682 ++it) { | |
683 GpuMemoryManagerClientState* client_state = *it; | |
684 | |
685 // If this client is nonvisible and has already had its contents discarded, | |
686 // don't re-generate the contents until the client becomes visible again. | |
687 if (!client_state->bytes_allocation_when_nonvisible_) | |
688 continue; | |
689 | |
690 client_state->bytes_allocation_when_nonvisible_ = | |
691 ComputeClientAllocationWhenNonvisible(client_state); | |
692 | |
693 // Take into account all more recently used nonvisible clients, and only if | |
694 // this client still fits, all it to keep its contents. | |
695 if (bytes_allocated_nonvisible + | |
696 client_state->bytes_allocation_when_nonvisible_ > | |
697 bytes_available_nonvisible) { | |
698 client_state->bytes_allocation_when_nonvisible_ = 0; | |
699 } | |
700 bytes_allocated_nonvisible += | |
701 client_state->bytes_allocation_when_nonvisible_; | |
702 } | |
703 } | |
704 | |
705 void GpuMemoryManager::DistributeRemainingMemoryToVisibleSurfaces() { | 587 void GpuMemoryManager::DistributeRemainingMemoryToVisibleSurfaces() { |
706 uint64 bytes_available_total = GetAvailableGpuMemory(); | 588 uint64 bytes_available_total = GetAvailableGpuMemory(); |
707 uint64 bytes_allocated_total = 0; | 589 uint64 bytes_allocated_total = 0; |
708 | 590 |
709 for (ClientStateList::const_iterator it = clients_visible_mru_.begin(); | 591 for (ClientStateList::const_iterator it = clients_visible_mru_.begin(); |
710 it != clients_visible_mru_.end(); | 592 it != clients_visible_mru_.end(); |
711 ++it) { | 593 ++it) { |
712 GpuMemoryManagerClientState* client_state = *it; | 594 GpuMemoryManagerClientState* client_state = *it; |
713 bytes_allocated_total += client_state->bytes_allocation_when_visible_; | 595 bytes_allocated_total += client_state->bytes_allocation_when_visible_; |
714 } | 596 } |
715 for (ClientStateList::const_iterator it = clients_nonvisible_mru_.begin(); | |
716 it != clients_nonvisible_mru_.end(); | |
717 ++it) { | |
718 GpuMemoryManagerClientState* client_state = *it; | |
719 bytes_allocated_total += client_state->bytes_allocation_when_nonvisible_; | |
720 } | |
721 | 597 |
722 if (bytes_allocated_total >= bytes_available_total) | 598 if (bytes_allocated_total >= bytes_available_total) |
723 return; | 599 return; |
724 | 600 |
725 std::vector<uint64> bytes_extra_requests; | 601 std::vector<uint64> bytes_extra_requests; |
726 for (ClientStateList::const_iterator it = clients_visible_mru_.begin(); | 602 for (ClientStateList::const_iterator it = clients_visible_mru_.begin(); |
727 it != clients_visible_mru_.end(); | 603 it != clients_visible_mru_.end(); |
728 ++it) { | 604 ++it) { |
729 GpuMemoryManagerClientState* client_state = *it; | 605 GpuMemoryManagerClientState* client_state = *it; |
730 CHECK(GetMaximumClientAllocation() >= | 606 CHECK(GetMaximumClientAllocation() >= |
(...skipping 11 matching lines...) Expand all Loading... |
742 uint64 bytes_extra = GetMaximumClientAllocation() - | 618 uint64 bytes_extra = GetMaximumClientAllocation() - |
743 client_state->bytes_allocation_when_visible_; | 619 client_state->bytes_allocation_when_visible_; |
744 client_state->bytes_allocation_when_visible_ += std::min( | 620 client_state->bytes_allocation_when_visible_ += std::min( |
745 bytes_extra, bytes_extra_cap); | 621 bytes_extra, bytes_extra_cap); |
746 } | 622 } |
747 } | 623 } |
748 | 624 |
749 void GpuMemoryManager::AssignSurfacesAllocations() { | 625 void GpuMemoryManager::AssignSurfacesAllocations() { |
750 // Compute allocation when for all clients. | 626 // Compute allocation when for all clients. |
751 ComputeVisibleSurfacesAllocations(); | 627 ComputeVisibleSurfacesAllocations(); |
752 ComputeNonvisibleSurfacesAllocations(); | |
753 | 628 |
754 // Distribute the remaining memory to visible clients. | 629 // Distribute the remaining memory to visible clients. |
755 DistributeRemainingMemoryToVisibleSurfaces(); | 630 DistributeRemainingMemoryToVisibleSurfaces(); |
756 | 631 |
757 // Send that allocation to the clients. | 632 // Send that allocation to the clients. |
758 ClientStateList clients = clients_visible_mru_; | 633 ClientStateList clients = clients_visible_mru_; |
759 clients.insert(clients.end(), | 634 clients.insert(clients.end(), |
760 clients_nonvisible_mru_.begin(), | 635 clients_nonvisible_mru_.begin(), |
761 clients_nonvisible_mru_.end()); | 636 clients_nonvisible_mru_.end()); |
762 for (ClientStateList::const_iterator it = clients.begin(); | 637 for (ClientStateList::const_iterator it = clients.begin(); |
(...skipping 17 matching lines...) Expand all Loading... |
780 // because the platform is unstable when under memory pressure. | 655 // because the platform is unstable when under memory pressure. |
781 // http://crbug.com/145600 (Linux) | 656 // http://crbug.com/145600 (Linux) |
782 // http://crbug.com/141377 (Mac) | 657 // http://crbug.com/141377 (Mac) |
783 allocation.priority_cutoff_when_visible = | 658 allocation.priority_cutoff_when_visible = |
784 #if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 659 #if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
785 MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 660 MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
786 #else | 661 #else |
787 MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; | 662 MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
788 #endif | 663 #endif |
789 | 664 |
790 allocation.bytes_limit_when_not_visible = | |
791 client_state->bytes_allocation_when_nonvisible_; | |
792 allocation.priority_cutoff_when_not_visible = | |
793 MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY; | |
794 | |
795 client_state->client_->SetMemoryAllocation(allocation); | 665 client_state->client_->SetMemoryAllocation(allocation); |
796 client_state->client_->SuggestHaveFrontBuffer(!client_state->hibernated_); | 666 client_state->client_->SuggestHaveFrontBuffer(!client_state->hibernated_); |
797 } | 667 } |
798 } | 668 } |
799 | 669 |
800 void GpuMemoryManager::AssignNonSurfacesAllocations() { | 670 void GpuMemoryManager::AssignNonSurfacesAllocations() { |
801 for (ClientStateList::const_iterator it = clients_nonsurface_.begin(); | 671 for (ClientStateList::const_iterator it = clients_nonsurface_.begin(); |
802 it != clients_nonsurface_.end(); | 672 it != clients_nonsurface_.end(); |
803 ++it) { | 673 ++it) { |
804 GpuMemoryManagerClientState* client_state = *it; | 674 GpuMemoryManagerClientState* client_state = *it; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 | 763 |
894 void GpuMemoryManager::RemoveClientFromList( | 764 void GpuMemoryManager::RemoveClientFromList( |
895 GpuMemoryManagerClientState* client_state) { | 765 GpuMemoryManagerClientState* client_state) { |
896 DCHECK(client_state->list_iterator_valid_); | 766 DCHECK(client_state->list_iterator_valid_); |
897 ClientStateList* client_list = GetClientList(client_state); | 767 ClientStateList* client_list = GetClientList(client_state); |
898 client_list->erase(client_state->list_iterator_); | 768 client_list->erase(client_state->list_iterator_); |
899 client_state->list_iterator_valid_ = false; | 769 client_state->list_iterator_valid_ = false; |
900 } | 770 } |
901 | 771 |
902 } // namespace content | 772 } // namespace content |
OLD | NEW |