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

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

Issue 13983014: [CLOSED] Cleaning up the plethora of switches for GPU vs software vs SwiftShader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
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"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 GpuChildThread* child_thread_; 318 GpuChildThread* child_thread_;
319 319
320 DISALLOW_COPY_AND_ASSIGN(GpuMainThread); 320 DISALLOW_COPY_AND_ASSIGN(GpuMainThread);
321 }; 321 };
322 322
323 // static 323 // static
324 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { 324 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) {
325 if (!host) 325 if (!host)
326 return false; 326 return false;
327 327
328 // The Gpu process is invalid if it's not using software, the card is 328 // The Gpu process is invalid if it's not using SwiftShader, the card is
329 // blacklisted, and we can kill it and start over. 329 // blacklisted, and we can kill it and start over.
330 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || 330 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) ||
331 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) || 331 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) ||
332 (host->valid_ && 332 (host->valid_ &&
333 (host->software_rendering() || 333 (host->swiftshader_rendering_ ||
334 !GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()))) { 334 !GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()))) {
335 return true; 335 return true;
336 } 336 }
337 337
338 host->ForceShutdown(); 338 host->ForceShutdown();
339 return false; 339 return false;
340 } 340 }
341 341
342 // static 342 // static
343 GpuProcessHost* GpuProcessHost::Get(GpuProcessKind kind, 343 GpuProcessHost* GpuProcessHost::Get(GpuProcessKind kind,
344 CauseForGpuLaunch cause) { 344 CauseForGpuLaunch cause) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 return host; 416 return host;
417 } 417 }
418 418
419 return NULL; 419 return NULL;
420 } 420 }
421 421
422 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) 422 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind)
423 : host_id_(host_id), 423 : host_id_(host_id),
424 valid_(true), 424 valid_(true),
425 in_process_(false), 425 in_process_(false),
426 software_rendering_(false), 426 swiftshader_rendering_(false),
427 kind_(kind), 427 kind_(kind),
428 process_launched_(false), 428 process_launched_(false),
429 initialized_(false), 429 initialized_(false),
430 uma_memory_stats_received_(false) { 430 uma_memory_stats_received_(false) {
431 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || 431 CommandLine* command_line = CommandLine::ForCurrentProcess();
432 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) { 432 if (command_line->HasSwitch(switches::kSingleProcess) ||
433 command_line->HasSwitch(switches::kInProcessGPU)) {
433 in_process_ = true; 434 in_process_ = true;
434 } 435 }
435 436
436 // If the 'single GPU process' policy ever changes, we still want to maintain 437 // If the 'single GPU process' policy ever changes, we still want to maintain
437 // it for 'gpu thread' mode and only create one instance of host and thread. 438 // it for 'gpu thread' mode and only create one instance of host and thread.
438 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); 439 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL);
439 440
440 g_gpu_process_hosts[kind] = this; 441 g_gpu_process_hosts[kind] = this;
441 442
442 // Post a task to create the corresponding GpuProcessHostUIShim. The 443 // Post a task to create the corresponding GpuProcessHostUIShim. The
(...skipping 17 matching lines...) Expand all
460 // Maximum number of times the gpu process is allowed to crash in a session. 461 // Maximum number of times the gpu process is allowed to crash in a session.
461 // Once this limit is reached, any request to launch the gpu process will 462 // Once this limit is reached, any request to launch the gpu process will
462 // fail. 463 // fail.
463 const int kGpuMaxCrashCount = 3; 464 const int kGpuMaxCrashCount = 3;
464 465
465 // Number of times the gpu process has crashed in the current browser session. 466 // Number of times the gpu process has crashed in the current browser session.
466 static int gpu_crash_count = 0; 467 static int gpu_crash_count = 0;
467 static int gpu_recent_crash_count = 0; 468 static int gpu_recent_crash_count = 0;
468 static base::Time last_gpu_crash_time; 469 static base::Time last_gpu_crash_time;
469 static bool crashed_before = false; 470 static bool crashed_before = false;
470 static int gpu_software_crash_count = 0; 471 static int swiftshader_crash_count = 0;
471 472
472 // Ending only acts as a failure if the GPU process was actually started and 473 // Ending only acts as a failure if the GPU process was actually started and
473 // was intended for actual rendering (and not just checking caps or other 474 // was intended for actual rendering (and not just checking caps or other
474 // options). 475 // options).
475 if (process_launched_ && kind_ == GPU_PROCESS_KIND_SANDBOXED) { 476 if (process_launched_ && kind_ == GPU_PROCESS_KIND_SANDBOXED) {
476 if (software_rendering_) { 477 if (swiftshader_rendering_) {
477 UMA_HISTOGRAM_ENUMERATION("GPU.SoftwareRendererLifetimeEvents", 478 UMA_HISTOGRAM_ENUMERATION("GPU.SwiftShaderLifetimeEvents",
478 DIED_FIRST_TIME + gpu_software_crash_count, 479 DIED_FIRST_TIME + swiftshader_crash_count,
479 GPU_PROCESS_LIFETIME_EVENT_MAX); 480 GPU_PROCESS_LIFETIME_EVENT_MAX);
480 481
481 if (++gpu_software_crash_count >= kGpuMaxCrashCount) { 482 if (++swiftshader_crash_count >= kGpuMaxCrashCount) {
482 // The software renderer is too unstable to use. Disable it for current 483 // SwiftShader is too unstable to use. Disable it for current session.
483 // session.
484 gpu_enabled_ = false; 484 gpu_enabled_ = false;
485 } 485 }
486 } else { 486 } else {
487 ++gpu_crash_count; 487 ++gpu_crash_count;
488 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", 488 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents",
489 std::min(DIED_FIRST_TIME + gpu_crash_count, 489 std::min(DIED_FIRST_TIME + gpu_crash_count,
490 GPU_PROCESS_LIFETIME_EVENT_MAX - 1), 490 GPU_PROCESS_LIFETIME_EVENT_MAX - 1),
491 GPU_PROCESS_LIFETIME_EVENT_MAX); 491 GPU_PROCESS_LIFETIME_EVENT_MAX);
492 492
493 // Allow about 1 GPU crash per hour to be removed from the crash count, 493 // Allow about 1 GPU crash per hour to be removed from the crash count,
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", 1048 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime",
1049 base::TimeTicks::Now() - init_start_time_); 1049 base::TimeTicks::Now() - init_start_time_);
1050 } 1050 }
1051 1051
1052 void GpuProcessHost::OnProcessCrashed(int exit_code) { 1052 void GpuProcessHost::OnProcessCrashed(int exit_code) {
1053 SendOutstandingReplies(); 1053 SendOutstandingReplies();
1054 GpuDataManagerImpl::GetInstance()->ProcessCrashed( 1054 GpuDataManagerImpl::GetInstance()->ProcessCrashed(
1055 process_->GetTerminationStatus(NULL)); 1055 process_->GetTerminationStatus(NULL));
1056 } 1056 }
1057 1057
1058 bool GpuProcessHost::software_rendering() {
1059 return software_rendering_;
1060 }
1061
1062 GpuProcessHost::GpuProcessKind GpuProcessHost::kind() { 1058 GpuProcessHost::GpuProcessKind GpuProcessHost::kind() {
1063 return kind_; 1059 return kind_;
1064 } 1060 }
1065 1061
1066 void GpuProcessHost::ForceShutdown() { 1062 void GpuProcessHost::ForceShutdown() {
1067 // This is only called on the IO thread so no race against the constructor 1063 // This is only called on the IO thread so no race against the constructor
1068 // for another GpuProcessHost. 1064 // for another GpuProcessHost.
1069 if (g_gpu_process_hosts[kind_] == this) 1065 if (g_gpu_process_hosts[kind_] == this)
1070 g_gpu_process_hosts[kind_] = NULL; 1066 g_gpu_process_hosts[kind_] = NULL;
1071 1067
1072 process_->ForceShutdown(); 1068 process_->ForceShutdown();
1073 } 1069 }
1074 1070
1075 void GpuProcessHost::BeginFrameSubscription( 1071 void GpuProcessHost::BeginFrameSubscription(
1076 int surface_id, 1072 int surface_id,
1077 base::WeakPtr<RenderWidgetHostViewFrameSubscriber> subscriber) { 1073 base::WeakPtr<RenderWidgetHostViewFrameSubscriber> subscriber) {
1078 frame_subscribers_[surface_id] = subscriber; 1074 frame_subscribers_[surface_id] = subscriber;
1079 } 1075 }
1080 1076
1081 void GpuProcessHost::EndFrameSubscription(int surface_id) { 1077 void GpuProcessHost::EndFrameSubscription(int surface_id) {
1082 frame_subscribers_.erase(surface_id); 1078 frame_subscribers_.erase(surface_id);
1083 } 1079 }
1084 1080
1085 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { 1081 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) {
1086 if (!(gpu_enabled_ && 1082 if (!(gpu_enabled_ &&
1087 GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) && 1083 GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()) &&
1088 !hardware_gpu_enabled_) { 1084 !hardware_gpu_enabled_) {
1089 SendOutstandingReplies(); 1085 SendOutstandingReplies();
1090 return false; 1086 return false;
1091 } 1087 }
1092 1088
1093 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 1089 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1094 1090
1095 CommandLine::StringType gpu_launcher = 1091 CommandLine::StringType gpu_launcher =
1096 browser_command_line.GetSwitchValueNative(switches::kGpuLauncher); 1092 browser_command_line.GetSwitchValueNative(switches::kGpuLauncher);
1097 1093
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 cmd_line->CopySwitchesFrom( 1145 cmd_line->CopySwitchesFrom(
1150 browser_command_line, switches::kGLSwitchesCopiedFromGpuProcessHost, 1146 browser_command_line, switches::kGLSwitchesCopiedFromGpuProcessHost,
1151 switches::kGLSwitchesCopiedFromGpuProcessHostNumSwitches); 1147 switches::kGLSwitchesCopiedFromGpuProcessHostNumSwitches);
1152 1148
1153 GetContentClient()->browser()->AppendExtraCommandLineSwitches( 1149 GetContentClient()->browser()->AppendExtraCommandLineSwitches(
1154 cmd_line, process_->GetData().id); 1150 cmd_line, process_->GetData().id);
1155 1151
1156 GpuDataManagerImpl::GetInstance()->AppendGpuCommandLine(cmd_line); 1152 GpuDataManagerImpl::GetInstance()->AppendGpuCommandLine(cmd_line);
1157 1153
1158 if (cmd_line->HasSwitch(switches::kUseGL)) { 1154 if (cmd_line->HasSwitch(switches::kUseGL)) {
1159 software_rendering_ = 1155 swiftshader_rendering_ =
1160 (cmd_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"); 1156 (cmd_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader");
1161 } 1157 }
1162 1158
1163 UMA_HISTOGRAM_BOOLEAN("GPU.GPUProcessSoftwareRendering", software_rendering_); 1159 UMA_HISTOGRAM_BOOLEAN("GPU.GPUProcessSwiftShaderRendering",
1160 swiftshader_rendering_);
1164 1161
1165 // If specified, prepend a launcher program to the command line. 1162 // If specified, prepend a launcher program to the command line.
1166 if (!gpu_launcher.empty()) 1163 if (!gpu_launcher.empty())
1167 cmd_line->PrependWrapper(gpu_launcher); 1164 cmd_line->PrependWrapper(gpu_launcher);
1168 1165
1169 process_->Launch( 1166 process_->Launch(
1170 #if defined(OS_WIN) 1167 #if defined(OS_WIN)
1171 new GpuSandboxedProcessLauncherDelegate(cmd_line), 1168 new GpuSandboxedProcessLauncherDelegate(cmd_line),
1172 #elif defined(OS_POSIX) 1169 #elif defined(OS_POSIX)
1173 false, 1170 false,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); 1243 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader");
1247 ClientIdToShaderCacheMap::iterator iter = 1244 ClientIdToShaderCacheMap::iterator iter =
1248 client_id_to_shader_cache_.find(client_id); 1245 client_id_to_shader_cache_.find(client_id);
1249 // If the cache doesn't exist then this is an off the record profile. 1246 // If the cache doesn't exist then this is an off the record profile.
1250 if (iter == client_id_to_shader_cache_.end()) 1247 if (iter == client_id_to_shader_cache_.end())
1251 return; 1248 return;
1252 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); 1249 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader);
1253 } 1250 }
1254 1251
1255 } // namespace content 1252 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host.h ('k') | content/browser/renderer_host/image_transport_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698