From fcf0af15deb1cb87233ace17a6d193db73552a15 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 30 Apr 2019 18:45:48 +0200 Subject: [PATCH] feat: support ELECTRON_DEFAULT_ERROR_MODE in the GPU process (#17728) --- BUILD.gn | 1 + atom/app/atom_main_delegate.cc | 6 +++ atom/app/atom_main_delegate.h | 2 + atom/browser/atom_gpu_client.cc | 25 ++++++++++ atom/browser/atom_gpu_client.h | 25 ++++++++++ filenames.gni | 2 + patches/common/chromium/.patches | 1 + ...client_precreatemessageloop_callback.patch | 48 +++++++++++++++++++ 8 files changed, 110 insertions(+) create mode 100644 atom/browser/atom_gpu_client.cc create mode 100644 atom/browser/atom_gpu_client.h create mode 100644 patches/common/chromium/add_contentgpuclient_precreatemessageloop_callback.patch diff --git a/BUILD.gn b/BUILD.gn index e695838b9f95..8ed1099684e5 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -436,6 +436,7 @@ static_library("electron_lib") { "//content/public/browser", "//content/public/child", "//content/public/common:service_names", + "//content/public/gpu", "//content/public/renderer", "//content/public/utility", "//device/bluetooth", diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 5080fc7a53ab..518ca75c9320 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -14,6 +14,7 @@ #include "atom/app/atom_content_client.h" #include "atom/browser/atom_browser_client.h" +#include "atom/browser/atom_gpu_client.h" #include "atom/browser/feature_list.h" #include "atom/browser/relauncher.h" #include "atom/common/options_switches.h" @@ -262,6 +263,11 @@ content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() { return browser_client_.get(); } +content::ContentGpuClient* AtomMainDelegate::CreateContentGpuClient() { + gpu_client_.reset(new AtomGpuClient); + return gpu_client_.get(); +} + content::ContentRendererClient* AtomMainDelegate::CreateContentRendererClient() { if (base::CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/atom/app/atom_main_delegate.h b/atom/app/atom_main_delegate.h index 3c2dfe194bbb..de30536a061e 100644 --- a/atom/app/atom_main_delegate.h +++ b/atom/app/atom_main_delegate.h @@ -27,6 +27,7 @@ class AtomMainDelegate : public content::ContentMainDelegate { void PreCreateMainMessageLoop() override; void PostEarlyInitialization(bool is_running_tests) override; content::ContentBrowserClient* CreateContentBrowserClient() override; + content::ContentGpuClient* CreateContentGpuClient() override; content::ContentRendererClient* CreateContentRendererClient() override; content::ContentUtilityClient* CreateContentUtilityClient() override; int RunProcess( @@ -48,6 +49,7 @@ class AtomMainDelegate : public content::ContentMainDelegate { std::unique_ptr browser_client_; std::unique_ptr content_client_; + std::unique_ptr gpu_client_; std::unique_ptr renderer_client_; std::unique_ptr utility_client_; diff --git a/atom/browser/atom_gpu_client.cc b/atom/browser/atom_gpu_client.cc new file mode 100644 index 000000000000..faa6bd9a38c9 --- /dev/null +++ b/atom/browser/atom_gpu_client.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2019 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/atom_gpu_client.h" + +#include "base/environment.h" + +#if defined(OS_WIN) +#include +#endif + +namespace atom { + +AtomGpuClient::AtomGpuClient() = default; + +void AtomGpuClient::PreCreateMessageLoop() { +#if defined(OS_WIN) + auto env = base::Environment::Create(); + if (env->HasVar("ELECTRON_DEFAULT_ERROR_MODE")) + SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX); +#endif +} + +} // namespace atom diff --git a/atom/browser/atom_gpu_client.h b/atom/browser/atom_gpu_client.h new file mode 100644 index 000000000000..cfa180725c3d --- /dev/null +++ b/atom/browser/atom_gpu_client.h @@ -0,0 +1,25 @@ +// Copyright (c) 2019 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_ATOM_GPU_CLIENT_H_ +#define ATOM_BROWSER_ATOM_GPU_CLIENT_H_ + +#include "content/public/gpu/content_gpu_client.h" + +namespace atom { + +class AtomGpuClient : public content::ContentGpuClient { + public: + AtomGpuClient(); + + // content::ContentGpuClient: + void PreCreateMessageLoop() override; + + private: + DISALLOW_COPY_AND_ASSIGN(AtomGpuClient); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_ATOM_GPU_CLIENT_H_ diff --git a/filenames.gni b/filenames.gni index 97afae152f1f..06292e72e0be 100644 --- a/filenames.gni +++ b/filenames.gni @@ -232,6 +232,8 @@ filenames = { "atom/browser/atom_browser_context.h", "atom/browser/atom_download_manager_delegate.cc", "atom/browser/atom_download_manager_delegate.h", + "atom/browser/atom_gpu_client.cc", + "atom/browser/atom_gpu_client.h", "atom/browser/atom_browser_main_parts.cc", "atom/browser/atom_browser_main_parts.h", "atom/browser/atom_browser_main_parts_mac.mm", diff --git a/patches/common/chromium/.patches b/patches/common/chromium/.patches index 1526d7e6916e..3331c56b4f60 100644 --- a/patches/common/chromium/.patches +++ b/patches/common/chromium/.patches @@ -76,3 +76,4 @@ viz_osr.patch patch_the_ensure_gn_version_py_script_to_work_on_mac_ci.patch revert_roll_clang_356356_357569.patch build_add_electron_tracing_category.patch +add_contentgpuclient_precreatemessageloop_callback.patch diff --git a/patches/common/chromium/add_contentgpuclient_precreatemessageloop_callback.patch b/patches/common/chromium/add_contentgpuclient_precreatemessageloop_callback.patch new file mode 100644 index 000000000000..07aac78dbb4f --- /dev/null +++ b/patches/common/chromium/add_contentgpuclient_precreatemessageloop_callback.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Milan Burda +Date: Thu, 11 Apr 2019 14:49:20 +0200 +Subject: Add ContentGpuClient::PreCreateMessageLoop() callback + +Invoke in GpuMain after SetErrorMode, before starting the message loop. +Allows Electron to restore WER when ELECTRON_DEFAULT_ERROR_MODE is set. + +This should be upstreamed + +diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc +index 39e87967360a9c7a2856ce4df9c182c782efb2a5..ade3e7905d01b25128f477c68c10edd0f96626c3 100644 +--- a/content/gpu/gpu_main.cc ++++ b/content/gpu/gpu_main.cc +@@ -234,6 +234,10 @@ int GpuMain(const MainFunctionParams& parameters) { + + logging::SetLogMessageHandler(GpuProcessLogMessageHandler); + ++ auto* client = GetContentClient()->gpu(); ++ if (client) ++ client->PreCreateMessageLoop(); ++ + // We are experiencing what appear to be memory-stomp issues in the GPU + // process. These issues seem to be impacting the message loop and listeners + // registered to it. Create the message loop on the heap to guard against +@@ -329,7 +333,6 @@ int GpuMain(const MainFunctionParams& parameters) { + + GpuProcess gpu_process(io_thread_priority); + +- auto* client = GetContentClient()->gpu(); + if (client) + client->PostIOThreadCreated(gpu_process.io_task_runner()); + +diff --git a/content/public/gpu/content_gpu_client.h b/content/public/gpu/content_gpu_client.h +index 20e31e1bd96395cb4350aa6ae84cc16c4ca2116b..d89af81ef9426c197a62027b514011afd10ea3ce 100644 +--- a/content/public/gpu/content_gpu_client.h ++++ b/content/public/gpu/content_gpu_client.h +@@ -35,6 +35,10 @@ class CONTENT_EXPORT ContentGpuClient { + public: + virtual ~ContentGpuClient() {} + ++ // Allows the embedder to perform platform-specific initialization before ++ // creating the message loop. ++ virtual void PreCreateMessageLoop() {} ++ + // Initializes the registry. |registry| will be passed to a ConnectionFilter + // (which lives on the IO thread). Unlike other childthreads, the client must + // register additional interfaces on this registry rather than just creating