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/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 private: | 274 private: |
275 CommandLine* cmd_line_; | 275 CommandLine* cmd_line_; |
276 }; | 276 }; |
277 #endif // defined(OS_WIN) | 277 #endif // defined(OS_WIN) |
278 | 278 |
279 } // anonymous namespace | 279 } // anonymous namespace |
280 | 280 |
281 // Single process not supported in multiple dll mode currently. | |
282 #if !defined(CHROME_MULTIPLE_DLL) | |
283 // This class creates a GPU thread (instead of a GPU process), when running | |
284 // with --in-process-gpu or --single-process. | |
285 class GpuMainThread : public base::Thread { | |
286 public: | |
287 explicit GpuMainThread(const std::string& channel_id) | |
288 : base::Thread("Chrome_InProcGpuThread"), | |
289 channel_id_(channel_id), | |
290 gpu_process_(NULL) { | |
291 } | |
292 | |
293 virtual ~GpuMainThread() { | |
294 Stop(); | |
295 } | |
296 | |
297 protected: | |
298 virtual void Init() OVERRIDE { | |
299 gpu_process_ = new GpuProcess(); | |
300 // The process object takes ownership of the thread object, so do not | |
301 // save and delete the pointer. | |
302 gpu_process_->set_main_thread(new GpuChildThread(channel_id_)); | |
303 } | |
304 | |
305 virtual void CleanUp() OVERRIDE { | |
306 delete gpu_process_; | |
307 } | |
308 | |
309 private: | |
310 std::string channel_id_; | |
311 // Deleted in CleanUp() on the gpu thread, so don't use smart pointers. | |
312 GpuProcess* gpu_process_; | |
313 | |
314 DISALLOW_COPY_AND_ASSIGN(GpuMainThread); | |
315 }; | |
316 #endif // !CHROME_MULTIPLE_DLL | |
317 | |
318 // static | 281 // static |
319 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { | 282 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { |
320 if (!host) | 283 if (!host) |
321 return false; | 284 return false; |
322 | 285 |
323 // The Gpu process is invalid if it's not using SwiftShader, the card is | 286 // The Gpu process is invalid if it's not using SwiftShader, the card is |
324 // blacklisted, and we can kill it and start over. | 287 // blacklisted, and we can kill it and start over. |
325 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 288 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || |
326 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) || | 289 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) || |
327 (host->valid_ && | 290 (host->valid_ && |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 CauseForGpuLaunch cause, | 357 CauseForGpuLaunch cause, |
395 IPC::Message* message) { | 358 IPC::Message* message) { |
396 if (!BrowserThread::PostTask( | 359 if (!BrowserThread::PostTask( |
397 BrowserThread::IO, FROM_HERE, | 360 BrowserThread::IO, FROM_HERE, |
398 base::Bind( | 361 base::Bind( |
399 &SendGpuProcessMessage, kind, cause, message))) { | 362 &SendGpuProcessMessage, kind, cause, message))) { |
400 delete message; | 363 delete message; |
401 } | 364 } |
402 } | 365 } |
403 | 366 |
| 367 GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL; |
| 368 |
| 369 void GpuProcessHost::RegisterGpuMainThreadFactory( |
| 370 GpuMainThreadFactoryFunction create) { |
| 371 g_gpu_main_thread_factory = create; |
| 372 } |
| 373 |
404 // static | 374 // static |
405 GpuProcessHost* GpuProcessHost::FromID(int host_id) { | 375 GpuProcessHost* GpuProcessHost::FromID(int host_id) { |
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
407 | 377 |
408 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { | 378 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { |
409 GpuProcessHost* host = g_gpu_process_hosts[i]; | 379 GpuProcessHost* host = g_gpu_process_hosts[i]; |
410 if (host && host->host_id_ == host_id && ValidateHost(host)) | 380 if (host && host->host_id_ == host_id && ValidateHost(host)) |
411 return host; | 381 return host; |
412 } | 382 } |
413 | 383 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 | 561 |
592 bool GpuProcessHost::Init() { | 562 bool GpuProcessHost::Init() { |
593 init_start_time_ = base::TimeTicks::Now(); | 563 init_start_time_ = base::TimeTicks::Now(); |
594 | 564 |
595 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 565 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
596 | 566 |
597 std::string channel_id = process_->GetHost()->CreateChannel(); | 567 std::string channel_id = process_->GetHost()->CreateChannel(); |
598 if (channel_id.empty()) | 568 if (channel_id.empty()) |
599 return false; | 569 return false; |
600 | 570 |
601 // Single process not supported in multiple dll mode currently. | 571 if (in_process_ && g_gpu_main_thread_factory) { |
602 #if !defined(CHROME_MULTIPLE_DLL) | |
603 if (in_process_) { | |
604 CommandLine::ForCurrentProcess()->AppendSwitch( | 572 CommandLine::ForCurrentProcess()->AppendSwitch( |
605 switches::kDisableGpuWatchdog); | 573 switches::kDisableGpuWatchdog); |
606 | 574 |
607 in_process_gpu_thread_.reset(new GpuMainThread(channel_id)); | 575 in_process_gpu_thread_.reset(g_gpu_main_thread_factory(channel_id)); |
608 in_process_gpu_thread_->Start(); | 576 in_process_gpu_thread_->Start(); |
609 | 577 |
610 OnProcessLaunched(); // Fake a callback that the process is ready. | 578 OnProcessLaunched(); // Fake a callback that the process is ready. |
611 } else | 579 } else if (!LaunchGpuProcess(channel_id)) { |
612 #endif // !CHROME_MULTIPLE_DLL | |
613 if (!LaunchGpuProcess(channel_id)) { | |
614 return false; | 580 return false; |
615 } | 581 } |
616 | 582 |
617 if (!Send(new GpuMsg_Initialize())) | 583 if (!Send(new GpuMsg_Initialize())) |
618 return false; | 584 return false; |
619 | 585 |
620 return true; | 586 return true; |
621 } | 587 } |
622 | 588 |
623 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { | 589 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1242 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1277 ClientIdToShaderCacheMap::iterator iter = | 1243 ClientIdToShaderCacheMap::iterator iter = |
1278 client_id_to_shader_cache_.find(client_id); | 1244 client_id_to_shader_cache_.find(client_id); |
1279 // If the cache doesn't exist then this is an off the record profile. | 1245 // If the cache doesn't exist then this is an off the record profile. |
1280 if (iter == client_id_to_shader_cache_.end()) | 1246 if (iter == client_id_to_shader_cache_.end()) |
1281 return; | 1247 return; |
1282 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1248 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1283 } | 1249 } |
1284 | 1250 |
1285 } // namespace content | 1251 } // namespace content |
OLD | NEW |