[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: introduce platform compositor
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Jul 1 13:57:54 UTC 2024
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
2e82fbfe by Fatih Uzunoglu at 2024-07-01T13:42:56+00:00
qt: introduce platform compositor
If Qt QPA supports child window transparency,
make use of that.
- - - - -
7a794682 by Alexandre Janniaux at 2024-07-01T13:42:56+00:00
qt: compositor_platform: add darwin support
The integration works for video modules not requiring the main thread to
start displaying video.
- - - - -
7 changed files:
- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/compositor.cpp
- modules/gui/qt/maininterface/compositor.hpp
- + modules/gui/qt/maininterface/compositor_platform.cpp
- + modules/gui/qt/maininterface/compositor_platform.hpp
- modules/gui/qt/meson.build
- modules/gui/qt/qt.cpp
Changes:
=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -156,6 +156,8 @@ libqt_plugin_la_SOURCES = \
maininterface/compositor_accessibility.hpp \
maininterface/compositor_dummy.hpp \
maininterface/compositor_dummy.cpp \
+ maininterface/compositor_platform.hpp \
+ maininterface/compositor_platform.cpp \
maininterface/interface_window_handler.cpp \
maininterface/interface_window_handler.hpp \
maininterface/mainctx.cpp \
@@ -396,6 +398,7 @@ nodist_libqt_plugin_la_SOURCES = \
maininterface/compositor.moc.cpp \
maininterface/compositor_common.moc.cpp \
maininterface/compositor_dummy.moc.cpp \
+ maininterface/compositor_platform.moc.cpp \
maininterface/interface_window_handler.moc.cpp \
maininterface/mainctx.moc.cpp \
maininterface/mainctx_submodels.moc.cpp \
=====================================
modules/gui/qt/maininterface/compositor.cpp
=====================================
@@ -42,6 +42,8 @@
#include "maininterface/windoweffects_module.hpp"
+#include "compositor_platform.hpp"
+
#include <vlc_window.h>
#include <vlc_modules.h>
@@ -57,10 +59,13 @@ struct {
const char* name;
Compositor* (*instantiate)(qt_intf_t *p_intf);
} static compositorList[] = {
-#ifdef _WIN32
-#ifdef HAVE_DCOMP_H
+#if defined(_WIN32) && defined(HAVE_DCOMP_H)
{"dcomp", &instanciateCompositor<CompositorDirectComposition> },
#endif
+#if defined(_WIN32) || defined(__APPLE__)
+ {"platform", &instanciateCompositor<CompositorPlatform> },
+#endif
+#if defined(_WIN32)
{"win7", &instanciateCompositor<CompositorWin7> },
#endif
#ifdef QT_HAS_WAYLAND_COMPOSITOR
=====================================
modules/gui/qt/maininterface/compositor.hpp
=====================================
@@ -60,7 +60,8 @@ public:
Win7Compositor,
DirectCompositionCompositor,
X11Compositor,
- WaylandCompositor
+ WaylandCompositor,
+ PlatformCompositor
};
typedef void (*VoutDestroyCb)(vlc_window_t *p_wnd);
=====================================
modules/gui/qt/maininterface/compositor_platform.cpp
=====================================
@@ -0,0 +1,171 @@
+/*****************************************************************************
+ * Copyright (C) 2024 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include "compositor_platform.hpp"
+
+#include <QApplication>
+#include <QQuickView>
+#include <QOperatingSystemVersion>
+
+#include <vlc_window.h>
+
+#ifdef __APPLE__
+#include <objc/runtime.h>
+#endif
+
+using namespace vlc;
+
+
+CompositorPlatform::CompositorPlatform(qt_intf_t *p_intf, QObject *parent)
+ : CompositorVideo(p_intf, parent)
+{
+
+}
+
+bool CompositorPlatform::init()
+{
+ // TODO: For now only qwindows and qdirect2d
+ // running on Windows 8+, and cocoa
+ // platforms are supported.
+
+ const QString& platformName = qApp->platformName();
+
+#ifdef _WIN32
+ if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8)
+ {
+ if (platformName == QLatin1String("windows") || platformName == QLatin1String("direct2d"))
+ return true;
+ }
+#endif
+
+#ifdef __APPLE__
+ if (platformName == QLatin1String("cocoa"))
+ return true;
+#endif
+
+ return false;
+}
+
+bool CompositorPlatform::makeMainInterface(MainCtx *mainCtx)
+{
+ m_mainCtx = mainCtx;
+
+ m_rootWindow = std::make_unique<QWindow>();
+
+ m_videoWindow = new QWindow(m_rootWindow.get());
+
+ m_quickWindow = new QQuickView(m_rootWindow.get());
+ m_quickWindow->setResizeMode(QQuickView::SizeRootObjectToView);
+
+ {
+ // Transparency set-up:
+ m_quickWindow->setColor(Qt::transparent);
+
+ QSurfaceFormat format = m_quickWindow->format();
+ format.setAlphaBufferSize(8);
+ m_quickWindow->setFormat(format);
+ }
+
+ // Make sure the UI child window has the same size as the root parent window:
+ connect(m_rootWindow.get(), &QWindow::widthChanged, m_quickWindow, &QWindow::setWidth);
+ connect(m_rootWindow.get(), &QWindow::heightChanged, m_quickWindow, &QWindow::setHeight);
+
+ m_quickWindow->create();
+
+ const bool ret = commonGUICreate(m_rootWindow.get(), m_quickWindow, CompositorVideo::CAN_SHOW_PIP | CompositorVideo::HAS_ACRYLIC);
+
+ m_quickWindow->setFlag(Qt::FramelessWindowHint);
+ // Qt QPA Bug (qwindows, qdirect2d(?)): to trigger WS_EX_LAYERED set up.
+ m_quickWindow->setOpacity(0.0);
+ m_quickWindow->setOpacity(1.0);
+
+ m_rootWindow->show();
+ m_videoWindow->show();
+ m_quickWindow->show();
+
+ m_quickWindow->raise(); // Make sure quick window is above the video window.
+
+ return ret;
+}
+
+void CompositorPlatform::destroyMainInterface()
+{
+ commonIntfDestroy();
+}
+
+void CompositorPlatform::unloadGUI()
+{
+ commonGUIDestroy();
+}
+
+bool CompositorPlatform::setupVoutWindow(vlc_window_t *p_wnd, VoutDestroyCb destroyCb)
+{
+ commonSetupVoutWindow(p_wnd, destroyCb);
+
+#ifdef __WIN32
+ p_wnd->type = VLC_WINDOW_TYPE_HWND;
+ p_wnd->handle.hwnd = reinterpret_cast<void*>(m_videoWindow->winId());
+
+ return true;
+#endif
+
+#ifdef __APPLE__
+ p_wnd->type = VLC_WINDOW_TYPE_NSOBJECT;
+ p_wnd->handle.nsobject = reinterpret_cast<id>(m_videoWindow->winId());
+
+ return true;
+#endif
+
+ vlc_assert_unreachable();
+}
+
+QWindow *CompositorPlatform::interfaceMainWindow() const
+{
+ return m_rootWindow.get();
+}
+
+Compositor::Type CompositorPlatform::type() const
+{
+ return Compositor::PlatformCompositor;
+}
+
+QQuickItem *CompositorPlatform::activeFocusItem() const
+{
+ assert(m_quickWindow);
+ return m_quickWindow->activeFocusItem();
+}
+
+int CompositorPlatform::windowEnable(const vlc_window_cfg_t *)
+{
+ commonWindowEnable();
+ return VLC_SUCCESS;
+}
+
+void CompositorPlatform::windowDisable()
+{
+ commonWindowDisable();
+}
+
+void CompositorPlatform::onSurfacePositionChanged(const QPointF &position)
+{
+ m_videoWindow->setPosition((position / m_videoWindow->devicePixelRatio()).toPoint());
+}
+
+void CompositorPlatform::onSurfaceSizeChanged(const QSizeF &size)
+{
+ m_videoWindow->resize((size / m_videoWindow->devicePixelRatio()).toSize());
+}
=====================================
modules/gui/qt/maininterface/compositor_platform.hpp
=====================================
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (C) 2024 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef COMPOSITOR_PLATFORM_HPP
+#define COMPOSITOR_PLATFORM_HPP
+
+#include "compositor.hpp"
+
+#include <QWindow>
+#include <QPointer>
+
+#include <memory>
+
+class QQuickView;
+
+namespace vlc {
+
+class CompositorPlatform : public CompositorVideo
+{
+ Q_OBJECT
+
+public:
+ CompositorPlatform(qt_intf_t *p_intf, QObject* parent = nullptr);
+
+ bool init() override;
+
+ bool makeMainInterface(MainCtx *) override;
+ void destroyMainInterface() override;
+ void unloadGUI() override;
+ bool setupVoutWindow(vlc_window_t*, VoutDestroyCb destroyCb) override;
+ QWindow* interfaceMainWindow() const override;
+ Type type() const override;
+ QQuickItem * activeFocusItem() const override;
+
+private:
+ int windowEnable(const vlc_window_cfg_t *) override;
+ void windowDisable() override;
+
+private slots:
+ void onSurfacePositionChanged(const QPointF& position) override;
+ void onSurfaceSizeChanged(const QSizeF& size) override;
+
+private:
+ std::unique_ptr<QWindow> m_rootWindow;
+ QPointer<QWindow> m_videoWindow;
+ QPointer<QQuickView> m_quickWindow;
+};
+
+}
+
+#endif // COMPOSITOR_PLATFORM_HPP
=====================================
modules/gui/qt/meson.build
=====================================
@@ -70,6 +70,7 @@ moc_headers = files(
'maininterface/compositor.hpp',
'maininterface/compositor_common.hpp',
'maininterface/compositor_dummy.hpp',
+ 'maininterface/compositor_platform.hpp',
'maininterface/interface_window_handler.hpp',
'maininterface/mainctx.hpp',
'maininterface/mainctx_submodels.hpp',
@@ -283,6 +284,8 @@ some_sources = files(
'maininterface/compositor_accessibility.cpp',
'maininterface/compositor_dummy.hpp',
'maininterface/compositor_dummy.cpp',
+ 'maininterface/compositor_platform.hpp',
+ 'maininterface/compositor_platform.cpp',
'maininterface/interface_window_handler.cpp',
'maininterface/interface_window_handler.hpp',
'maininterface/mainctx.cpp',
=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -282,6 +282,7 @@ static const char *const compositor_vlc[] = {
#ifdef HAVE_DCOMP_H
"dcomp",
#endif
+ "platform",
"win7",
#endif
#ifdef QT_HAS_WAYLAND_COMPOSITOR
@@ -298,6 +299,7 @@ static const char *const compositor_user[] = {
#ifdef HAVE_DCOMP_H
"Direct Composition",
#endif
+ "Platform Composition",
"Windows 7",
#endif
#ifdef QT_HAS_WAYLAND_COMPOSITOR
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e5d8a48c66d4a422dfb7713555275409830d2a1e...7a7946821262aa5ccfc5ed0711a090888378a540
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e5d8a48c66d4a422dfb7713555275409830d2a1e...7a7946821262aa5ccfc5ed0711a090888378a540
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