From e89e30ca7fb6a8937480fa7783de8b6131d58e3a Mon Sep 17 00:00:00 2001
From: Andrew Osmond <aosmond@mozilla.com>
Date: Thu, 17 Sep 2020 14:04:24 +0000
Subject: [PATCH] Bug 1665648 - Initialize GPU process config before WebRender.
 r=kats

We need to initialize the GPU process config before WebRender because we
have a dependency on the GPU process to enable WebRender. Without this
patch, it gives very confusing initialization failures, which it should
be clear that it was disabled because there is no GPU process. The GPU
process feature itself will then have a clear reason why it was
disabled, typically because Windows did not support remote windowing
(e.g. too old).

Differential Revision: https://phabricator.services.mozilla.com/D90564
---
 gfx/thebes/gfxWindowsPlatform.cpp | 13 +++++++------
 gfx/thebes/gfxWindowsPlatform.h   |  2 +-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp
index e4794f6658cf8..7e807c5db9f04 100644
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -319,6 +319,7 @@ void gfxWindowsPlatform::InitAcceleration() {
   DeviceManagerDx::Init();
 
   InitializeConfig();
+  InitGPUProcessSupport();
   // Ensure devices initialization. SharedSurfaceANGLE and
   // SharedSurfaceD3D11Interop use them. The devices are lazily initialized
   // with WebRender to reduce memory usage.
@@ -439,6 +440,7 @@ bool gfxWindowsPlatform::HandleDeviceReset() {
   // XXX Add InitWebRenderConfig() calling.
   InitializeAdvancedLayersConfig();
   if (mInitializedDevices) {
+    InitGPUProcessSupport();
     InitializeDevices();
   }
   UpdateANGLEConfig();
@@ -1428,7 +1430,7 @@ void gfxWindowsPlatform::InitializeDevices() {
     // initialize any DirectX devices. We do leave them enabled in gfxConfig
     // though. If the GPU process fails to create these devices it will send
     // a message back and we'll update their status.
-    if (InitGPUProcessSupport()) {
+    if (gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
       return;
     }
 
@@ -1585,11 +1587,11 @@ void gfxWindowsPlatform::InitializeD2D() {
   d2d1_1.SetSuccessful();
 }
 
-bool gfxWindowsPlatform::InitGPUProcessSupport() {
+void gfxWindowsPlatform::InitGPUProcessSupport() {
   FeatureState& gpuProc = gfxConfig::GetFeature(Feature::GPU_PROCESS);
 
   if (!gpuProc.IsEnabled()) {
-    return false;
+    return;
   }
 
   nsCString message;
@@ -1597,14 +1599,14 @@ bool gfxWindowsPlatform::InitGPUProcessSupport() {
   if (!gfxPlatform::IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_GPU_PROCESS,
                                         &message, failureId)) {
     gpuProc.Disable(FeatureStatus::Blocklisted, message.get(), failureId);
-    return false;
+    return;
   }
 
   if (!gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
     // Don't use the GPU process if not using D3D11, unless software
     // compositor is allowed
     if (StaticPrefs::layers_gpu_process_allow_software_AtStartup()) {
-      return gpuProc.IsEnabled();
+      return;
     }
     gpuProc.Disable(FeatureStatus::Unavailable,
                     "Not using GPU Process since D3D11 is unavailable",
@@ -1630,7 +1632,6 @@ bool gfxWindowsPlatform::InitGPUProcessSupport() {
   }
 
   // If we're still enabled at this point, the user set the force-enabled pref.
-  return gpuProc.IsEnabled();
 }
 
 bool gfxWindowsPlatform::DwmCompositionEnabled() {
diff --git a/gfx/thebes/gfxWindowsPlatform.h b/gfx/thebes/gfxWindowsPlatform.h
index 09e55a86b7752..6dff24c8959f5 100644
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -241,7 +241,7 @@ class gfxWindowsPlatform final : public gfxPlatform {
   void InitializeD3D11();
   void InitializeD2D();
   bool InitDWriteSupport();
-  bool InitGPUProcessSupport();
+  void InitGPUProcessSupport();
 
   void DisableD2D(mozilla::gfx::FeatureStatus aStatus, const char* aMessage,
                   const nsACString& aFailureId);
-- 
GitLab