[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: add `priority` parameter in `AsyncTask::start()`
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Tue Jun 9 12:24:45 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
ba85af7d by Fatih Uzunoglu at 2026-06-09T14:03:34+02:00
qt: add `priority` parameter in `AsyncTask::start()`
- - - - -
cb361557 by Fatih Uzunoglu at 2026-06-09T14:03:34+02:00
qt: do asynchronous rhi probing at start in a separate thread
Qt Rhi docs clearly notes [1] that QRhi instance may be created
in any thread. With this change, we make sure to not slow down
the start.
Non-threaded asynchronous probing does not guarantee that the
start of the interface is not slowed down, because many things
in the interface depends on queued events.
[1] https://doc.qt.io/qt-6/qrhi.html#threading
- - - - -
2 changed files:
- modules/gui/qt/qt.cpp
- modules/gui/qt/util/asynctask.hpp
Changes:
=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -61,6 +61,8 @@ extern "C" char **environ;
#include <QTranslator>
#ifdef _WIN32
#include <QOperatingSystemVersion>
+#include <QThreadPool>
+#include "util/asynctask.hpp"
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
#include <rhi/qrhi.h>
#include <QOffscreenSurface>
@@ -1062,19 +1064,42 @@ static void *Thread( void *obj )
// item. Currently the player waits for the interface, and QQuickWindow initialization
// is therefore not enforced to be synchronous (`QWindow::setVisible(true)` which
// initializes the scene graph thus rhi is asynchronous).
- QMetaObject::invokeMethod(&app, [&app, settings = QPointer(p_intf->mainSettings)]() {
+
+ class RhiProbeTask : public AsyncTask<QPair<QSGRendererInterface::GraphicsApi, bool>>
+ {
+ public:
+ RhiProbeTask() = default;
+
+ QPair<QSGRendererInterface::GraphicsApi, bool> execute() override
+ {
+ return probeRhi();
+ }
+ };
+
+ const auto rhiProbeTask = QPointer(new RhiProbeTask);
+ QObject::connect(rhiProbeTask, &BaseAsyncTask::result, qApp, [rhiProbeTask, settings = QPointer(p_intf->mainSettings)]() {
// We can not use `QQuickWindow::setGraphicsApi()` here, as QQuickWindow
// may have already tried to initialize the scene graph hence rhi. If the
// cached graphics api is not optimal or not available anymore, the next
// startup will use the refreshed value. That's the best we can do here
// without forcing QQuickWindow to wait (hence delaying startup).
assert(settings);
- const auto rhiResult = probeRhi();
+ const QPair<QSGRendererInterface::GraphicsApi, bool> rhiResult = rhiProbeTask->takeResult();
settings->setValue(graphicsApiKey, static_cast<int>(rhiResult.first));
settings->setValue(graphicsApiRhiSoftwareKey, rhiResult.second);
settings->sync();
- app.setProperty(asyncRhiProbeCompletedProperty, true);
- }, Qt::QueuedConnection); // Asynchronous, so probing here does not cause start-up slowdown.
+ qApp->setProperty(asyncRhiProbeCompletedProperty, true);
+ qDebug() << "Asynchronous rhi re-probe completed. Graphics api (QSGRendererInterface::GraphicsApi):"
+ << rhiResult.first
+ << "Prefer software renderer:"
+ << rhiResult.second;
+ rhiProbeTask->abandon();
+ }, Qt::QueuedConnection);
+
+ const auto globalThreadPool = QThreadPool::globalInstance();
+ assert(globalThreadPool);
+
+ rhiProbeTask->start(*globalThreadPool, -1);
}
else
{
=====================================
modules/gui/qt/util/asynctask.hpp
=====================================
@@ -157,11 +157,11 @@ public:
/**
* Start the task on the thread pool
*/
- void start(QThreadPool &threadPool)
+ void start(QThreadPool &threadPool, int priority = 0)
{
m_threadPool = &threadPool;
m_runnable = std::make_unique<Runnable>(this);
- threadPool.start(&*m_runnable);
+ threadPool.start(&*m_runnable, priority);
}
/**
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e8f4a3d3ac7e94b95762e0bbc8b7010c06ad1d2b...cb361557b790d891fbf6b1fd3eb030f5bfc018da
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e8f4a3d3ac7e94b95762e0bbc8b7010c06ad1d2b...cb361557b790d891fbf6b1fd3eb030f5bfc018da
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list