[vlc-commits] qt: notity VideoSurface position to the VideoSurfaceProvider

Pierre Lamot git at videolan.org
Mon Dec 7 12:31:47 UTC 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Fri Oct 16 10:05:57 2020 +0200| [feb4fcf5bcdd8e18606f5b78a7cee28fc3b5f099] | committer: Pierre Lamot

qt: notity VideoSurface position to the VideoSurfaceProvider

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=feb4fcf5bcdd8e18606f5b78a7cee28fc3b5f099
---

 modules/gui/qt/maininterface/videosurface.cpp | 46 ++++++++++++++++++++++++---
 modules/gui/qt/maininterface/videosurface.hpp |  5 +++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt/maininterface/videosurface.cpp b/modules/gui/qt/maininterface/videosurface.cpp
index de74872145..aa746d5890 100644
--- a/modules/gui/qt/maininterface/videosurface.cpp
+++ b/modules/gui/qt/maininterface/videosurface.cpp
@@ -118,6 +118,7 @@ void VideoSurfaceProvider::onKeyPressed(int key, Qt::KeyboardModifiers modifiers
 
 void VideoSurfaceProvider::onSurfaceSizeChanged(QSizeF size)
 {
+    emit surfaceSizeChanged(size);
     QMutexLocker lock(&m_voutlock);
     if (m_voutWindow)
         vout_window_ReportSize(m_voutWindow, size.width(), size.height());
@@ -132,6 +133,8 @@ VideoSurface::VideoSurface(QQuickItem* parent)
     setFlag(ItemAcceptsInputMethod, true);
     setFlag(ItemHasContents, true);
 
+    connect(this, &QQuickItem::xChanged, this, &VideoSurface::onSurfacePositionChanged);
+    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);
@@ -281,22 +284,55 @@ QSGNode*VideoSurface::updatePaintNode(QSGNode* oldNode, QQuickItem::UpdatePaintN
         connect(this, &VideoSurface::mouseWheeled, m_provider, &VideoSurfaceProvider::onMouseWheeled);
         connect(this, &VideoSurface::keyPressed, m_provider, &VideoSurfaceProvider::onKeyPressed);
         connect(this, &VideoSurface::surfaceSizeChanged, m_provider, &VideoSurfaceProvider::onSurfaceSizeChanged);
+        connect(this, &VideoSurface::surfacePositionChanged, m_provider, &VideoSurfaceProvider::surfacePositionChanged);
 
         connect(m_provider, &VideoSurfaceProvider::hasVideoEmbedChanged, this, &VideoSurface::onProviderVideoChanged);
 
-        onSurfaceSizeChanged();
+        updatePositionAndSize();
     }
     return node;
 }
 
 void VideoSurface::onProviderVideoChanged(bool hasVideo)
 {
-    if (hasVideo)
-        emit surfaceSizeChanged(size() * this->window()->effectiveDevicePixelRatio());
+    if (!hasVideo)
+        return;
+    updatePositionAndSize();
 }
 
 void VideoSurface::onSurfaceSizeChanged()
 {
-    if (isEnabled())
-        emit surfaceSizeChanged(size() * this->window()->effectiveDevicePixelRatio());
+    if (!isEnabled())
+        return;
+    QQuickWindow* window = this->window();
+    if (!window)
+        return;
+    emit surfaceSizeChanged(size() * window->effectiveDevicePixelRatio());
+}
+
+void VideoSurface::onSurfacePositionChanged()
+{
+    if (!isEnabled())
+        return;
+
+    QPointF scenePosition = this->mapToScene(QPointF(0,0));
+    QQuickWindow* window = this->window();
+    if (!window)
+        return;
+    qreal dpr = this->window()->effectiveDevicePixelRatio();
+    emit surfacePositionChanged(scenePosition * dpr);
+}
+
+void VideoSurface::updatePositionAndSize()
+{
+    if (!isEnabled())
+        return;
+
+    QQuickWindow* window = this->window();
+    if (!window)
+        return;
+    qreal dpr = this->window()->effectiveDevicePixelRatio();
+    emit surfaceSizeChanged(size() * dpr);
+    QPointF scenePosition = this->mapToScene(QPointF(0, 0));
+    emit surfacePositionChanged(scenePosition * dpr);
 }
diff --git a/modules/gui/qt/maininterface/videosurface.hpp b/modules/gui/qt/maininterface/videosurface.hpp
index a3b70daa5a..d4570af5b7 100644
--- a/modules/gui/qt/maininterface/videosurface.hpp
+++ b/modules/gui/qt/maininterface/videosurface.hpp
@@ -43,6 +43,8 @@ signals:
     void ctxChanged(QmlMainContext*);
     bool videoEnabledChanged(bool);
     bool hasVideoEmbedChanged(bool);
+    void surfacePositionChanged(QPointF position);
+    void surfaceSizeChanged(QSizeF size);
 
 public slots:
     void onWindowClosed();
@@ -101,6 +103,7 @@ signals:
     void ctxChanged(QmlMainContext*);
     void sourceSizeChanged(QSize);
     void surfaceSizeChanged(QSizeF);
+    void surfacePositionChanged(QPointF);
 
     void mousePressed( int vlcButton );
     void mouseReleased( int vlcButton );
@@ -112,6 +115,8 @@ signals:
 protected slots:
     void onProviderVideoChanged(bool);
     void onSurfaceSizeChanged();
+    void onSurfacePositionChanged();
+    void updatePositionAndSize();
 
 private:
     QmlMainContext* m_mainCtx = nullptr;



More information about the vlc-commits mailing list