有没有办法在没有 OpenGL 的情况下使用 QtWebEngine?

Is there any way to use QtWebEngine without OpenGL?

我正在尝试在 VM 上获取 QtWebEngine 运行,但遇到了困难。根据的回答:

Eventually I realised that OpenGL 3.3 wouldn't work easily on virtual machines .. yet. I had to boot from ubuntu usb and work from there by installing latest mesa 3d package.

有没有办法让 QtWebEngine 在没有 OpenGL 的情况下工作?我没有直接使用任何 OpenGL 调用,也不需要任何 3d 功能。我只想嵌入一个 QWebEngineView 来显示动态 HTML 页面。我猜这应该是可能的,因为 Chrome 在同一个虚拟机上工作没有问题。

我认为没有 OpenGL 就无法使用 Qt WebEngine。文档中没有明确说明,但这是我从发现的内容中了解到的内容。

关于Chromium

据说here, QtWebEngine integrates chromium's fast moving web capabilities into Qt. Plus, it is Chromium that allows the manipulation of OpenGL via the Qt Quick scene graph (source) :

Chromium is tightly integrated to the Qt Quick scene graph, which is based on OpenGL ES 2.0 or OpenGL 2.0 for its rendering. This provides you with one-pass compositing of web content and all the Qt Quick UI. The integration to Chromium is transparent to developers, who just work with Qt and JavaScript.

也有人说渲染进程和GUI进程应该共享一个OpenGL上下文:

Because the render process is separated from the GUI process, they should ideally share an OpenGL context to enable one process to access the resources uploaded by the other, such as images or textures.

关于 Qt WebEngine 本身

我们刚才讲了Qt的GUI:其实Qt WebEngine并不依赖这个GUI(页面渲染和JavaScript执行从GUI进程分离到Qt WebEngine进程),但是记住如果你想让你的应用程序工作,你将需要在两个进程之间共享一个 OpenGL 上下文。特别是,这是默认情况下使用 QSurfaceFormat, which has a OpenGLContextProfile accessible by the function QSurfaceFormat::profile(). Now, we look back at the Qt WebEngine platform notes 实现的,它声明:

If a new default QSurfaceFormat with a modified OpenGL profile has to be set, it should be set before the application instance is declared, to make sure that all created OpenGL contexts use the same OpenGL profile.

On OS X, if the default QSurfaceFormat is set after the application instance, the application will exit with qFatal(), and print a message that the default QSurfaceFormat should be set before the application instance.

如果我们查看 Qt 的源代码,会在几个重要文件中调用 OpenGL,例如 qtwebengine\src\core\web_engine_context.cppqtwebengine\src\webengine\api\qtwebengineglobal.cpp。此外,我还发现 qtwebengine\srcrdparty\chromium\ 中源代码中的函数调用了 OpenGL,因此我怀疑 Chromium 有时需要调用 OpenGL 函数。

简而言之

Qt WebEngine 使用 Chromium(不一定使用 OpenGL)和 Qt GUI,后者使用必须由 Web 引擎共享的 OpenGL 上下文。因此,我的结论是没有 OpenGL 就不能使用 Qt WebEngine。

我在尝试启动使用 QtWebEngine 的应用程序时在我的 VM 环境中遇到了同样的问题,但它崩溃了。

我会添加这个答案作为参考 - 尽管 Sergey Khasanov 已经在上面的评论中提到了它

使用软件 Qt Quick2DRenderer - 参见 https://doc.qt.io/QtQuick2DRenderer/

为此,只需设置环境变量:

export QMLSCENE_DEVICE=softwarecontext

然后重新启动您的应用程序。它可能还会抱怨

libEGL warning: GLX/DRI2 is not supported
libEGL warning: DRI2: failed to authenticate

但是(就我而言)最终 成功了!