mirror of https://code.videolan.org/videolan/vlc
Merge branch 'qt-add-platform-supported-compositing' into 'master'
qt: platform supported composition integration See merge request videolan/vlc!2419
This commit is contained in:
commit
6ba2e4eb52
|
@ -177,6 +177,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 \
|
||||
|
@ -412,6 +414,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 \
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
# include "compositor_x11.hpp"
|
||||
#endif
|
||||
|
||||
#include "compositor_platform.hpp"
|
||||
|
||||
#include <vlc_window.h>
|
||||
|
||||
using namespace vlc;
|
||||
|
@ -63,6 +65,7 @@ struct {
|
|||
#ifdef HAVE_DCOMP_H
|
||||
{"dcomp", &instanciateCompositor<CompositorDirectComposition>, &preInit<CompositorDirectComposition> },
|
||||
#endif
|
||||
{"platform", &instanciateCompositor<CompositorPlatform>, &preInit<CompositorPlatform>},
|
||||
{"win7", &instanciateCompositor<CompositorWin7>, &preInit<CompositorWin7> },
|
||||
#endif
|
||||
#ifdef QT_HAS_WAYLAND_COMPOSITOR
|
||||
|
|
|
@ -59,7 +59,8 @@ public:
|
|||
Win7Compositor,
|
||||
DirectCompositionCompositor,
|
||||
X11Compositor,
|
||||
WaylandCompositor
|
||||
WaylandCompositor,
|
||||
PlatformCompositor
|
||||
};
|
||||
|
||||
typedef void (*VoutDestroyCb)(vlc_window_t *p_wnd);
|
||||
|
|
|
@ -0,0 +1,194 @@
|
|||
/*****************************************************************************
|
||||
* 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 _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <versionhelpers.h> // Check if Windows8+
|
||||
#include <dwmapi.h> // To enable native acrylic effect
|
||||
#endif
|
||||
|
||||
|
||||
using namespace vlc;
|
||||
|
||||
|
||||
CompositorPlatform::CompositorPlatform(qt_intf_t *p_intf, QObject *parent)
|
||||
: CompositorVideo(p_intf, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CompositorPlatform::preInit(qt_intf_t *p_intf)
|
||||
{
|
||||
// TODO: For now only qwindows and qdirect2d platforms
|
||||
// running under Windows 8+ are supported.
|
||||
// See if other platforms are also working.
|
||||
// It might be possible to support cocoa,
|
||||
// and wayland.
|
||||
|
||||
#ifdef _WIN32
|
||||
if (IsWindows8OrGreater())
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CompositorPlatform::init()
|
||||
{
|
||||
{
|
||||
const QString& platformName = qApp->platformName();
|
||||
if (platformName == QLatin1String("windows") || platformName == QLatin1String("direct2d"))
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
CompositorVideo::Flags flags = CompositorVideo::CAN_SHOW_PIP;
|
||||
|
||||
// If Windows 11 Build 22621, enable acrylic effect:
|
||||
#ifdef _WIN32
|
||||
if (QOperatingSystemVersion::current()
|
||||
>= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 11, 0, 22621))
|
||||
{
|
||||
flags |= CompositorVideo::HAS_ACRYLIC;
|
||||
}
|
||||
#endif
|
||||
|
||||
const bool ret = commonGUICreate(m_rootWindow.get(), m_quickWindow, flags);
|
||||
|
||||
m_quickWindow->create();
|
||||
|
||||
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);
|
||||
|
||||
#ifdef _WIN32
|
||||
if (flags | CompositorVideo::HAS_ACRYLIC)
|
||||
{
|
||||
enum BackdropType
|
||||
{
|
||||
DWMSBT_TRANSIENTWINDOW = 3
|
||||
} backdropType = DWMSBT_TRANSIENTWINDOW;
|
||||
DwmSetWindowAttribute(reinterpret_cast<HWND>(m_quickWindow->winId()),
|
||||
38 /* DWMWA_SYSTEMBACKDROP_TYPE */,
|
||||
&backdropType,
|
||||
sizeof(backdropType));
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
assert(qApp->platformName() == QLatin1String("windows") || qApp->platformName() == QLatin1String("direct2d"));
|
||||
|
||||
p_wnd->type = VLC_WINDOW_TYPE_HWND;
|
||||
p_wnd->handle.hwnd = reinterpret_cast<void*>(m_videoWindow->winId());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*****************************************************************************
|
||||
* 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);
|
||||
|
||||
static bool preInit(qt_intf_t *p_intf);
|
||||
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
|
|
@ -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',
|
||||
|
@ -280,6 +281,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',
|
||||
|
|
|
@ -270,6 +270,7 @@ static const char *const compositor_vlc[] = {
|
|||
#ifdef HAVE_DCOMP_H
|
||||
"dcomp",
|
||||
#endif
|
||||
"platform",
|
||||
"win7",
|
||||
#endif
|
||||
#ifdef QT_HAS_WAYLAND_COMPOSITOR
|
||||
|
@ -286,6 +287,7 @@ static const char *const compositor_user[] = {
|
|||
#ifdef HAVE_DCOMP_H
|
||||
"Direct Composition",
|
||||
#endif
|
||||
"Platform Composition",
|
||||
"Windows 7",
|
||||
#endif
|
||||
#ifdef QT_HAS_WAYLAND_COMPOSITOR
|
||||
|
|
Loading…
Reference in New Issue