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_channel_manager.h" | 5 #include "content/common/gpu/gpu_channel_manager.h" |
6 | 6 |
7 #include <algorithm> | |
8 #include "base/bind.h" | 7 #include "base/bind.h" |
9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
10 #include "base/location.h" | 9 #include "base/location.h" |
11 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
12 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
13 #include "base/trace_event/memory_dump_manager.h" | |
14 #include "base/trace_event/process_memory_dump.h" | |
15 #include "content/common/gpu/gpu_channel.h" | 12 #include "content/common/gpu/gpu_channel.h" |
16 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 13 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
17 #include "content/common/gpu/gpu_memory_manager.h" | 14 #include "content/common/gpu/gpu_memory_manager.h" |
18 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
19 #include "content/common/message_router.h" | 16 #include "content/common/message_router.h" |
20 #include "gpu/command_buffer/common/value_state.h" | 17 #include "gpu/command_buffer/common/value_state.h" |
21 #include "gpu/command_buffer/service/feature_info.h" | 18 #include "gpu/command_buffer/service/feature_info.h" |
22 #include "gpu/command_buffer/service/gpu_switches.h" | 19 #include "gpu/command_buffer/service/gpu_switches.h" |
23 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 20 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
24 #include "gpu/command_buffer/service/memory_program_cache.h" | 21 #include "gpu/command_buffer/service/memory_program_cache.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 gpu_memory_buffer_factory_( | 105 gpu_memory_buffer_factory_( |
109 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), | 106 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), |
110 channel_(channel), | 107 channel_(channel), |
111 filter_( | 108 filter_( |
112 new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), | 109 new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), |
113 relinquish_resources_pending_(false), | 110 relinquish_resources_pending_(false), |
114 weak_factory_(this) { | 111 weak_factory_(this) { |
115 DCHECK(router_); | 112 DCHECK(router_); |
116 DCHECK(io_task_runner); | 113 DCHECK(io_task_runner); |
117 DCHECK(shutdown_event); | 114 DCHECK(shutdown_event); |
118 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
119 this, io_task_runner_); | |
120 channel_->AddFilter(filter_.get()); | 115 channel_->AddFilter(filter_.get()); |
121 } | 116 } |
122 | 117 |
123 GpuChannelManager::~GpuChannelManager() { | 118 GpuChannelManager::~GpuChannelManager() { |
124 gpu_channels_.clear(); | 119 gpu_channels_.clear(); |
125 if (default_offscreen_surface_.get()) { | 120 if (default_offscreen_surface_.get()) { |
126 default_offscreen_surface_->Destroy(); | 121 default_offscreen_surface_->Destroy(); |
127 default_offscreen_surface_ = NULL; | 122 default_offscreen_surface_ = NULL; |
128 } | 123 } |
129 } | 124 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 336 } |
342 | 337 |
343 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 338 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
344 if (!default_offscreen_surface_.get()) { | 339 if (!default_offscreen_surface_.get()) { |
345 default_offscreen_surface_ = | 340 default_offscreen_surface_ = |
346 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 341 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
347 } | 342 } |
348 return default_offscreen_surface_.get(); | 343 return default_offscreen_surface_.get(); |
349 } | 344 } |
350 | 345 |
351 bool GpuChannelManager::OnMemoryDump( | |
352 base::trace_event::ProcessMemoryDump* pmd) { | |
353 for (const auto& channel : gpu_channels_) { | |
354 auto dump_name = channel.second->GetChannelName(); | |
355 std::replace(dump_name.begin(), dump_name.end(), '.', '_'); | |
356 | |
357 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( | |
358 base::StringPrintf("gl/%s", dump_name.c_str())); | |
359 | |
360 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
361 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
362 channel.second->GetMemoryUsage()); | |
363 } | |
364 | |
365 return true; | |
366 } | |
367 | |
368 void GpuChannelManager::OnRelinquishResources() { | 346 void GpuChannelManager::OnRelinquishResources() { |
369 relinquish_resources_pending_ = true; | 347 relinquish_resources_pending_ = true; |
370 CheckRelinquishGpuResources(); | 348 CheckRelinquishGpuResources(); |
371 } | 349 } |
372 | 350 |
373 void GpuChannelManager::CheckRelinquishGpuResources() { | 351 void GpuChannelManager::CheckRelinquishGpuResources() { |
374 if (relinquish_resources_pending_ && gpu_channels_.size() <= 1) { | 352 if (relinquish_resources_pending_ && gpu_channels_.size() <= 1) { |
375 relinquish_resources_pending_ = false; | 353 relinquish_resources_pending_ = false; |
376 if (default_offscreen_surface_.get()) { | 354 if (default_offscreen_surface_.get()) { |
377 default_offscreen_surface_->DestroyAndTerminateDisplay(); | 355 default_offscreen_surface_->DestroyAndTerminateDisplay(); |
378 default_offscreen_surface_ = NULL; | 356 default_offscreen_surface_ = NULL; |
379 } | 357 } |
380 #if defined(USE_OZONE) | 358 #if defined(USE_OZONE) |
381 ui::OzonePlatform::GetInstance() | 359 ui::OzonePlatform::GetInstance() |
382 ->GetGpuPlatformSupport() | 360 ->GetGpuPlatformSupport() |
383 ->RelinquishGpuResources( | 361 ->RelinquishGpuResources( |
384 base::Bind(&GpuChannelManager::OnResourcesRelinquished, | 362 base::Bind(&GpuChannelManager::OnResourcesRelinquished, |
385 weak_factory_.GetWeakPtr())); | 363 weak_factory_.GetWeakPtr())); |
386 #else | 364 #else |
387 OnResourcesRelinquished(); | 365 OnResourcesRelinquished(); |
388 #endif | 366 #endif |
389 } | 367 } |
390 } | 368 } |
391 | 369 |
392 void GpuChannelManager::OnResourcesRelinquished() { | 370 void GpuChannelManager::OnResourcesRelinquished() { |
393 Send(new GpuHostMsg_ResourcesRelinquished()); | 371 Send(new GpuHostMsg_ResourcesRelinquished()); |
394 } | 372 } |
395 | 373 |
396 } // namespace content | 374 } // namespace content |
OLD | NEW |