Skip to content

Draft: Zero copy QtQuick window thumbnails

Vlad Zahorodnii requested to merge work/shared-surface into master

Currently, qtquick window thumbnails are implemented as follows - when a WindowThumbnailItem is instantiated, it will connect the Scene::frameRendered signal. After kwin performs a compositing cycle, the Scene::frameRendered signal is going to be emitted and the thumbnail item will paint the window in an offscreen texture. A frame after that, the offscreen texture will be used in ThumbnailItemBase::updatePaintNode(). [vlad: yes, window thumbnails lag by 2 frames]

As is, an intermediate offscreen texture is created for every window, which is not an issue if the window is shown only once. For example, that is the case in the task switcher.

However, this creates a problem for the overview effect. Since every window must be rendered in an offscreen texture, there is some delay with which the overview effect shows up. With relatively small number of windows, it's unnoticeable though. As the number of windows increases, this becomes an issue that can't be ignored.

Another problem is that the overview effect (or the desktop grid effect) may want to display the desktop window more than once. It will be great to re-use dmabufs to improve performance as desktop windows are usually big.

This change attempts to make qtquick window thumbnails re-use surface texture data as much as possible. It also refactors scene to prepare it for having a scene graph per output.

Killing the offscreen texture step also improves the latency and makes kwin one step closer to completely switching to qtquick and ditching our scene code.

Decoration textures are not re-used as it's not worth due to required fencing between kwin and qtquick. It's much simpler to have qtquick render decorations and there are less chances of qtquick stalling kwin's graphics pipeline.

The SurfaceItem has been split in two pieces - the Surface and the SurfaceView. The Surface can be viewed as the model and the SurfaceView is the view to that surface on a particular output or scene graph. In its turn, the SurfaceItem has become a SurfaceView.

QtQuick window thumbnail is no longer a single texture, it's made of several smaller pieces - shadow item, decoration item, and a tree of surface items. If the size of the window item doesn't match Toplevel::size(), the child items (shadow, decoration, surface) will be scaled down at the item polishing step.

If you want to apply graphical effects to window thumbnails, you could still use layer.enabled and layer.effect.

The introduction of the Surface class opens up new questions about kwayland-server. Specifically, I think it is worth to merge the SurfaceWayland class and the KWaylandServer::SurfaceInterface class. KWaylandServer only adds an extra layer of (unnecessary) indirection.

The merge request can be viewed as two independent patch series - splitting SurfaceItem in Surface/SurfaceView and implementing a more efficient window thumbnail item. So far, this MR is a giant bowl of changes, which I would like to clean up a bit later and move preparation changes in their own MRs. The main purpose behind uploading this is to gather initial design feedback.

Edited by Vlad Zahorodnii

Merge request reports