[vlc-commits] [Git][videolan/vlc][master] 4 commits: qt: notify position and size when video surface gets activated

Pierre Lamot (@chub) gitlab at videolan.org
Thu Oct 14 08:02:12 UTC 2021



Pierre Lamot pushed to branch master at VideoLAN / VLC


Commits:
451c0eb1 by Pierre Lamot at 2021-10-14T07:47:44+00:00
qt: notify position and size when video surface gets activated

- - - - -
df7d6325 by Pierre Lamot at 2021-10-14T07:47:44+00:00
qt: move MainInterface instantiation outside of the compositor

- - - - -
12676dcb by Pierre Lamot at 2021-10-14T07:47:44+00:00
qt: factorize vout window callbacks

- - - - -
66e297e7 by Pierre Lamot at 2021-10-14T07:47:44+00:00
qt: factorize interface construction across compositor

- - - - -


13 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/dialogs/extended/extended.cpp
- modules/gui/qt/maininterface/compositor.cpp
- modules/gui/qt/maininterface/compositor.hpp
- modules/gui/qt/maininterface/compositor_dcomp.cpp
- modules/gui/qt/maininterface/compositor_dcomp.hpp
- modules/gui/qt/maininterface/compositor_dcomp_uisurface.hpp
- modules/gui/qt/maininterface/compositor_dummy.cpp
- modules/gui/qt/maininterface/compositor_dummy.hpp
- modules/gui/qt/maininterface/compositor_win7.cpp
- modules/gui/qt/maininterface/compositor_win7.hpp
- modules/gui/qt/maininterface/videosurface.cpp
- modules/gui/qt/qt.cpp


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -340,6 +340,7 @@ nodist_libqt_plugin_la_SOURCES = \
 	gui/qt/dialogs/toolbar/controlbar_profile.moc.cpp \
 	gui/qt/dialogs/toolbar/controlbar_profile_model.moc.cpp \
 	gui/qt/dialogs/playlists/playlists.moc.cpp \
+	gui/qt/maininterface/compositor.moc.cpp \
 	gui/qt/maininterface/compositor_dummy.moc.cpp \
 	gui/qt/maininterface/interface_window_handler.moc.cpp \
 	gui/qt/maininterface/main_interface.moc.cpp \


=====================================
modules/gui/qt/dialogs/extended/extended.cpp
=====================================
@@ -35,6 +35,7 @@
 #include <QGridLayout>
 #include <QDialogButtonBox>
 #include <QPushButton>
+#include <QWindow>
 #include <vlc_modules.h>
 
 ExtendedDialog::ExtendedDialog( qt_intf_t *_p_intf )


=====================================
modules/gui/qt/maininterface/compositor.cpp
=====================================
@@ -18,15 +18,21 @@
 
 #include "compositor.hpp"
 #include "compositor_dummy.hpp"
+#include "main_interface.hpp"
+#include "video_window_handler.hpp"
+#include "videosurface.hpp"
+#include "interface_window_handler.hpp"
+#include "mainui.hpp"
 
 #ifdef _WIN32
+#include "main_interface_win32.hpp"
 #ifdef HAVE_DCOMP_H
 #  include "compositor_dcomp.hpp"
 #endif
 #  include "compositor_win7.hpp"
 #endif
 
