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

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

Issue 12226082: Distribute extra memory evenly among visible tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch branches Created 7 years, 10 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_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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 SendUmaStatsToBrowser(); 524 SendUmaStatsToBrowser();
525 } 525 }
526 526
527 // static 527 // static
528 uint64 GpuMemoryManager::ComputeCap( 528 uint64 GpuMemoryManager::ComputeCap(
529 std::vector<uint64> bytes, uint64 bytes_sum_limit) 529 std::vector<uint64> bytes, uint64 bytes_sum_limit)
530 { 530 {
531 size_t bytes_size = bytes.size(); 531 size_t bytes_size = bytes.size();
532 uint64 bytes_sum = 0; 532 uint64 bytes_sum = 0;
533 533
534 if (bytes_size == 0)
535 return std::numeric_limits<uint64>::max();
536
534 // Sort and add up all entries 537 // Sort and add up all entries
535 std::sort(bytes.begin(), bytes.end()); 538 std::sort(bytes.begin(), bytes.end());
536 for (size_t i = 0; i < bytes_size; ++i) 539 for (size_t i = 0; i < bytes_size; ++i)
537 bytes_sum += bytes[i]; 540 bytes_sum += bytes[i];
538 541
539 // As we go through the below loop, let bytes_partial_sum be the 542 // As we go through the below loop, let bytes_partial_sum be the
540 // sum of bytes[0] + ... + bytes[bytes_size - i - 1] 543 // sum of bytes[0] + ... + bytes[bytes_size - i - 1]
541 uint64 bytes_partial_sum = bytes_sum; 544 uint64 bytes_partial_sum = bytes_sum;
542 545
543 // Try using each entry as a cap, and see where we get cut off. 546 // Try using each entry as a cap, and see where we get cut off.
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 if (bytes_allocated_nonvisible + 787 if (bytes_allocated_nonvisible +
785 client_state->bytes_allocation_when_nonvisible_ > 788 client_state->bytes_allocation_when_nonvisible_ >
786 bytes_available_nonvisible) { 789 bytes_available_nonvisible) {
787 client_state->bytes_allocation_when_nonvisible_ = 0; 790 client_state->bytes_allocation_when_nonvisible_ = 0;
788 } 791 }
789 bytes_allocated_nonvisible += 792 bytes_allocated_nonvisible +=
790 client_state->bytes_allocation_when_nonvisible_; 793 client_state->bytes_allocation_when_nonvisible_;
791 } 794 }
792 } 795 }
793 796
797 void GpuMemoryManager::DistributeRemainingMemoryToVisibleSurfaces() {
798 uint64 bytes_available_total = GetAvailableGpuMemory();
799 uint64 bytes_allocated_total = 0;
800
801 for (ClientStateList::const_iterator it = clients_visible_mru_.begin();
klobag.chromium 2013/02/09 04:10:10 Should we expect the number of client_visible_mru
ccameron 2013/02/09 04:45:28 We should only have one entry in clients_visible_m
ccameron 2013/02/11 20:55:56 I double-checked this an only got 1 visible tab wh
802 it != clients_visible_mru_.end();
803 ++it) {
804 GpuMemoryManagerClientState* client_state = *it;
805 bytes_allocated_total += client_state->bytes_allocation_when_visible_;
806 }
807 for (ClientStateList::const_iterator it = clients_nonvisible_mru_.begin();
808 it != clients_nonvisible_mru_.end();
809 ++it) {
810 GpuMemoryManagerClientState* client_state = *it;
811 bytes_allocated_total += client_state->bytes_allocation_when_nonvisible_;
812 }
813
814 if (bytes_allocated_total >= bytes_available_total)
815 return;
816
817 std::vector<uint64> bytes_extra_requests;
818 for (ClientStateList::const_iterator it = clients_visible_mru_.begin();
819 it != clients_visible_mru_.end();
820 ++it) {
821 GpuMemoryManagerClientState* client_state = *it;
822 CHECK(GetMaximumClientAllocation() >=
823 client_state->bytes_allocation_when_visible_);
824 uint64 bytes_extra = GetMaximumClientAllocation() -
825 client_state->bytes_allocation_when_visible_;
826 bytes_extra_requests.push_back(bytes_extra);
827 }
828 uint64 bytes_extra_cap = ComputeCap(
829 bytes_extra_requests, bytes_available_total - bytes_allocated_total);
830 for (ClientStateList::const_iterator it = clients_visible_mru_.begin();
831 it != clients_visible_mru_.end();
832 ++it) {
833 GpuMemoryManagerClientState* client_state = *it;
834 uint64 bytes_extra = GetMaximumClientAllocation() -
835 client_state->bytes_allocation_when_visible_;
836 client_state->bytes_allocation_when_visible_ += std::min(
837 bytes_extra, bytes_extra_cap);
838 }
839 }
840
794 void GpuMemoryManager::AssignSurfacesAllocationsNonuniform() { 841 void GpuMemoryManager::AssignSurfacesAllocationsNonuniform() {
795 // Compute allocation when for all clients. 842 // Compute allocation when for all clients.
796 ComputeVisibleSurfacesAllocationsNonuniform(); 843 ComputeVisibleSurfacesAllocationsNonuniform();
797 ComputeNonvisibleSurfacesAllocationsNonuniform(); 844 ComputeNonvisibleSurfacesAllocationsNonuniform();
798 845
846 // Distribute the remaining memory to visible clients.
847 DistributeRemainingMemoryToVisibleSurfaces();
848
799 // Send that allocation to the clients. 849 // Send that allocation to the clients.
800 ClientStateList clients = clients_visible_mru_; 850 ClientStateList clients = clients_visible_mru_;
801 clients.insert(clients.end(), 851 clients.insert(clients.end(),
802 clients_nonvisible_mru_.begin(), 852 clients_nonvisible_mru_.begin(),
803 clients_nonvisible_mru_.end()); 853 clients_nonvisible_mru_.end());
804 for (ClientStateList::const_iterator it = clients.begin(); 854 for (ClientStateList::const_iterator it = clients.begin();
805 it != clients.end(); 855 it != clients.end();
806 ++it) { 856 ++it) {
807 GpuMemoryManagerClientState* client_state = *it; 857 GpuMemoryManagerClientState* client_state = *it;
808 858
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 1096
1047 void GpuMemoryManager::RemoveClientFromList( 1097 void GpuMemoryManager::RemoveClientFromList(
1048 GpuMemoryManagerClientState* client_state) { 1098 GpuMemoryManagerClientState* client_state) {
1049 DCHECK(client_state->list_iterator_valid_); 1099 DCHECK(client_state->list_iterator_valid_);
1050 ClientStateList* client_list = GetClientList(client_state); 1100 ClientStateList* client_list = GetClientList(client_state);
1051 client_list->erase(client_state->list_iterator_); 1101 client_list->erase(client_state->list_iterator_);
1052 client_state->list_iterator_valid_ = false; 1102 client_state->list_iterator_valid_ = false;
1053 } 1103 }
1054 1104
1055 } // namespace content 1105 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_memory_manager.h ('k') | content/common/gpu/gpu_memory_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698