Commit 4ccdeaaf authored by Pierre Lamot's avatar Pierre Lamot
Browse files

resize & factory

parent 5b64600f
#include "qvoutwindow.hpp"
#include "util/customwidgets.hpp" //for qtEventToVLCKey
#include "main_interface.hpp"
QVoutWindow::QVoutWindow(QObject* parent)
: QObject(parent)
QVoutWindow::QVoutWindow(MainInterface* p_mi)
: QObject(p_mi)
, m_mainInterface(p_mi)
{
}
......@@ -38,6 +40,15 @@ void QVoutWindow::windowClosed()
vout_window_ReportClose(m_voutWindow);
}
QQuickWidget* QVoutWindow::createQuickWindow()
{
QQuickWidget* mainWindow = new QQuickWidget(m_mainInterface);
mainWindow->setAttribute(Qt::WA_TranslucentBackground);
mainWindow->setClearColor(Qt::transparent);
m_mainInterface->setCentralWidget(mainWindow);
return mainWindow;
}
void QVoutWindow::onMousePressed(int vlcButton)
{
QMutexLocker lock(&m_voutlock);
......@@ -86,7 +97,7 @@ void QVoutWindow::onKeyPressed(QKeyEvent* event)
void QVoutWindow::onSurfaceSizeChanged(QSizeF size)
{
qWarning() << "QVoutWindow::onSurfaceSizeChanged";
QMutexLocker lock(&m_voutlock);
if (m_hasVideo)
vout_window_ReportSize(m_voutWindow, size.width(), size.height());
......
......@@ -6,12 +6,13 @@
#include "qt.hpp"
#include "vlc_vout_window.h"
#include "videosurface.hpp"
#include <QtQuickWidgets//QQuickWidget>
class QVoutWindow : public QObject
{
Q_OBJECT
public:
QVoutWindow(QObject* parent = nullptr);
QVoutWindow(MainInterface* p_mi);
virtual ~QVoutWindow();
virtual void setupVoutWindow(vout_window_t* window);
......@@ -21,6 +22,12 @@ public:
virtual VideoSurfaceProvider* getVideoSurfaceProvider() = 0;
/*
* Create the main QML view and parent it to the main window
* This can be overloaded for special needs (ie: draw the interface in an offscreen window)
*/
virtual QQuickWidget* createQuickWindow();
public slots:
void onMousePressed( int vlcButton );
void onMouseReleased( int vlcButton );
......@@ -33,6 +40,7 @@ public slots:
protected:
QMutex m_voutlock;
vout_window_t* m_voutWindow = nullptr;
MainInterface* m_mainInterface = nullptr;
bool m_hasVideo = false;
};
......
......@@ -28,21 +28,11 @@ static void HR(HRESULT const result, const char* msg = "")
}
QVoutWindowDirectComposition::QVoutWindowDirectComposition(MainInterface* p_mi, QObject* parent)
: QVoutWindow(parent)
, m_mainInterface(p_mi)
QVoutWindowDirectComposition::QVoutWindowDirectComposition(MainInterface* p_mi)
: QVoutWindow(p_mi)
{
// //create the video native surface
// m_videoWindow = new QWidget();
// //m_videoWindow->setWindowFlag(Qt::ToolTip); //so it won't appears in window list
// //m_videoWindow->setAttribute(Qt::WA_TranslucentBackground); //set the window as layered
// m_videoWindow->setAttribute(Qt::WA_NativeWindow);
// m_videoHwnd =(HWND) m_videoWindow->winId(); //this force the creation of the native widget
//
// BOOL dwma_true = TRUE;
// //window won't be rendered on screen
// DwmSetWindowAttribute(m_videoHwnd, DWMWA_CLOAK, &dwma_true, sizeof(dwma_true));
// m_videoWindow->show();
assert(p_mi);
m_surfaceProvider = new VideoSurfaceProviderDirectComposition( this, this );
p_mi->installEventFilter(this);
......@@ -87,76 +77,95 @@ QVoutWindowDirectComposition::QVoutWindowDirectComposition(MainInterface* p_mi,
if( FAILED( hr ) )
m_d3d11Device.Reset();
}
}
ComPtr<IDXGIDevice> dxgiDevice;
m_d3d11Device.As(&dxgiDevice);
// Create the DirectComposition device object.
HR(DCompositionCreateDevice(dxgiDevice.Get(),
__uuidof(IDCompositionDevice),
reinterpret_cast<void**>(m_dcompDevice.GetAddressOf())), "create device" );
HR(m_dcompDevice->CreateTargetForHwnd((HWND)m_mainInterface->winId(), TRUE, &m_dcompTarget), "create target");
HR(m_dcompDevice->CreateVisual(&m_rootVisual), "create root visual");
HR(m_dcompTarget->SetRoot(m_rootVisual.Get()), "set root visual");
/**** create swapchain */
DXGI_FORMAT output_format = DXGI_FORMAT_B8G8R8A8_UNORM; //DXGI_FORMAT_R16G16B16A16_FLOAT for HDR
int width = 1024;
int height = 768;
ComPtr<IDXGIAdapter> dxgi_adapter;
HR(dxgiDevice->GetAdapter(dxgi_adapter.GetAddressOf()));
ComPtr<IDXGIFactory2> dxgi_factory;
HR(dxgi_adapter->GetParent(IID_PPV_ARGS(dxgi_factory.GetAddressOf())));
DXGI_SWAP_CHAIN_DESC1 desc = { 0 };
desc.Width = width;
desc.Height = height;
desc.Format = output_format;
desc.Stereo = FALSE;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.BufferCount = 2;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Scaling = DXGI_SCALING_STRETCH;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
desc.Flags = 0;
HR(dxgi_factory->CreateSwapChainForComposition(
m_d3d11Device.Get(), &desc, nullptr,
m_videoSwapChain.GetAddressOf()));
HR(m_dcompDevice->CreateVisual(&m_videoVisual), "create video visual");
HR(m_videoVisual->SetContent(m_videoSwapChain.Get()), "set video content");
}
VideoSurfaceProvider*QVoutWindowDirectComposition::getVideoSurfaceProvider()
{
return m_surfaceProvider;
}
void QVoutWindowDirectComposition::setupVoutWindow(vout_window_t* window)
QQuickWidget*QVoutWindowDirectComposition::createQuickWindow()
{
QVoutWindow::setupVoutWindow(window);
//window->type = VOUT_WINDOW_TYPE_HWND;
//window->handle.hwnd = m_videoHwnd;
////run on UI thread
//QMetaObject::invokeMethod(m_mainInterface, [this]() {
ComPtr<IDXGIDevice> dxgiDevice;
m_d3d11Device.As(&dxgiDevice);
QQuickWidget* mainWindow = new QQuickWidget(m_mainInterface);
mainWindow->setWindowFlag(Qt::ToolTip); //set window as tooltip so it won't appears in window list
mainWindow->setAttribute(Qt::WA_TranslucentBackground);
mainWindow->setClearColor(Qt::transparent);
// Create the DirectComposition device object.
HR(DCompositionCreateDevice(dxgiDevice.Get(),
__uuidof(IDCompositionDevice),
reinterpret_cast<void**>(m_dcompDevice.GetAddressOf())), "create device" );
BOOL dwma_true = TRUE;
////set ui windows out of screen
HWND uiHwnd = (HWND)mainWindow->winId();
DwmSetWindowAttribute(uiHwnd, DWMWA_CLOAK, &dwma_true, sizeof(dwma_true));
HR(m_dcompDevice->CreateTargetForHwnd((HWND)m_mainInterface->effectiveWinId(), TRUE, &m_dcompTarget), "create target");
//create visual for ui layer
HR(m_dcompDevice->CreateVisual(&m_uiVisual), "create ui visual");
HR(m_dcompDevice->CreateSurfaceFromHwnd(uiHwnd, &m_uiSurface), "create ui surface from hwnd");
HR(m_uiVisual->SetContent(m_uiSurface.Get()), "set video content");
HR(m_rootVisual->AddVisual(m_uiVisual.Get(), TRUE, NULL), "add video visual to root");
HR(m_dcompDevice->CreateVisual(&m_rootVisual), "create root visual");
HR(m_dcompTarget->SetRoot(m_rootVisual.Get()), "set root visual");
HR(m_dcompDevice->Commit(), "commit");
/**** create swapchain */
DXGI_FORMAT output_format = DXGI_FORMAT_B8G8R8A8_UNORM; //DXGI_FORMAT_R16G16B16A16_FLOAT for HDR
int width = 1024;
int height = 768;
ComPtr<IDXGIAdapter> dxgi_adapter;
HR(dxgiDevice->GetAdapter(dxgi_adapter.GetAddressOf()));
ComPtr<IDXGIFactory2> dxgi_factory;
HR(dxgi_adapter->GetParent(IID_PPV_ARGS(dxgi_factory.GetAddressOf())));
DXGI_SWAP_CHAIN_DESC1 desc = { 0 };
desc.Width = width;
desc.Height = height;
desc.Format = output_format;
desc.Stereo = FALSE;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.BufferCount = 2;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Scaling = DXGI_SCALING_STRETCH;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
desc.Flags = 0;
HR(dxgi_factory->CreateSwapChainForComposition(
m_d3d11Device.Get(), &desc, nullptr,
m_videoSwapChain.GetAddressOf()));
HR(m_dcompDevice->CreateVisual(&m_videoVisual), "create video visual");
HR(m_videoVisual->SetContent(m_videoSwapChain.Get()), "set video content");
HR(m_rootVisual->AddVisual(m_videoVisual.Get(), TRUE, NULL), "add video visual to root");
return mainWindow;
}
msg_Info(window, "m_videoSwapChain %p", m_videoSwapChain.Get());
void QVoutWindowDirectComposition::setupVoutWindow(vout_window_t* window)
{
if (m_voutWindow)
{
var_Destroy(m_voutWindow->obj.libvlc, "vout");
var_Destroy(m_voutWindow->obj.libvlc, "winrt-d3dcontext");
var_Destroy(m_voutWindow->obj.libvlc, "winrt-swapchain");
DXGI_SWAP_CHAIN_DESC1 desc2 = { 0 };
HR(m_videoSwapChain->GetDesc1(&desc2));
HR(m_rootVisual->RemoveVisual(m_videoVisual.Get()), "remove video visual from root");
}
msg_Info(window, "m_videoSwapChain getDesc OK");
QVoutWindow::setupVoutWindow(window);
if (window)
{
var_Create(window->obj.libvlc, "vout", VLC_VAR_STRING );
var_Create(window->obj.libvlc, "winrt-d3dcontext", VLC_VAR_INTEGER );
var_Create(window->obj.libvlc, "winrt-swapchain", VLC_VAR_INTEGER );
......@@ -165,65 +174,72 @@ void QVoutWindowDirectComposition::setupVoutWindow(vout_window_t* window)
var_SetInteger(window->obj.libvlc, "winrt-d3dcontext", (int64_t)m_d3d11Context.Get());
var_SetInteger(window->obj.libvlc, "winrt-swapchain", (int64_t)m_videoSwapChain.Get());
//create visual for video layer
/// HR(m_dcompDevice->CreateVisual(&m_videoVisual), "create video visual");
/// HR(m_dcompDevice->CreateSurfaceFromHwnd(m_videoHwnd, &m_videoSurface), "create video surface from hwnd");
/// HR(m_videoVisual->SetContent(m_videoSurface.Get()), "set video content");
/// HR(m_rootVisual->AddVisual(m_videoVisual.Get(), TRUE, NULL), "add video visual to root");
BOOL dwma_true = TRUE;
////set ui windows out of screen
HWND uiHwnd = (HWND)m_mainInterface->mediacenterView->effectiveWinId();
//m_mainInterface->setWindowFlag(Qt::ToolTip);
DwmSetWindowAttribute(uiHwnd, DWMWA_CLOAK, &dwma_true, sizeof(dwma_true));
//create visual for ui layer
HR(m_dcompDevice->CreateVisual(&m_uiVisual), "create ui visual");
HR(m_dcompDevice->CreateSurfaceFromHwnd(uiHwnd, &m_uiSurface), "create ui surface from hwnd");
HR(m_uiVisual->SetContent(m_uiSurface.Get()), "set video content");
HR(m_rootVisual->AddVisual(m_uiVisual.Get(), TRUE, m_videoVisual.Get()), "add video visual to root");
////commit compisition
HR(m_dcompDevice->Commit(), "commit");
//}, Qt::QueuedConnection, nullptr);
//place it bellow UI visual
HR(m_rootVisual->AddVisual(m_videoVisual.Get(), FALSE, m_uiVisual.Get()), "remove video visual from root");
}
HR(m_dcompDevice->Commit(), "commit");
}
bool QVoutWindowDirectComposition::eventFilter(QObject* obj, QEvent* event)
{
if (obj == m_mainInterface)
#define PRINT_EVENT(S) case S: { qWarning("got event %s obj is %p (%smi)", #S, obj, obj == m_mainInterface ? "" : "not " ); break; }
switch (event->type()) {
PRINT_EVENT(QEvent::MouseMove)
PRINT_EVENT(QEvent::MouseButtonPress)
PRINT_EVENT(QEvent::MouseButtonRelease)
PRINT_EVENT(QEvent::MouseButtonDblClick)
PRINT_EVENT(QEvent::Wheel)
PRINT_EVENT(QEvent::KeyPress)
PRINT_EVENT(QEvent::KeyRelease)
PRINT_EVENT(QEvent::HoverEnter)
PRINT_EVENT(QEvent::HoverLeave)
PRINT_EVENT(QEvent::HoverMove)
PRINT_EVENT(QEvent::Enter)
PRINT_EVENT(QEvent::Leave)
PRINT_EVENT(QEvent::FocusIn)
PRINT_EVENT(QEvent::FocusOut)
PRINT_EVENT(QEvent::FocusAboutToChange)
PRINT_EVENT(QEvent::GrabMouse)
PRINT_EVENT(QEvent::UngrabMouse)
PRINT_EVENT(QEvent::GrabKeyboard)
PRINT_EVENT(QEvent::UngrabKeyboard)
}
switch (event->type()) {
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::Wheel:
case QEvent::HoverEnter:
case QEvent::HoverLeave:
case QEvent::HoverMove:
case QEvent::Enter:
case QEvent::Leave:
case QEvent::FocusIn:
case QEvent::FocusOut:
case QEvent::FocusAboutToChange:
case QEvent::GrabMouse:
case QEvent::UngrabMouse:
case QEvent::GrabKeyboard:
case QEvent::UngrabKeyboard:
case QEvent::KeyPress:
case QEvent::KeyRelease:
{
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::MouseMove:
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::HoverEnter:
case QEvent::HoverLeave:
case QEvent::HoverMove:
case QEvent::Enter:
case QEvent::Leave:
case QEvent::FocusIn:
case QEvent::FocusOut:
case QEvent::GrabMouse:
case QEvent::UngrabMouse:
case QEvent::GrabKeyboard:
case QEvent::UngrabKeyboard:
case QEvent::FocusAboutToChange:
return QApplication::sendEvent(m_mainInterface->mediacenterView, event);
break;
case QEvent::Resize:
{
QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
m_mainInterface->mediacenterView->resize(resizeEvent->size().width(), resizeEvent->size().height());
return false;
}
default:
break;
}
return QApplication::sendEvent(m_mainInterface->mediacenterView->quickWindow(), event);
}
case QEvent::Resize:
{
QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
m_mainInterface->mediacenterView->resize(resizeEvent->size().width(), resizeEvent->size().height());
return false;
}
default:
break;
}
return false;
return QObject::eventFilter(obj, event);
}
VideoSurfaceProviderDirectComposition::VideoSurfaceProviderDirectComposition(QVoutWindowDirectComposition* renderer, QObject* parent)
......
......@@ -34,18 +34,18 @@ class QVoutWindowDirectComposition : public QVoutWindow
{
Q_OBJECT
public:
QVoutWindowDirectComposition(MainInterface* p_mi, QObject *parent = nullptr);
QVoutWindowDirectComposition(MainInterface* p_mi);
VideoSurfaceProvider* getVideoSurfaceProvider() override;
QQuickWidget* createQuickWindow() override;
virtual void setupVoutWindow(vout_window_t* window) override;
bool eventFilter(QObject *obj, QEvent *event);
private:
VideoSurfaceProviderDirectComposition* m_surfaceProvider = nullptr;
MainInterface* m_mainInterface = nullptr;
QWidget* m_mainWindow;
HWND m_mainHwnd = nullptr;
......
......@@ -17,6 +17,7 @@
*****************************************************************************/
#include "qvoutwindowdummy.hpp"
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGImageNode>
VideoSurfaceProviderDummy::VideoSurfaceProviderDummy(QObject* parent)
: VideoSurfaceProvider(parent)
......@@ -36,8 +37,8 @@ QSGNode*VideoSurfaceProviderDummy::updatePaintNode(QQuickItem* item, QSGNode* ol
return node;
}
QVoutWindowDummy::QVoutWindowDummy(MainInterface* p_mi, QObject* parent)
: QVoutWindow(parent)
QVoutWindowDummy::QVoutWindowDummy(MainInterface* p_mi)
: QVoutWindow(p_mi)
, m_surfaceProvider(new VideoSurfaceProviderDummy(this))
{
}
......
......@@ -40,7 +40,7 @@ class QVoutWindowDummy : public QVoutWindow
{
Q_OBJECT
public:
QVoutWindowDummy(MainInterface* p_mi, QObject *parent = nullptr);
QVoutWindowDummy(MainInterface* p_mi);
VideoSurfaceProvider* getVideoSurfaceProvider() override;
......
......@@ -6,9 +6,8 @@
#include <vlc_vout_window.h>
#include "main_interface.hpp"
QVoutWindowGL::QVoutWindowGL(MainInterface* p_mi, QObject* parent)
: QVoutWindow(parent)
, m_mainInterface(p_mi)
QVoutWindowGL::QVoutWindowGL(MainInterface* p_mi)
: QVoutWindow(p_mi)
{
assert(m_mainInterface);
m_surfaceProvider = new VideoSurfaceGL(this);
......
......@@ -37,7 +37,7 @@ class QVoutWindowGL : public QVoutWindow
{
Q_OBJECT
public:
QVoutWindowGL(MainInterface* p_mi, QObject *parent = nullptr);
QVoutWindowGL(MainInterface* p_mi);
virtual ~QVoutWindowGL();
QSharedPointer<QSGTexture> getDisplayTexture();
......@@ -65,7 +65,6 @@ private:
QOpenGLContext* m_ctx = nullptr;
QOffscreenSurface* m_surface = nullptr;
MainInterface* m_mainInterface = nullptr;
QQuickWindow* m_window = nullptr;
QSize m_size;
......
......@@ -35,9 +35,8 @@ void QVoutWindowWayland::registry_global_remove( void *, wl_registry *, uint32_t
// nothing to do
}
QVoutWindowWayland::QVoutWindowWayland( MainInterface* p_mi, QObject* parent )
: QVoutWindow( parent )
, m_mainInterface( p_mi )
QVoutWindowWayland::QVoutWindowWayland(MainInterface* p_mi)
: QVoutWindow( p_mi )
{
assert( m_mainInterface );
m_surfaceProvider = new VideoSurfaceWayland( this, this );
......
......@@ -22,7 +22,7 @@ class QVoutWindowWayland: public QVoutWindow
{
Q_OBJECT
public:
QVoutWindowWayland(MainInterface* p_mi, QObject *parent = nullptr);
QVoutWindowWayland(MainInterface* p_mi);
~QVoutWindowWayland() override;
void enableVideo(unsigned int width, unsigned int height, bool fullscreen);
......@@ -39,7 +39,6 @@ private:
const char *, uint32_t );
static void registry_global_remove( void *, wl_registry *, uint32_t );
MainInterface *m_mainInterface;
VideoSurfaceWayland *m_surfaceProvider = nullptr;
wl_compositor *m_compositor = nullptr;
wl_subcompositor *m_subcompositor = nullptr;
......
......@@ -180,19 +180,19 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ),
//fixme use a factory
if (platformName == qfu("xcb"))
{
m_videoRenderer = new QVoutWindowGL(this, this);
m_videoRenderer = new QVoutWindowGL(this);
}
#ifdef QT5_HAS_WAYLAND
else if( b_hasWayland )
{
m_videoRenderer = new QVoutWindowWayland(this, this);
m_videoRenderer = new QVoutWindowWayland(this);
setAttribute(Qt::WA_TranslucentBackground);
}
#endif
#ifdef _WIN32
else if (platformName == qfu("windows"))
{
m_videoRenderer = new QVoutWindowDirectComposition(this, this);
m_videoRenderer = new QVoutWindowDirectComposition(this);
}
#endif
else
......@@ -384,15 +384,12 @@ void MainInterface::createMainWidget( QSettings *creationSettings )
qmlRegisterType<QmlEventFilter>( "org.videolan.vlc", 0, 1, "EventFilter" );
mediacenterView = new QQuickWidget();
mediacenterView->setAttribute(Qt::WA_TranslucentBackground);
mediacenterView->setClearColor(Qt::transparent);
mediacenterView = m_videoRenderer->createQuickWindow();
NavigationHistory* navigation_history = new NavigationHistory(mediacenterView);
QmlMainContext* mainCtx = new QmlMainContext(p_intf, this, mediacenterView);
QQmlContext *rootCtx = mediacenterView->rootContext();
rootCtx->setContextProperty( "history", navigation_history );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment