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 "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/gpu/sync_point_manager.h" | 13 #include "content/common/gpu/sync_point_manager.h" |
| 14 #include "content/common/message_router.h" | 14 #include "content/common/message_router.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.h" | 17 #include "gpu/command_buffer/service/mailbox_manager.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 "ipc/message_filter.h" | |
| 20 #include "ui/gl/gl_bindings.h" | 21 #include "ui/gl/gl_bindings.h" |
| 21 #include "ui/gl/gl_share_group.h" | 22 #include "ui/gl/gl_share_group.h" |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 GpuChannelManager::GpuMemoryBufferOperation::GpuMemoryBufferOperation( | 26 namespace { |
| 26 int32 sync_point, | |
| 27 base::Closure callback) | |
| 28 : sync_point(sync_point), callback(callback) { | |
| 29 } | |
| 30 | 27 |
| 31 GpuChannelManager::GpuMemoryBufferOperation::~GpuMemoryBufferOperation() { | 28 class GpuChannelManagerMessageFilter : public IPC::MessageFilter { |
|
reveman
2014/09/04 19:43:31
I would much prefer if this "allocation on IO thre
alexst (slow to review)
2014/09/04 21:14:47
I originally started writing these as two separate
reveman
2014/09/04 22:37:24
Ok, makes sense. You can include it in this patch
| |
| 29 public: | |
| 30 GpuChannelManagerMessageFilter( | |
| 31 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | |
| 32 : sender_(NULL), gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {} | |
| 33 | |
| 34 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE { | |
| 35 DCHECK(!sender_); | |
| 36 sender_ = sender; | |
| 37 } | |
| 38 | |
| 39 virtual void OnFilterRemoved() OVERRIDE { | |
| 40 DCHECK(sender_); | |
| 41 sender_ = NULL; | |
| 42 } | |
| 43 | |
| 44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | |
| 45 DCHECK(sender_); | |
| 46 bool handled = true; | |
| 47 IPC_BEGIN_MESSAGE_MAP(GpuChannelManagerMessageFilter, message) | |
| 48 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | |
| 49 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 50 IPC_END_MESSAGE_MAP() | |
| 51 return handled; | |
| 52 } | |
| 53 | |
| 54 protected: | |
| 55 virtual ~GpuChannelManagerMessageFilter() {} | |
| 56 | |
| 57 void OnCreateGpuMemoryBuffer(const gfx::GpuMemoryBufferHandle& handle, | |
| 58 const gfx::Size& size, | |
| 59 unsigned internalformat, | |
| 60 unsigned usage) { | |
| 61 TRACE_EVENT2("gpu", | |
| 62 "GpuChannelManagerMessageFilter::OnCreateGpuMemoryBuffer", | |
| 63 "primary_id", | |
| 64 handle.global_id.primary_id, | |
| 65 "secondary_id", | |
| 66 handle.global_id.secondary_id); | |
| 67 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated( | |
| 68 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
| 69 handle, size, internalformat, usage))); | |
| 70 } | |
| 71 | |
| 72 IPC::Sender* sender_; | |
| 73 GpuMemoryBufferFactory* gpu_memory_buffer_factory_; | |
| 74 }; | |
|
reveman
2014/09/04 19:43:31
style nit: blank line after this
alexst (slow to review)
2014/09/04 21:14:47
Done.
| |
| 32 } | 75 } |
| 33 | 76 |
| 34 GpuChannelManager::GpuChannelManager(MessageRouter* router, | 77 GpuChannelManager::GpuChannelManager(MessageRouter* router, |
| 35 GpuWatchdog* watchdog, | 78 GpuWatchdog* watchdog, |
| 36 base::MessageLoopProxy* io_message_loop, | 79 base::MessageLoopProxy* io_message_loop, |
| 37 base::WaitableEvent* shutdown_event) | 80 base::WaitableEvent* shutdown_event, |
| 81 IPC::SyncChannel* channel) | |
| 38 : weak_factory_(this), | 82 : weak_factory_(this), |
| 39 io_message_loop_(io_message_loop), | 83 io_message_loop_(io_message_loop), |
| 40 shutdown_event_(shutdown_event), | 84 shutdown_event_(shutdown_event), |
| 41 router_(router), | 85 router_(router), |
| 42 gpu_memory_manager_( | 86 gpu_memory_manager_( |
| 43 this, | 87 this, |
| 44 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 88 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
| 45 watchdog_(watchdog), | 89 watchdog_(watchdog), |
| 46 sync_point_manager_(new SyncPointManager), | 90 sync_point_manager_(new SyncPointManager), |
| 47 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()) { | 91 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()), |
| 92 channel_(channel), | |
| 93 filter_(new GpuChannelManagerMessageFilter( | |
| 94 gpu_memory_buffer_factory_.get())) { | |
| 48 DCHECK(router_); | 95 DCHECK(router_); |
| 49 DCHECK(io_message_loop); | 96 DCHECK(io_message_loop); |
| 50 DCHECK(shutdown_event); | 97 DCHECK(shutdown_event); |
| 98 channel_->AddFilter(filter_.get()); | |
| 51 } | 99 } |
| 52 | 100 |
| 53 GpuChannelManager::~GpuChannelManager() { | 101 GpuChannelManager::~GpuChannelManager() { |
| 54 gpu_channels_.clear(); | 102 gpu_channels_.clear(); |
| 55 if (default_offscreen_surface_.get()) { | 103 if (default_offscreen_surface_.get()) { |
| 56 default_offscreen_surface_->Destroy(); | 104 default_offscreen_surface_->Destroy(); |
| 57 default_offscreen_surface_ = NULL; | 105 default_offscreen_surface_ = NULL; |
| 58 } | 106 } |
| 59 DCHECK(gpu_memory_buffer_operations_.empty()); | |
| 60 } | 107 } |
| 61 | 108 |
| 62 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { | 109 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { |
| 63 if (!program_cache_.get() && | 110 if (!program_cache_.get() && |
| 64 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || | 111 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || |
| 65 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && | 112 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && |
| 66 !CommandLine::ForCurrentProcess()->HasSwitch( | 113 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 67 switches::kDisableGpuProgramCache)) { | 114 switches::kDisableGpuProgramCache)) { |
| 68 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); | 115 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); |
| 69 } | 116 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 return iter->second; | 150 return iter->second; |
| 104 } | 151 } |
| 105 | 152 |
| 106 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 153 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
| 107 bool handled = true; | 154 bool handled = true; |
| 108 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | 155 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) |
| 109 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 156 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
| 110 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 157 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
| 111 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 158 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
| 112 OnCreateViewCommandBuffer) | 159 OnCreateViewCommandBuffer) |
| 113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | |
| 114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | 160 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) |
| 115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 161 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
| 116 IPC_MESSAGE_UNHANDLED(handled = false) | 162 IPC_MESSAGE_UNHANDLED(handled = false) |
| 117 IPC_END_MESSAGE_MAP() | 163 IPC_END_MESSAGE_MAP() |
| 118 return handled; | 164 return handled; |
| 119 } | 165 } |
| 120 | 166 |
| 121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } | 167 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } |
| 122 | 168 |
| 123 void GpuChannelManager::OnEstablishChannel(int client_id, | 169 void GpuChannelManager::OnEstablishChannel(int client_id, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 CreateCommandBufferResult result = CREATE_COMMAND_BUFFER_FAILED; | 227 CreateCommandBufferResult result = CREATE_COMMAND_BUFFER_FAILED; |
| 182 | 228 |
| 183 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | 229 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
| 184 if (iter != gpu_channels_.end()) { | 230 if (iter != gpu_channels_.end()) { |
| 185 result = iter->second->CreateViewCommandBuffer( | 231 result = iter->second->CreateViewCommandBuffer( |
| 186 window, surface_id, init_params, route_id); | 232 window, surface_id, init_params, route_id); |
| 187 } | 233 } |
| 188 | 234 |
| 189 Send(new GpuHostMsg_CommandBufferCreated(result)); | 235 Send(new GpuHostMsg_CommandBufferCreated(result)); |
| 190 } | 236 } |
| 191 | 237 void GpuChannelManager::DestroyGpuMemoryBuffer( |
| 192 void GpuChannelManager::CreateGpuMemoryBuffer( | 238 const gfx::GpuMemoryBufferHandle& handle) { |
| 193 const gfx::GpuMemoryBufferHandle& handle, | 239 io_message_loop_->PostTask( |
| 194 const gfx::Size& size, | 240 FROM_HERE, |
| 195 unsigned internalformat, | 241 base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, |
| 196 unsigned usage) { | 242 base::Unretained(this), |
| 197 Send(new GpuHostMsg_GpuMemoryBufferCreated( | 243 handle)); |
| 198 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
| 199 handle, size, internalformat, usage))); | |
| 200 } | 244 } |
| 201 | 245 |
| 202 void GpuChannelManager::OnCreateGpuMemoryBuffer( | 246 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( |
| 203 const gfx::GpuMemoryBufferHandle& handle, | |
| 204 const gfx::Size& size, | |
| 205 unsigned internalformat, | |
| 206 unsigned usage) { | |
| 207 if (gpu_memory_buffer_operations_.empty()) { | |
| 208 CreateGpuMemoryBuffer(handle, size, internalformat, usage); | |
| 209 } else { | |
| 210 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation( | |
| 211 0, | |
| 212 base::Bind(&GpuChannelManager::CreateGpuMemoryBuffer, | |
| 213 base::Unretained(this), | |
| 214 handle, | |
| 215 size, | |
| 216 internalformat, | |
| 217 usage))); | |
| 218 } | |
| 219 } | |
| 220 | |
| 221 void GpuChannelManager::DestroyGpuMemoryBuffer( | |
| 222 const gfx::GpuMemoryBufferHandle& handle) { | 247 const gfx::GpuMemoryBufferHandle& handle) { |
| 223 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); | 248 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); |
| 224 } | 249 } |
| 225 | 250 |
| 226 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 251 void GpuChannelManager::OnDestroyGpuMemoryBuffer( |
| 227 const gfx::GpuMemoryBufferHandle& handle, | 252 const gfx::GpuMemoryBufferHandle& handle, |
| 228 int32 sync_point) { | 253 int32 sync_point) { |
| 229 if (!sync_point && gpu_memory_buffer_operations_.empty()) { | 254 if (!sync_point) { |
| 230 DestroyGpuMemoryBuffer(handle); | 255 DestroyGpuMemoryBuffer(handle); |
| 231 } else { | 256 } else { |
| 232 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation( | 257 sync_point_manager()->AddSyncPointCallback( |
| 233 sync_point, | 258 sync_point, |
| 234 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, | 259 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, |
| 235 base::Unretained(this), | 260 base::Unretained(this), |
| 236 handle))); | 261 handle)); |
| 237 if (sync_point) { | |
| 238 sync_point_manager()->AddSyncPointCallback( | |
| 239 sync_point, | |
| 240 base::Bind( | |
| 241 &GpuChannelManager::OnDestroyGpuMemoryBufferSyncPointRetired, | |
| 242 base::Unretained(this), | |
| 243 gpu_memory_buffer_operations_.back())); | |
| 244 } | |
| 245 } | 262 } |
| 246 } | 263 } |
| 247 | 264 |
| 248 void GpuChannelManager::OnDestroyGpuMemoryBufferSyncPointRetired( | |
| 249 GpuMemoryBufferOperation* gpu_memory_buffer_operation) { | |
| 250 // Mark operation as no longer having a pending sync point. | |
| 251 gpu_memory_buffer_operation->sync_point = 0; | |
| 252 | |
| 253 // De-queue operations until we reach a pending sync point. | |
| 254 while (!gpu_memory_buffer_operations_.empty()) { | |
| 255 // Check if operation has a pending sync point. | |
| 256 if (gpu_memory_buffer_operations_.front()->sync_point) | |
| 257 break; | |
| 258 | |
| 259 gpu_memory_buffer_operations_.front()->callback.Run(); | |
| 260 delete gpu_memory_buffer_operations_.front(); | |
| 261 gpu_memory_buffer_operations_.pop_front(); | |
| 262 } | |
| 263 } | |
| 264 | |
| 265 void GpuChannelManager::OnLoadedShader(std::string program_proto) { | 265 void GpuChannelManager::OnLoadedShader(std::string program_proto) { |
| 266 if (program_cache()) | 266 if (program_cache()) |
| 267 program_cache()->LoadProgram(program_proto); | 267 program_cache()->LoadProgram(program_proto); |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool GpuChannelManager::HandleMessagesScheduled() { | 270 bool GpuChannelManager::HandleMessagesScheduled() { |
| 271 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 271 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
| 272 iter != gpu_channels_.end(); ++iter) { | 272 iter != gpu_channels_.end(); ++iter) { |
| 273 if (iter->second->handle_messages_scheduled()) | 273 if (iter->second->handle_messages_scheduled()) |
| 274 return true; | 274 return true; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 303 | 303 |
| 304 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 304 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
| 305 if (!default_offscreen_surface_.get()) { | 305 if (!default_offscreen_surface_.get()) { |
| 306 default_offscreen_surface_ = | 306 default_offscreen_surface_ = |
| 307 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 307 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
| 308 } | 308 } |
| 309 return default_offscreen_surface_.get(); | 309 return default_offscreen_surface_.get(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 } // namespace content | 312 } // namespace content |
| OLD | NEW |