| 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 "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
| 10 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 10 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 11 #include "content/common/gpu/gpu_memory_manager.h" | 11 #include "content/common/gpu/gpu_memory_manager.h" |
| 12 #include "content/common/gpu/gpu_messages.h" | 12 #include "content/common/gpu/gpu_messages.h" |
| 13 #include "content/common/message_router.h" | 13 #include "content/common/message_router.h" |
| 14 #include "gpu/command_buffer/common/value_state.h" | 14 #include "gpu/command_buffer/common/value_state.h" |
| 15 #include "gpu/command_buffer/service/feature_info.h" | 15 #include "gpu/command_buffer/service/feature_info.h" |
| 16 #include "gpu/command_buffer/service/gpu_switches.h" | 16 #include "gpu/command_buffer/service/gpu_switches.h" |
| 17 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 17 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
| 18 #include "gpu/command_buffer/service/memory_program_cache.h" | 18 #include "gpu/command_buffer/service/memory_program_cache.h" |
| 19 #include "gpu/command_buffer/service/shader_translator_cache.h" | 19 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 20 #include "gpu/command_buffer/service/sync_point_manager.h" | 20 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 21 #include "ipc/message_filter.h" | |
| 22 #include "ui/gl/gl_bindings.h" | 21 #include "ui/gl/gl_bindings.h" |
| 23 #include "ui/gl/gl_share_group.h" | 22 #include "ui/gl/gl_share_group.h" |
| 24 #if defined(USE_OZONE) | 23 #if defined(USE_OZONE) |
| 25 #include "ui/ozone/public/gpu_platform_support.h" | 24 #include "ui/ozone/public/gpu_platform_support.h" |
| 26 #include "ui/ozone/public/ozone_platform.h" | 25 #include "ui/ozone/public/ozone_platform.h" |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 namespace content { | 28 namespace content { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 class GpuChannelManagerMessageFilter : public IPC::MessageFilter { | |
| 34 public: | |
| 35 GpuChannelManagerMessageFilter( | |
| 36 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | |
| 37 : sender_(NULL), gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {} | |
| 38 | |
| 39 void OnFilterAdded(IPC::Sender* sender) override { | |
| 40 DCHECK(!sender_); | |
| 41 sender_ = sender; | |
| 42 } | |
| 43 | |
| 44 void OnFilterRemoved() override { | |
| 45 DCHECK(sender_); | |
| 46 sender_ = NULL; | |
| 47 } | |
| 48 | |
| 49 bool OnMessageReceived(const IPC::Message& message) override { | |
| 50 DCHECK(sender_); | |
| 51 bool handled = true; | |
| 52 IPC_BEGIN_MESSAGE_MAP(GpuChannelManagerMessageFilter, message) | |
| 53 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | |
| 54 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 55 IPC_END_MESSAGE_MAP() | |
| 56 return handled; | |
| 57 } | |
| 58 | |
| 59 protected: | |
| 60 ~GpuChannelManagerMessageFilter() override {} | |
| 61 | |
| 62 void OnCreateGpuMemoryBuffer( | |
| 63 const GpuMsg_CreateGpuMemoryBuffer_Params& params) { | |
| 64 TRACE_EVENT2("gpu", | |
| 65 "GpuChannelManagerMessageFilter::OnCreateGpuMemoryBuffer", | |
| 66 "id", params.id, "client_id", params.client_id); | |
| 67 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated( | |
| 68 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
| 69 params.id, params.size, params.format, params.usage, | |
| 70 params.client_id, params.surface_handle))); | |
| 71 } | |
| 72 | |
| 73 IPC::Sender* sender_; | |
| 74 GpuMemoryBufferFactory* gpu_memory_buffer_factory_; | |
| 75 }; | |
| 76 | |
| 77 gfx::GpuMemoryBufferType GetGpuMemoryBufferFactoryType() { | 32 gfx::GpuMemoryBufferType GetGpuMemoryBufferFactoryType() { |
| 78 std::vector<gfx::GpuMemoryBufferType> supported_types; | 33 std::vector<gfx::GpuMemoryBufferType> supported_types; |
| 79 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 34 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
| 80 DCHECK(!supported_types.empty()); | 35 DCHECK(!supported_types.empty()); |
| 81 return supported_types[0]; | 36 return supported_types[0]; |
| 82 } | 37 } |
| 83 | 38 |
| 84 } // namespace | 39 } // namespace |
| 85 | 40 |
| 86 GpuChannelManager::GpuChannelManager(MessageRouter* router, | 41 GpuChannelManager::GpuChannelManager(MessageRouter* router, |
| 87 GpuWatchdog* watchdog, | 42 GpuWatchdog* watchdog, |
| 88 base::MessageLoopProxy* io_message_loop, | 43 base::MessageLoopProxy* io_message_loop, |
| 89 base::WaitableEvent* shutdown_event, | 44 base::WaitableEvent* shutdown_event, |
| 90 IPC::SyncChannel* channel) | 45 IPC::SyncChannel* channel) |
| 91 : io_message_loop_(io_message_loop), | 46 : io_message_loop_(io_message_loop), |
| 92 shutdown_event_(shutdown_event), | 47 shutdown_event_(shutdown_event), |
| 93 router_(router), | 48 router_(router), |
| 94 gpu_memory_manager_( | 49 gpu_memory_manager_( |
| 95 this, | 50 this, |
| 96 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 51 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
| 97 watchdog_(watchdog), | 52 watchdog_(watchdog), |
| 98 sync_point_manager_(gpu::SyncPointManager::Create(false)), | 53 sync_point_manager_(gpu::SyncPointManager::Create(false)), |
| 99 gpu_memory_buffer_factory_( | 54 gpu_memory_buffer_factory_( |
| 100 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), | 55 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), |
| 101 channel_(channel), | 56 channel_(channel), |
| 102 filter_( | |
| 103 new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), | |
| 104 relinquish_resources_pending_(false), | 57 relinquish_resources_pending_(false), |
| 105 weak_factory_(this) { | 58 weak_factory_(this) { |
| 106 DCHECK(router_); | 59 DCHECK(router_); |
| 107 DCHECK(io_message_loop); | 60 DCHECK(io_message_loop); |
| 108 DCHECK(shutdown_event); | 61 DCHECK(shutdown_event); |
| 109 channel_->AddFilter(filter_.get()); | |
| 110 } | 62 } |
| 111 | 63 |
| 112 GpuChannelManager::~GpuChannelManager() { | 64 GpuChannelManager::~GpuChannelManager() { |
| 113 gpu_channels_.clear(); | 65 gpu_channels_.clear(); |
| 114 if (default_offscreen_surface_.get()) { | 66 if (default_offscreen_surface_.get()) { |
| 115 default_offscreen_surface_->Destroy(); | 67 default_offscreen_surface_->Destroy(); |
| 116 default_offscreen_surface_ = NULL; | 68 default_offscreen_surface_ = NULL; |
| 117 } | 69 } |
| 118 } | 70 } |
| 119 | 71 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return iter->second; | 114 return iter->second; |
| 163 } | 115 } |
| 164 | 116 |
| 165 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 117 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
| 166 bool handled = true; | 118 bool handled = true; |
| 167 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | 119 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) |
| 168 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 120 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
| 169 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 121 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
| 170 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 122 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
| 171 OnCreateViewCommandBuffer) | 123 OnCreateViewCommandBuffer) |
| 124 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) |
| 172 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | 125 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) |
| 173 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 126 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
| 174 IPC_MESSAGE_HANDLER(GpuMsg_RelinquishResources, OnRelinquishResources) | 127 IPC_MESSAGE_HANDLER(GpuMsg_RelinquishResources, OnRelinquishResources) |
| 175 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState) | 128 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState) |
| 176 IPC_MESSAGE_UNHANDLED(handled = false) | 129 IPC_MESSAGE_UNHANDLED(handled = false) |
| 177 IPC_END_MESSAGE_MAP() | 130 IPC_END_MESSAGE_MAP() |
| 178 return handled; | 131 return handled; |
| 179 } | 132 } |
| 180 | 133 |
| 181 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } | 134 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 196 |
| 244 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | 197 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
| 245 if (iter != gpu_channels_.end()) { | 198 if (iter != gpu_channels_.end()) { |
| 246 result = iter->second->CreateViewCommandBuffer( | 199 result = iter->second->CreateViewCommandBuffer( |
| 247 window, surface_id, init_params, route_id); | 200 window, surface_id, init_params, route_id); |
| 248 } | 201 } |
| 249 | 202 |
| 250 Send(new GpuHostMsg_CommandBufferCreated(result)); | 203 Send(new GpuHostMsg_CommandBufferCreated(result)); |
| 251 } | 204 } |
| 252 | 205 |
| 206 void GpuChannelManager::OnCreateGpuMemoryBuffer( |
| 207 const GpuMsg_CreateGpuMemoryBuffer_Params& params) { |
| 208 TRACE_EVENT2("gpu", |
| 209 "GpuChannelManager::OnCreateGpuMemoryBuffer", |
| 210 "id", params.id, "client_id", params.client_id); |
| 211 Send(new GpuHostMsg_GpuMemoryBufferCreated( |
| 212 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
| 213 params.id, params.size, params.format, params.usage, |
| 214 params.client_id, params.surface_handle))); |
| 215 } |
| 216 |
| 253 void GpuChannelManager::DestroyGpuMemoryBuffer( | 217 void GpuChannelManager::DestroyGpuMemoryBuffer( |
| 254 gfx::GpuMemoryBufferId id, | 218 gfx::GpuMemoryBufferId id, |
| 255 int client_id) { | 219 int client_id) { |
| 256 io_message_loop_->PostTask( | |
| 257 FROM_HERE, | |
| 258 base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, | |
| 259 base::Unretained(this), | |
| 260 id, | |
| 261 client_id)); | |
| 262 } | |
| 263 | |
| 264 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( | |
| 265 gfx::GpuMemoryBufferId id, | |
| 266 int client_id) { | |
| 267 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); | 220 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); |
| 268 } | 221 } |
| 269 | 222 |
| 270 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 223 void GpuChannelManager::OnDestroyGpuMemoryBuffer( |
| 271 gfx::GpuMemoryBufferId id, | 224 gfx::GpuMemoryBufferId id, |
| 272 int client_id, | 225 int client_id, |
| 273 int32 sync_point) { | 226 int32 sync_point) { |
| 274 if (!sync_point) { | 227 if (!sync_point) { |
| 275 DestroyGpuMemoryBuffer(id, client_id); | 228 DestroyGpuMemoryBuffer(id, client_id); |
| 276 } else { | 229 } else { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 OnResourcesRelinquished(); | 316 OnResourcesRelinquished(); |
| 364 #endif | 317 #endif |
| 365 } | 318 } |
| 366 } | 319 } |
| 367 | 320 |
| 368 void GpuChannelManager::OnResourcesRelinquished() { | 321 void GpuChannelManager::OnResourcesRelinquished() { |
| 369 Send(new GpuHostMsg_ResourcesRelinquished()); | 322 Send(new GpuHostMsg_ResourcesRelinquished()); |
| 370 } | 323 } |
| 371 | 324 |
| 372 } // namespace content | 325 } // namespace content |
| OLD | NEW |