[vlc-commits] [Git][videolan/vlc][master] 3 commits: Revert "qt: fix video surface being displaced when extended margin changes"
Steve Lhomme (@robUx4)
gitlab at videolan.org
Thu Mar 6 16:09:22 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
afe64921 by Fatih Uzunoglu at 2025-03-06T15:55:35+00:00
Revert "qt: fix video surface being displaced when extended margin changes"
This reverts commit af27693dc2755064c55da76301412b47cccd6711.
- - - - -
d155ffa5 by Fatih Uzunoglu at 2025-03-06T15:55:35+00:00
qt: introduce `MatrixChangeObserverNode` and use it to signal `ViewBlockingRectangle::scenePositionHasChanged()`
- - - - -
29793d55 by Fatih Uzunoglu at 2025-03-06T15:55:35+00:00
qt: use `scenePositionHasChanged()` signal to update surface position in `VideoSurface`
- - - - -
4 changed files:
- modules/gui/qt/maininterface/videosurface.cpp
- modules/gui/qt/maininterface/videosurface.hpp
- modules/gui/qt/widgets/native/viewblockingrectangle.cpp
- modules/gui/qt/widgets/native/viewblockingrectangle.hpp
Changes:
=====================================
modules/gui/qt/maininterface/videosurface.cpp
=====================================
@@ -214,8 +214,9 @@ VideoSurface::VideoSurface(QQuickItem* parent)
connect(this, &QQuickItem::xChanged, this, &VideoSurface::updateSurfacePosition);
connect(this, &QQuickItem::yChanged, this, &VideoSurface::updateSurfacePosition);
- connect(this, &QQuickItem::parentChanged, this, &VideoSurface::updateParentChanged);
- updateParentChanged();
+
+ // This is for the case when the item's parent-relative position stays the same, but ancestors change position:
+ connect(this, &ViewBlockingRectangle::scenePositionHasChanged, this, &VideoSurface::updateSurfacePosition, Qt::QueuedConnection);
}
}
@@ -420,27 +421,3 @@ void VideoSurface::setVideoSurfaceProvider(VideoSurfaceProvider *newVideoSurface
emit videoSurfaceProviderChanged();
}
-
-void VideoSurface::updateParentChanged()
-{
- //we need to track the global position of the VideoSurface within the scene
- //it depends on the position of the VideoSurface itself and all its parents
-
- for (const QPointer<QQuickItem>& p : m_parentList)
- {
- if (!p)
- continue;
- disconnect(p, &QQuickItem::xChanged, this, &VideoSurface::updateSurfacePosition);
- disconnect(p, &QQuickItem::yChanged, this, &VideoSurface::updateSurfacePosition);
- disconnect(p, &QQuickItem::parentChanged, this, &VideoSurface::updateParentChanged);
- }
- m_parentList.clear();
-
- for (QQuickItem* p = parentItem(); p != nullptr; p = p->parentItem())
- {
- connect(p, &QQuickItem::xChanged, this, &VideoSurface::updateSurfacePosition);
- connect(p, &QQuickItem::yChanged, this, &VideoSurface::updateSurfacePosition);
- connect(p, &QQuickItem::parentChanged, this, &VideoSurface::updateParentChanged);
- m_parentList.push_back(p);
- }
-}
=====================================
modules/gui/qt/maininterface/videosurface.hpp
=====================================
@@ -148,8 +148,6 @@ protected slots:
void updateSurfaceScale();
void updateSurface();
- void updateParentChanged();
-
private:
QPointF m_oldHoverPos;
@@ -157,8 +155,6 @@ private:
QPointer<VideoSurfaceProvider> m_provider;
- std::vector<QPointer<QQuickItem>> m_parentList;
-
bool m_sizeDirty = false;
bool m_positionDirty = false;
bool m_scaleDirty = false;
=====================================
modules/gui/qt/widgets/native/viewblockingrectangle.cpp
=====================================
@@ -122,15 +122,23 @@ QSGNode *ViewBlockingRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNod
if (!oldNode)
{
+ const auto observerNode = new MatrixChangeObserverNode([p = QPointer(this)]() {
+ if (Q_LIKELY(p))
+ emit p->scenePositionHasChanged();
+ });
+ observerNode->setFlag(QSGNode::OwnedByParent);
+
if (softwareMode)
{
softwareRenderNode = new SoftwareRenderNode;
softwareRenderNode->setWindow(window());
+ softwareRenderNode->appendChildNode(observerNode);
}
else
{
rectangleNode = window()->createRectangleNode();
assert(rectangleNode);
+ rectangleNode->appendChildNode(observerNode);
const auto material = rectangleNode->material();
if (!material ||
=====================================
modules/gui/qt/widgets/native/viewblockingrectangle.hpp
=====================================
@@ -21,6 +21,37 @@
#include <QQuickItem>
#include <QColor>
+#include <QMatrix4x4>
+#include <QSGRenderNode>
+
+// WARNING: Do not use QSGTransformNode here with preprocess, Qt does not
+// necessarily call preprocess when the combined matrix changes!
+class MatrixChangeObserverNode : public QSGRenderNode
+{
+public:
+ explicit MatrixChangeObserverNode(const std::function<void()>& callback)
+ : m_callback(callback) { }
+
+ void render(const RenderState *) override
+ {
+ assert(matrix());
+ const QMatrix4x4 m = *matrix(); // matrix() is the combined matrix here
+ if (m_lastCombinedMatrix != m)
+ {
+ m_callback();
+ m_lastCombinedMatrix = m;
+ }
+ }
+
+ RenderingFlags flags() const override
+ {
+ // Enable all optimizations, as we are not actually rendering anything in this node:
+ return static_cast<RenderingFlags>(BoundedRectRendering | DepthAwareRendering | OpaqueRendering | NoExternalRendering);
+ }
+private:
+ std::function<void()> m_callback;
+ QMatrix4x4 m_lastCombinedMatrix;
+};
class ViewBlockingRectangle : public QQuickItem
{
@@ -29,7 +60,7 @@ class ViewBlockingRectangle : public QQuickItem
Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged FINAL)
public:
- ViewBlockingRectangle(QQuickItem *parent = nullptr);
+ explicit ViewBlockingRectangle(QQuickItem *parent = nullptr);
protected:
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
@@ -39,6 +70,9 @@ private:
bool m_windowChanged = false;
signals:
+ // NOTE: `scenePositionHasChanged()` signal is emitted from the render thread,
+ // and NOT during synchronization (meaning, GUI thread is not blocked):
+ void scenePositionHasChanged();
void colorChanged();
};
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/484506e3cd39c6e5551eed440fbb25a174791cca...29793d55e1bbe9f2be97ae77bde48522164d8d7c
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/484506e3cd39c6e5551eed440fbb25a174791cca...29793d55e1bbe9f2be97ae77bde48522164d8d7c
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