By Toradex秦海
1).?簡介
目前主流的?ARM?平臺嵌入式?Linux BSP?的顯示后端基本都已經從?X11?升級到了?Wayland, 而常用的?Wayland Compositor - Weston?對于?Linux?下常用的?Qt?圖形界面開發(fā)框架的一些?Plugin (比如?Qt VirtualKeyboard)?的配合并不完善,因此本文就基于?TI AM62?處理器平臺測試?Qt?提供的?Wayland Compositor - QtWayland?的部署測試。
本文所演示的平臺來自于?Toradex?Verdin?AM62?嵌入式平臺。
2.?準備
a).?Verdin AM62 ARM核心版配合Dahlia載板,并連接調試串口和?HDMI?顯示器以及?USB?觸摸/鼠標用于測試。
3).?Verdin?AM62?Yocto?Linux?編譯部署以及配置
a).?由于需要增加對Qt Eglfs/KMS, QtWayland?和?Qt VirtualKeyboard?的支持,需要通過Yocto/Openembedded?框架重新編譯?Yocto Linux BSP,具體的配置方法請參考這里,部署如下修改后編譯Reference-Multimedia?image鏡像
-------------------------------
###?local.conf,增加Qt?eglfs/kms, Qtwayland?和?Qt VirtualKeyboard?支持###
+?TOOLCHAIN_TARGET_TASK:append = " libgles3-mesa-dev"
+?IMAGE_INSTALL:append = " qtvirtualkeyboard qtwayland ttf-droid-sans ttf-droid-sans-fallback ttf-droid-sans-mono ttf-droid-serif freetype"
+?PACKAGECONFIG:append:pn-qtvirtualkeyboard = " lang-zh_CN"
+?PACKAGECONFIG:append:pn-qtbase = " gles2extra eglfs kms"
+?PACKAGECONFIG_DISTRO:pn-qtbase = "icu examples accessibility gif gbm kms libinput"
+?PACKAGECONFIG_FONTS:pn-qtbase = "fontconfig"
+?PACKAGECONFIG:remove:pn-qtwayland = "xcomposite-egl xcomposite-glx"
###?layers/meta-toradex-ti/qt5-layer/recipes-qt/qt5/qtbase_%.bbappend,注釋掉以下內容?###
############################### TDX added
# from meta-arago/conf/layer.conf
-PACKAGECONFIG_GL:am62xx = "gles2extra linuxfb"
-PACKAGECONFIG_DISTRO:am62xx = "icu examples accessibility gif gbm kms libinput"
-PACKAGECONFIG_FONTS:am62xx = "fontconfig"
+#PACKAGECONFIG_GL:am62xx = "gles2extra linuxfb"
+#PACKAGECONFIG_DISTRO:am62xx = "icu examples accessibility gif gbm kms libinput"
+#PACKAGECONFIG_FONTS:am62xx = "fontconfig"
-PACKAGECONFIG:remove:am62xx = "kms"
-PACKAGECONFIG:remove:am62xx = "vulkan"
-PACKAGECONFIG:remove:am62xx = "glib xcb"
+#PACKAGECONFIG:remove:am62xx = "kms"
+#PACKAGECONFIG:remove:am62xx = "vulkan"
+#PACKAGECONFIG:remove:am62xx = "glib xcb"
# they don't apply without changes, drop them for now
-SRC_URI:remove = " \
- ???file://0002-deform-disable-opengl-button.patch \
- ???\
- ???file://0001-deform-Fix-how-controls-are-shown.patch \
- ???file://0001-qtbase-plugins-platforms-eglfs_kms-fix-compiler-erro.patch \
- ???file://0001-eglfs-Force-888-format-only-on-env-flag.patch \
-"
+#SRC_URI:remove = " \
+# ???file://0002-deform-disable-opengl-button.patch \
+# ???\
+# ???file://0001-deform-Fix-how-controls-are-shown.patch \
+# ???file://0001-qtbase-plugins-platforms-eglfs_kms-fix-compiler-erro.patch \
+# ???file://0001-eglfs-Force-888-format-only-on-env-flag.patch \
+#"
###compile?Reference-Multimedia?image###
$?MACHINE="verdin-am62"?bitbake bitbake tdx-reference-multimedia-image
###?compile SDK###
$?MACHINE="verdin-am62"?bitbake tdx-reference-multimedia-image -c populate_sdk
-------------------------------
b).?YoctoLinux?image部署
參考這里通過Toradex?Easy?installer將上面編譯好的image更新部署到模塊
c).?顯示配置
./?HDMI默認即可正常顯示,如果實際測試是連接其他接口如?LVDS?等顯示設備,可以參考這里調整?Device-Tree Overlay?設置來使能相關的顯示設備。
./?輸入設備如?USB HID?電容式觸摸或者?USB?鼠標通常無需額外設置,插上即可使用。
?
?
4). Qtwayland compositor?編譯部署
a).?Qt?Qtwayland組件可以非常方便的使用C++/QML語言開發(fā)定制化的Wayland?compositor,詳細說明請見這里,也提供了很多sample?project供參考
b).?本文測試所使用的Qtwayland?compositor?來自于Qt?官方的?Pure-qml sample?示例,源代碼請參考這里,這是一個基于?QML?開發(fā)的并且支持?Qt VirtualKeyboard plugin?的簡單?Qtwayland?compositor
c).?參考這里說明使用上面章節(jié)?3.a編譯出的SDK文件配置QtcreatorIDE?工具交叉編譯環(huán)境,然后下載Pure-qml?工程源代碼后通過?Qtcreator IDE?進行交叉編譯,生成pure-qml?可執(zhí)行二進制文件上傳到Verdin AM62 Linux?系統中
d).?使用編譯好的pure-qml?Qtwayland compositor?替換系統默認的Weston?compositor
./?創(chuàng)建pure-qml.sh執(zhí)行腳本文件
-------------------------------
#copy?pure-qml?binary to /usr/bin
$ cp?pure-qml?/usr/bin/
#create?pure-qml.sh script,?detailed content in below
$?vi /usr/bin/pure-qml.sh
#?add executable permission
$chmod +x?pure-qml.sh
-------------------------------
./?pure-qml.sh –?由于系統DRM?掛載顯示設備在啟動過程中,其對應的card?號碼可能會變化,?因此腳本前面先對?“kms.conf”?文件里面的設置和系統啟動后的設備card0?或者?card1?進行匹配修改,然后再啟動compositor。
-------------------------------
#!/bin/sh
set -e
# modify kms.conf if seetings is not consistent with system drm card device name
if [ -d /sys/class/drm/card0-HDMI-A-1 ];then
sed -i '2 s/card1/card0/' /etc/qt5/eglfs_kms_cfg.json
fi
if [ -d /sys/class/drm/card1-HDMI-A-1 ];then
sed -i '2 s/card0/card1/' /etc/qt5/eglfs_kms_cfg.json
fi
# execute qtwayland compositor
/usr/bin/pure-qml &
-------------------------------
./?創(chuàng)建Qtwayland?systemd?service?文件,參考這里說明,Qt VirtualKeyboard?基于?Wayland Compositor?使用時候,需要在?Compositor?側配置?“QT_IM_MODULE”環(huán)境變量,而不是應用側。
-------------------------------
$ vi /lib/systemd/system/qtwayland.service
------
# This is a system unit for launching QtWayland
[Unit]
Description=Qt Wayland, a Wayland compositor, as a system service
RequiresMountsFor=/run
# Make sure we are started after logins are permitted.
Requires=systemd-user-sessions.service
After=systemd-user-sessions.service
After=plymouth-quit-wait.service
Before=graphical.target
[Service]
Environment="QT_QPA_EGLFS_KMS_CONFIG=/etc/qt5/eglfs_kms_cfg.json"
Environment="QT_QPA_EGLFS_INTEGRATION=eglfs_kms"
Environment="QT_QPA_PLATFORM=eglfs"
Environment="QT_QPA_EGLFS_KMS_ATOMIC=1"
Environment="QT_IM_MODULE=qtvirtualkeyboard"
ExecStart=/usr/bin/pure-qml.sh
User=root
Group=root
PAMName=login
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=graphical.target
------
-------------------------------
e).?測試Qtwayland?compositor
-------------------------------
###disable default?Weston compositor and?Qt demo app###
$?systemctl disable?weston.service
$?systemctl disable?weston.socket
$?systemctl disable wayland-app-launch
### enable Qt wayland compositor ###
$systemctl?enable?qtwayland
$?reboot
-------------------------------
重啟后,可以看到如下?Qt Compositor pure-qml?顯示結果

