| 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 <set> | 7 #include <set> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" | 
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 274     case gfx::IO_SURFACE_BUFFER: | 274     case gfx::IO_SURFACE_BUFFER: | 
| 275       // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. | 275       // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. | 
| 276       return GL_TEXTURE_RECTANGLE_ARB; | 276       return GL_TEXTURE_RECTANGLE_ARB; | 
| 277     default: | 277     default: | 
| 278       return GL_TEXTURE_2D; | 278       return GL_TEXTURE_2D; | 
| 279   } | 279   } | 
| 280 } | 280 } | 
| 281 | 281 | 
| 282 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 282 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 
| 283     : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 283     : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 
|  | 284       main_task_runner_(base::MessageLoopProxy::current()), | 
| 284       shutdown_event_(new base::WaitableEvent(true, false)), | 285       shutdown_event_(new base::WaitableEvent(true, false)), | 
| 285       gpu_memory_buffer_manager_( | 286       gpu_memory_buffer_manager_( | 
| 286           new BrowserGpuMemoryBufferManager(this, gpu_client_id_)), | 287           new BrowserGpuMemoryBufferManager(this, gpu_client_id_)), | 
| 287       gpu_host_id_(0), | 288       gpu_host_id_(0), | 
| 288       next_create_gpu_memory_buffer_request_id_(0) { | 289       next_create_gpu_memory_buffer_request_id_(0) { | 
| 289 } | 290 } | 
| 290 | 291 | 
| 291 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 292 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 
| 292   DCHECK(IsMainThread()); | 293   DCHECK(main_task_runner_->BelongsToCurrentThread()); | 
| 293   if (pending_request_.get()) | 294   if (pending_request_.get()) | 
| 294     pending_request_->Cancel(); | 295     pending_request_->Cancel(); | 
| 295   for (size_t n = 0; n < established_callbacks_.size(); n++) | 296   for (size_t n = 0; n < established_callbacks_.size(); n++) | 
| 296     established_callbacks_[n].Run(); | 297     established_callbacks_[n].Run(); | 
| 297   shutdown_event_->Signal(); | 298   shutdown_event_->Signal(); | 
| 298 } | 299 } | 
| 299 | 300 | 
| 300 bool BrowserGpuChannelHostFactory::IsMainThread() { | 301 scoped_refptr<base::SingleThreadTaskRunner> | 
| 301   return BrowserThread::CurrentlyOn(BrowserThread::UI); | 302 BrowserGpuChannelHostFactory::GetMainTaskRunner() { | 
| 302 } | 303   return main_task_runner_; | 
| 303 |  | 
| 304 base::MessageLoop* BrowserGpuChannelHostFactory::GetMainLoop() { |  | 
| 305   return BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::UI); |  | 
| 306 } | 304 } | 
| 307 | 305 | 
| 308 scoped_refptr<base::MessageLoopProxy> | 306 scoped_refptr<base::MessageLoopProxy> | 
| 309 BrowserGpuChannelHostFactory::GetIOLoopProxy() { | 307 BrowserGpuChannelHostFactory::GetIOLoopProxy() { | 
| 310   return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 308   return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 
| 311 } | 309 } | 
| 312 | 310 | 
| 313 scoped_ptr<base::SharedMemory> | 311 scoped_ptr<base::SharedMemory> | 
| 314 BrowserGpuChannelHostFactory::AllocateSharedMemory(size_t size) { | 312 BrowserGpuChannelHostFactory::AllocateSharedMemory(size_t size) { | 
| 315   scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 313   scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 414 } | 412 } | 
| 415 | 413 | 
| 416 GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() { | 414 GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() { | 
| 417   if (gpu_channel_.get() && !gpu_channel_->IsLost()) | 415   if (gpu_channel_.get() && !gpu_channel_->IsLost()) | 
| 418     return gpu_channel_.get(); | 416     return gpu_channel_.get(); | 
| 419 | 417 | 
| 420   return NULL; | 418   return NULL; | 
| 421 } | 419 } | 
| 422 | 420 | 
| 423 void BrowserGpuChannelHostFactory::GpuChannelEstablished() { | 421 void BrowserGpuChannelHostFactory::GpuChannelEstablished() { | 
| 424   DCHECK(IsMainThread()); | 422   DCHECK(main_task_runner_->BelongsToCurrentThread()); | 
| 425   DCHECK(pending_request_.get()); | 423   DCHECK(pending_request_.get()); | 
| 426   if (pending_request_->channel_handle().name.empty()) { | 424   if (pending_request_->channel_handle().name.empty()) { | 
| 427     DCHECK(!gpu_channel_.get()); | 425     DCHECK(!gpu_channel_.get()); | 
| 428   } else { | 426   } else { | 
| 429     // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466866 | 427     // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466866 | 
| 430     // is fixed. | 428     // is fixed. | 
| 431     tracked_objects::ScopedTracker tracking_profile1( | 429     tracked_objects::ScopedTracker tracking_profile1( | 
| 432         FROM_HERE_WITH_EXPLICIT_FUNCTION( | 430         FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 433             "466866 BrowserGpuChannelHostFactory::GpuChannelEstablished1")); | 431             "466866 BrowserGpuChannelHostFactory::GpuChannelEstablished1")); | 
| 434     GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); | 432     GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 559   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 557   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
| 560 | 558 | 
| 561   CreateGpuMemoryBufferCallbackMap::iterator iter = | 559   CreateGpuMemoryBufferCallbackMap::iterator iter = | 
| 562       create_gpu_memory_buffer_requests_.find(request_id); | 560       create_gpu_memory_buffer_requests_.find(request_id); | 
| 563   DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 561   DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 
| 564   iter->second.Run(handle); | 562   iter->second.Run(handle); | 
| 565   create_gpu_memory_buffer_requests_.erase(iter); | 563   create_gpu_memory_buffer_requests_.erase(iter); | 
| 566 } | 564 } | 
| 567 | 565 | 
| 568 }  // namespace content | 566 }  // namespace content | 
| OLD | NEW | 
|---|