| 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_manager.h" | 11 #include "content/common/gpu/gpu_memory_manager.h" |
| 11 #include "content/common/gpu/gpu_messages.h" | 12 #include "content/common/gpu/gpu_messages.h" |
| 12 #include "content/common/gpu/sync_point_manager.h" | 13 #include "content/common/gpu/sync_point_manager.h" |
| 13 #include "content/common/message_router.h" | 14 #include "content/common/message_router.h" |
| 14 #include "gpu/command_buffer/service/feature_info.h" | 15 #include "gpu/command_buffer/service/feature_info.h" |
| 15 #include "gpu/command_buffer/service/gpu_switches.h" | 16 #include "gpu/command_buffer/service/gpu_switches.h" |
| 16 #include "gpu/command_buffer/service/mailbox_manager.h" | 17 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 17 #include "gpu/command_buffer/service/memory_program_cache.h" | 18 #include "gpu/command_buffer/service/memory_program_cache.h" |
| 18 #include "gpu/command_buffer/service/shader_translator_cache.h" | 19 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 19 #include "ui/gl/gl_bindings.h" | 20 #include "ui/gl/gl_bindings.h" |
| 20 #include "ui/gl/gl_share_group.h" | 21 #include "ui/gl/gl_share_group.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 GpuChannelManager::ImageOperation::ImageOperation( | 25 GpuChannelManager::GpuMemoryBufferOperation::GpuMemoryBufferOperation( |
| 25 int32 sync_point, base::Closure callback) | 26 int32 sync_point, |
| 26 : sync_point(sync_point), | 27 base::Closure callback) |
| 27 callback(callback) { | 28 : sync_point(sync_point), callback(callback) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 GpuChannelManager::ImageOperation::~ImageOperation() { | 31 GpuChannelManager::GpuMemoryBufferOperation::~GpuMemoryBufferOperation() { |
| 31 } | 32 } |
| 32 | 33 |
| 33 GpuChannelManager::GpuChannelManager(MessageRouter* router, | 34 GpuChannelManager::GpuChannelManager(MessageRouter* router, |
| 34 GpuWatchdog* watchdog, | 35 GpuWatchdog* watchdog, |
| 35 base::MessageLoopProxy* io_message_loop, | 36 base::MessageLoopProxy* io_message_loop, |
| 36 base::WaitableEvent* shutdown_event) | 37 base::WaitableEvent* shutdown_event) |
| 37 : weak_factory_(this), | 38 : weak_factory_(this), |
| 38 io_message_loop_(io_message_loop), | 39 io_message_loop_(io_message_loop), |
| 39 shutdown_event_(shutdown_event), | 40 shutdown_event_(shutdown_event), |
| 40 router_(router), | 41 router_(router), |
| 41 gpu_memory_manager_( | 42 gpu_memory_manager_( |
| 42 this, | 43 this, |
| 43 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 44 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
| 44 watchdog_(watchdog), | 45 watchdog_(watchdog), |
| 45 sync_point_manager_(new SyncPointManager) { | 46 sync_point_manager_(new SyncPointManager), |
| 47 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()) { |
| 46 DCHECK(router_); | 48 DCHECK(router_); |
| 47 DCHECK(io_message_loop); | 49 DCHECK(io_message_loop); |
| 48 DCHECK(shutdown_event); | 50 DCHECK(shutdown_event); |
| 49 } | 51 } |
| 50 | 52 |
| 51 GpuChannelManager::~GpuChannelManager() { | 53 GpuChannelManager::~GpuChannelManager() { |
| 52 gpu_channels_.clear(); | 54 gpu_channels_.clear(); |
| 53 if (default_offscreen_surface_.get()) { | 55 if (default_offscreen_surface_.get()) { |
| 54 default_offscreen_surface_->Destroy(); | 56 default_offscreen_surface_->Destroy(); |
| 55 default_offscreen_surface_ = NULL; | 57 default_offscreen_surface_ = NULL; |
| 56 } | 58 } |
| 57 DCHECK(image_operations_.empty()); | 59 DCHECK(gpu_memory_buffer_operations_.empty()); |
| 58 } | 60 } |
| 59 | 61 |
| 60 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { | 62 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { |
| 61 if (!program_cache_.get() && | 63 if (!program_cache_.get() && |
| 62 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || | 64 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || |
| 63 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && | 65 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && |
| 64 !CommandLine::ForCurrentProcess()->HasSwitch( | 66 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 65 switches::kDisableGpuProgramCache)) { | 67 switches::kDisableGpuProgramCache)) { |
| 66 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); | 68 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); |
| 67 } | 69 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return iter->second; | 103 return iter->second; |
| 102 } | 104 } |
| 103 | 105 |
| 104 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 106 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
| 105 bool handled = true; | 107 bool handled = true; |
| 106 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | 108 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) |
| 107 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 109 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
| 108 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 110 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
| 109 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 111 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
| 110 OnCreateViewCommandBuffer) | 112 OnCreateViewCommandBuffer) |
| 111 IPC_MESSAGE_HANDLER(GpuMsg_CreateImage, OnCreateImage) | |
| 112 IPC_MESSAGE_HANDLER(GpuMsg_DeleteImage, OnDeleteImage) | |
| 113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | 113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) |
| 114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | 114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) |
| 115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
| 116 IPC_MESSAGE_UNHANDLED(handled = false) | 116 IPC_MESSAGE_UNHANDLED(handled = false) |
| 117 IPC_END_MESSAGE_MAP() | 117 IPC_END_MESSAGE_MAP() |
| 118 return handled; | 118 return handled; |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } | 121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } |
| 122 | 122 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | 183 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
| 184 if (iter != gpu_channels_.end()) { | 184 if (iter != gpu_channels_.end()) { |
| 185 result = iter->second->CreateViewCommandBuffer( | 185 result = iter->second->CreateViewCommandBuffer( |
| 186 window, surface_id, init_params, route_id); | 186 window, surface_id, init_params, route_id); |
| 187 } | 187 } |
| 188 | 188 |
| 189 Send(new GpuHostMsg_CommandBufferCreated(result)); | 189 Send(new GpuHostMsg_CommandBufferCreated(result)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void GpuChannelManager::CreateImage( | 192 void GpuChannelManager::CreateGpuMemoryBuffer( |
| 193 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { | 193 const gfx::GpuMemoryBufferHandle& handle, |
| 194 gfx::Size size; | 194 const gfx::Size& size, |
| 195 | 195 unsigned internalformat, |
| 196 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | 196 unsigned usage) { |
| 197 if (iter != gpu_channels_.end()) { | 197 Send(new GpuHostMsg_GpuMemoryBufferCreated( |
| 198 iter->second->CreateImage(window, image_id, &size); | 198 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
| 199 } | 199 handle, size, internalformat, usage))); |
| 200 | |
| 201 Send(new GpuHostMsg_ImageCreated(size)); | |
| 202 } | |
| 203 | |
| 204 void GpuChannelManager::OnCreateImage( | |
| 205 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { | |
| 206 DCHECK(image_id); | |
| 207 | |
| 208 if (image_operations_.empty()) { | |
| 209 CreateImage(window, client_id, image_id); | |
| 210 } else { | |
| 211 image_operations_.push_back( | |
| 212 new ImageOperation(0, base::Bind(&GpuChannelManager::CreateImage, | |
| 213 base::Unretained(this), | |
| 214 window, | |
| 215 client_id, | |
| 216 image_id))); | |
| 217 } | |
| 218 } | |
| 219 | |
| 220 void GpuChannelManager::DeleteImage(int32 client_id, int32 image_id) { | |
| 221 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | |
| 222 if (iter != gpu_channels_.end()) { | |
| 223 iter->second->DeleteImage(image_id); | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 void GpuChannelManager::OnDeleteImage( | |
| 228 int32 client_id, int32 image_id, int32 sync_point) { | |
| 229 DCHECK(image_id); | |
| 230 | |
| 231 if (!sync_point && image_operations_.empty()) { | |
| 232 DeleteImage(client_id, image_id); | |
| 233 } else { | |
| 234 image_operations_.push_back( | |
| 235 new ImageOperation(sync_point, | |
| 236 base::Bind(&GpuChannelManager::DeleteImage, | |
| 237 base::Unretained(this), | |
| 238 client_id, | |
| 239 image_id))); | |
| 240 if (sync_point) { | |
| 241 sync_point_manager()->AddSyncPointCallback( | |
| 242 sync_point, | |
| 243 base::Bind(&GpuChannelManager::OnDeleteImageSyncPointRetired, | |
| 244 base::Unretained(this), | |
| 245 image_operations_.back())); | |
| 246 } | |
| 247 } | |
| 248 } | |
| 249 | |
| 250 void GpuChannelManager::OnDeleteImageSyncPointRetired( | |
| 251 ImageOperation* image_operation) { | |
| 252 // Mark operation as no longer having a pending sync point. | |
| 253 image_operation->sync_point = 0; | |
| 254 | |
| 255 // De-queue operations until we reach a pending sync point. | |
| 256 while (!image_operations_.empty()) { | |
| 257 // Check if operation has a pending sync point. | |
| 258 if (image_operations_.front()->sync_point) | |
| 259 return; | |
| 260 | |
| 261 image_operations_.front()->callback.Run(); | |
| 262 delete image_operations_.front(); | |
| 263 image_operations_.pop_front(); | |
| 264 } | |
| 265 } | 200 } |
| 266 | 201 |
| 267 void GpuChannelManager::OnCreateGpuMemoryBuffer( | 202 void GpuChannelManager::OnCreateGpuMemoryBuffer( |
| 268 const gfx::GpuMemoryBufferHandle& handle, | 203 const gfx::GpuMemoryBufferHandle& handle, |
| 269 const gfx::Size& size, | 204 const gfx::Size& size, |
| 270 unsigned internalformat, | 205 unsigned internalformat, |
| 271 unsigned usage) { | 206 unsigned usage) { |
| 272 Send(new GpuHostMsg_GpuMemoryBufferCreated(gfx::GpuMemoryBufferHandle())); | 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) { |
| 223 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); |
| 273 } | 224 } |
| 274 | 225 |
| 275 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 226 void GpuChannelManager::OnDestroyGpuMemoryBuffer( |
| 276 const gfx::GpuMemoryBufferHandle& handle, | 227 const gfx::GpuMemoryBufferHandle& handle, |
| 277 int32 sync_point) { | 228 int32 sync_point) { |
| 229 if (!sync_point && gpu_memory_buffer_operations_.empty()) { |
| 230 DestroyGpuMemoryBuffer(handle); |
| 231 } else { |
| 232 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation( |
| 233 sync_point, |
| 234 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, |
| 235 base::Unretained(this), |
| 236 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 } |
| 246 } |
| 247 |
| 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 } |
| 278 } | 263 } |
| 279 | 264 |
| 280 void GpuChannelManager::OnLoadedShader(std::string program_proto) { | 265 void GpuChannelManager::OnLoadedShader(std::string program_proto) { |
| 281 if (program_cache()) | 266 if (program_cache()) |
| 282 program_cache()->LoadProgram(program_proto); | 267 program_cache()->LoadProgram(program_proto); |
| 283 } | 268 } |
| 284 | 269 |
| 285 bool GpuChannelManager::HandleMessagesScheduled() { | 270 bool GpuChannelManager::HandleMessagesScheduled() { |
| 286 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 271 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
| 287 iter != gpu_channels_.end(); ++iter) { | 272 iter != gpu_channels_.end(); ++iter) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 318 | 303 |
| 319 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 304 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
| 320 if (!default_offscreen_surface_.get()) { | 305 if (!default_offscreen_surface_.get()) { |
| 321 default_offscreen_surface_ = | 306 default_offscreen_surface_ = |
| 322 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 307 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
| 323 } | 308 } |
| 324 return default_offscreen_surface_.get(); | 309 return default_offscreen_surface_.get(); |
| 325 } | 310 } |
| 326 | 311 |
| 327 } // namespace content | 312 } // namespace content |
| OLD | NEW |