summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-15 11:07:50 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-16 09:27:30 +0000
commitaf29cec0a428108274a60fca3738f67cadbaf23b (patch)
tree2b9cf987a7ccbbb3baef57f2d6acc15b085d0a2a /src/core
parent396ca081d7b0d9dab7de14ebaec7943c3f857a24 (diff)
Move thread setup out of the web_engine_context.cpp
This helps avoid conflicts between Qt and Chromium OpenGL headers. Change-Id: Ib77d0d985397ef2b9792b26df4bec69bbfbe4611 Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core_chromium.pri1
-rw-r--r--src/core/web_engine_context.cpp72
-rw-r--r--src/core/web_engine_context.h7
-rw-r--r--src/core/web_engine_context_threads.cpp132
4 files changed, 138 insertions, 74 deletions
diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri
index 05324ec6b..e6ccdc848 100644
--- a/src/core/core_chromium.pri
+++ b/src/core/core_chromium.pri
@@ -120,6 +120,7 @@ SOURCES = \
web_contents_delegate_qt.cpp \
web_contents_view_qt.cpp \
web_engine_context.cpp \
+ web_engine_context_threads.cpp \
web_engine_error.cpp \
web_engine_library_info.cpp \
web_engine_settings.cpp \
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index 096568570..dc7459e9f 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -54,12 +54,6 @@
#include "components/viz/common/features.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/browser/devtools/devtools_http_handler.h"
-#include "content/browser/gpu/gpu_main_thread_factory.h"
-#include "content/browser/renderer_host/render_process_host_impl.h"
-#include "content/browser/utility_process_host.h"
-#include "content/gpu/gpu_child_thread.h"
-#include "content/gpu/gpu_process.h"
-#include "content/gpu/in_process_gpu_thread.h"
#include "content/public/app/content_main.h"
#include "content/public/app/content_main_runner.h"
#include "content/public/browser/browser_main_runner.h"
@@ -69,9 +63,8 @@
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
-#include "content/renderer/in_process_renderer_thread.h"
-#include "content/utility/in_process_utility_thread.h"
#include "gpu/command_buffer/service/gpu_switches.h"
+#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/ipc/host/gpu_switches.h"
#include "media/audio/audio_manager.h"
#include "mojo/core/embedder/embedder.h"
@@ -551,13 +544,11 @@ WebEngineContext::WebEngineContext()
parsedCommandLine->AppendSwitch(switches::kDisableGpu);
}
- content::UtilityProcessHost::RegisterUtilityMainThreadFactory(content::CreateInProcessUtilityThread);
- content::RenderProcessHostImpl::RegisterRendererMainThreadFactory(content::CreateInProcessRendererThread);
- content::RegisterGpuMainThreadFactory(content::CreateInProcessGpuThread);
+ bool threadedGpu = true;
#ifndef QT_NO_OPENGL
- if (!QOpenGLContext::supportsThreadedOpenGL())
- content::RegisterGpuMainThreadFactory(createGpuThreadController);
+ threadedGpu = QOpenGLContext::supportsThreadedOpenGL();
#endif
+ registerMainThreadFactories(threadedGpu);
mojo::core::Init();
@@ -619,59 +610,4 @@ printing::PrintJobManager* WebEngineContext::getPrintJobManager()
}
#endif
-// static
-std::unique_ptr<content::GpuThreadController> WebEngineContext::createGpuThreadController(
- const content::InProcessChildThreadParams &params, const gpu::GpuPreferences &gpuPreferences)
-{
- struct Controller : content::GpuThreadController
- {
- Controller(const content::InProcessChildThreadParams &params, const gpu::GpuPreferences &gpuPreferences)
- {
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::BindOnce(&WebEngineContext::createGpuProcess, params, gpuPreferences));
- }
- ~Controller()
- {
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::BindOnce(&WebEngineContext::destroyGpuProcess));
- }
- };
- return std::make_unique<Controller>(params, gpuPreferences);
-}
-
-// static
-void WebEngineContext::createGpuProcess(
- const content::InProcessChildThreadParams &params, const gpu::GpuPreferences &gpuPreferences)
-{
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-
- WebEngineContext *context = current();
- if (!context || context->m_gpuProcessDestroyed)
- return;
-
- context->m_gpuProcess = std::make_unique<content::GpuProcess>(base::ThreadPriority::NORMAL);
- auto gpuInit = std::make_unique<gpu::GpuInit>();
- gpuInit->InitializeInProcess(base::CommandLine::ForCurrentProcess(), gpuPreferences);
- auto childThread = new content::GpuChildThread(params, std::move(gpuInit));
- childThread->Init(base::Time::Now());
- context->m_gpuProcess->set_main_thread(childThread);
-}
-
-// static
-void WebEngineContext::destroyGpuProcess()
-{
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-
- WebEngineContext *context = current();
- if (!context)
- return;
-
- // viz::GpuServiceImpl::~GpuServiceImpl waits for io task.
- base::ScopedAllowBaseSyncPrimitivesForTesting allow;
- context->m_gpuProcess.reset();
- context->m_gpuProcessDestroyed = true;
-}
-
} // namespace
diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h
index 036dc4ccb..cca14194d 100644
--- a/src/core/web_engine_context.h
+++ b/src/core/web_engine_context.h
@@ -100,10 +100,7 @@ private:
WebEngineContext();
~WebEngineContext();
- static std::unique_ptr<content::GpuThreadController> createGpuThreadController(
- const content::InProcessChildThreadParams &params, const gpu::GpuPreferences &gpuPreferences);
- static void createGpuProcess(
- const content::InProcessChildThreadParams &params, const gpu::GpuPreferences &gpuPreferences);
+ static void registerMainThreadFactories(bool threaded);
static void destroyGpuProcess();
std::unique_ptr<base::RunLoop> m_runLoop;
@@ -113,8 +110,6 @@ private:
std::unique_ptr<QObject> m_globalQObject;
std::unique_ptr<ProfileAdapter> m_defaultProfileAdapter;
std::unique_ptr<DevToolsServerQt> m_devtoolsServer;
- std::unique_ptr<content::GpuProcess> m_gpuProcess;
- bool m_gpuProcessDestroyed = false;
QVector<ProfileAdapter*> m_profileAdapters;
#if QT_CONFIG(webengine_printing_and_pdf)
diff --git a/src/core/web_engine_context_threads.cpp b/src/core/web_engine_context_threads.cpp
new file mode 100644
index 000000000..3e5d47b92
--- /dev/null
+++ b/src/core/web_engine_context_threads.cpp
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "web_engine_context.h"
+
+#include "base/bind.h"
+#include "base/threading/platform_thread.h"
+#include "base/threading/thread_restrictions.h"
+#include "content/browser/gpu/gpu_main_thread_factory.h"
+#include "content/browser/renderer_host/render_process_host_impl.h"
+#include "content/browser/utility_process_host.h"
+#include "content/gpu/gpu_child_thread.h"
+#include "content/gpu/gpu_process.h"
+#include "content/gpu/in_process_gpu_thread.h"
+#include "content/renderer/in_process_renderer_thread.h"
+#include "content/utility/in_process_utility_thread.h"
+
+#include <memory>
+
+namespace QtWebEngineCore {
+
+struct GpuThreadControllerQt : content::GpuThreadController
+{
+ GpuThreadControllerQt(const content::InProcessChildThreadParams &params, const gpu::GpuPreferences &gpuPreferences)
+ {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::BindOnce(&GpuThreadControllerQt::createGpuProcess, params, gpuPreferences));
+ }
+ ~GpuThreadControllerQt() override
+ {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::BindOnce(&GpuThreadControllerQt::destroyGpuProcess));
+ }
+
+ static void createGpuProcess(
+ const content::InProcessChildThreadParams &params,
+ const gpu::GpuPreferences &gpuPreferences)
+ {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (s_gpuProcessDestroyed)
+ return;
+
+ s_gpuProcess = std::make_unique<content::GpuProcess>(base::ThreadPriority::NORMAL);
+ auto gpuInit = std::make_unique<gpu::GpuInit>();
+ gpuInit->InitializeInProcess(base::CommandLine::ForCurrentProcess(), gpuPreferences);
+ auto childThread = new content::GpuChildThread(params, std::move(gpuInit));
+ childThread->Init(base::Time::Now());
+ s_gpuProcess->set_main_thread(childThread);
+ }
+
+ static void destroyGpuProcess()
+ {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (s_gpuProcessDestroyed)
+ return;
+
+ // viz::GpuServiceImpl::~GpuServiceImpl waits for io task.
+ base::ScopedAllowBaseSyncPrimitivesForTesting allow;
+ s_gpuProcess.reset();
+ s_gpuProcessDestroyed = true;
+ }
+
+ static std::unique_ptr<content::GpuProcess> s_gpuProcess;
+ static bool s_gpuProcessDestroyed;
+};
+
+std::unique_ptr<content::GpuProcess> GpuThreadControllerQt::s_gpuProcess;
+bool GpuThreadControllerQt::s_gpuProcessDestroyed = false;
+
+static std::unique_ptr<content::GpuThreadController> createGpuThreadController(
+ const content::InProcessChildThreadParams &params,
+ const gpu::GpuPreferences &gpuPreferences)
+{
+ return std::make_unique<GpuThreadControllerQt>(params, gpuPreferences);
+}
+
+// static
+void WebEngineContext::destroyGpuProcess()
+{
+ GpuThreadControllerQt::destroyGpuProcess();
+}
+
+// static
+void WebEngineContext::registerMainThreadFactories(bool threaded)
+{
+ content::UtilityProcessHost::RegisterUtilityMainThreadFactory(content::CreateInProcessUtilityThread);
+ content::RenderProcessHostImpl::RegisterRendererMainThreadFactory(content::CreateInProcessRendererThread);
+ if (threaded)
+ content::RegisterGpuMainThreadFactory(content::CreateInProcessGpuThread);
+ else
+ content::RegisterGpuMainThreadFactory(createGpuThreadController);
+}
+
+} // namespace QtWebEngineCore