Chromium Code Reviews| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 gpu::GPUInfo gpu_info() { return gpu_info_; } | 49 gpu::GPUInfo gpu_info() { return gpu_info_; } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 friend class base::RefCountedThreadSafe<EstablishRequest>; | 52 friend class base::RefCountedThreadSafe<EstablishRequest>; |
| 53 explicit EstablishRequest(int gpu_client_id, | 53 explicit EstablishRequest(int gpu_client_id, |
| 54 uint64_t gpu_client_tracing_id, | 54 uint64_t gpu_client_tracing_id, |
| 55 int gpu_host_id); | 55 int gpu_host_id); |
| 56 ~EstablishRequest() {} | 56 ~EstablishRequest() {} |
| 57 void EstablishOnIO(); | 57 void EstablishOnIO(); |
| 58 void OnEstablishedOnIO(const IPC::ChannelHandle& channel_handle, | 58 void OnEstablishedOnIO(const IPC::ChannelHandle& channel_handle, |
| 59 const gpu::GPUInfo& gpu_info); | 59 const gpu::GPUInfo& gpu_info, |
| 60 GpuProcessHost::EstablishChannelStatus status); | |
| 60 void FinishOnIO(); | 61 void FinishOnIO(); |
| 61 void FinishOnMain(); | 62 void FinishOnMain(); |
| 62 | 63 |
| 63 base::WaitableEvent event_; | 64 base::WaitableEvent event_; |
| 64 const int gpu_client_id_; | 65 const int gpu_client_id_; |
| 65 const uint64_t gpu_client_tracing_id_; | 66 const uint64_t gpu_client_tracing_id_; |
| 66 int gpu_host_id_; | 67 int gpu_host_id_; |
| 67 bool reused_gpu_process_; | |
| 68 IPC::ChannelHandle channel_handle_; | 68 IPC::ChannelHandle channel_handle_; |
| 69 gpu::GPUInfo gpu_info_; | 69 gpu::GPUInfo gpu_info_; |
| 70 bool finished_; | 70 bool finished_; |
| 71 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 71 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest> | 74 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest> |
| 75 BrowserGpuChannelHostFactory::EstablishRequest::Create( | 75 BrowserGpuChannelHostFactory::EstablishRequest::Create( |
| 76 int gpu_client_id, | 76 int gpu_client_id, |
| 77 uint64_t gpu_client_tracing_id, | 77 uint64_t gpu_client_tracing_id, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 89 } | 89 } |
| 90 | 90 |
| 91 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest( | 91 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest( |
| 92 int gpu_client_id, | 92 int gpu_client_id, |
| 93 uint64_t gpu_client_tracing_id, | 93 uint64_t gpu_client_tracing_id, |
| 94 int gpu_host_id) | 94 int gpu_host_id) |
| 95 : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 95 : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 96 base::WaitableEvent::InitialState::NOT_SIGNALED), | 96 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 97 gpu_client_id_(gpu_client_id), | 97 gpu_client_id_(gpu_client_id), |
| 98 gpu_client_tracing_id_(gpu_client_tracing_id), | 98 gpu_client_tracing_id_(gpu_client_tracing_id), |
| 99 gpu_host_id_(gpu_host_id), | 99 gpu_host_id_(gpu_host_id), |
|
piman
2017/04/06 18:16:39
I think we don't need this one any more.
sadrul
2017/04/07 04:10:53
Yep. Removed.
| |
| 100 reused_gpu_process_(false), | |
| 101 finished_(false), | 100 finished_(false), |
| 102 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 101 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 103 | 102 |
| 104 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() { | 103 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() { |
| 105 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 104 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
| 106 tracked_objects::ScopedTracker tracking_profile( | 105 tracked_objects::ScopedTracker tracking_profile( |
| 107 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 106 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 108 "477117 " | 107 "477117 " |
| 109 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO")); | 108 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO")); |
| 110 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 109 GpuProcessHost* host = |
| 110 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); | |
| 111 if (!host) { | 111 if (!host) { |
| 112 host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); | 112 LOG(ERROR) << "Failed to launch GPU process."; |
| 113 if (!host) { | 113 FinishOnIO(); |
| 114 LOG(ERROR) << "Failed to launch GPU process."; | 114 return; |
| 115 FinishOnIO(); | |
| 116 return; | |
| 117 } | |
| 118 gpu_host_id_ = host->host_id(); | |
| 119 reused_gpu_process_ = false; | |
| 120 } else { | |
| 121 if (reused_gpu_process_) { | |
| 122 // We come here if we retried to establish the channel because of a | |
| 123 // failure in ChannelEstablishedOnIO, but we ended up with the same | |
| 124 // process ID, meaning the failure was not because of a channel error, | |
| 125 // but another reason. So fail now. | |
| 126 LOG(ERROR) << "Failed to create channel."; | |
| 127 FinishOnIO(); | |
| 128 return; | |
| 129 } | |
| 130 reused_gpu_process_ = true; | |
| 131 } | 115 } |
| 132 | 116 |
| 133 bool preempts = true; | 117 bool preempts = true; |
| 134 bool allow_view_command_buffers = true; | 118 bool allow_view_command_buffers = true; |
| 135 bool allow_real_time_streams = true; | 119 bool allow_real_time_streams = true; |
| 136 host->EstablishGpuChannel( | 120 host->EstablishGpuChannel( |
| 137 gpu_client_id_, gpu_client_tracing_id_, preempts, | 121 gpu_client_id_, gpu_client_tracing_id_, preempts, |
| 138 allow_view_command_buffers, allow_real_time_streams, | 122 allow_view_command_buffers, allow_real_time_streams, |
| 139 base::Bind( | 123 base::Bind( |
| 140 &BrowserGpuChannelHostFactory::EstablishRequest::OnEstablishedOnIO, | 124 &BrowserGpuChannelHostFactory::EstablishRequest::OnEstablishedOnIO, |
| 141 this)); | 125 this)); |
| 142 } | 126 } |
| 143 | 127 |
| 144 void BrowserGpuChannelHostFactory::EstablishRequest::OnEstablishedOnIO( | 128 void BrowserGpuChannelHostFactory::EstablishRequest::OnEstablishedOnIO( |
| 145 const IPC::ChannelHandle& channel_handle, | 129 const IPC::ChannelHandle& channel_handle, |
| 146 const gpu::GPUInfo& gpu_info) { | 130 const gpu::GPUInfo& gpu_info, |
| 147 if (!channel_handle.mojo_handle.is_valid() && reused_gpu_process_) { | 131 GpuProcessHost::EstablishChannelStatus status) { |
| 148 // We failed after re-using the GPU process, but it may have died in the | 132 if (!channel_handle.mojo_handle.is_valid() && |
| 149 // mean time. Retry to have a chance to create a fresh GPU process. | 133 status == GpuProcessHost::EstablishChannelStatus::GPU_HOST_INVALID) { |
| 150 DVLOG(1) << "Failed to create channel on existing GPU process. Trying to " | |
| 151 "restart GPU process."; | |
| 152 EstablishOnIO(); | 134 EstablishOnIO(); |
| 153 } else { | 135 return; |
| 154 channel_handle_ = channel_handle; | |
| 155 gpu_info_ = gpu_info; | |
| 156 FinishOnIO(); | |
| 157 } | 136 } |
| 137 channel_handle_ = channel_handle; | |
| 138 gpu_info_ = gpu_info; | |
| 139 FinishOnIO(); | |
| 158 } | 140 } |
| 159 | 141 |
| 160 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnIO() { | 142 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnIO() { |
| 161 event_.Signal(); | 143 event_.Signal(); |
| 162 main_task_runner_->PostTask( | 144 main_task_runner_->PostTask( |
| 163 FROM_HERE, | 145 FROM_HERE, |
| 164 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain, | 146 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain, |
| 165 this)); | 147 this)); |
| 166 } | 148 } |
| 167 | 149 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 } | 347 } |
| 366 | 348 |
| 367 // static | 349 // static |
| 368 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( | 350 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( |
| 369 int gpu_client_id, | 351 int gpu_client_id, |
| 370 const base::FilePath& cache_dir) { | 352 const base::FilePath& cache_dir) { |
| 371 GetShaderCacheFactorySingleton()->SetCacheInfo(gpu_client_id, cache_dir); | 353 GetShaderCacheFactorySingleton()->SetCacheInfo(gpu_client_id, cache_dir); |
| 372 } | 354 } |
| 373 | 355 |
| 374 } // namespace content | 356 } // namespace content |
| OLD | NEW |