| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/trace_event/memory_dump_manager.h" | 15 #include "base/trace_event/memory_dump_manager.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "build/build_config.h" |
| 17 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 18 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 18 #include "content/browser/gpu/gpu_data_manager_impl.h" | 19 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 19 #include "content/browser/gpu/gpu_process_host.h" | 20 #include "content/browser/gpu/gpu_process_host.h" |
| 20 #include "content/browser/gpu/gpu_surface_tracker.h" | 21 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 21 #include "content/browser/gpu/shader_disk_cache.h" | 22 #include "content/browser/gpu/shader_disk_cache.h" |
| 22 #include "content/common/child_process_host_impl.h" | 23 #include "content/common/child_process_host_impl.h" |
| 23 #include "content/common/gpu/gpu_messages.h" | 24 #include "content/common/gpu/gpu_messages.h" |
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
| 26 #include "content/public/browser/gpu_data_manager.h" | 27 #include "content/public/browser/gpu_data_manager.h" |
| 27 #include "content/public/common/content_client.h" | 28 #include "content/public/common/content_client.h" |
| 28 #include "gpu/command_buffer/service/gpu_switches.h" | 29 #include "gpu/command_buffer/service/gpu_switches.h" |
| 29 #include "ipc/ipc_channel_handle.h" | 30 #include "ipc/ipc_channel_handle.h" |
| 30 #include "ipc/message_filter.h" | 31 #include "ipc/message_filter.h" |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 | 34 |
| 34 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; | 35 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; |
| 35 | 36 |
| 36 struct BrowserGpuChannelHostFactory::CreateRequest { | 37 struct BrowserGpuChannelHostFactory::CreateRequest { |
| 37 CreateRequest(int32 route_id) | 38 CreateRequest(int32_t route_id) |
| 38 : event(true, false), | 39 : event(true, false), |
| 39 gpu_host_id(0), | 40 gpu_host_id(0), |
| 40 route_id(route_id), | 41 route_id(route_id), |
| 41 result(CREATE_COMMAND_BUFFER_FAILED) {} | 42 result(CREATE_COMMAND_BUFFER_FAILED) {} |
| 42 ~CreateRequest() {} | 43 ~CreateRequest() {} |
| 43 base::WaitableEvent event; | 44 base::WaitableEvent event; |
| 44 int gpu_host_id; | 45 int gpu_host_id; |
| 45 int32 route_id; | 46 int32_t route_id; |
| 46 CreateCommandBufferResult result; | 47 CreateCommandBufferResult result; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 class BrowserGpuChannelHostFactory::EstablishRequest | 50 class BrowserGpuChannelHostFactory::EstablishRequest |
| 50 : public base::RefCountedThreadSafe<EstablishRequest> { | 51 : public base::RefCountedThreadSafe<EstablishRequest> { |
| 51 public: | 52 public: |
| 52 static scoped_refptr<EstablishRequest> Create(CauseForGpuLaunch cause, | 53 static scoped_refptr<EstablishRequest> Create(CauseForGpuLaunch cause, |
| 53 int gpu_client_id, | 54 int gpu_client_id, |
| 54 uint64_t gpu_client_tracing_id, | 55 uint64_t gpu_client_tracing_id, |
| 55 int gpu_host_id); | 56 int gpu_host_id); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 scoped_ptr<base::SharedMemory> | 286 scoped_ptr<base::SharedMemory> |
| 286 BrowserGpuChannelHostFactory::AllocateSharedMemory(size_t size) { | 287 BrowserGpuChannelHostFactory::AllocateSharedMemory(size_t size) { |
| 287 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 288 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 288 if (!shm->CreateAnonymous(size)) | 289 if (!shm->CreateAnonymous(size)) |
| 289 return scoped_ptr<base::SharedMemory>(); | 290 return scoped_ptr<base::SharedMemory>(); |
| 290 return shm.Pass(); | 291 return shm.Pass(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO( | 294 void BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO( |
| 294 CreateRequest* request, | 295 CreateRequest* request, |
| 295 int32 surface_id, | 296 int32_t surface_id, |
| 296 const GPUCreateCommandBufferConfig& init_params) { | 297 const GPUCreateCommandBufferConfig& init_params) { |
| 297 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 298 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 298 if (!host) { | 299 if (!host) { |
| 299 request->event.Signal(); | 300 request->event.Signal(); |
| 300 return; | 301 return; |
| 301 } | 302 } |
| 302 | 303 |
| 303 gfx::GLSurfaceHandle surface = | 304 gfx::GLSurfaceHandle surface = |
| 304 GpuSurfaceTracker::Get()->GetSurfaceHandle(surface_id); | 305 GpuSurfaceTracker::Get()->GetSurfaceHandle(surface_id); |
| 305 | 306 |
| 306 host->CreateViewCommandBuffer( | 307 host->CreateViewCommandBuffer( |
| 307 surface, | 308 surface, |
| 308 gpu_client_id_, | 309 gpu_client_id_, |
| 309 init_params, | 310 init_params, |
| 310 request->route_id, | 311 request->route_id, |
| 311 base::Bind(&BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO, | 312 base::Bind(&BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO, |
| 312 request)); | 313 request)); |
| 313 } | 314 } |
| 314 | 315 |
| 315 // static | 316 // static |
| 316 void BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO( | 317 void BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO( |
| 317 CreateRequest* request, CreateCommandBufferResult result) { | 318 CreateRequest* request, CreateCommandBufferResult result) { |
| 318 request->result = result; | 319 request->result = result; |
| 319 request->event.Signal(); | 320 request->event.Signal(); |
| 320 } | 321 } |
| 321 | 322 |
| 322 CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer( | 323 CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer( |
| 323 int32 surface_id, | 324 int32_t surface_id, |
| 324 const GPUCreateCommandBufferConfig& init_params, | 325 const GPUCreateCommandBufferConfig& init_params, |
| 325 int32 route_id) { | 326 int32_t route_id) { |
| 326 CreateRequest request(route_id); | 327 CreateRequest request(route_id); |
| 327 GetIOThreadTaskRunner()->PostTask( | 328 GetIOThreadTaskRunner()->PostTask( |
| 328 FROM_HERE, | 329 FROM_HERE, |
| 329 base::Bind(&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO, | 330 base::Bind(&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO, |
| 330 base::Unretained(this), &request, surface_id, init_params)); | 331 base::Unretained(this), &request, surface_id, init_params)); |
| 331 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. | 332 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. |
| 332 tracked_objects::ScopedTracker tracking_profile( | 333 tracked_objects::ScopedTracker tracking_profile( |
| 333 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 334 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 334 "125248 BrowserGpuChannelHostFactory::CreateViewCommandBuffer")); | 335 "125248 BrowserGpuChannelHostFactory::CreateViewCommandBuffer")); |
| 335 | 336 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 437 } |
| 437 | 438 |
| 438 // static | 439 // static |
| 439 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( | 440 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( |
| 440 int gpu_client_id, | 441 int gpu_client_id, |
| 441 const base::FilePath& cache_dir) { | 442 const base::FilePath& cache_dir) { |
| 442 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id, cache_dir); | 443 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id, cache_dir); |
| 443 } | 444 } |
| 444 | 445 |
| 445 } // namespace content | 446 } // namespace content |
| OLD | NEW |