| 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" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 gpu_memory_manager_( | 94 gpu_memory_manager_( |
| 95 this, | 95 this, |
| 96 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 96 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
| 97 watchdog_(watchdog), | 97 watchdog_(watchdog), |
| 98 sync_point_manager_(new gpu::SyncPointManager), | 98 sync_point_manager_(new gpu::SyncPointManager), |
| 99 gpu_memory_buffer_factory_( | 99 gpu_memory_buffer_factory_( |
| 100 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), | 100 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), |
| 101 channel_(channel), | 101 channel_(channel), |
| 102 filter_( | 102 filter_( |
| 103 new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), | 103 new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), |
| 104 relinquish_resources_pending_(false), |
| 104 weak_factory_(this) { | 105 weak_factory_(this) { |
| 105 DCHECK(router_); | 106 DCHECK(router_); |
| 106 DCHECK(io_message_loop); | 107 DCHECK(io_message_loop); |
| 107 DCHECK(shutdown_event); | 108 DCHECK(shutdown_event); |
| 108 channel_->AddFilter(filter_.get()); | 109 channel_->AddFilter(filter_.get()); |
| 109 } | 110 } |
| 110 | 111 |
| 111 GpuChannelManager::~GpuChannelManager() { | 112 GpuChannelManager::~GpuChannelManager() { |
| 112 gpu_channels_.clear(); | 113 gpu_channels_.clear(); |
| 113 if (default_offscreen_surface_.get()) { | 114 if (default_offscreen_surface_.get()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 130 gpu::gles2::ShaderTranslatorCache* | 131 gpu::gles2::ShaderTranslatorCache* |
| 131 GpuChannelManager::shader_translator_cache() { | 132 GpuChannelManager::shader_translator_cache() { |
| 132 if (!shader_translator_cache_.get()) | 133 if (!shader_translator_cache_.get()) |
| 133 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; | 134 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; |
| 134 return shader_translator_cache_.get(); | 135 return shader_translator_cache_.get(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void GpuChannelManager::RemoveChannel(int client_id) { | 138 void GpuChannelManager::RemoveChannel(int client_id) { |
| 138 Send(new GpuHostMsg_DestroyChannel(client_id)); | 139 Send(new GpuHostMsg_DestroyChannel(client_id)); |
| 139 gpu_channels_.erase(client_id); | 140 gpu_channels_.erase(client_id); |
| 141 CheckRelinquishGpuResources(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 int GpuChannelManager::GenerateRouteID() { | 144 int GpuChannelManager::GenerateRouteID() { |
| 143 static int last_id = 0; | 145 static int last_id = 0; |
| 144 return ++last_id; | 146 return ++last_id; |
| 145 } | 147 } |
| 146 | 148 |
| 147 void GpuChannelManager::AddRoute(int32 routing_id, IPC::Listener* listener) { | 149 void GpuChannelManager::AddRoute(int32 routing_id, IPC::Listener* listener) { |
| 148 router_->AddRoute(routing_id, listener); | 150 router_->AddRoute(routing_id, listener); |
| 149 } | 151 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 219 |
| 218 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); | 220 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); |
| 219 } | 221 } |
| 220 | 222 |
| 221 void GpuChannelManager::OnCloseChannel( | 223 void GpuChannelManager::OnCloseChannel( |
| 222 const IPC::ChannelHandle& channel_handle) { | 224 const IPC::ChannelHandle& channel_handle) { |
| 223 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 225 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
| 224 iter != gpu_channels_.end(); ++iter) { | 226 iter != gpu_channels_.end(); ++iter) { |
| 225 if (iter->second->GetChannelName() == channel_handle.name) { | 227 if (iter->second->GetChannelName() == channel_handle.name) { |
| 226 gpu_channels_.erase(iter); | 228 gpu_channels_.erase(iter); |
| 229 CheckRelinquishGpuResources(); |
| 227 return; | 230 return; |
| 228 } | 231 } |
| 229 } | 232 } |
| 230 } | 233 } |
| 231 | 234 |
| 232 void GpuChannelManager::OnCreateViewCommandBuffer( | 235 void GpuChannelManager::OnCreateViewCommandBuffer( |
| 233 const gfx::GLSurfaceHandle& window, | 236 const gfx::GLSurfaceHandle& window, |
| 234 int32 surface_id, | 237 int32 surface_id, |
| 235 int32 client_id, | 238 int32 client_id, |
| 236 const GPUCreateCommandBufferConfig& init_params, | 239 const GPUCreateCommandBufferConfig& init_params, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 iter->second->MarkAllContextsLost(); | 323 iter->second->MarkAllContextsLost(); |
| 321 } | 324 } |
| 322 base::MessageLoop::current()->PostTask( | 325 base::MessageLoop::current()->PostTask( |
| 323 FROM_HERE, | 326 FROM_HERE, |
| 324 base::Bind(&GpuChannelManager::OnLoseAllContexts, | 327 base::Bind(&GpuChannelManager::OnLoseAllContexts, |
| 325 weak_factory_.GetWeakPtr())); | 328 weak_factory_.GetWeakPtr())); |
| 326 } | 329 } |
| 327 | 330 |
| 328 void GpuChannelManager::OnLoseAllContexts() { | 331 void GpuChannelManager::OnLoseAllContexts() { |
| 329 gpu_channels_.clear(); | 332 gpu_channels_.clear(); |
| 333 CheckRelinquishGpuResources(); |
| 330 } | 334 } |
| 331 | 335 |
| 332 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 336 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
| 333 if (!default_offscreen_surface_.get()) { | 337 if (!default_offscreen_surface_.get()) { |
| 334 default_offscreen_surface_ = | 338 default_offscreen_surface_ = |
| 335 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 339 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
| 336 } | 340 } |
| 337 return default_offscreen_surface_.get(); | 341 return default_offscreen_surface_.get(); |
| 338 } | 342 } |
| 339 | 343 |
| 340 void GpuChannelManager::OnRelinquishResources() { | 344 void GpuChannelManager::OnRelinquishResources() { |
| 341 if (default_offscreen_surface_.get()) { | 345 relinquish_resources_pending_ = true; |
| 342 default_offscreen_surface_->DestroyAndTerminateDisplay(); | 346 CheckRelinquishGpuResources(); |
| 343 default_offscreen_surface_ = nullptr; | 347 } |
| 348 |
| 349 void GpuChannelManager::CheckRelinquishGpuResources() { |
| 350 if (relinquish_resources_pending_ && gpu_channels_.size() <= 1) { |
| 351 relinquish_resources_pending_ = false; |
| 352 if (default_offscreen_surface_.get()) { |
| 353 default_offscreen_surface_->DestroyAndTerminateDisplay(); |
| 354 default_offscreen_surface_ = NULL; |
| 355 } |
| 356 #if defined(USE_OZONE) |
| 357 ui::OzonePlatform::GetInstance() |
| 358 ->GetGpuPlatformSupport() |
| 359 ->RelinquishGpuResources( |
| 360 base::Bind(&GpuChannelManager::OnResourcesRelinquished, |
| 361 weak_factory_.GetWeakPtr())); |
| 362 #else |
| 363 OnResourcesRelinquished(); |
| 364 #endif |
| 344 } | 365 } |
| 345 #if defined(USE_OZONE) | |
| 346 ui::OzonePlatform::GetInstance() | |
| 347 ->GetGpuPlatformSupport() | |
| 348 ->RelinquishGpuResources( | |
| 349 base::Bind(&GpuChannelManager::OnResourcesRelinquished, | |
| 350 weak_factory_.GetWeakPtr())); | |
| 351 #else | |
| 352 OnResourcesRelinquished(); | |
| 353 #endif | |
| 354 } | 366 } |
| 355 | 367 |
| 356 void GpuChannelManager::OnResourcesRelinquished() { | 368 void GpuChannelManager::OnResourcesRelinquished() { |
| 357 Send(new GpuHostMsg_ResourcesRelinquished()); | 369 Send(new GpuHostMsg_ResourcesRelinquished()); |
| 358 } | 370 } |
| 359 | 371 |
| 360 } // namespace content | 372 } // namespace content |
| OLD | NEW |