QtWayland client distorted on Raspberry Pi 4

734 Views Asked by At

I'm trying to create a very simple wayland compositor using the examples found here, like this:

import QtQuick 2.12
import QtQuick.Window 2.2
import QtWayland.Compositor 1.3

WaylandCompositor {
    id: wlcompositor
    WaylandOutput {
        compositor: wlcompositor
        window: Window {
            width: 800
            height: 480
            visible: true
            title: wlcompositor.socketName
            Grid {
                anchors.fill: parent
                anchors.margins: 100
                columns: 2
                Repeater {
                    model: shellSurfaces
                    ShellSurfaceItem {
                        id: shellSurfaceItem
                        autoCreatePopupItems: true
                        shellSurface: modelData
                        onSurfaceDestroyed: shellSurfaces.remove(index)
                    }
                }
            }
        }
    }
    ListModel { id: shellSurfaces }

    XdgShell {
        onToplevelCreated: shellSurfaces.append({shellSurface: xdgSurface})
    }
}

And then I'm creating a separate client app that just creates a couple Rectangles as a test.

import QtQuick 2.12
import QtQuick.Window 2.12

Window
{
    id: window
    visible: true
    width: 200
    height: 200

    Rectangle
    {
        anchors.fill: parent
        color: "green"

        Rectangle
        {
            x: 10
            y: 10
            width: 100
            height: 100
            color: "blue"
        }
    }
}

Everything seems simple and straightforward. But when I run it on my Pi4 (using the -platform wayland flags), the client gets crazy distortion, like this: Screenshot

I'm testing it with Boot2Qt, which is a yocto linux image. I've tried Qt versions 5.14.2 and the newest 5.15.0 with the same results. There are no errors on the console. Nothing that indicates anything is wrong except that it looks awful.

I did notice that if I use weston as my compositor instead of QtWayland, then the app looks perfect. So that makes me think there's something wrong with WaylandCompositor. But my search of google found nobody else complaining of the same thing.

I don't even know what to try. Does anybody have any ideas?

3

There are 3 best solutions below

3
jns On

I had similar effects using qt 5.15.1 and qt 5.15.2 with qt wayland on the pi 4. I managed to get QT Wayland working with no distortion by compiling the mesa driver 20.3.3 and 20.3.4, using the following options:
-Dplatforms=x11,wayland -Dvulkan-drivers=broadcom -Ddri-drivers= -Dgallium-drivers=kmsro,v3d,vc4 -Dbuildtype=release -Dprefix=/usr -Degl=true

After installing the drivers i updated the sysroot on my host and cross-compiled the QT Lib. That made it finally working. Good luck.

0
bobbaluba On

If memory serves me correctly, the closed-source graphics driver are a real pain when it comes to wayland support. You may have some luck by enabling the broadcom backend (which I think it's what appropriate for rpis) for qt wayland by setting QT_WAYLAND_CLIENT_BUFFER_INTEGRATION=brcm before starting the compositor.

There is some info about this env var in this readme: https://code.qt.io/cgit/qt/qtwayland.git/tree/README

But if practically possible, I would think the mesa open-source drivers will give you a lot less pain, as it's much more widely used and support is likely much better.

1
penk On

I've encountered this very same issue from Qt 5.12 to 5.15, and Qt 6.2.0 RC.

The solution to avoid distortion is to enable dma-buf in QtWayland, and set hardware integration from the compositor side:

export QT_WAYLAND_CLIENT_BUFFER_INTEGRATION=linux-dmabuf-unstable-v1
export QT_WAYLAND_SERVER_BUFFER_INTEGRATION=dmabuf-server 

Note that in order to enable dma-buf it required me to tweak .pro and configure.json files (I'm doing native build on the Pi4), as the libdrm-dev header couldn't be detected by qmake or cmake correctly.

Add INCLUDEPATH += /usr/include/libdrm/ to the following two:

./src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.pro
./src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pro

And add libdrm/ before drm headers in following files:

./src/client/configure.json
./src/compositor/configure.json

A re-configure & rebuild should work. Tested on Pi4 + Qt 5.15.2 with both armhf and arm64 image, using dtoverlay=vc4-kms-v3d-pi4 overlay.