Bug 1763893: Avoid late creation of the GPU process. r=aosmond

The GPU process is destroyed in `ShutdownPhase::XPCOMShutdown` thus we shall not try to create it if we are in or beyond that phase.
Actually we might want to consider to block the creation even earlier if it does not exist, maybe from `ShutdownPhase::AppShutdown`, but this patch wants to just repair the crashes.

Differential Revision: https://phabricator.services.mozilla.com/D143349
This commit is contained in:
Jens Stutte 2022-04-11 11:49:21 +00:00
parent 80d0e18901
commit cbf1df6c09
4 changed files with 16 additions and 8 deletions

View File

@ -10,6 +10,7 @@
#include "gfxPlatform.h"
#include "GPUProcessHost.h"
#include "GPUProcessListener.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/MemoryReportingProcess.h"
#include "mozilla/Preferences.h"
#include "mozilla/Sprintf.h"
@ -135,7 +136,7 @@ GPUProcessManager::Observer::Observe(nsISupports* aSubject, const char* aTopic,
} else if (!strcmp(aTopic, "application-foreground")) {
mManager->mAppInForeground = true;
if (!mManager->mProcess && gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
mManager->LaunchGPUProcess();
Unused << mManager->LaunchGPUProcess();
}
} else if (!strcmp(aTopic, "application-background")) {
mManager->mAppInForeground = false;
@ -177,9 +178,13 @@ void GPUProcessManager::OnPreferenceChange(const char16_t* aData) {
}
}
void GPUProcessManager::LaunchGPUProcess() {
bool GPUProcessManager::LaunchGPUProcess() {
if (mProcess) {
return;
return true;
}
if (AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdown)) {
return false;
}
// Start listening for pref changes so we can
@ -224,6 +229,8 @@ void GPUProcessManager::LaunchGPUProcess() {
if (!mProcess->Launch(extraArgs)) {
DisableGPUProcess("Failed to launch GPU process");
}
return true;
}
bool GPUProcessManager::IsGPUProcessLaunching() {
@ -286,7 +293,9 @@ bool GPUProcessManager::EnsureGPUReady() {
// Launch the GPU process if it is enabled but hasn't been (re-)launched yet.
if (!mProcess && gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
LaunchGPUProcess();
if (!LaunchGPUProcess()) {
return false;
}
}
if (mProcess && !mProcess->IsConnected()) {
@ -772,7 +781,7 @@ void GPUProcessManager::HandleProcessLost() {
// until the app is in the foreground again.
if (gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
if (mAppInForeground) {
LaunchGPUProcess();
Unused << LaunchGPUProcess();
}
} else {
// If the GPU process is disabled we can reinitialize rendering immediately.

View File

@ -87,7 +87,7 @@ class GPUProcessManager final : public GPUProcessHost::Listener {
~GPUProcessManager();
// If not using a GPU process, launch a new GPU process asynchronously.
void LaunchGPUProcess();
bool LaunchGPUProcess();
bool IsGPUProcessLaunching();
// Ensure that GPU-bound methods can be used. If no GPU process is being

View File

@ -932,7 +932,7 @@ void gfxPlatform::Init() {
if (gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
GPUProcessManager* gpu = GPUProcessManager::Get();
gpu->LaunchGPUProcess();
Unused << gpu->LaunchGPUProcess();
}
if (XRE_IsParentProcess()) {

View File

@ -1912,7 +1912,6 @@ GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) {
if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS)) {
gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
}
gpm->LaunchGPUProcess();
gpm->EnsureGPUReady();
} else {
gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS, "xpcshell-test");