[vlc-commits] [Git][videolan/vlc][master] qt: wait for Qt to initialize the dcomp device in `setupVoutWindow()`

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Sep 30 15:28:32 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
42d0ca06 by Fatih Uzunoglu at 2024-09-30T15:14:30+00:00
qt: wait for Qt to initialize the dcomp device in `setupVoutWindow()`

This method requires the direct composition device
in order to create the video visual.

When this method is called, Qt might not have fully
initialized the interface as scene graph initialization
is done asynchronously.

In this case, simply wait for the initialization to
complete. If the initialization fails or takes too
much time to complete, then fail by returning false.

Co-authored-by: Pierre Lamot <pierre at videolabs.io>

- - - - -


2 changed files:

- modules/gui/qt/maininterface/compositor_dcomp.cpp
- modules/gui/qt/maininterface/compositor_dcomp.hpp


Changes:

=====================================
modules/gui/qt/maininterface/compositor_dcomp.cpp
=====================================
@@ -229,6 +229,12 @@ void CompositorDirectComposition::setup()
             }
         }
     }
+
+    {
+        QMutexLocker lock(&m_setupStateLock);
+        m_setupState = SetupState::Success;
+        m_setupStateCond.notify_all();
+    }
 }
 
 bool CompositorDirectComposition::makeMainInterface(MainCtx* mainCtx)
@@ -244,8 +250,6 @@ bool CompositorDirectComposition::makeMainInterface(MainCtx* mainCtx)
 
     m_quickView->installEventFilter(this);
 
-    bool appropriateGraphicsApi = true;
-
     connect(quickViewPtr,
             &QQuickWindow::frameSwapped, // At this stage, we can be sure that QRhi and QRhiSwapChain are valid.
             this,
@@ -259,6 +263,16 @@ bool CompositorDirectComposition::makeMainInterface(MainCtx* mainCtx)
     if (!ret)
         return false;
 
+    connect(quickViewPtr,
+            &QQuickWindow::sceneGraphError,
+            this,
+            [this](QQuickWindow::SceneGraphError error, const QString &message) {
+                qWarning() << "CompositorDComp: Scene Graph Error: " << error << ", Message: " << message;
+                QMutexLocker lock(&m_setupStateLock);
+                m_setupState = SetupState::Fail;
+                m_setupStateCond.notify_all();
+            }, static_cast<Qt::ConnectionType>(Qt::SingleShotConnection | Qt::DirectConnection));
+
     m_quickView->show();
 
     return true;
@@ -296,6 +310,20 @@ void CompositorDirectComposition::unloadGUI()
 
 bool CompositorDirectComposition::setupVoutWindow(vlc_window_t *p_wnd, VoutDestroyCb destroyCb)
 {
+    {
+        QMutexLocker lock(&m_setupStateLock);
+        while (m_setupState == SetupState::Uninitialized)
+        {
+            const bool ret = m_setupStateCond.wait(&m_setupStateLock, QDeadlineTimer(2500));
+            if (!ret)
+                return false;
+        }
+        if (m_setupState != SetupState::Success)
+        {
+            return false;
+        }
+    }
+
     assert(m_dcompDevice);
 
     const HRESULT hr = m_dcompDevice->CreateVisual(&m_videoVisual);


=====================================
modules/gui/qt/maininterface/compositor_dcomp.hpp
=====================================
@@ -25,6 +25,8 @@
 #include "video_window_handler.hpp"
 
 #include <QPointer>
+#include <QWaitCondition>
+#include <QMutex>
 
 #include <memory>
 
@@ -78,6 +80,15 @@ protected:
     void windowDestroy() override;
 
 private:
+    enum class SetupState {
+        Uninitialized,
+        Success,
+        Fail
+    };
+    SetupState m_setupState = SetupState::Uninitialized;
+    QWaitCondition m_setupStateCond;
+    QMutex m_setupStateLock;
+
     std::unique_ptr<QQuickView> m_quickView;
 
     IDCompositionDevice *m_dcompDevice = nullptr;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/42d0ca063f7fd63c8ccc5ab521ee2cf7a0b149cc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/42d0ca063f7fd63c8ccc5ab521ee2cf7a0b149cc
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list