-namespace vlc {
+using namespace vlc;
 
 template<typename T>
 static Compositor* instanciateCompositor(qt_intf_t *p_intf) {
@@ -86,10 +92,207 @@ Compositor* CompositorFactory::createCompositor()
     return nullptr;
 }
 
-void Compositor::onWindowDestruction(vout_window_t *p_wnd)
+
+extern "C"
+{
+
+static int windowEnableCb(vout_window_t* p_wnd, const vout_window_cfg_t * cfg)
+{
+    assert(p_wnd->sys);
+    auto that = static_cast<vlc::CompositorVideo*>(p_wnd->sys);
+    int ret = VLC_EGENERIC;
+    QMetaObject::invokeMethod(that, [&](){
+        ret = that->windowEnable(cfg);
+    }, Qt::BlockingQueuedConnection);
+    return ret;
+}
+
+static void windowDisableCb(vout_window_t* p_wnd)
+{
+    assert(p_wnd->sys);
+    auto that = static_cast<vlc::CompositorVideo*>(p_wnd->sys);
+    QMetaObject::invokeMethod(that, [that](){
+        that->windowDisable();
+    }, Qt::BlockingQueuedConnection);
+}
+
+static void windowResizeCb(vout_window_t* p_wnd, unsigned width, unsigned height)
+{
+    assert(p_wnd->sys);
+    auto that = static_cast<vlc::CompositorVideo*>(p_wnd->sys);
+    that->windowResize(width, height);
+}
+
+static void windowDestroyCb(struct vout_window_t * p_wnd)
+{
+    assert(p_wnd->sys);
+    auto that = static_cast<vlc::CompositorVideo*>(p_wnd->sys);
+    that->windowDestroy();
+}
+
+static void windowSetStateCb(vout_window_t* p_wnd, unsigned state)
+{
+    assert(p_wnd->sys);
+    auto that = static_cast<vlc::CompositorVideo*>(p_wnd->sys);
+    that->windowSetState(state);
+}
+
+static void windowUnsetFullscreenCb(vout_window_t* p_wnd)
+{
+    assert(p_wnd->sys);
+    auto that = static_cast<vlc::CompositorVideo*>(p_wnd->sys);
+    that->windowUnsetFullscreen();
+}
+
+static void windowSetFullscreenCb(vout_window_t* p_wnd, const char *id)
+{
+    assert(p_wnd->sys);
+    auto that = static_cast<vlc::CompositorVideo*>(p_wnd->sys);
+    that->windowSetFullscreen(id);
+}
+
+}
+
+CompositorVideo::CompositorVideo(qt_intf_t *p_intf, QObject* parent)
+    : QObject(parent)
+    , m_intf(p_intf)
+{
+}
+
+CompositorVideo::~CompositorVideo()
+{
+
+}
+
+void CompositorVideo::commonSetupVoutWindow(vout_window_t* p_wnd, VoutDestroyCb destroyCb)
+{
+    static const struct vout_window_operations ops = {
+        windowEnableCb,
+        windowDisableCb,
+        windowResizeCb,
+        windowDestroyCb,
+        windowSetStateCb,
+        windowUnsetFullscreenCb,
+        windowSetFullscreenCb,
+        nullptr, //window_set_title
+    };
+
+    m_wnd = p_wnd;
+    m_destroyCb = destroyCb;
+    p_wnd->sys = this;
+    p_wnd->ops = &ops;
+    p_wnd->info.has_double_click = true;
+}
+
+void CompositorVideo::windowDestroy()
 {
     if (m_destroyCb)
-        m_destroyCb(p_wnd);
+        m_destroyCb(m_wnd);
+}
+
+void CompositorVideo::windowResize(unsigned width, unsigned height)
+{
+    m_videoWindowHandler->requestResizeVideo(width, height);
 }
 
+void CompositorVideo::windowSetState(unsigned state)
+{
+    m_videoWindowHandler->requestVideoState(static_cast<vout_window_state>(state));
+}
+
+void CompositorVideo::windowUnsetFullscreen()
+{
+    m_videoWindowHandler->requestVideoWindowed();
+}
+
+void CompositorVideo::windowSetFullscreen(const char *id)
+{
+    m_videoWindowHandler->requestVideoFullScreen(id);
+}
+
+void CompositorVideo::commonWindowEnable()
+{
+    m_videoSurfaceProvider->enable(m_wnd);
+    m_videoSurfaceProvider->setVideoEmbed(true);
+}
+
+void CompositorVideo::commonWindowDisable()
+{
+    m_videoSurfaceProvider->setVideoEmbed(false);
+    m_videoSurfaceProvider->disable();
+    m_videoWindowHandler->disable();
+}
+
+
+bool CompositorVideo::commonGUICreateImpl(QWindow* window, CompositorVideo::Flags flags)
+{
+    assert(m_mainInterface);
+
+    m_videoSurfaceProvider = std::make_unique<VideoSurfaceProvider>();
+    m_mainInterface->setVideoSurfaceProvider(m_videoSurfaceProvider.get());
+    if (flags & CompositorVideo::CAN_SHOW_PIP)
+    {
+        m_mainInterface->setCanShowVideoPIP(true);
+        connect(m_videoSurfaceProvider.get(), &VideoSurfaceProvider::surfacePositionChanged,
+                this, &CompositorVideo::onSurfacePositionChanged);
+        connect(m_videoSurfaceProvider.get(), &VideoSurfaceProvider::surfaceSizeChanged,
+                this, &CompositorVideo::onSurfaceSizeChanged);
+    }
+    m_videoWindowHandler = std::make_unique<VideoWindowHandler>(m_intf);
+    m_videoWindowHandler->setWindow( window );
+
+#ifdef _WIN32
+    m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandlerWin32>(m_intf, m_mainInterface, window);
+#else
+    m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandler>(m_intf, m_mainInterface, window);
+#endif
+    m_mainInterface->setHasAcrylicSurface(flags & CompositorVideo::HAS_ACRYLIC);
+
+#ifdef _WIN32
+    m_taskbarWidget = std::make_unique<WinTaskbarWidget>(m_intf, window);
+    qApp->installNativeEventFilter(m_taskbarWidget.get());
+#endif
+    m_ui = std::make_unique<MainUI>(m_intf, m_mainInterface, window);
+    return true;
+}
+
+bool CompositorVideo::commonGUICreate(QWindow* window, QmlUISurface* qmlSurface, CompositorVideo::Flags flags)
+{
+    bool ret = commonGUICreateImpl(window, flags);
+    if (!ret)
+        return false;
+    ret = m_ui->setup(qmlSurface->engine());
+    if (! ret)
+        return false;
+    qmlSurface->setContent(m_ui->getComponent(), m_ui->createRootItem());
+    return true;
+}
+
+bool CompositorVideo::commonGUICreate(QWindow* window, QQuickView* qmlView, CompositorVideo::Flags flags)
+{
+    bool ret = commonGUICreateImpl(window, flags);
+    if (!ret)
+        return false;
+    ret = m_ui->setup(qmlView->engine());
+    if (! ret)
+        return false;
+    qmlView->setContent(QUrl(), m_ui->getComponent(), m_ui->createRootItem());
+    return true;
+}
+
+void CompositorVideo::commonGUIDestroy()
+{
+    m_ui.reset();
+#ifdef _WIN32
+    qApp->removeNativeEventFilter(m_taskbarWidget.get());
+    m_taskbarWidget.reset();
+#endif
+    m_interfaceWindowHandler.reset();
+}
+
+void CompositorVideo::commonIntfDestroy()
+{
+    unloadGUI();
+    m_videoWindowHandler.reset();
+    m_videoSurfaceProvider.reset();
 }


=====================================
modules/gui/qt/maininterface/compositor.hpp
=====================================
@@ -22,15 +22,29 @@
 # include "config.h"
 #endif
 
+#include <memory>
+
+#include <QObject>
+
 #include <vlc_common.h>
 #include <vlc_interface.h>
 #include <vlc_vout_window.h>
 
-#include <QQuickView>
 
 #include "qt.hpp"
 
+
 class MainInterface;
+class VideoWindowHandler;
+class VideoSurfaceProvider;
+class InterfaceWindowHandler;
+class WinTaskbarWidget;
+class MainUI;
+class QQmlEngine;
+class QQmlComponent;
+class QWindow;
+class QQuickItem;
+class QQuickView;
 
 namespace vlc {
 
@@ -50,7 +64,7 @@ public:
 
     virtual bool init() = 0;
 
-    virtual MainInterface* makeMainInterface() = 0;
+    virtual bool makeMainInterface(MainInterface* intf) = 0;
     virtual void destroyMainInterface() = 0;
 
     virtual void unloadGUI() = 0;
@@ -61,12 +75,80 @@ public:
 
     virtual QWindow* interfaceMainWindow() const = 0;
 
+};
+
+/**
+ * @brief The CompositorVideo class is a base class for compositor that implements video embeding
+ */
+class CompositorVideo: public QObject, public Compositor
+{
+    Q_OBJECT
+public:
+    enum Flag : unsigned
+    {
+        CAN_SHOW_PIP = 1,
+        HAS_ACRYLIC = 2
+    };
+    Q_DECLARE_FLAGS(Flags, Flag)
+
+    class QmlUISurface
+    {
+    public:
+        virtual QQmlEngine* engine() const = 0;
+        virtual void setContent(QQmlComponent *component, QQuickItem *item) = 0;
+    };
+public:
+    explicit CompositorVideo(qt_intf_t* p_intf, QObject* parent = nullptr);
+    virtual ~CompositorVideo();
+
+public:
+    virtual int windowEnable(const vout_window_cfg_t *) = 0;
+    virtual void windowDisable() = 0;
+    virtual void windowDestroy();
+    virtual void windowResize(unsigned width, unsigned height);
+    virtual void windowSetState(unsigned state);
+    virtual void windowUnsetFullscreen();
+    virtual void windowSetFullscreen(const char *id);
+
+protected:
+    void commonSetupVoutWindow(vout_window_t* p_wnd, VoutDestroyCb destroyCb);
+    void commonWindowEnable();
+    void commonWindowDisable();
+
 protected:
-    void onWindowDestruction(vout_window_t *p_wnd);
+    bool commonGUICreate(QWindow* window, QmlUISurface* , CompositorVideo::Flags flags);
+    bool commonGUICreate(QWindow* window, QQuickView* , CompositorVideo::Flags flags);
+    void commonGUIDestroy();
+    void commonIntfDestroy();
+
+private:
+    bool commonGUICreateImpl(QWindow* window, CompositorVideo::Flags flags);
+
+
+protected slots:
+    virtual void onSurfacePositionChanged(const QPointF&) {}
+    virtual void onSurfaceSizeChanged(const QSizeF&) {}
+
+protected:
+    qt_intf_t *m_intf = nullptr;
+    vout_window_t* m_wnd = nullptr;
+
+    MainInterface* m_mainInterface = nullptr;
 
     VoutDestroyCb m_destroyCb = nullptr;
+    std::unique_ptr<VideoWindowHandler> m_videoWindowHandler;
+
+    std::unique_ptr<InterfaceWindowHandler> m_interfaceWindowHandler;
+    std::unique_ptr<MainUI> m_ui;
+    std::unique_ptr<VideoSurfaceProvider> m_videoSurfaceProvider;
+#ifdef _WIN32
+    std::unique_ptr<WinTaskbarWidget> m_taskbarWidget;
+#endif
 };
 
+Q_DECLARE_OPERATORS_FOR_FLAGS(CompositorVideo::Flags)
+
+
 /**
  * @brief The CompositorFactory class will instanciate a compositor
  * in auto mode, compositor will be instantiated from the list by order declaration,


=====================================
modules/gui/qt/maininterface/compositor_dcomp.cpp
=====================================
@@ -47,89 +47,50 @@ using namespace Microsoft::WRL;
 //Signature for DCompositionCreateDevice
 typedef HRESULT (*DCompositionCreateDeviceFun)(IDXGIDevice *dxgiDevice, REFIID iid, void** dcompositionDevice);
 
-int CompositorDirectComposition::window_enable(struct vout_window_t * p_wnd, const vout_window_cfg_t *)
+int CompositorDirectComposition::windowEnable(const vout_window_cfg_t *)
 {
-    CompositorDirectComposition* that = static_cast<CompositorDirectComposition*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_enable");
-    if (!that->m_videoVisual)
+    if (!m_videoVisual)
     {
-        msg_Err(that->m_intf, "m_videoVisual is null");
+        msg_Err(m_intf, "m_videoVisual is null");
         return VLC_EGENERIC;
     }
 
     try
     {
-        that->m_qmlVideoSurfaceProvider->enable(p_wnd);
-        that->m_qmlVideoSurfaceProvider->setVideoEmbed(true);
-        HR(that->m_rootVisual->AddVisual(that->m_videoVisual.Get(), FALSE, that->m_uiVisual.Get()), "add video visual to root");
-        HR(that->m_dcompDevice->Commit(), "commit");
+        commonWindowEnable();
+        HR(m_rootVisual->AddVisual(m_videoVisual.Get(), FALSE, m_uiVisual.Get()), "add video visual to root");
+        HR(m_dcompDevice->Commit(), "commit");
     }
     catch (const DXError& err)
     {
-        msg_Err(that->m_intf, "failed to enable window: %s code 0x%lX", err.what(), err.code());
+        msg_Err(m_intf, "failed to enable window: %s code 0x%lX", err.what(), err.code());
         return VLC_EGENERIC;
     }
     return VLC_SUCCESS;
 }
 
-void CompositorDirectComposition::window_disable(struct vout_window_t * p_wnd)
+void CompositorDirectComposition::windowDisable()
 {
-    CompositorDirectComposition* that = static_cast<CompositorDirectComposition*>(p_wnd->sys);
     try
     {
-        that->m_qmlVideoSurfaceProvider->setVideoEmbed(false);
-        that->m_qmlVideoSurfaceProvider->disable();
-        that->m_videoWindowHandler->disable();
-        msg_Dbg(that->m_intf, "window_disable");
-        HR(that->m_rootVisual->RemoveVisual(that->m_videoVisual.Get()), "remove video visual from root");
-        HR(that->m_dcompDevice->Commit(), "commit");
+        commonWindowDisable();
+        HR(m_rootVisual->RemoveVisual(m_videoVisual.Get()), "remove video visual from root");
+        HR(m_dcompDevice->Commit(), "commit");
     }
     catch (const DXError& err)
     {
-        msg_Err(that->m_intf, "failed to disable window: '%s' code: 0x%lX", err.what(), err.code());
+        msg_Err(m_intf, "failed to disable window: '%s' code: 0x%lX", err.what(), err.code());
     }
 }
 
-void CompositorDirectComposition::window_resize(struct vout_window_t * p_wnd, unsigned width, unsigned height)
+void CompositorDirectComposition::windowDestroy()
 {
-    CompositorDirectComposition* that = static_cast<CompositorDirectComposition*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_resize %ux%u", width, height);
-    that->m_videoWindowHandler->requestResizeVideo(width, height);
-}
-
-void CompositorDirectComposition::window_destroy(struct vout_window_t * p_wnd)
-{
-    CompositorDirectComposition* that = static_cast<CompositorDirectComposition*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_destroy");
-    that->m_window = nullptr;
-    that->m_videoVisual.Reset();
-    that->onWindowDestruction(p_wnd);
-}
-
-void CompositorDirectComposition::window_set_state(struct vout_window_t * p_wnd, unsigned state)
-{
-    CompositorDirectComposition* that = static_cast<CompositorDirectComposition*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_set_state");
-    that->m_videoWindowHandler->requestVideoState(static_cast<vout_window_state>(state));
-}
-
-void CompositorDirectComposition::window_unset_fullscreen(struct vout_window_t * p_wnd)
-{
-    CompositorDirectComposition* that = static_cast<CompositorDirectComposition*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_unset_fullscreen");
-    that->m_videoWindowHandler->requestVideoWindowed();
-}
-
-void CompositorDirectComposition::window_set_fullscreen(struct vout_window_t * p_wnd, const char *id)
-{
-    CompositorDirectComposition* that = static_cast<CompositorDirectComposition*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_set_fullscreen");
-    that->m_videoWindowHandler->requestVideoFullScreen(id);
+    m_videoVisual.Reset();
+    CompositorVideo::windowDestroy();
 }
 
 CompositorDirectComposition::CompositorDirectComposition( qt_intf_t* p_intf,  QObject *parent)
-    : QObject(parent)
-    , m_intf(p_intf)
+    : CompositorVideo(p_intf, parent)
 {
 }
 
@@ -284,18 +245,15 @@ bool CompositorDirectComposition::init()
     return true;
 }
 
-MainInterface* CompositorDirectComposition::makeMainInterface()
+bool CompositorDirectComposition::makeMainInterface(MainInterface* mainInterface)
 {
     try
     {
         bool ret;
-        m_mainInterface = new MainInterfaceWin32(m_intf);
+        m_mainInterface = mainInterface;
 
         m_rootWindow = new QWindow();
 
-        m_taskbarWidget = std::make_unique<WinTaskbarWidget>(m_intf, m_rootWindow);
-        qApp->installNativeEventFilter(m_taskbarWidget.get());
-
         m_videoWindowHandler = std::make_unique<VideoWindowHandler>(m_intf);
         m_videoWindowHandler->setWindow( m_rootWindow );
 
@@ -310,32 +268,12 @@ MainInterface* CompositorDirectComposition::makeMainInterface()
                                                                          m_uiVisual);
         ret = m_uiSurface->init();
         if (!ret)
-        {
-            destroyMainInterface();
-            return nullptr;
-        }
-
-        //install the interface window handler after the creation of CompositorDCompositionUISurface
-        //so the event filter is handled before the one of the UISurface (for wheel events)
-        m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandlerWin32>(m_intf, m_mainInterface, m_rootWindow);
-
-        m_qmlVideoSurfaceProvider = std::make_unique<VideoSurfaceProvider>();
-        m_mainInterface->setVideoSurfaceProvider(m_qmlVideoSurfaceProvider.get());
-        m_mainInterface->setCanShowVideoPIP(true);
-
-        connect(m_qmlVideoSurfaceProvider.get(), &VideoSurfaceProvider::hasVideoEmbedChanged,
-                m_interfaceWindowHandler.get(), &InterfaceWindowHandlerWin32::onVideoEmbedChanged);
-        connect(m_qmlVideoSurfaceProvider.get(), &VideoSurfaceProvider::surfacePositionChanged,
-                this, &CompositorDirectComposition::onSurfacePositionChanged);
-
-        m_ui = std::make_unique<MainUI>(m_intf, m_mainInterface, m_rootWindow);
-        ret = m_ui->setup(m_uiSurface->engine());
-        if (! ret)
-        {
-            destroyMainInterface();
-            return nullptr;
-        }
-        m_uiSurface->setContent(m_ui->getComponent(), m_ui->createRootItem());
+            return false;
+
+        ret = commonGUICreate(m_rootWindow, m_uiSurface.get(), CompositorVideo::CAN_SHOW_PIP);
+        if (!ret)
+            return false;
+
         HR(m_rootVisual->AddVisual(m_uiVisual.Get(), FALSE, nullptr), "add ui visual to root");
         HR(m_dcompDevice->Commit(), "commit UI visual");
 
@@ -349,33 +287,36 @@ MainInterface* CompositorDirectComposition::makeMainInterface()
         connect(qGuiApp, &QGuiApplication::screenRemoved, this, resetAcrylicSurface);
 
         m_rootWindow->show();
-        return m_mainInterface;
+        return true;
     }
     catch (const DXError& err)
     {
         msg_Err(m_intf, "failed to initialise compositor: '%s' code: 0x%lX", err.what(), err.code());
-        destroyMainInterface();
-        return nullptr;
+        return false;
     }
 }
 
-void CompositorDirectComposition::onSurfacePositionChanged(QPointF position)
+void CompositorDirectComposition::onSurfacePositionChanged(const QPointF& position)
 {
     HR(m_videoVisual->SetOffsetX(position.x()));
     HR(m_videoVisual->SetOffsetY(position.y()));
     HR(m_dcompDevice->Commit(), "commit UI visual");
 }
 
+void CompositorDirectComposition::onSurfaceSizeChanged(const QSizeF&)
+{
+    //N/A
+}
+
 void CompositorDirectComposition::destroyMainInterface()
 {
     if (m_videoVisual)
         msg_Err(m_intf, "video surface still active while destroying main interface");
 
-    unloadGUI();
+    commonIntfDestroy();
 
     m_rootVisual.Reset();
     m_dcompTarget.Reset();
-    m_qmlVideoSurfaceProvider.reset();
     if (m_rootWindow)
     {
         delete m_rootWindow;
@@ -393,20 +334,11 @@ void CompositorDirectComposition::unloadGUI()
     }
     m_acrylicSurface.reset();
     m_uiSurface.reset();
-    m_ui.reset();
-    m_taskbarWidget.reset();
-    m_interfaceWindowHandler.reset();
-    if (m_mainInterface)
-    {
-        delete m_mainInterface;
-        m_mainInterface = nullptr;
-    }
+    commonGUIDestroy();
 }
 
 bool CompositorDirectComposition::setupVoutWindow(vout_window_t *p_wnd, VoutDestroyCb destroyCb)
 {
-    m_destroyCb = destroyCb;
-
     //Only the first video is embedded
     if (m_videoVisual.Get())
         return false;
@@ -418,23 +350,10 @@ bool CompositorDirectComposition::setupVoutWindow(vout_window_t *p_wnd, VoutDest
         return false;
     }
 
-    static const struct vout_window_operations ops = {
-        CompositorDirectComposition::window_enable,
-        CompositorDirectComposition::window_disable,
-        CompositorDirectComposition::window_resize,
-        CompositorDirectComposition::window_destroy,
-        CompositorDirectComposition::window_set_state,
-        CompositorDirectComposition::window_unset_fullscreen,
-        CompositorDirectComposition::window_set_fullscreen,
-        nullptr, //window_set_title
-    };
-    p_wnd->sys = this;
+    commonSetupVoutWindow(p_wnd, destroyCb);
     p_wnd->type = VOUT_WINDOW_TYPE_DCOMP;
     p_wnd->display.dcomp_device = m_dcompDevice.Get();
     p_wnd->handle.dcomp_visual = m_videoVisual.Get();
-    p_wnd->ops = &ops;
-    p_wnd->info.has_double_click = true;
-    m_window = p_wnd;
     return true;
 }
 


=====================================
modules/gui/qt/maininterface/compositor_dcomp.hpp
=====================================
@@ -36,7 +36,7 @@ class WinTaskbarWidget;
 
 namespace vlc {
 
-class CompositorDirectComposition : public QObject, public Compositor
+class CompositorDirectComposition : public CompositorVideo
 {
     Q_OBJECT
 public:
@@ -46,7 +46,7 @@ public:
     static bool preInit(qt_intf_t *);
     bool init() override;
 
-    MainInterface *makeMainInterface() override;
+    bool makeMainInterface(MainInterface*) override;
     void destroyMainInterface() override;
     void unloadGUI() override;
 
@@ -59,30 +59,21 @@ public:
     void removeVisual(Microsoft::WRL::ComPtr<IDCompositionVisual> visual);
 
 private slots:
-    void onSurfacePositionChanged(QPointF position);
+    void onSurfacePositionChanged(const QPointF& position) override;
+    void onSurfaceSizeChanged(const QSizeF& size) override;
 
-private:
-    static int window_enable(struct vout_window_t *, const vout_window_cfg_t *);
-    static void window_disable(struct vout_window_t *);
-    static void window_resize(struct vout_window_t *, unsigned width, unsigned height);
-    static void window_destroy(struct vout_window_t *);
-    static void window_set_state(struct vout_window_t *, unsigned state);
-    static void window_unset_fullscreen(struct vout_window_t *);
-    static void window_set_fullscreen(struct vout_window_t *, const char *id);
-
-    qt_intf_t *m_intf = nullptr;
+protected:
+    int windowEnable(const vout_window_cfg_t *) override;
+    void windowDisable() override;
+    void windowDestroy() override;
 
-    MainInterface* m_mainInterface = nullptr;
+private:
     QWindow* m_rootWindow = nullptr;
+
     std::unique_ptr<WinTaskbarWidget> m_taskbarWidget;
 
     std::unique_ptr<CompositorDCompositionUISurface> m_uiSurface;
     std::unique_ptr<CompositorDCompositionAcrylicSurface> m_acrylicSurface;
-    vout_window_t *m_window = nullptr;
-    std::unique_ptr<MainUI> m_ui;
-    std::unique_ptr<VideoWindowHandler> m_videoWindowHandler;
-    std::unique_ptr<VideoSurfaceProvider> m_qmlVideoSurfaceProvider;
-    std::unique_ptr<InterfaceWindowHandler> m_interfaceWindowHandler;
 
     //main window composition
     HINSTANCE m_dcomp_dll = nullptr;


=====================================
modules/gui/qt/maininterface/compositor_dcomp_uisurface.hpp
=====================================
@@ -58,6 +58,7 @@
 #include <QtPlatformHeaders/QEGLNativeContext>
 
 #include "qt.hpp"
+#include "compositor.hpp"
 
 namespace vlc {
 
@@ -79,7 +80,7 @@ private:
     QWindow *m_window;
 };
 
-class CompositorDCompositionUISurface : public QObject
+class CompositorDCompositionUISurface : public QObject, public CompositorVideo::QmlUISurface
 {
     Q_OBJECT
 public:
@@ -92,9 +93,9 @@ public:
 
     bool init();
 
-    QQmlEngine* engine() const { return m_qmlEngine; }
+    QQmlEngine* engine() const override { return m_qmlEngine; }
 
-    void setContent(QQmlComponent* component,  QQuickItem* rootItem);
+    void setContent(QQmlComponent* component,  QQuickItem* rootItem) override;
 
     void timerEvent(QTimerEvent *event) override;
     bool eventFilter(QObject* object, QEvent* event) override;


=====================================
modules/gui/qt/maininterface/compositor_dummy.cpp
=====================================
@@ -45,24 +45,24 @@ bool CompositorDummy::init()
     return true;
 }
 
-MainInterface* CompositorDummy::makeMainInterface()
+bool CompositorDummy::makeMainInterface(MainInterface* mainInterface)
 {
-    m_mainInterface = std::make_unique<MainInterface>(m_intf);
+    m_mainInterface = mainInterface;
 
     m_qmlWidget = std::make_unique<QQuickView>();
     if (m_mainInterface->useClientSideDecoration())
         m_qmlWidget->setFlag(Qt::FramelessWindowHint);
     m_qmlWidget->setResizeMode(QQuickView::SizeRootObjectToView);
 
-    m_intfWindowHandler = std::make_unique<InterfaceWindowHandler>(m_intf, m_mainInterface.get(), m_qmlWidget.get());
+    m_intfWindowHandler = std::make_unique<InterfaceWindowHandler>(m_intf, m_mainInterface, m_qmlWidget.get());
 
-    MainUI* ui = new MainUI(m_intf, m_mainInterface.get(), m_qmlWidget.get(), m_qmlWidget.get());
+    MainUI* ui = new MainUI(m_intf, m_mainInterface, m_qmlWidget.get(), m_qmlWidget.get());
     ui->setup(m_qmlWidget->engine());
     m_qmlWidget->setContent(QUrl(), ui->getComponent(), ui->createRootItem());
 
     m_qmlWidget->show();
 
-    return m_mainInterface.get();
+    return true;
 }
 
 QWindow* CompositorDummy::interfaceMainWindow() const
@@ -79,7 +79,6 @@ void CompositorDummy::unloadGUI()
 {
     m_intfWindowHandler.reset();
     m_qmlWidget.reset();
-    m_mainInterface.reset();
 }
 
 bool CompositorDummy::setupVoutWindow(vout_window_t*, VoutDestroyCb)


=====================================
modules/gui/qt/maininterface/compositor_dummy.hpp
=====================================
@@ -41,7 +41,7 @@ public:
     static bool preInit(qt_intf_t*);
     virtual bool init() override;
 
-    virtual MainInterface *makeMainInterface() override;
+    virtual bool makeMainInterface(MainInterface*) override;
 
     /**
      * @brief release all resources used by the compositor.
@@ -65,7 +65,7 @@ protected:
     qt_intf_t *m_intf;
 
     std::unique_ptr<InterfaceWindowHandler> m_intfWindowHandler;
-    std::unique_ptr<MainInterface> m_mainInterface;
+    MainInterface* m_mainInterface;
     std::unique_ptr<QQuickView> m_qmlWidget;
 };
 


=====================================
modules/gui/qt/maininterface/compositor_win7.cpp
=====================================
@@ -26,63 +26,20 @@
 
 using namespace vlc;
 
-int CompositorWin7::window_enable(struct vout_window_t * p_wnd, const vout_window_cfg_t *)
+int CompositorWin7::windowEnable(const vout_window_cfg_t *)
 {
-    CompositorWin7* that = static_cast<CompositorWin7*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_enable");
-    that->m_videoSurfaceProvider->enable(p_wnd);
-    that->m_videoSurfaceProvider->setVideoEmbed(true);
+    commonWindowEnable();
     return VLC_SUCCESS;
 }
 
-void CompositorWin7::window_disable(struct vout_window_t * p_wnd)
+void CompositorWin7::windowDisable()
 {
-    CompositorWin7* that = static_cast<CompositorWin7*>(p_wnd->sys);
-    that->m_videoSurfaceProvider->setVideoEmbed(false);
-    that->m_videoSurfaceProvider->disable();
-    that->m_videoWindowHandler->disable();
-    msg_Dbg(that->m_intf, "window_disable");
-}
-
-void CompositorWin7::window_resize(struct vout_window_t * p_wnd, unsigned width, unsigned height)
-{
-    CompositorWin7* that = static_cast<CompositorWin7*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_resize %ux%u", width, height);
-    that->m_videoWindowHandler->requestResizeVideo(width, height);
-}
-
-void CompositorWin7::window_destroy(struct vout_window_t * p_wnd)
-{
-    CompositorWin7* that = static_cast<CompositorWin7*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_destroy");
-    that->onWindowDestruction(p_wnd);
-}
-
-void CompositorWin7::window_set_state(struct vout_window_t * p_wnd, unsigned state)
-{
-    CompositorWin7* that = static_cast<CompositorWin7*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_set_state");
-    that->m_videoWindowHandler->requestVideoState(static_cast<vout_window_state>(state));
-}
-
-void CompositorWin7::window_unset_fullscreen(struct vout_window_t * p_wnd)
-{
-    CompositorWin7* that = static_cast<CompositorWin7*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_unset_fullscreen");
-    that->m_videoWindowHandler->requestVideoWindowed();
-}
-
-void CompositorWin7::window_set_fullscreen(struct vout_window_t * p_wnd, const char *id)
-{
-    CompositorWin7* that = static_cast<CompositorWin7*>(p_wnd->sys);
-    msg_Dbg(that->m_intf, "window_set_fullscreen");
-    that->m_videoWindowHandler->requestVideoFullScreen(id);
+    commonWindowDisable();
 }
 
 
 CompositorWin7::CompositorWin7(qt_intf_t *p_intf, QObject* parent)
-    : QObject(parent)
-    , m_intf(p_intf)
+    : CompositorVideo(p_intf, parent)
 {
 }
 
@@ -140,10 +97,9 @@ bool CompositorWin7::init()
     return true;
 }
 
-MainInterface* CompositorWin7::makeMainInterface()
+bool CompositorWin7::makeMainInterface(MainInterface* mainInterface)
 {
-    MainInterfaceWin32* mainInterfaceW32 =  new MainInterfaceWin32(m_intf);
-    m_mainInterface = mainInterfaceW32;
+    m_mainInterface = mainInterface;
 
     /*
      * m_stable is not attached to the main interface because dialogs are attached to the mainInterface
@@ -171,22 +127,13 @@ MainInterface* CompositorWin7::makeMainInterface()
     DwmSetWindowAttribute(m_videoWindowHWND, DWMWA_EXCLUDED_FROM_PEEK, &excluseFromPeek, sizeof(excluseFromPeek));
     DwmSetWindowAttribute(m_videoWindowHWND, DWMWA_DISALLOW_PEEK, &excluseFromPeek, sizeof(excluseFromPeek));
 
-    m_videoSurfaceProvider = std::make_unique<VideoSurfaceProvider>();
-    m_mainInterface->setVideoSurfaceProvider(m_videoSurfaceProvider.get());
-    m_mainInterface->setCanShowVideoPIP(true);
-
-    connect(m_videoSurfaceProvider.get(), &VideoSurfaceProvider::surfacePositionChanged,
-            this, &CompositorWin7::onSurfacePositionChanged);
-    connect(m_videoSurfaceProvider.get(), &VideoSurfaceProvider::surfaceSizeChanged,
-            this, &CompositorWin7::onSurfaceSizeChanged);
-
     m_qmlView = std::make_unique<QQuickView>();
     m_qmlView->setResizeMode(QQuickView::SizeRootObjectToView);
     m_qmlView->setClearBeforeRendering(true);
     m_qmlView->setColor(QColor(Qt::transparent));
 
     m_qmlView->installEventFilter(this);
-    m_nativeEventFilter = std::make_unique<Win7NativeEventFilter>(this);
+    m_nativeEventFilter = std::make_unique<Win7NativeEventFilter>();
     qApp->installNativeEventFilter(m_nativeEventFilter.get());
     connect(m_nativeEventFilter.get(), &Win7NativeEventFilter::windowStyleChanged,
             this, &CompositorWin7::resetVideoZOrder);
@@ -195,26 +142,14 @@ MainInterface* CompositorWin7::makeMainInterface()
 
     m_qmlWindowHWND = (HWND)m_qmlView->winId();
 
-    m_videoWindowHandler = std::make_unique<VideoWindowHandler>(m_intf, m_mainInterface);
-    m_videoWindowHandler->setWindow( m_qmlView.get() );
-
-    m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandlerWin32>(m_intf, m_mainInterface, m_qmlView.get());
-
-    m_taskbarWidget = std::make_unique<WinTaskbarWidget>(m_intf, m_qmlView.get());
-    qApp->installNativeEventFilter(m_taskbarWidget.get());
+    commonGUICreate(m_qmlView.get(), m_qmlView.get(), CompositorVideo::CAN_SHOW_PIP);
 
-    MainUI* m_ui = new MainUI(m_intf, m_mainInterface, m_qmlView.get(), this);
-    m_ui->setup(m_qmlView->engine());
-
-
-    m_qmlView->setContent(QUrl(), m_ui->getComponent(), m_ui->createRootItem());
-
-    return m_mainInterface;
+    return true;
 }
 
 void CompositorWin7::destroyMainInterface()
 {
-    unloadGUI();
+    commonIntfDestroy();
     if (m_videoWidget)
     {
         delete m_videoWidget;
@@ -224,16 +159,8 @@ void CompositorWin7::destroyMainInterface()
 
 void CompositorWin7::unloadGUI()
 {
-    m_videoSurfaceProvider.reset();
-    m_videoWindowHandler.reset();
-    m_interfaceWindowHandler.reset();
+    commonGUIDestroy();
     m_qmlView.reset();
-    m_taskbarWidget.reset();
-    if (m_mainInterface)
-    {
-        delete m_mainInterface;
-        m_mainInterface = nullptr;
-    }
 }
 
 bool CompositorWin7::setupVoutWindow(vout_window_t *p_wnd, VoutDestroyCb destroyCb)
@@ -246,24 +173,10 @@ bool CompositorWin7::setupVoutWindow(vout_window_t *p_wnd, VoutDestroyCb destroy
     if (FAILED(hr) || !isCompositionEnabled)
         return false;
 
-    static const struct vout_window_operations ops = {
-        CompositorWin7::window_enable,
-        CompositorWin7::window_disable,
-        CompositorWin7::window_resize,
-        CompositorWin7::window_destroy,
-        CompositorWin7::window_set_state,
-        CompositorWin7::window_unset_fullscreen,
-        CompositorWin7::window_set_fullscreen,
-        nullptr, //window_set_title
-    };
-
-    m_destroyCb = destroyCb;
-    p_wnd->sys = this;
+    commonSetupVoutWindow(p_wnd, destroyCb);
     p_wnd->type = VOUT_WINDOW_TYPE_HWND;
     p_wnd->handle.hwnd = (HWND)m_stable->winId();
     p_wnd->display.x11 = nullptr;
-    p_wnd->ops = &ops;
-    p_wnd->info.has_double_click = true;
     return true;
 }
 
@@ -272,7 +185,6 @@ QWindow *CompositorWin7::interfaceMainWindow() const
     return m_qmlView.get();
 }
 
-
 Compositor::Type CompositorWin7::type() const
 {
     return Compositor::Win7Compositor;
@@ -280,6 +192,9 @@ Compositor::Type CompositorWin7::type() const
 
 bool CompositorWin7::eventFilter(QObject*, QEvent* ev)
 {
+    if (!m_videoWidget || !m_qmlView)
+        return false;
+
     switch (ev->type())
     {
     case QEvent::Move:
@@ -335,12 +250,12 @@ void CompositorWin7::resetVideoZOrder()
     );
 }
 
-void CompositorWin7::onSurfacePositionChanged(QPointF position)
+void CompositorWin7::onSurfacePositionChanged(const QPointF& position)
 {
     m_stable->move((position / m_stable->window()->devicePixelRatioF()).toPoint());
 }
 
-void CompositorWin7::onSurfaceSizeChanged(QSizeF size)
+void CompositorWin7::onSurfaceSizeChanged(const QSizeF& size)
 {
     m_stable->resize((size / m_stable->window()->devicePixelRatioF()).toSize());
 }


=====================================
modules/gui/qt/maininterface/compositor_win7.hpp
=====================================
@@ -39,7 +39,7 @@ signals:
     void windowStyleChanged();
 };
 
-class CompositorWin7 : public QObject, public Compositor
+class CompositorWin7 : public CompositorVideo
 {
     Q_OBJECT
 public:
@@ -50,7 +50,7 @@ public:
     static bool preInit(qt_intf_t *p_intf);
     virtual bool init() override;
 
-    virtual MainInterface *makeMainInterface() override;
+    virtual bool makeMainInterface(MainInterface*) override;
     virtual void destroyMainInterface() override;
     virtual void unloadGUI() override;
     virtual bool setupVoutWindow(vout_window_t*, VoutDestroyCb destroyCb) override;
@@ -62,30 +62,18 @@ protected:
     bool eventFilter(QObject *obj, QEvent *ev) override;
 
 private:
-    static int window_enable(struct vout_window_t *, const vout_window_cfg_t *);
-    static void window_disable(struct vout_window_t *);
-    static void window_resize(struct vout_window_t *, unsigned width, unsigned height);
-    static void window_destroy(struct vout_window_t *);
-    static void window_set_state(struct vout_window_t *, unsigned state);
-    static void window_unset_fullscreen(struct vout_window_t *);
-    static void window_set_fullscreen(struct vout_window_t *, const char *id);
+    int windowEnable(const vout_window_cfg_t *) override;
+    void windowDisable() override;
 
 private slots:
     void resetVideoZOrder();
-    void onSurfacePositionChanged(QPointF position);
-    void onSurfaceSizeChanged(QSizeF size);
+    void onSurfacePositionChanged(const QPointF& position) override;
+    void onSurfaceSizeChanged(const QSizeF& size) override;
 
 private:
-    qt_intf_t *m_intf = nullptr;
-
-    MainInterface* m_mainInterface = nullptr;
     QWidget* m_videoWidget = nullptr;
     QWidget* m_stable = nullptr;
-    std::unique_ptr<InterfaceWindowHandlerWin32> m_interfaceWindowHandler;
     std::unique_ptr<QQuickView> m_qmlView;
-    std::unique_ptr<VideoWindowHandler> m_videoWindowHandler;
-    std::unique_ptr<VideoSurfaceProvider> m_videoSurfaceProvider;
-    std::unique_ptr<WinTaskbarWidget> m_taskbarWidget;
     std::unique_ptr<Win7NativeEventFilter> m_nativeEventFilter;
 
     HWND m_qmlWindowHWND = nullptr;


=====================================
modules/gui/qt/maininterface/videosurface.cpp
=====================================
@@ -136,7 +136,7 @@ VideoSurface::VideoSurface(QQuickItem* parent)
     connect(this, &QQuickItem::yChanged, this, &VideoSurface::onSurfacePositionChanged);
     connect(this, &QQuickItem::widthChanged, this, &VideoSurface::onSurfaceSizeChanged);
     connect(this, &QQuickItem::heightChanged, this, &VideoSurface::onSurfaceSizeChanged);
-    connect(this, &QQuickItem::enabledChanged, this, &VideoSurface::onSurfaceSizeChanged);
+    connect(this, &VideoSurface::enabledChanged, this, &VideoSurface::updatePositionAndSize);
 }
 
 QmlMainContext*VideoSurface::getCtx()


=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -757,21 +757,29 @@ static void *Thread( void *obj )
 #endif
 
     /* Create the normal interface in non-DP mode */
-    MainInterface *p_mi = NULL;
+#ifdef _WIN32
+    p_intf->p_mi = new MainInterfaceWin32(p_intf);
+#else
+    p_intf->p_mi = new MainInterface(p_intf);
+#endif
 
     if( !p_intf->b_isDialogProvider )
     {
+        bool ret = false;
         do {
             p_intf->p_compositor = compositorFactory.createCompositor();
             if (! p_intf->p_compositor)
                 break;
-            p_mi = p_intf->p_compositor->makeMainInterface();
-        } while(p_mi == nullptr);
-        p_intf->p_mi = p_mi;
+            ret = p_intf->p_compositor->makeMainInterface(p_intf->p_mi);
+            if (!ret)
+                p_intf->p_compositor->destroyMainInterface();
+        } while(!ret);
 
-        if (!p_mi)
+        if (!ret)
         {
             msg_Err(p_intf, "unable to create main interface");
+            delete p_intf->p_mi;
+            p_intf->p_mi = nullptr;
             return ThreadCleanup( p_intf, CLEANUP_ERROR );
         }
 
@@ -860,10 +868,15 @@ static void *ThreadCleanup( qt_intf_t *p_intf, CleanupReason cleanupReason )
         if (cleanupReason == CLEANUP_INTF_CLOSED)
         {
             p_intf->p_compositor->unloadGUI();
+            if (p_intf->p_mi)
+                delete p_intf->p_mi;
+            p_intf->p_mi = nullptr;
         }
         else // CLEANUP_APP_TERMINATED
         {
             p_intf->p_compositor->destroyMainInterface();
+            if (p_intf->p_mi)
+                delete p_intf->p_mi;
             p_intf->p_mi = nullptr;
 
             delete p_intf->mainSettings;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c3550f2348b54e05667ee45afc3b4b68eb050afb...66e297e7cb9355e0215ff863e38c9e8e2c400c81

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c3550f2348b54e05667ee45afc3b4b68eb050afb...66e297e7cb9355e0215ff863e38c9e8e2c400c81
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list