Skip to content

Commit

Permalink
feat: support ELECTRON_DEFAULT_ERROR_MODE in the GPU process
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Apr 11, 2019
1 parent 748632d commit c30fd5a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 0 deletions.
6 changes: 6 additions & 0 deletions atom/app/atom_main_delegate.cc
Expand Up @@ -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/relauncher.h"
#include "atom/common/options_switches.h"
#include "atom/renderer/atom_renderer_client.h"
Expand Down Expand Up @@ -257,6 +258,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(
Expand Down
2 changes: 2 additions & 0 deletions atom/app/atom_main_delegate.h
Expand Up @@ -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(
Expand All @@ -48,6 +49,7 @@ class AtomMainDelegate : public content::ContentMainDelegate {

std::unique_ptr<content::ContentBrowserClient> browser_client_;
std::unique_ptr<content::ContentClient> content_client_;
std::unique_ptr<content::ContentGpuClient> gpu_client_;
std::unique_ptr<content::ContentRendererClient> renderer_client_;
std::unique_ptr<content::ContentUtilityClient> utility_client_;

Expand Down
25 changes: 25 additions & 0 deletions 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 <windows.h>
#endif

namespace atom {

AtomGpuClient::AtomGpuClient() = default;

void AtomGpuClient::PreCreateMainMessageLoop() {
#if defined(OS_WIN)
auto env = base::Environment::Create();
if (env->HasVar("ELECTRON_DEFAULT_ERROR_MODE"))
SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX);
#endif
}

} // namespace atom
25 changes: 25 additions & 0 deletions 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 PreCreateMainMessageLoop() override;

private:
DISALLOW_COPY_AND_ASSIGN(AtomGpuClient);
};

} // namespace atom

#endif // ATOM_BROWSER_ATOM_GPU_CLIENT_H_
2 changes: 2 additions & 0 deletions filenames.gni
Expand Up @@ -226,6 +226,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",
Expand Down
1 change: 1 addition & 0 deletions patches/common/chromium/.patches
Expand Up @@ -73,3 +73,4 @@ fix_disable_usage_of_setapplicationisdaemon_and.patch
disable_custom_libcxx_on_windows.patch
fix_retain_compatibility_with_msvc.patch
disable_network_services_by_default.patch
add_contentgpuclient_precreatemainmessageloop_callback.patch
@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Milan Burda <milan.burda@gmail.com>
Date: Thu, 11 Apr 2019 14:49:20 +0200
Subject: Add ContentGpuClient::PreCreateMainMessageLoop() callback


diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc
index 39e87967360a9c7a2856ce4df9c182c782efb2a5..cb82d66212430a01605231ffe4596fc7d794577a 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->PreCreateMainMessageLoop();
+
// 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..abf347a94e47ca2d9383eaaa526c313c42ac146e 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 initializatioion before
+ // creating the main message loop.
+ virtual void PreCreateMainMessageLoop() {}
+
// 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

0 comments on commit c30fd5a

Please sign in to comment.