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/gpu/gpu_child_thread.h" | 5 #include "content/gpu/gpu_child_thread.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/lazy_instance.h" | |
| 13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | |
| 16 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
| 17 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 18 #include "content/child/child_process.h" | 16 #include "content/child/child_process.h" |
| 19 #include "content/child/thread_safe_sender.h" | 17 #include "content/child/thread_safe_sender.h" |
| 20 #include "content/common/establish_channel_params.h" | 18 #include "content/common/establish_channel_params.h" |
| 21 #include "content/common/gpu_host_messages.h" | 19 #include "content/common/gpu_host_messages.h" |
| 22 #include "content/gpu/gpu_service_factory.h" | 20 #include "content/gpu/gpu_service_factory.h" |
| 23 #include "content/public/common/content_client.h" | 21 #include "content/public/common/content_client.h" |
| 24 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/common/service_manager_connection.h" | 23 #include "content/public/common/service_manager_connection.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 51 #include "ui/ozone/public/ozone_platform.h" | 49 #include "ui/ozone/public/ozone_platform.h" |
| 52 #endif | 50 #endif |
| 53 | 51 |
| 54 #if defined(OS_ANDROID) | 52 #if defined(OS_ANDROID) |
| 55 #include "media/base/android/media_client_android.h" | 53 #include "media/base/android/media_client_android.h" |
| 56 #endif | 54 #endif |
| 57 | 55 |
| 58 namespace content { | 56 namespace content { |
| 59 namespace { | 57 namespace { |
| 60 | 58 |
| 61 static base::LazyInstance<scoped_refptr<ThreadSafeSender>>::DestructorAtExit | |
| 62 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | |
| 63 | |
| 64 bool GpuProcessLogMessageHandler(int severity, | |
| 65 const char* file, int line, | |
| 66 size_t message_start, | |
| 67 const std::string& str) { | |
| 68 std::string header = str.substr(0, message_start); | |
| 69 std::string message = str.substr(message_start); | |
| 70 | |
| 71 g_thread_safe_sender.Get()->Send( | |
| 72 new GpuHostMsg_OnLogMessage(severity, header, message)); | |
| 73 | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages | 59 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages |
| 78 // on the IO thread. This allows the UI thread in the browser process to remain | 60 // on the IO thread. This allows the UI thread in the browser process to remain |
| 79 // fast at all times. | 61 // fast at all times. |
| 80 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { | 62 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { |
| 81 public: | 63 public: |
| 82 explicit GpuMemoryBufferMessageFilter( | 64 explicit GpuMemoryBufferMessageFilter( |
| 83 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 65 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
| 84 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 66 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 85 sender_(nullptr) {} | 67 sender_(nullptr) {} |
| 86 | 68 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 in_browser_process_(false), | 139 in_browser_process_(false), |
| 158 gpu_service_(new ui::GpuService(gpu_info, | 140 gpu_service_(new ui::GpuService(gpu_info, |
| 159 std::move(watchdog_thread), | 141 std::move(watchdog_thread), |
| 160 gpu_memory_buffer_factory, | 142 gpu_memory_buffer_factory, |
| 161 ChildProcess::current()->io_task_runner(), | 143 ChildProcess::current()->io_task_runner(), |
| 162 gpu_feature_info)), | 144 gpu_feature_info)), |
| 163 gpu_main_binding_(this) { | 145 gpu_main_binding_(this) { |
| 164 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
| 165 target_services_ = NULL; | 147 target_services_ = NULL; |
| 166 #endif | 148 #endif |
| 167 g_thread_safe_sender.Get() = thread_safe_sender(); | |
| 168 } | 149 } |
| 169 | 150 |
| 170 GpuChildThread::GpuChildThread( | 151 GpuChildThread::GpuChildThread( |
| 171 const InProcessChildThreadParams& params, | 152 const InProcessChildThreadParams& params, |
| 172 const gpu::GPUInfo& gpu_info, | 153 const gpu::GPUInfo& gpu_info, |
| 173 const gpu::GpuFeatureInfo& gpu_feature_info, | 154 const gpu::GpuFeatureInfo& gpu_feature_info, |
| 174 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 155 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
| 175 : ChildThreadImpl(ChildThreadImpl::Options::Builder() | 156 : ChildThreadImpl(ChildThreadImpl::Options::Builder() |
| 176 .InBrowserProcess(params) | 157 .InBrowserProcess(params) |
| 177 .AddStartupFilter(new GpuMemoryBufferMessageFilter( | 158 .AddStartupFilter(new GpuMemoryBufferMessageFilter( |
| 178 gpu_memory_buffer_factory)) | 159 gpu_memory_buffer_factory)) |
| 179 .ConnectToBrowser(true) | 160 .ConnectToBrowser(true) |
| 180 .Build()), | 161 .Build()), |
| 181 dead_on_arrival_(false), | 162 dead_on_arrival_(false), |
| 182 gpu_info_(gpu_info), | 163 gpu_info_(gpu_info), |
| 183 in_browser_process_(true), | 164 in_browser_process_(true), |
| 184 gpu_service_(new ui::GpuService(gpu_info, | 165 gpu_service_(new ui::GpuService(gpu_info, |
| 185 nullptr /* watchdog thread */, | 166 nullptr /* watchdog thread */, |
| 186 gpu_memory_buffer_factory, | 167 gpu_memory_buffer_factory, |
| 187 ChildProcess::current()->io_task_runner(), | 168 ChildProcess::current()->io_task_runner(), |
| 188 gpu_feature_info)), | 169 gpu_feature_info)), |
| 189 gpu_main_binding_(this) { | 170 gpu_main_binding_(this) { |
| 190 #if defined(OS_WIN) | 171 #if defined(OS_WIN) |
| 191 target_services_ = NULL; | 172 target_services_ = NULL; |
| 192 #endif | 173 #endif |
| 193 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 174 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 194 switches::kSingleProcess) || | 175 switches::kSingleProcess) || |
| 195 base::CommandLine::ForCurrentProcess()->HasSwitch( | 176 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 196 switches::kInProcessGPU)); | 177 switches::kInProcessGPU)); |
| 197 | |
| 198 g_thread_safe_sender.Get() = thread_safe_sender(); | |
| 199 } | 178 } |
| 200 | 179 |
| 201 GpuChildThread::~GpuChildThread() { | 180 GpuChildThread::~GpuChildThread() { |
| 202 } | 181 } |
| 203 | 182 |
| 204 void GpuChildThread::Shutdown() { | 183 void GpuChildThread::Shutdown() { |
| 205 ChildThreadImpl::Shutdown(); | 184 ChildThreadImpl::Shutdown(); |
| 206 logging::SetLogMessageHandler(NULL); | |
| 207 } | 185 } |
| 208 | 186 |
| 209 void GpuChildThread::Init(const base::Time& process_start_time) { | 187 void GpuChildThread::Init(const base::Time& process_start_time) { |
| 210 process_start_time_ = process_start_time; | 188 process_start_time_ = process_start_time; |
| 211 | 189 |
| 212 #if defined(OS_ANDROID) | 190 #if defined(OS_ANDROID) |
| 213 // When running in in-process mode, this has been set in the browser at | 191 // When running in in-process mode, this has been set in the browser at |
| 214 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). | 192 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
| 215 if (!in_browser_process_) | 193 if (!in_browser_process_) |
| 216 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); | 194 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 media::GpuJpegDecodeAcceleratorFactoryProvider:: | 272 media::GpuJpegDecodeAcceleratorFactoryProvider:: |
| 295 IsAcceleratedJpegDecodeSupported(); | 273 IsAcceleratedJpegDecodeSupported(); |
| 296 | 274 |
| 297 // Record initialization only after collecting the GPU info because that can | 275 // Record initialization only after collecting the GPU info because that can |
| 298 // take a significant amount of time. | 276 // take a significant amount of time. |
| 299 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; | 277 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; |
| 300 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_, | 278 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_, |
| 301 gpu_service_->gpu_feature_info())); | 279 gpu_service_->gpu_feature_info())); |
| 302 while (!deferred_messages_.empty()) { | 280 while (!deferred_messages_.empty()) { |
| 303 const LogMessage& log = deferred_messages_.front(); | 281 const LogMessage& log = deferred_messages_.front(); |
| 304 Send(new GpuHostMsg_OnLogMessage(log.severity, log.header, log.message)); | 282 gpu_host->RecordLogMessage(log.severity, log.header, log.message); |
|
piman
2017/03/20 21:20:26
Just checking, is it ok to do this before we initi
sadrul
2017/03/20 21:40:17
For now, this is OK. GpuProcessHost::DidInitialize
| |
| 305 deferred_messages_.pop(); | 283 deferred_messages_.pop(); |
| 306 } | 284 } |
| 307 | 285 |
| 308 if (dead_on_arrival_) { | 286 if (dead_on_arrival_) { |
| 309 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; | 287 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
| 310 base::MessageLoop::current()->QuitWhenIdle(); | 288 base::MessageLoop::current()->QuitWhenIdle(); |
| 311 return; | 289 return; |
| 312 } | 290 } |
| 313 | 291 |
| 314 // We don't need to pipe log messages if we are running the GPU thread in | |
| 315 // the browser process. | |
| 316 if (!in_browser_process_) | |
| 317 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | |
| 318 | |
| 319 gpu::SyncPointManager* sync_point_manager = nullptr; | 292 gpu::SyncPointManager* sync_point_manager = nullptr; |
| 320 // Note SyncPointManager from ContentGpuClient cannot be owned by this. | 293 // Note SyncPointManager from ContentGpuClient cannot be owned by this. |
| 321 if (GetContentClient()->gpu()) | 294 if (GetContentClient()->gpu()) |
| 322 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); | 295 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); |
| 323 gpu_service_->InitializeWithHost( | 296 gpu_service_->InitializeWithHost( |
| 324 std::move(gpu_host), gpu_preferences, | 297 std::move(gpu_host), gpu_preferences, |
| 325 gpu::GpuProcessActivityFlags(std::move(activity_flags)), | 298 gpu::GpuProcessActivityFlags(std::move(activity_flags)), |
| 326 sync_point_manager, ChildProcess::current()->GetShutDownEvent()); | 299 sync_point_manager, ChildProcess::current()->GetShutDownEvent()); |
| 327 CHECK(gpu_service_->media_gpu_channel_manager()); | 300 CHECK(gpu_service_->media_gpu_channel_manager()); |
| 328 | 301 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 | 339 |
| 367 void GpuChildThread::BindServiceFactoryRequest( | 340 void GpuChildThread::BindServiceFactoryRequest( |
| 368 service_manager::mojom::ServiceFactoryRequest request) { | 341 service_manager::mojom::ServiceFactoryRequest request) { |
| 369 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; | 342 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; |
| 370 DCHECK(service_factory_); | 343 DCHECK(service_factory_); |
| 371 service_factory_bindings_.AddBinding(service_factory_.get(), | 344 service_factory_bindings_.AddBinding(service_factory_.get(), |
| 372 std::move(request)); | 345 std::move(request)); |
| 373 } | 346 } |
| 374 | 347 |
| 375 } // namespace content | 348 } // namespace content |
| OLD | NEW |