QQuickWindow: skip child window restacking when no child windows
QQuickWindowPrivate::dirtyItem() requests a child window stacking
order update whenever any item in the scene gets the
ChildrenStackingChanged dirty bit, which happens on every z change,
stackBefore/stackAfter, effective visibility change, and layer/effect
reference change. The next polishItems() then calls
updateChildWindowStackingOrder(), which walks the entire item tree,
calling paintOrderChildItems() and a qobject_cast on every item, to
raise embedded native child windows in paint order.
In typical scenes some item changes visibility or z nearly every
frame, so this full tree walk runs on almost every polish pass, even
in scenes without a single child window, where there is nothing to
restack.
The walk only raises windows whose parent window is this window, and
QWindow::setParent() also makes the window a QObject child of its
parent. So skip the deferred restacking in polishItems() when the
window has no direct QWindow child. The check is cheap, as it only
looks at the direct children of the window: the root item, the items
and value sources declared directly inside the Window in QML, and any
child windows. Other declared objects, including nested transient
Windows, are reparented to the content item. A window container
reparents its window in its own updatePolish(), which runs earlier in
the same polishItems(), so the restacking still happens in the pass
where the window arrives.
The synchronous restacking on ChildWindowAdded and SurfaceCreated is
unchanged, as is the behavior when child windows are present.
Pick-to: 6.12 6.8
Fixes: QTBUG-150923
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Change-Id: Ib763fb4f0fad63d5bfc93199ce64d99dcf9fb57c
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>