Chromium Code Reviews| 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 #if defined(ENABLE_GPU) | 7 #if defined(ENABLE_GPU) |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 GpuMemoryManager::GpuMemoryManager( | 37 GpuMemoryManager::GpuMemoryManager( |
| 38 GpuChannelManager* channel_manager, | 38 GpuChannelManager* channel_manager, |
| 39 size_t max_surfaces_with_frontbuffer_soft_limit) | 39 size_t max_surfaces_with_frontbuffer_soft_limit) |
| 40 : channel_manager_(channel_manager), | 40 : channel_manager_(channel_manager), |
| 41 manage_immediate_scheduled_(false), | 41 manage_immediate_scheduled_(false), |
| 42 max_surfaces_with_frontbuffer_soft_limit_( | 42 max_surfaces_with_frontbuffer_soft_limit_( |
| 43 max_surfaces_with_frontbuffer_soft_limit), | 43 max_surfaces_with_frontbuffer_soft_limit), |
| 44 bytes_available_gpu_memory_(0), | 44 bytes_available_gpu_memory_(0), |
| 45 bytes_available_gpu_memory_overridden_(false), | 45 bytes_available_gpu_memory_overridden_(false), |
| 46 bytes_backgrounded_available_gpu_memory_(0), | 46 bytes_backgrounded_available_gpu_memory_(0), |
| 47 bytes_allocated_current_(0), | 47 bytes_allocated_managed_current_(0), |
| 48 bytes_allocated_managed_visible_(0), | 48 bytes_allocated_managed_visible_(0), |
| 49 bytes_allocated_managed_backgrounded_(0), | 49 bytes_allocated_managed_backgrounded_(0), |
| 50 bytes_allocated_unmanaged_current_(0), | |
| 50 bytes_allocated_historical_max_(0), | 51 bytes_allocated_historical_max_(0), |
| 51 window_count_has_been_received_(false), | 52 window_count_has_been_received_(false), |
| 52 window_count_(0), | 53 window_count_(0), |
| 53 disable_schedule_manage_(false) | 54 disable_schedule_manage_(false) |
| 54 { | 55 { |
| 55 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 56 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 56 if (command_line->HasSwitch(switches::kForceGpuMemAvailableMb)) { | 57 if (command_line->HasSwitch(switches::kForceGpuMemAvailableMb)) { |
| 57 base::StringToSizeT( | 58 base::StringToSizeT( |
| 58 command_line->GetSwitchValueASCII(switches::kForceGpuMemAvailableMb), | 59 command_line->GetSwitchValueASCII(switches::kForceGpuMemAvailableMb), |
| 59 &bytes_available_gpu_memory_); | 60 &bytes_available_gpu_memory_); |
| 60 bytes_available_gpu_memory_ *= 1024 * 1024; | 61 bytes_available_gpu_memory_ *= 1024 * 1024; |
| 61 bytes_available_gpu_memory_overridden_ = true; | 62 bytes_available_gpu_memory_overridden_ = true; |
| 62 } else | 63 } else |
| 63 bytes_available_gpu_memory_ = GetDefaultAvailableGpuMemory(); | 64 bytes_available_gpu_memory_ = GetDefaultAvailableGpuMemory(); |
| 64 UpdateBackgroundedAvailableGpuMemory(); | 65 UpdateBackgroundedAvailableGpuMemory(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 GpuMemoryManager::~GpuMemoryManager() { | 68 GpuMemoryManager::~GpuMemoryManager() { |
| 68 DCHECK(tracking_groups_.empty()); | 69 DCHECK(tracking_groups_.empty()); |
| 69 DCHECK(clients_.empty()); | 70 DCHECK(clients_.empty()); |
| 70 DCHECK(!bytes_allocated_current_); | 71 DCHECK(!bytes_allocated_managed_current_); |
| 72 DCHECK(!bytes_allocated_unmanaged_current_); | |
| 71 DCHECK(!bytes_allocated_managed_visible_); | 73 DCHECK(!bytes_allocated_managed_visible_); |
| 72 DCHECK(!bytes_allocated_managed_backgrounded_); | 74 DCHECK(!bytes_allocated_managed_backgrounded_); |
| 73 } | 75 } |
| 74 | 76 |
| 75 size_t GpuMemoryManager::GetAvailableGpuMemory() const { | 77 size_t GpuMemoryManager::GetAvailableGpuMemory() const { |
| 76 return bytes_available_gpu_memory_; | 78 return bytes_available_gpu_memory_; |
| 77 } | 79 } |
| 78 | 80 |
| 79 size_t GpuMemoryManager::GetCurrentBackgroundedAvailableGpuMemory() const { | 81 size_t GpuMemoryManager::GetCurrentBackgroundedAvailableGpuMemory() const { |
| 80 if (bytes_allocated_managed_visible_ < GetAvailableGpuMemory()) { | 82 if (bytes_allocated_managed_visible_ < GetAvailableGpuMemory()) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 return; | 253 return; |
| 252 delayed_manage_callback_.Reset(base::Bind(&GpuMemoryManager::Manage, | 254 delayed_manage_callback_.Reset(base::Bind(&GpuMemoryManager::Manage, |
| 253 AsWeakPtr())); | 255 AsWeakPtr())); |
| 254 MessageLoop::current()->PostDelayedTask( | 256 MessageLoop::current()->PostDelayedTask( |
| 255 FROM_HERE, | 257 FROM_HERE, |
| 256 delayed_manage_callback_.callback(), | 258 delayed_manage_callback_.callback(), |
| 257 base::TimeDelta::FromMilliseconds(kDelayedScheduleManageTimeoutMs)); | 259 base::TimeDelta::FromMilliseconds(kDelayedScheduleManageTimeoutMs)); |
| 258 } | 260 } |
| 259 } | 261 } |
| 260 | 262 |
| 261 void GpuMemoryManager::TrackMemoryAllocatedChange(size_t old_size, | 263 void GpuMemoryManager::TrackMemoryAllocatedChange( |
| 262 size_t new_size) { | 264 size_t old_size, |
| 263 TrackValueChanged(old_size, new_size, &bytes_allocated_current_); | 265 size_t new_size, |
| 266 gpu::gles2::MemoryTracker::Pool tracking_pool) { | |
| 267 switch (tracking_pool) { | |
| 268 case gpu::gles2::MemoryTracker::Managed: | |
|
greggman
2012/12/12 07:17:47
style: case is intended from switch
ccameron
2012/12/12 21:12:33
Done.
| |
| 269 TrackValueChanged(old_size, new_size, &bytes_allocated_managed_current_); | |
| 270 break; | |
| 271 case gpu::gles2::MemoryTracker::Unmanaged: | |
| 272 TrackValueChanged(old_size, new_size, &bytes_allocated_unmanaged_current_); | |
| 273 break; | |
| 274 default: | |
| 275 NOTREACHED(); | |
| 276 break; | |
| 277 } | |
| 264 if (new_size != old_size) { | 278 if (new_size != old_size) { |
| 265 TRACE_COUNTER1("gpu", | 279 TRACE_COUNTER1("gpu", |
| 266 "GpuMemoryUsage", | 280 "GpuMemoryUsage", |
| 267 bytes_allocated_current_); | 281 GetCurrentUsage()); |
| 268 } | 282 } |
| 269 if (bytes_allocated_current_ > bytes_allocated_historical_max_) { | 283 if (GetCurrentUsage() > bytes_allocated_historical_max_) { |
| 270 bytes_allocated_historical_max_ = bytes_allocated_current_; | 284 bytes_allocated_historical_max_ = GetCurrentUsage(); |
| 271 // If we're blowing into new memory usage territory, spam the browser | 285 // If we're blowing into new memory usage territory, spam the browser |
| 272 // process with the most up-to-date information about our memory usage. | 286 // process with the most up-to-date information about our memory usage. |
| 273 SendUmaStatsToBrowser(); | 287 SendUmaStatsToBrowser(); |
| 274 } | 288 } |
| 275 } | 289 } |
| 276 | 290 |
| 277 void GpuMemoryManager::AddClient(GpuMemoryManagerClient* client, | 291 void GpuMemoryManager::AddClient(GpuMemoryManagerClient* client, |
| 278 bool has_surface, | 292 bool has_surface, |
| 279 bool visible, | 293 bool visible, |
| 280 base::TimeTicks last_used_time) { | 294 base::TimeTicks last_used_time) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 video_memory_usage_stats.process_map.clear(); | 406 video_memory_usage_stats.process_map.clear(); |
| 393 for (std::set<GpuMemoryTrackingGroup*>::const_iterator i = | 407 for (std::set<GpuMemoryTrackingGroup*>::const_iterator i = |
| 394 tracking_groups_.begin(); i != tracking_groups_.end(); ++i) { | 408 tracking_groups_.begin(); i != tracking_groups_.end(); ++i) { |
| 395 const GpuMemoryTrackingGroup* tracking_group = (*i); | 409 const GpuMemoryTrackingGroup* tracking_group = (*i); |
| 396 video_memory_usage_stats.process_map[ | 410 video_memory_usage_stats.process_map[ |
| 397 tracking_group->GetPid()].video_memory += tracking_group->GetSize(); | 411 tracking_group->GetPid()].video_memory += tracking_group->GetSize(); |
| 398 } | 412 } |
| 399 | 413 |
| 400 // Assign the total across all processes in the GPU process | 414 // Assign the total across all processes in the GPU process |
| 401 video_memory_usage_stats.process_map[ | 415 video_memory_usage_stats.process_map[ |
| 402 base::GetCurrentProcId()].video_memory = bytes_allocated_current_; | 416 base::GetCurrentProcId()].video_memory = GetCurrentUsage(); |
| 403 video_memory_usage_stats.process_map[ | 417 video_memory_usage_stats.process_map[ |
| 404 base::GetCurrentProcId()].has_duplicates = true; | 418 base::GetCurrentProcId()].has_duplicates = true; |
| 405 } | 419 } |
| 406 | 420 |
| 407 void GpuMemoryManager::SetWindowCount(uint32 window_count) { | 421 void GpuMemoryManager::SetWindowCount(uint32 window_count) { |
| 408 bool should_schedule_manage = !window_count_has_been_received_ || | 422 bool should_schedule_manage = !window_count_has_been_received_ || |
| 409 (window_count != window_count_); | 423 (window_count != window_count_); |
| 410 window_count_has_been_received_ = true; | 424 window_count_has_been_received_ = true; |
| 411 window_count_ = window_count; | 425 window_count_ = window_count; |
| 412 if (should_schedule_manage) | 426 if (should_schedule_manage) |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 if (clients_allocation_when_visible >= GetMaximumTabAllocation()) | 621 if (clients_allocation_when_visible >= GetMaximumTabAllocation()) |
| 608 clients_allocation_when_visible = GetMaximumTabAllocation(); | 622 clients_allocation_when_visible = GetMaximumTabAllocation(); |
| 609 | 623 |
| 610 return clients_allocation_when_visible; | 624 return clients_allocation_when_visible; |
| 611 } | 625 } |
| 612 | 626 |
| 613 void GpuMemoryManager::SendUmaStatsToBrowser() { | 627 void GpuMemoryManager::SendUmaStatsToBrowser() { |
| 614 if (!channel_manager_) | 628 if (!channel_manager_) |
| 615 return; | 629 return; |
| 616 GPUMemoryUmaStats params; | 630 GPUMemoryUmaStats params; |
| 617 params.bytes_allocated_current = bytes_allocated_current_; | 631 params.bytes_allocated_current = GetCurrentUsage(); |
| 618 params.bytes_allocated_max = bytes_allocated_historical_max_; | 632 params.bytes_allocated_max = bytes_allocated_historical_max_; |
| 619 params.bytes_limit = bytes_available_gpu_memory_; | 633 params.bytes_limit = bytes_available_gpu_memory_; |
| 620 params.window_count = window_count_; | 634 params.window_count = window_count_; |
| 621 channel_manager_->Send(new GpuHostMsg_GpuMemoryUmaStats(params)); | 635 channel_manager_->Send(new GpuHostMsg_GpuMemoryUmaStats(params)); |
| 622 } | 636 } |
| 623 | 637 |
| 624 GpuMemoryManager::ClientState::ClientState( | 638 GpuMemoryManager::ClientState::ClientState( |
| 625 GpuMemoryManagerClient* client, | 639 GpuMemoryManagerClient* client, |
| 626 bool has_surface, | 640 bool has_surface, |
| 627 bool visible, | 641 bool visible, |
| 628 base::TimeTicks last_used_time) | 642 base::TimeTicks last_used_time) |
| 629 : client(client), | 643 : client(client), |
| 630 has_surface(has_surface), | 644 has_surface(has_surface), |
| 631 visible(visible), | 645 visible(visible), |
| 632 last_used_time(last_used_time), | 646 last_used_time(last_used_time), |
| 633 hibernated(false) { | 647 hibernated(false) { |
| 634 } | 648 } |
| 635 | 649 |
| 636 } // namespace content | 650 } // namespace content |
| 637 | 651 |
| 638 #endif | 652 #endif |
| OLD | NEW |