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_channel_manager.h" | 5 #include "content/common/gpu/gpu_channel_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "content/common/gpu/gpu_channel.h" | 12 #include "content/common/gpu/gpu_channel.h" |
| 13 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 13 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 14 #include "content/common/gpu/gpu_memory_manager.h" | 14 #include "content/common/gpu/gpu_memory_manager.h" |
| 15 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
| 16 #include "content/common/message_router.h" | 16 #include "content/common/message_router.h" |
| 17 #include "gpu/command_buffer/common/value_state.h" | 17 #include "gpu/command_buffer/common/value_state.h" |
| 18 #include "gpu/command_buffer/service/feature_info.h" | 18 #include "gpu/command_buffer/service/feature_info.h" |
| 19 #include "gpu/command_buffer/service/gpu_switches.h" | 19 #include "gpu/command_buffer/service/gpu_switches.h" |
| 20 #include "gpu/command_buffer/service/mailbox_manager.h" | 20 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 21 #include "gpu/command_buffer/service/memory_program_cache.h" | 21 #include "gpu/command_buffer/service/memory_program_cache.h" |
| 22 #include "gpu/command_buffer/service/shader_translator_cache.h" | 22 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 23 #include "gpu/command_buffer/service/sync_point_manager.h" | 23 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 24 #include "ipc/message_filter.h" | 24 #include "ipc/message_filter.h" |
| 25 #include "ui/gl/gl_bindings.h" | 25 #include "ui/gl/gl_bindings.h" |
| 26 #include "ui/gl/gl_share_group.h" | 26 #include "ui/gl/gl_share_group.h" |
| 27 #if defined(USE_OZONE) | |
| 28 #include "ui/ozone/public/gpu_platform_support.h" | |
| 29 #include "ui/ozone/public/ozone_platform.h" | |
| 30 #endif | |
| 31 | 27 |
| 32 namespace content { | 28 namespace content { |
| 33 | 29 |
| 34 GpuChannelManager::GpuChannelManager( | 30 GpuChannelManager::GpuChannelManager( |
| 35 MessageRouter* router, | 31 MessageRouter* router, |
| 36 GpuWatchdog* watchdog, | 32 GpuWatchdog* watchdog, |
| 37 base::SingleThreadTaskRunner* io_task_runner, | 33 base::SingleThreadTaskRunner* io_task_runner, |
| 38 base::WaitableEvent* shutdown_event, | 34 base::WaitableEvent* shutdown_event, |
| 39 IPC::SyncChannel* channel, | 35 IPC::SyncChannel* channel, |
| 40 IPC::AttachmentBroker* broker, | 36 IPC::AttachmentBroker* broker, |
| 41 gpu::SyncPointManager* sync_point_manager, | 37 gpu::SyncPointManager* sync_point_manager, |
| 42 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 38 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
| 43 : io_task_runner_(io_task_runner), | 39 : io_task_runner_(io_task_runner), |
| 44 shutdown_event_(shutdown_event), | 40 shutdown_event_(shutdown_event), |
| 45 router_(router), | 41 router_(router), |
| 46 gpu_memory_manager_( | 42 gpu_memory_manager_( |
| 47 this, | 43 this, |
| 48 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 44 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
| 49 watchdog_(watchdog), | 45 watchdog_(watchdog), |
| 50 sync_point_manager_(sync_point_manager), | 46 sync_point_manager_(sync_point_manager), |
| 51 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 47 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 52 channel_(channel), | 48 channel_(channel), |
| 53 relinquish_resources_pending_(false), | |
| 54 attachment_broker_(broker), | 49 attachment_broker_(broker), |
| 55 weak_factory_(this) { | 50 weak_factory_(this) { |
| 56 DCHECK(router_); | 51 DCHECK(router_); |
| 57 DCHECK(io_task_runner); | 52 DCHECK(io_task_runner); |
| 58 DCHECK(shutdown_event); | 53 DCHECK(shutdown_event); |
| 59 } | 54 } |
| 60 | 55 |
| 61 GpuChannelManager::~GpuChannelManager() { | 56 GpuChannelManager::~GpuChannelManager() { |
| 62 gpu_channels_.clear(); | 57 gpu_channels_.clear(); |
| 63 if (default_offscreen_surface_.get()) { | 58 if (default_offscreen_surface_.get()) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 80 gpu::gles2::ShaderTranslatorCache* | 75 gpu::gles2::ShaderTranslatorCache* |
| 81 GpuChannelManager::shader_translator_cache() { | 76 GpuChannelManager::shader_translator_cache() { |
| 82 if (!shader_translator_cache_.get()) | 77 if (!shader_translator_cache_.get()) |
| 83 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; | 78 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; |
| 84 return shader_translator_cache_.get(); | 79 return shader_translator_cache_.get(); |
| 85 } | 80 } |
| 86 | 81 |
| 87 void GpuChannelManager::RemoveChannel(int client_id) { | 82 void GpuChannelManager::RemoveChannel(int client_id) { |
| 88 Send(new GpuHostMsg_DestroyChannel(client_id)); | 83 Send(new GpuHostMsg_DestroyChannel(client_id)); |
| 89 gpu_channels_.erase(client_id); | 84 gpu_channels_.erase(client_id); |
| 90 CheckRelinquishGpuResources(); | |
| 91 } | 85 } |
| 92 | 86 |
| 93 int GpuChannelManager::GenerateRouteID() { | 87 int GpuChannelManager::GenerateRouteID() { |
| 94 static int last_id = 0; | 88 static int last_id = 0; |
| 95 return ++last_id; | 89 return ++last_id; |
| 96 } | 90 } |
| 97 | 91 |
| 98 void GpuChannelManager::AddRoute(int32 routing_id, IPC::Listener* listener) { | 92 void GpuChannelManager::AddRoute(int32 routing_id, IPC::Listener* listener) { |
| 99 router_->AddRoute(routing_id, listener); | 93 router_->AddRoute(routing_id, listener); |
| 100 } | 94 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 113 | 107 |
| 114 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 108 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
| 115 bool handled = true; | 109 bool handled = true; |
| 116 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | 110 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) |
| 117 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 111 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
| 118 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 112 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
| 119 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 113 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
| 120 OnCreateViewCommandBuffer) | 114 OnCreateViewCommandBuffer) |
| 121 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | 115 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) |
| 122 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 116 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
| 123 IPC_MESSAGE_HANDLER(GpuMsg_RelinquishResources, OnRelinquishResources) | 117 IPC_MESSAGE_HANDLER(GpuMsg_Finalize, OnFinalize) |
| 124 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState) | 118 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState) |
| 125 IPC_MESSAGE_UNHANDLED(handled = false) | 119 IPC_MESSAGE_UNHANDLED(handled = false) |
| 126 IPC_END_MESSAGE_MAP() | 120 IPC_END_MESSAGE_MAP() |
| 127 return handled; | 121 return handled; |
| 128 } | 122 } |
| 129 | 123 |
| 130 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } | 124 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } |
| 131 | 125 |
| 132 void GpuChannelManager::OnEstablishChannel(int client_id, | 126 void GpuChannelManager::OnEstablishChannel(int client_id, |
| 133 bool share_context, | 127 bool share_context, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 | 162 |
| 169 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); | 163 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); |
| 170 } | 164 } |
| 171 | 165 |
| 172 void GpuChannelManager::OnCloseChannel( | 166 void GpuChannelManager::OnCloseChannel( |
| 173 const IPC::ChannelHandle& channel_handle) { | 167 const IPC::ChannelHandle& channel_handle) { |
| 174 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 168 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
| 175 iter != gpu_channels_.end(); ++iter) { | 169 iter != gpu_channels_.end(); ++iter) { |
| 176 if (iter->second->GetChannelName() == channel_handle.name) { | 170 if (iter->second->GetChannelName() == channel_handle.name) { |
| 177 gpu_channels_.erase(iter); | 171 gpu_channels_.erase(iter); |
| 178 CheckRelinquishGpuResources(); | |
| 179 return; | 172 return; |
| 180 } | 173 } |
| 181 } | 174 } |
| 182 } | 175 } |
| 183 | 176 |
| 184 void GpuChannelManager::OnCreateViewCommandBuffer( | 177 void GpuChannelManager::OnCreateViewCommandBuffer( |
| 185 const gfx::GLSurfaceHandle& window, | 178 const gfx::GLSurfaceHandle& window, |
| 186 int32 surface_id, | 179 int32 surface_id, |
| 187 int32 client_id, | 180 int32 client_id, |
| 188 const GPUCreateCommandBufferConfig& init_params, | 181 const GPUCreateCommandBufferConfig& init_params, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 iter != gpu_channels_.end(); ++iter) { | 261 iter != gpu_channels_.end(); ++iter) { |
| 269 iter->second->MarkAllContextsLost(); | 262 iter->second->MarkAllContextsLost(); |
| 270 } | 263 } |
| 271 base::ThreadTaskRunnerHandle::Get()->PostTask( | 264 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 272 FROM_HERE, base::Bind(&GpuChannelManager::OnLoseAllContexts, | 265 FROM_HERE, base::Bind(&GpuChannelManager::OnLoseAllContexts, |
| 273 weak_factory_.GetWeakPtr())); | 266 weak_factory_.GetWeakPtr())); |
| 274 } | 267 } |
| 275 | 268 |
| 276 void GpuChannelManager::OnLoseAllContexts() { | 269 void GpuChannelManager::OnLoseAllContexts() { |
| 277 gpu_channels_.clear(); | 270 gpu_channels_.clear(); |
| 278 CheckRelinquishGpuResources(); | |
| 279 } | 271 } |
| 280 | 272 |
| 281 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 273 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
| 282 if (!default_offscreen_surface_.get()) { | 274 if (!default_offscreen_surface_.get()) { |
| 283 default_offscreen_surface_ = | 275 default_offscreen_surface_ = |
| 284 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 276 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
| 285 } | 277 } |
| 286 return default_offscreen_surface_.get(); | 278 return default_offscreen_surface_.get(); |
| 287 } | 279 } |
| 288 | 280 |
| 289 void GpuChannelManager::OnRelinquishResources() { | 281 void GpuChannelManager::OnFinalize() { |
| 290 relinquish_resources_pending_ = true; | 282 // Quit the GPU process |
| 291 CheckRelinquishGpuResources(); | 283 base::MessageLoop::current()->Quit(); |
|
halliwell
2015/07/25 17:00:38
Question: are there any circumstances in which the
| |
| 292 } | |
| 293 | |
| 294 void GpuChannelManager::CheckRelinquishGpuResources() { | |
| 295 if (relinquish_resources_pending_ && gpu_channels_.size() <= 1) { | |
| 296 relinquish_resources_pending_ = false; | |
| 297 if (default_offscreen_surface_.get()) { | |
| 298 default_offscreen_surface_->DestroyAndTerminateDisplay(); | |
| 299 default_offscreen_surface_ = NULL; | |
| 300 } | |
| 301 #if defined(USE_OZONE) | |
| 302 ui::OzonePlatform::GetInstance() | |
| 303 ->GetGpuPlatformSupport() | |
| 304 ->RelinquishGpuResources( | |
| 305 base::Bind(&GpuChannelManager::OnResourcesRelinquished, | |
| 306 weak_factory_.GetWeakPtr())); | |
| 307 #else | |
| 308 OnResourcesRelinquished(); | |
| 309 #endif | |
| 310 } | |
| 311 } | |
| 312 | |
| 313 void GpuChannelManager::OnResourcesRelinquished() { | |
| 314 Send(new GpuHostMsg_ResourcesRelinquished()); | |
| 315 } | 284 } |
| 316 | 285 |
| 317 } // namespace content | 286 } // namespace content |
| OLD | NEW |