[vlc-commits] [Git][videolan/vlc][master] qt: do not call `QQuickItem::mapToScene()` in hot path in `VideoSurface`
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Sat Nov 7 08:43:11 UTC 2026
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
e66669f3 by Fatih Uzunoglu at 2026-11-07T09:21:44+01:00
qt: do not call `QQuickItem::mapToScene()` in hot path in `VideoSurface`
The Qt renderer already maps the position implicitly, we can get the
value directly from it through custom render node as we are doing in
threaded render loop case.
Amends b27332d3.
- - - - -
1 changed file:
- modules/gui/qt/maininterface/videosurface.cpp
Changes:
=====================================
modules/gui/qt/maininterface/videosurface.cpp
=====================================
@@ -126,7 +126,13 @@ VideoSurface::VideoSurface(QQuickItem* parent)
setFlag(ItemAcceptsInputMethod, true);
{
- // This is for initialization, they are adjusted in `::updatePaintNode()`:
+ // NOTE: Update render position even if render loop is not threaded, since
+ // calling `QQuickItem::mapToScene()` is expensive whereas the Qt
+ // renderer can provide the scene position/matrix to the nodes by
+ // reusing parent item's matrix. Using the inherited value can be
+ // considered cheaper than having an additional render node, since
+ // `::mapToScene()` requires traversing through all parent items.
+ // Disadvantage of this is mainly some bytes of extra memory usage.
setUpdateRenderPosition(true);
setFlag(ItemHasContents, false); // `setUpdateRenderPosition(true)` sets `ItemHasContents`
}
@@ -239,24 +245,8 @@ void VideoSurface::synchronize()
// during synchronization (GUI thread is not blocked). Try to
// be very careful.
- QSizeF size;
- QPointF position;
-
- static const bool isObjectThread = QThread::currentThread() == thread();
- if (isObjectThread)
- {
- assert(QThread::currentThread() == thread());
- // Item's thread (GUI thread):
- size = this->size();
- position = this->mapToScene(QPointF(0,0));
- }
- else
- {
- assert(QThread::currentThread() != thread());
- // Render thread:
- size = renderSize();
- position = renderPosition();
- }
+ const QSizeF size = renderSize();
+ const QPointF position = renderPosition();
std::optional<QSizeF> newSize;
std::optional<QPointF> newPosition;
@@ -436,18 +426,5 @@ QSGNode *VideoSurface::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data)
m_videoEnabledChanged = false;
}
- if (QThread::currentThread() == thread())
- {
- // As per `::synchronize()` we do not need `ViewBlockingRectangle` to provide the render position in this case:
- setUpdateRenderPosition(false);
- // Override `ViewBlockingRectangle`'s `ItemHasContents`, if it is unset (when both `renderEnabled` and
- // `updateRenderPosition()` are false):
- setFlag(ItemHasContents, true);
- }
- else
- {
- setUpdateRenderPosition(true);
- }
-
return ViewBlockingRectangle::updatePaintNode(node, data);
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e66669f35a943d599534d2ce3dc247e7c3acd20e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e66669f35a943d599534d2ce3dc247e7c3acd20e
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list