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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 bool GpuProcessHost::gpu_enabled_ = true; | 64 bool GpuProcessHost::gpu_enabled_ = true; |
65 bool GpuProcessHost::hardware_gpu_enabled_ = true; | 65 bool GpuProcessHost::hardware_gpu_enabled_ = true; |
66 int GpuProcessHost::gpu_crash_count_ = 0; | 66 int GpuProcessHost::gpu_crash_count_ = 0; |
67 int GpuProcessHost::gpu_recent_crash_count_ = 0; | 67 int GpuProcessHost::gpu_recent_crash_count_ = 0; |
68 bool GpuProcessHost::crashed_before_ = false; | 68 bool GpuProcessHost::crashed_before_ = false; |
69 int GpuProcessHost::swiftshader_crash_count_ = 0; | 69 int GpuProcessHost::swiftshader_crash_count_ = 0; |
70 | 70 |
71 namespace { | 71 namespace { |
72 | 72 |
| 73 // Command-line switches to propagate to the GPU process. |
| 74 static const char* const kSwitchNames[] = { |
| 75 switches::kDisableAcceleratedVideoDecode, |
| 76 switches::kDisableBreakpad, |
| 77 switches::kDisableGpuSandbox, |
| 78 switches::kDisableGpuWatchdog, |
| 79 switches::kDisableLogging, |
| 80 switches::kDisableSeccompFilterSandbox, |
| 81 #if defined(ENABLE_WEBRTC) |
| 82 switches::kDisableWebRtcHWEncoding, |
| 83 #endif |
| 84 switches::kEnableLogging, |
| 85 switches::kEnableShareGroupAsyncTextureUpload, |
| 86 #if defined(OS_CHROMEOS) |
| 87 switches::kDisableVaapiAcceleratedVideoEncode, |
| 88 #endif |
| 89 switches::kGpuStartupDialog, |
| 90 switches::kGpuSandboxAllowSysVShm, |
| 91 switches::kGpuSandboxFailuresFatal, |
| 92 switches::kGpuSandboxStartEarly, |
| 93 switches::kIgnoreResolutionLimitsForAcceleratedVideoDecode, |
| 94 switches::kLoggingLevel, |
| 95 switches::kLowEndDeviceMode, |
| 96 switches::kNoSandbox, |
| 97 switches::kTestGLLib, |
| 98 switches::kTraceStartup, |
| 99 switches::kTraceToConsole, |
| 100 switches::kV, |
| 101 switches::kVModule, |
| 102 #if defined(OS_MACOSX) |
| 103 switches::kEnableRemoteCoreAnimation, |
| 104 switches::kEnableSandboxLogging, |
| 105 #endif |
| 106 #if defined(USE_AURA) |
| 107 switches::kUIPrioritizeInGpuProcess, |
| 108 #endif |
| 109 #if defined(USE_OZONE) |
| 110 switches::kOzonePlatform, |
| 111 switches::kOzoneUseSurfaceless, |
| 112 #endif |
| 113 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 114 switches::kX11Display, |
| 115 #endif |
| 116 }; |
| 117 |
73 enum GPUProcessLifetimeEvent { | 118 enum GPUProcessLifetimeEvent { |
74 LAUNCHED, | 119 LAUNCHED, |
75 DIED_FIRST_TIME, | 120 DIED_FIRST_TIME, |
76 DIED_SECOND_TIME, | 121 DIED_SECOND_TIME, |
77 DIED_THIRD_TIME, | 122 DIED_THIRD_TIME, |
78 DIED_FOURTH_TIME, | 123 DIED_FOURTH_TIME, |
79 GPU_PROCESS_LIFETIME_EVENT_MAX = 100 | 124 GPU_PROCESS_LIFETIME_EVENT_MAX = 100 |
80 }; | 125 }; |
81 | 126 |
82 // Indexed by GpuProcessKind. There is one of each kind maximum. This array may | 127 // Indexed by GpuProcessKind. There is one of each kind maximum. This array may |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 if (exe_path.empty()) | 868 if (exe_path.empty()) |
824 return false; | 869 return false; |
825 | 870 |
826 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 871 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
827 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 872 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
828 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 873 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
829 | 874 |
830 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) | 875 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) |
831 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); | 876 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); |
832 | 877 |
833 // Propagate relevant command line switches. | 878 // If you want a browser command-line switch passed to the GPU process |
834 static const char* const kSwitchNames[] = { | 879 // you need to add it to |kSwitchNames| at the beginning of this file. |
835 switches::kDisableAcceleratedVideoDecode, | |
836 switches::kDisableBreakpad, | |
837 switches::kDisableGpuSandbox, | |
838 switches::kDisableGpuWatchdog, | |
839 switches::kDisableLogging, | |
840 switches::kDisableSeccompFilterSandbox, | |
841 #if defined(ENABLE_WEBRTC) | |
842 switches::kDisableWebRtcHWEncoding, | |
843 #endif | |
844 switches::kEnableLogging, | |
845 switches::kEnableShareGroupAsyncTextureUpload, | |
846 #if defined(OS_CHROMEOS) | |
847 switches::kDisableVaapiAcceleratedVideoEncode, | |
848 #endif | |
849 switches::kGpuStartupDialog, | |
850 switches::kGpuSandboxAllowSysVShm, | |
851 switches::kGpuSandboxFailuresFatal, | |
852 switches::kGpuSandboxStartEarly, | |
853 switches::kIgnoreResolutionLimitsForAcceleratedVideoDecode, | |
854 switches::kLoggingLevel, | |
855 switches::kLowEndDeviceMode, | |
856 switches::kNoSandbox, | |
857 switches::kTestGLLib, | |
858 switches::kTraceStartup, | |
859 switches::kTraceToConsole, | |
860 switches::kV, | |
861 switches::kVModule, | |
862 #if defined(OS_MACOSX) | |
863 switches::kEnableRemoteCoreAnimation, | |
864 switches::kEnableSandboxLogging, | |
865 #endif | |
866 #if defined(USE_AURA) | |
867 switches::kUIPrioritizeInGpuProcess, | |
868 #endif | |
869 #if defined(USE_OZONE) | |
870 switches::kOzonePlatform, | |
871 switches::kOzoneUseSurfaceless, | |
872 #endif | |
873 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
874 switches::kX11Display, | |
875 #endif | |
876 }; | |
877 cmd_line->CopySwitchesFrom(browser_command_line, kSwitchNames, | 880 cmd_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
878 arraysize(kSwitchNames)); | 881 arraysize(kSwitchNames)); |
879 cmd_line->CopySwitchesFrom( | 882 cmd_line->CopySwitchesFrom( |
880 browser_command_line, switches::kGpuSwitches, switches::kNumGpuSwitches); | 883 browser_command_line, switches::kGpuSwitches, switches::kNumGpuSwitches); |
881 cmd_line->CopySwitchesFrom( | 884 cmd_line->CopySwitchesFrom( |
882 browser_command_line, switches::kGLSwitchesCopiedFromGpuProcessHost, | 885 browser_command_line, switches::kGLSwitchesCopiedFromGpuProcessHost, |
883 switches::kGLSwitchesCopiedFromGpuProcessHostNumSwitches); | 886 switches::kGLSwitchesCopiedFromGpuProcessHostNumSwitches); |
884 | 887 |
885 GetContentClient()->browser()->AppendExtraCommandLineSwitches( | 888 GetContentClient()->browser()->AppendExtraCommandLineSwitches( |
886 cmd_line, process_->GetData().id); | 889 cmd_line, process_->GetData().id); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 GpuDataManagerImpl::GetInstance()->BlockDomainFrom3DAPIs( | 937 GpuDataManagerImpl::GetInstance()->BlockDomainFrom3DAPIs( |
935 *iter, GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN); | 938 *iter, GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN); |
936 } | 939 } |
937 } | 940 } |
938 | 941 |
939 void GpuProcessHost::RecordProcessCrash() { | 942 void GpuProcessHost::RecordProcessCrash() { |
940 // Skip if a GPU process crash was already counted. | 943 // Skip if a GPU process crash was already counted. |
941 if (gpu_crash_recorded_) | 944 if (gpu_crash_recorded_) |
942 return; | 945 return; |
943 | 946 |
944 // Maximum number of times the gpu process is allowed to crash in a session. | 947 // Maximum number of times the GPU process is allowed to crash in a session. |
945 // Once this limit is reached, any request to launch the gpu process will | 948 // Once this limit is reached, any request to launch the GPU process will |
946 // fail. | 949 // fail. |
947 const int kGpuMaxCrashCount = 3; | 950 const int kGpuMaxCrashCount = 3; |
948 | 951 |
949 // Last time the GPU process crashed. | 952 // Last time the GPU process crashed. |
950 static base::Time last_gpu_crash_time; | 953 static base::Time last_gpu_crash_time; |
951 | 954 |
952 bool disable_crash_limit = base::CommandLine::ForCurrentProcess()->HasSwitch( | 955 bool disable_crash_limit = base::CommandLine::ForCurrentProcess()->HasSwitch( |
953 switches::kDisableGpuProcessCrashLimit); | 956 switches::kDisableGpuProcessCrashLimit); |
954 | 957 |
955 // Ending only acts as a failure if the GPU process was actually started and | 958 // Ending only acts as a failure if the GPU process was actually started and |
(...skipping 29 matching lines...) Expand all Loading... |
985 std::max(0, gpu_recent_crash_count_ - hours_different); | 988 std::max(0, gpu_recent_crash_count_ - hours_different); |
986 } | 989 } |
987 | 990 |
988 crashed_before_ = true; | 991 crashed_before_ = true; |
989 last_gpu_crash_time = current_time; | 992 last_gpu_crash_time = current_time; |
990 | 993 |
991 if ((gpu_recent_crash_count_ >= kGpuMaxCrashCount && | 994 if ((gpu_recent_crash_count_ >= kGpuMaxCrashCount && |
992 !disable_crash_limit) || | 995 !disable_crash_limit) || |
993 !initialized_) { | 996 !initialized_) { |
994 #if !defined(OS_CHROMEOS) | 997 #if !defined(OS_CHROMEOS) |
995 // The gpu process is too unstable to use. Disable it for current | 998 // The GPU process is too unstable to use. Disable it for current |
996 // session. | 999 // session. |
997 hardware_gpu_enabled_ = false; | 1000 hardware_gpu_enabled_ = false; |
998 GpuDataManagerImpl::GetInstance()->DisableHardwareAcceleration(); | 1001 GpuDataManagerImpl::GetInstance()->DisableHardwareAcceleration(); |
999 #endif | 1002 #endif |
1000 } | 1003 } |
1001 } | 1004 } |
1002 } | 1005 } |
1003 } | 1006 } |
1004 | 1007 |
1005 std::string GpuProcessHost::GetShaderPrefixKey() { | 1008 std::string GpuProcessHost::GetShaderPrefixKey() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1050 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1048 ClientIdToShaderCacheMap::iterator iter = | 1051 ClientIdToShaderCacheMap::iterator iter = |
1049 client_id_to_shader_cache_.find(client_id); | 1052 client_id_to_shader_cache_.find(client_id); |
1050 // If the cache doesn't exist then this is an off the record profile. | 1053 // If the cache doesn't exist then this is an off the record profile. |
1051 if (iter == client_id_to_shader_cache_.end()) | 1054 if (iter == client_id_to_shader_cache_.end()) |
1052 return; | 1055 return; |
1053 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1056 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1054 } | 1057 } |
1055 | 1058 |
1056 } // namespace content | 1059 } // namespace content |
OLD | NEW |