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::kManaged: |
| 269 TrackValueChanged(old_size, new_size, &bytes_allocated_managed_current_); |
| 270 break; |
| 271 case gpu::gles2::MemoryTracker::kUnmanaged: |
| 272 TrackValueChanged(old_size, |
| 273 new_size, |
| 274 &bytes_allocated_unmanaged_current_); |
| 275 break; |
| 276 default: |
| 277 NOTREACHED(); |
| 278 break; |
| 279 } |
264 if (new_size != old_size) { | 280 if (new_size != old_size) { |
265 TRACE_COUNTER1("gpu", | 281 TRACE_COUNTER1("gpu", |
266 "GpuMemoryUsage", | 282 "GpuMemoryUsage", |
267 bytes_allocated_current_); | 283 GetCurrentUsage()); |
268 } | 284 } |
269 if (bytes_allocated_current_ > bytes_allocated_historical_max_) { | 285 if (GetCurrentUsage() > bytes_allocated_historical_max_) { |
270 bytes_allocated_historical_max_ = bytes_allocated_current_; | 286 bytes_allocated_historical_max_ = GetCurrentUsage(); |
271 // If we're blowing into new memory usage territory, spam the browser | 287 // 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. | 288 // process with the most up-to-date information about our memory usage. |
273 SendUmaStatsToBrowser(); | 289 SendUmaStatsToBrowser(); |
274 } | 290 } |
275 } | 291 } |
276 | 292 |
277 void GpuMemoryManager::AddClient(GpuMemoryManagerClient* client, | 293 void GpuMemoryManager::AddClient(GpuMemoryManagerClient* client, |
278 bool has_surface, | 294 bool has_surface, |
279 bool visible, | 295 bool visible, |
280 base::TimeTicks last_used_time) { | 296 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(); | 408 video_memory_usage_stats.process_map.clear(); |
393 for (std::set<GpuMemoryTrackingGroup*>::const_iterator i = | 409 for (std::set<GpuMemoryTrackingGroup*>::const_iterator i = |
394 tracking_groups_.begin(); i != tracking_groups_.end(); ++i) { | 410 tracking_groups_.begin(); i != tracking_groups_.end(); ++i) { |
395 const GpuMemoryTrackingGroup* tracking_group = (*i); | 411 const GpuMemoryTrackingGroup* tracking_group = (*i); |
396 video_memory_usage_stats.process_map[ | 412 video_memory_usage_stats.process_map[ |
397 tracking_group->GetPid()].video_memory += tracking_group->GetSize(); | 413 tracking_group->GetPid()].video_memory += tracking_group->GetSize(); |
398 } | 414 } |
399 | 415 |
400 // Assign the total across all processes in the GPU process | 416 // Assign the total across all processes in the GPU process |
401 video_memory_usage_stats.process_map[ | 417 video_memory_usage_stats.process_map[ |
402 base::GetCurrentProcId()].video_memory = bytes_allocated_current_; | 418 base::GetCurrentProcId()].video_memory = GetCurrentUsage(); |
403 video_memory_usage_stats.process_map[ | 419 video_memory_usage_stats.process_map[ |
404 base::GetCurrentProcId()].has_duplicates = true; | 420 base::GetCurrentProcId()].has_duplicates = true; |
405 } | 421 } |
406 | 422 |
407 void GpuMemoryManager::SetWindowCount(uint32 window_count) { | 423 void GpuMemoryManager::SetWindowCount(uint32 window_count) { |
408 bool should_schedule_manage = !window_count_has_been_received_ || | 424 bool should_schedule_manage = !window_count_has_been_received_ || |
409 (window_count != window_count_); | 425 (window_count != window_count_); |
410 window_count_has_been_received_ = true; | 426 window_count_has_been_received_ = true; |
411 window_count_ = window_count; | 427 window_count_ = window_count; |
412 if (should_schedule_manage) | 428 if (should_schedule_manage) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 if (clients_allocation_when_visible >= GetMaximumTabAllocation()) | 623 if (clients_allocation_when_visible >= GetMaximumTabAllocation()) |
608 clients_allocation_when_visible = GetMaximumTabAllocation(); | 624 clients_allocation_when_visible = GetMaximumTabAllocation(); |
609 | 625 |
610 return clients_allocation_when_visible; | 626 return clients_allocation_when_visible; |
611 } | 627 } |
612 | 628 |
613 void GpuMemoryManager::SendUmaStatsToBrowser() { | 629 void GpuMemoryManager::SendUmaStatsToBrowser() { |
614 if (!channel_manager_) | 630 if (!channel_manager_) |
615 return; | 631 return; |
616 GPUMemoryUmaStats params; | 632 GPUMemoryUmaStats params; |
617 params.bytes_allocated_current = bytes_allocated_current_; | 633 params.bytes_allocated_current = GetCurrentUsage(); |
618 params.bytes_allocated_max = bytes_allocated_historical_max_; | 634 params.bytes_allocated_max = bytes_allocated_historical_max_; |
619 params.bytes_limit = bytes_available_gpu_memory_; | 635 params.bytes_limit = bytes_available_gpu_memory_; |
620 params.window_count = window_count_; | 636 params.window_count = window_count_; |
621 channel_manager_->Send(new GpuHostMsg_GpuMemoryUmaStats(params)); | 637 channel_manager_->Send(new GpuHostMsg_GpuMemoryUmaStats(params)); |
622 } | 638 } |
623 | 639 |
624 GpuMemoryManager::ClientState::ClientState( | 640 GpuMemoryManager::ClientState::ClientState( |
625 GpuMemoryManagerClient* client, | 641 GpuMemoryManagerClient* client, |
626 bool has_surface, | 642 bool has_surface, |
627 bool visible, | 643 bool visible, |
628 base::TimeTicks last_used_time) | 644 base::TimeTicks last_used_time) |
629 : client(client), | 645 : client(client), |
630 has_surface(has_surface), | 646 has_surface(has_surface), |
631 visible(visible), | 647 visible(visible), |
632 last_used_time(last_used_time), | 648 last_used_time(last_used_time), |
633 hibernated(false) { | 649 hibernated(false) { |
634 } | 650 } |
635 | 651 |
636 } // namespace content | 652 } // namespace content |
637 | 653 |
638 #endif | 654 #endif |
OLD | NEW |