summaryrefslogtreecommitdiffstats
path: root/src/core/web_engine_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/web_engine_context.cpp')
-rw-r--r--src/core/web_engine_context.cpp53
1 files changed, 41 insertions, 12 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index 622670acf..cd2ff8be5 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -51,6 +51,9 @@
#include "base/threading/thread_restrictions.h"
#include "cc/base/switches.h"
#include "chrome/common/chrome_switches.h"
+#include "content/gpu/gpu_child_thread.h"
+#include "content/browser/compositor/surface_utils.h"
+#include "components/viz/host/host_frame_sink_manager.h"
#if QT_CONFIG(webengine_printing_and_pdf)
#include "chrome/browser/printing/print_job_manager.h"
#include "components/printing/browser/features.h"
@@ -230,6 +233,26 @@ void setupProxyPac(base::CommandLine *commandLine){
}
}
+static bool waitForViz = false;
+static void completeVizCleanup()
+{
+ waitForViz = false;
+}
+
+static void cleanupVizProcess()
+{
+ auto gpuChildThread = content::GpuChildThread::instance();
+ if (!gpuChildThread)
+ return;
+ auto vizMain = gpuChildThread->viz_main();
+ auto vizCompositorThreadRunner = vizMain->viz_compositor_thread_runner();
+ if (!vizCompositorThreadRunner)
+ return;
+ waitForViz = true;
+ content::GetHostFrameSinkManager()->SetConnectionLostCallback(base::DoNothing());
+ vizCompositorThreadRunner->CleanupForShutdown(base::BindOnce(&completeVizCleanup));
+}
+
scoped_refptr<QtWebEngineCore::WebEngineContext> WebEngineContext::m_handle;
bool WebEngineContext::m_destroyed = false;
@@ -276,14 +299,21 @@ void WebEngineContext::destroy()
if (m_devtoolsServer)
m_devtoolsServer->stop();
- // Normally the GPU thread is shut down when the GpuProcessHost is destroyed
- // on IO thread (triggered by ~BrowserMainRunner). But by that time the UI
- // task runner is not working anymore so we need to do this earlier.
- destroyGpuProcess(m_threadedGpu);
base::MessagePump::Delegate *delegate =
static_cast<base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl *>(
m_runLoop->delegate_);
+ // Normally the GPU thread is shut down when the GpuProcessHost is destroyed
+ // on IO thread (triggered by ~BrowserMainRunner). But by that time the UI
+ // task runner is not working anymore so we need to do this earlier.
+ if (features::IsVizDisplayCompositorEnabled()) {
+ cleanupVizProcess();
+ while (waitForViz) {
+ while (delegate->DoWork()){}
+ QThread::msleep(50);
+ }
+ }
+ destroyGpuProcess();
// Flush the UI message loop before quitting.
while (delegate->DoWork()) { }
@@ -431,8 +461,7 @@ static void appendToFeatureSwitch(base::CommandLine *commandLine, const char *fe
}
WebEngineContext::WebEngineContext()
- : m_threadedGpu(true)
- , m_mainDelegate(new ContentMainDelegateQt)
+ : m_mainDelegate(new ContentMainDelegateQt)
, m_globalQObject(new QObject())
{
#if defined(Q_OS_MACOS)
@@ -520,18 +549,18 @@ WebEngineContext::WebEngineContext()
if (isDesktopGLOrSoftware || isGLES2Context)
parsedCommandLine->AppendSwitch(switches::kDisableES3GLContext);
#endif
-
+ bool threadedGpu = false;
#ifndef QT_NO_OPENGL
- m_threadedGpu = QOpenGLContext::supportsThreadedOpenGL();
+ threadedGpu = QOpenGLContext::supportsThreadedOpenGL();
#if defined(Q_OS_MACOS)
// QtBase disabled it when building on 10.14+, unfortunately we still need it
// until we have fixed single-threaded viz-display-compositor.
- m_threadedGpu = true;
+ threadedGpu = true;
#endif
#endif
- m_threadedGpu = m_threadedGpu && !qEnvironmentVariableIsSet(kDisableInProcGpuThread);
+ threadedGpu = threadedGpu && !qEnvironmentVariableIsSet(kDisableInProcGpuThread);
- bool enableViz = ((m_threadedGpu && !parsedCommandLine->HasSwitch("disable-viz-display-compositor"))
+ bool enableViz = ((threadedGpu && !parsedCommandLine->HasSwitch("disable-viz-display-compositor"))
|| parsedCommandLine->HasSwitch("enable-viz-display-compositor"));
parsedCommandLine->RemoveSwitch("disable-viz-display-compositor");
parsedCommandLine->RemoveSwitch("enable-viz-display-compositor");
@@ -685,7 +714,7 @@ WebEngineContext::WebEngineContext()
parsedCommandLine->AppendSwitch(switches::kDisableGpu);
}
- registerMainThreadFactories(m_threadedGpu);
+ registerMainThreadFactories(threadedGpu);
SetContentClient(new ContentClientQt);