Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: content/browser/gpu/gpu_process_host.cc

Issue 23235002: Set up content in-process main threads via factory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ios Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/gpu/gpu_process_host.h ('k') | content/browser/renderer_host/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/sha1.h" 16 #include "base/sha1.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "content/browser/browser_child_process_host_impl.h" 18 #include "content/browser/browser_child_process_host_impl.h"
19 #include "content/browser/gpu/gpu_data_manager_impl.h" 19 #include "content/browser/gpu/gpu_data_manager_impl.h"
20 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 20 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
21 #include "content/browser/gpu/shader_disk_cache.h" 21 #include "content/browser/gpu/shader_disk_cache.h"
22 #include "content/browser/renderer_host/render_widget_helper.h" 22 #include "content/browser/renderer_host/render_widget_helper.h"
23 #include "content/browser/renderer_host/render_widget_host_impl.h" 23 #include "content/browser/renderer_host/render_widget_host_impl.h"
24 #include "content/common/child_process_host_impl.h" 24 #include "content/common/child_process_host_impl.h"
25 #include "content/common/gpu/gpu_messages.h" 25 #include "content/common/gpu/gpu_messages.h"
26 #include "content/common/view_messages.h" 26 #include "content/common/view_messages.h"
27 #include "content/gpu/gpu_child_thread.h" 27 #include "content/gpu/gpu_child_thread.h"
28 #include "content/gpu/gpu_process.h" 28 #include "content/gpu/gpu_process.h"
jam 2013/08/25 08:09:16 nit: remove these and and "content/gpu" from conte
29 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" 29 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/content_browser_client.h" 31 #include "content/public/browser/content_browser_client.h"
32 #include "content/public/browser/render_process_host.h" 32 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/render_widget_host_view.h" 33 #include "content/public/browser/render_widget_host_view.h"
34 #include "content/public/common/content_client.h" 34 #include "content/public/common/content_client.h"
35 #include "content/public/common/content_switches.h" 35 #include "content/public/common/content_switches.h"
36 #include "content/public/common/result_codes.h" 36 #include "content/public/common/result_codes.h"
37 #include "gpu/command_buffer/service/gpu_switches.h" 37 #include "gpu/command_buffer/service/gpu_switches.h"
38 #include "ipc/ipc_channel_handle.h" 38 #include "ipc/ipc_channel_handle.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host.h ('k') | content/browser/renderer_host/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698