| 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/browser/gpu/browser_gpu_channel_host_factory.h" | 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 209 |
| 210 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 210 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() |
| 211 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 211 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
| 212 shutdown_event_(new base::WaitableEvent(true, false)), | 212 shutdown_event_(new base::WaitableEvent(true, false)), |
| 213 gpu_host_id_(0), | 213 gpu_host_id_(0), |
| 214 next_create_gpu_memory_buffer_request_id_(0) { | 214 next_create_gpu_memory_buffer_request_id_(0) { |
| 215 } | 215 } |
| 216 | 216 |
| 217 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 217 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
| 218 DCHECK(IsMainThread()); | 218 DCHECK(IsMainThread()); |
| 219 if (pending_request_) | 219 if (pending_request_.get()) |
| 220 pending_request_->Cancel(); | 220 pending_request_->Cancel(); |
| 221 for (size_t n = 0; n < established_callbacks_.size(); n++) | 221 for (size_t n = 0; n < established_callbacks_.size(); n++) |
| 222 established_callbacks_[n].Run(); | 222 established_callbacks_[n].Run(); |
| 223 shutdown_event_->Signal(); | 223 shutdown_event_->Signal(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 bool BrowserGpuChannelHostFactory::IsMainThread() { | 226 bool BrowserGpuChannelHostFactory::IsMainThread() { |
| 227 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 227 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 228 } | 228 } |
| 229 | 229 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 "BrowserGpuChannelHostFactory::CreateViewCommandBuffer"); | 294 "BrowserGpuChannelHostFactory::CreateViewCommandBuffer"); |
| 295 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 295 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 296 request.event.Wait(); | 296 request.event.Wait(); |
| 297 return request.result; | 297 return request.result; |
| 298 } | 298 } |
| 299 | 299 |
| 300 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( | 300 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( |
| 301 CauseForGpuLaunch cause_for_gpu_launch) { | 301 CauseForGpuLaunch cause_for_gpu_launch) { |
| 302 EstablishGpuChannel(cause_for_gpu_launch, base::Closure()); | 302 EstablishGpuChannel(cause_for_gpu_launch, base::Closure()); |
| 303 | 303 |
| 304 if (pending_request_) | 304 if (pending_request_.get()) |
| 305 pending_request_->Wait(); | 305 pending_request_->Wait(); |
| 306 | 306 |
| 307 return gpu_channel_.get(); | 307 return gpu_channel_.get(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void BrowserGpuChannelHostFactory::EstablishGpuChannel( | 310 void BrowserGpuChannelHostFactory::EstablishGpuChannel( |
| 311 CauseForGpuLaunch cause_for_gpu_launch, | 311 CauseForGpuLaunch cause_for_gpu_launch, |
| 312 const base::Closure& callback) { | 312 const base::Closure& callback) { |
| 313 if (gpu_channel_.get() && gpu_channel_->IsLost()) { | 313 if (gpu_channel_.get() && gpu_channel_->IsLost()) { |
| 314 DCHECK(!pending_request_); | 314 DCHECK(!pending_request_.get()); |
| 315 // Recreate the channel if it has been lost. | 315 // Recreate the channel if it has been lost. |
| 316 gpu_channel_ = NULL; | 316 gpu_channel_ = NULL; |
| 317 } | 317 } |
| 318 | 318 |
| 319 if (!gpu_channel_ && !pending_request_) { | 319 if (!gpu_channel_.get() && !pending_request_.get()) { |
| 320 // We should only get here if the context was lost. | 320 // We should only get here if the context was lost. |
| 321 pending_request_ = EstablishRequest::Create( | 321 pending_request_ = EstablishRequest::Create( |
| 322 cause_for_gpu_launch, gpu_client_id_, gpu_host_id_); | 322 cause_for_gpu_launch, gpu_client_id_, gpu_host_id_); |
| 323 } | 323 } |
| 324 | 324 |
| 325 if (!callback.is_null()) { | 325 if (!callback.is_null()) { |
| 326 if (gpu_channel_) | 326 if (gpu_channel_.get()) |
| 327 callback.Run(); | 327 callback.Run(); |
| 328 else | 328 else |
| 329 established_callbacks_.push_back(callback); | 329 established_callbacks_.push_back(callback); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() { | 333 GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() { |
| 334 if (gpu_channel_ && !gpu_channel_->IsLost()) | 334 if (gpu_channel_.get() && !gpu_channel_->IsLost()) |
| 335 return gpu_channel_; | 335 return gpu_channel_.get(); |
| 336 | 336 |
| 337 return NULL; | 337 return NULL; |
| 338 } | 338 } |
| 339 | 339 |
| 340 void BrowserGpuChannelHostFactory::GpuChannelEstablished() { | 340 void BrowserGpuChannelHostFactory::GpuChannelEstablished() { |
| 341 DCHECK(IsMainThread()); | 341 DCHECK(IsMainThread()); |
| 342 DCHECK(pending_request_); | 342 DCHECK(pending_request_.get()); |
| 343 if (pending_request_->channel_handle().name.empty()) { | 343 if (pending_request_->channel_handle().name.empty()) { |
| 344 DCHECK(!gpu_channel_); | 344 DCHECK(!gpu_channel_.get()); |
| 345 } else { | 345 } else { |
| 346 GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); | 346 GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); |
| 347 gpu_channel_ = GpuChannelHost::Create(this, | 347 gpu_channel_ = GpuChannelHost::Create(this, |
| 348 pending_request_->gpu_info(), | 348 pending_request_->gpu_info(), |
| 349 pending_request_->channel_handle(), | 349 pending_request_->channel_handle(), |
| 350 shutdown_event_.get()); | 350 shutdown_event_.get()); |
| 351 } | 351 } |
| 352 gpu_host_id_ = pending_request_->gpu_host_id(); | 352 gpu_host_id_ = pending_request_->gpu_host_id(); |
| 353 pending_request_ = NULL; | 353 pending_request_ = NULL; |
| 354 | 354 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 const gfx::GpuMemoryBufferHandle& handle, | 486 const gfx::GpuMemoryBufferHandle& handle, |
| 487 int32 sync_point) { | 487 int32 sync_point) { |
| 488 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 488 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 489 if (!host) | 489 if (!host) |
| 490 return; | 490 return; |
| 491 | 491 |
| 492 host->DestroyGpuMemoryBuffer(handle, sync_point); | 492 host->DestroyGpuMemoryBuffer(handle, sync_point); |
| 493 } | 493 } |
| 494 | 494 |
| 495 } // namespace content | 495 } // namespace content |
| OLD | NEW |