5). QtVirtualKeyboard Example應用測試
a).?分別使用一個Qt?Widget應用和一個Qt?Quick應用進行測試
./?Qt?Widget應用?–?Line Edits Example,詳細說明請參考這里,源碼從這里下載,將編譯好的可執(zhí)行binary“l(fā)ineedits”?上傳到Verdin?AM62 Linux /home/root?目錄
./ Qt Quick?應用?–?Qt VirtualKeyboard Basic Example,詳細說明請參考這里,源碼從這里下載,如上面?4.d?章節(jié)所提到的,需要如下修改?main.cpp?將環(huán)境變量取消導出,然后將編譯好的可執(zhí)行binary“basic”?上傳到Verdin?AM62 Linux /home/root?目錄
-------------------------------
...
int main(int argc, char *argv[])
{
????//qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QGuiApplication app(argc, argv);
QQuickView view(QString("qrc:/%2").arg(MAIN_QML));
...
}
-------------------------------
b).?創(chuàng)建應用啟動腳本/home/root/qtwayland-app-launch.sh
-------------------------------
#!/bin/sh
# export display environment
export XDG_RUNTIME_DIR=/run/user/`id -u`
export WAYLAND_DISPLAY=/run/user/`id -u`/wayland-0
if ! test -d "$XDG_RUNTIME_DIR"; then
mkdir --parents $XDG_RUNTIME_DIR
chmod 0700 $XDG_RUNTIME_DIR
fi
# wait for qtwayland
while [ ! -e ?$XDG_RUNTIME_DIR/wayland-0 ] ; do sleep 0.1; done
sleep 1
# run basic or lineedits app
/home/root/basic -platform wayland &
#/home/root/lineedits -platform wayland &
-------------------------------
c).?創(chuàng)建開機自啟動systemd?service文件
-------------------------------
$?vi /lib/systemd/system/qtwayland-app-launch.service
[Unit]
Description=Start a Qt wayland application
After=qtwayland.service
Requires=qtwayland.service
[Service]
Restart=on-failure
Type=forking
ExecStart=/home/root/qtwayland-app-launch.sh
RestartSec=1
[Install]
WantedBy=graphical.target
-------------------------------
d). enable service?并測試
-------------------------------
$?systemctl enable qtwayland-app-launch
$?reboot
-------------------------------
e).?重啟后分別啟動?basic?和?lineedits?應用效果如下,USB HID?電容觸摸和鼠標都可以正常操作虛擬鍵盤輸入


6).?總結
本文基于?Ti AM62?處理器演示了?QtWayland compositor?的部署以及?Qt VirtualKeyboard?應用的測試。