| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "content/common/gpu/gpu_channel_manager.h" | 15 #include "content/common/gpu/gpu_channel_manager.h" |
| 16 #include "content/common/gpu/gpu_channel_manager_delegate.h" | |
| 17 #include "content/common/gpu/gpu_memory_tracking.h" | 16 #include "content/common/gpu/gpu_memory_tracking.h" |
| 18 #include "content/common/gpu/gpu_memory_uma_stats.h" | 17 #include "content/common/gpu/gpu_memory_uma_stats.h" |
| 18 #include "content/common/gpu/gpu_messages.h" |
| 19 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 19 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 20 #include "gpu/command_buffer/service/gpu_switches.h" | 20 #include "gpu/command_buffer/service/gpu_switches.h" |
| 21 | 21 |
| 22 using gpu::MemoryAllocation; | 22 using gpu::MemoryAllocation; |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const uint64_t kBytesAllocatedStep = 16 * 1024 * 1024; | 27 const uint64_t kBytesAllocatedStep = 16 * 1024 * 1024; |
| 28 | 28 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 uint64_t old_size, | 50 uint64_t old_size, |
| 51 uint64_t new_size) { | 51 uint64_t new_size) { |
| 52 TrackValueChanged(old_size, new_size, &tracking_group->size_); | 52 TrackValueChanged(old_size, new_size, &tracking_group->size_); |
| 53 TrackValueChanged(old_size, new_size, &bytes_allocated_current_); | 53 TrackValueChanged(old_size, new_size, &bytes_allocated_current_); |
| 54 | 54 |
| 55 if (GetCurrentUsage() > bytes_allocated_historical_max_ + | 55 if (GetCurrentUsage() > bytes_allocated_historical_max_ + |
| 56 kBytesAllocatedStep) { | 56 kBytesAllocatedStep) { |
| 57 bytes_allocated_historical_max_ = GetCurrentUsage(); | 57 bytes_allocated_historical_max_ = GetCurrentUsage(); |
| 58 // If we're blowing into new memory usage territory, spam the browser | 58 // If we're blowing into new memory usage territory, spam the browser |
| 59 // process with the most up-to-date information about our memory usage. | 59 // process with the most up-to-date information about our memory usage. |
| 60 SendUmaStatsToHost(); | 60 SendUmaStatsToBrowser(); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool GpuMemoryManager::EnsureGPUMemoryAvailable(uint64_t /* size_needed */) { | 64 bool GpuMemoryManager::EnsureGPUMemoryAvailable(uint64_t /* size_needed */) { |
| 65 // TODO: Check if there is enough space. Lose contexts until there is. | 65 // TODO: Check if there is enough space. Lose contexts until there is. |
| 66 return true; | 66 return true; |
| 67 } | 67 } |
| 68 | 68 |
| 69 uint64_t GpuMemoryManager::GetTrackerMemoryUsage( | 69 uint64_t GpuMemoryManager::GetTrackerMemoryUsage( |
| 70 gpu::gles2::MemoryTracker* tracker) const { | 70 gpu::gles2::MemoryTracker* tracker) const { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 video_memory_usage_stats->process_map[ | 105 video_memory_usage_stats->process_map[ |
| 106 base::GetCurrentProcId()].video_memory = GetCurrentUsage(); | 106 base::GetCurrentProcId()].video_memory = GetCurrentUsage(); |
| 107 video_memory_usage_stats->process_map[ | 107 video_memory_usage_stats->process_map[ |
| 108 base::GetCurrentProcId()].has_duplicates = true; | 108 base::GetCurrentProcId()].has_duplicates = true; |
| 109 | 109 |
| 110 video_memory_usage_stats->bytes_allocated = GetCurrentUsage(); | 110 video_memory_usage_stats->bytes_allocated = GetCurrentUsage(); |
| 111 video_memory_usage_stats->bytes_allocated_historical_max = | 111 video_memory_usage_stats->bytes_allocated_historical_max = |
| 112 bytes_allocated_historical_max_; | 112 bytes_allocated_historical_max_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void GpuMemoryManager::SendUmaStatsToHost() { | 115 void GpuMemoryManager::SendUmaStatsToBrowser() { |
| 116 if (!channel_manager_) | 116 if (!channel_manager_) |
| 117 return; | 117 return; |
| 118 GPUMemoryUmaStats params; | 118 GPUMemoryUmaStats params; |
| 119 params.bytes_allocated_current = GetCurrentUsage(); | 119 params.bytes_allocated_current = GetCurrentUsage(); |
| 120 params.bytes_allocated_max = bytes_allocated_historical_max_; | 120 params.bytes_allocated_max = bytes_allocated_historical_max_; |
| 121 params.context_group_count = static_cast<uint32_t>(tracking_groups_.size()); | 121 params.context_group_count = static_cast<uint32_t>(tracking_groups_.size()); |
| 122 channel_manager_->delegate()->GpuMemoryUmaStats(params); | 122 channel_manager_->Send(new GpuHostMsg_GpuMemoryUmaStats(params)); |
| 123 } | 123 } |
| 124 } // namespace content | 124 } // namespace content |
| OLD | NEW |