背景
基于weston使用qt或者gtk等UI框架显示应用程序的时候,需要明确是wayland平台还是x11平台,然后在run weston的时候选择合适的参数。
某些情况下在weston下运行demo时候会报错:Could not connect to display,通常网上的分析和采用的方法如下所示:
该错误是由于在远程或者串口终端环境下没有正确设置DISPLAY导致的。
在Linux/Unix类操作系统上, DISPLAY用来设置将图形显示到何处。直接登陆图形界面或者登陆命令行界面后使用startx启动图形, DISPLAY环境变量将自动设置为:0.0, 此时可以打开终端, 输出GUI程序的名称来启动程序, 图形将显示在本地窗口上, 在终端上输入printenv查看当前环境变量, 输出结果中有如下内容:
DISPLAY=:0.0
解决办法:
export DISPLAY=':0.0'
但是在weston下通过该方法有时候不能够解决问题呢?需要看下面进一步分析,只有适合的配置才能在weston下使用X应用,也才会出现X11系统下的DISPLAY参数
wayland框架
首先看一下wayland协议的整体框架,如图1所示。我们使用的weston是属于wayland compositor的参考实现。从图1中分析可知,wayland应用和x11应用都可以运行在weston,但是x11的应用程序需要通过xwayland模块将x11协议转为wayland协议与wayland compositor通信。与X11相比wayland最大的不同便是client可以自己通过EGL调用3D渲染库来渲染自己的界面,然后通过共享内存compositor即可获得client端的渲染数据,通过compositor合成渲染之后送output端。output端对接的绝多数情况都是基于drm的显示框架,通过drm将显示数据发送到panel。
图1 wayland框架
然后分析xwayland和weston的对接,有了xwayland模块,就可以在weston上无缝运行基于x11的应用。xwayland的module与weston的对接框架如图2所示:
图2 xwayland在weston中的位置和启动方式
当weston被运行时候,如果有xwayland module则会被launch,然后创建X sockets。该sockets会被添加到weston的main loop中去,用于监听是否有X clients连接,当第一个X client连接之后,在weston中会fork一个X Server,之后注销之前建立的X sokets。随后的X Client都会与X Server进行对接。采用该方式的原因是减少内存开销,避免weston在启动之后,并没有X11的应用被运行时,白白消耗内存。
针对X应用,weston启动时候会运行X Window Manager。使用X Window Manager可以把不同类型的X windows映射到wayland surfaces(xserver_set_window_id request),将一些X window中有用的用户界面接口提供给desktop shell,如X client端的界面大小和移动另一方面X Window Manager能够在window四周嵌入漂亮的装饰框架同时在端与端之间实现copy和paste。
对于weston中的compositor,如图3所示进行了很好的结构表示,当前多数情况下使用的是drm对接下层,所以可以在weston运行时候指定composito-core选择使用drm-backend,即compositor-drm。如果当前调试板没有GPU,则选择使用软件渲染工具pixman-renderer,若支持使用gl-renderer。渲染后的数据通过compositor-drm利用用户空间的libdrm库接口向下传递到DRM/KMS Driver,最终写入屏幕显示。
图3 weston中的drm-compositor
通过上述分析之后,运行weston时,如果要执行X11的应用,则需要选择xwayland module。通过weston -h可以看到:
-h, --help
-iN, --idle-time=N
--log=file.log
--modules=module1.so,module2.so
--no-config
使用--modules=xwayland.so即可。但是通常我们使用gdm来启动weston,所以采用上述方式有很大的局限性,该采用配置weston.ini的方式启用xwayland。
Weston.ini的描述:
1. Weston uses a configuration file called weston.ini for its setup. The weston.ini configuration file is searched for in one of the following places when the server is started:
2.
3. $XDG_CONFIG_HOME/weston.ini (if $XDG_CONFIG_HOME is set)
4. $HOME/.config/weston.ini (if $HOME is set)
5. weston/weston.ini in each
6. $XDG_CONFIG_DIR (if $XDG_CONFIG_DIRS is set)
7. /etc/xdg/weston/weston.ini (if $XDG_CONFIG_DIRS is not set)
8. <current dir>/weston.ini (if no variables were set)
环境变量:
$HOME是用户空间的路径
$XDG_CONFIG_HOME是用户指定的配置目录
$XDG_CONFIG_DIRS是通过:分割的配置目录,如/etc/xdg-foo:/etc/xdg
所以我们将weston.ini放入$HOME/.config/路径下,当weston启动时会去该路径下加载weston.ini,如果没有weston.ini则会加载失败,但是weston会使用默认的配置。
在weston.ini中配置:xwayland=true即可告诉weston来加载xwayland module。
配置重启开机后使用printenv查看环境变可以看到:DISPLAY=:0.0
所以DISPLAY这个环境变量的打印是X系统中用来设置将图形显示到何处,当然在wayland中也有类似的变量WAYLAND_DISPLAY
这里可以做一点延申:
如果需要其它用户的图形显示在当前屏幕上,则应以当前登陆的用户,也就是切换身份前的用户执行如下命令
xhost +
该命令将允许别的用户启动的图形程序将图形显示在当前屏幕上。这种场景常用于串口或者ssh登录开发板的情况。
通常我们在串口控制台使用命令运行应用界面时,会遇到一个问题:通常weston运行起来之后是在非root模式下,如test用户下。但是进入root模式执行各种命令是比较方便的,进入root模式之后有个问题是环境变量不能继承test用户的。所以有没有一个办法从test进入root模式之后还能保持test用户下的环境变量呢?
有——不要使用sudo切换,使用su命令
两者区别:
su命令用来切换用户,substitute英文含义“代替”的意思
- su:不加用户名默认是切换为root用户,切当前目录不改变,其他环境变量不变
- su - 或者su -l 或者 su --login:切换为root用户,同时变更工作目录,以及SHELL,USER,PATH,HOME,LOGNAME变量
sudo命令:sudo为superuser do 的简写,即使用超级用户来执行命令,一般是指root用户。sudoers文件存放在etc目录下,我们可以直接输入命令visudo编辑sudoers文件,使用visudo命令编辑文件,会验证我们添加的信息是否有语法错误。我们常用的sudo -s意思是:执行环境变数中的 SHELL 所指定的 shell ,或是 /etc/passwd 里所指定的 shell,及更改了环境变量。
综上分析可知,我们的使用weston命令,需要选择drm backend,在weston.ini中选择使能xwayland module,所以最终命令形式为:
weston --backend=drm-backend.so --tty=7 --use-pixman(使用软件渲染)
weston --backend=drm-backend.so --tty=7(使用硬件GPU渲染)
weston命令的使用方法
1. Usage: weston [OPTIONS]
2.
3. 该weston的版本型号为3.0.0,weston支持多种backend,每种backend都支持不同的子选项。
4.
5. Core options:
6.
7. --version Print weston version
8. -B, --backend=MODULE 后端加载模块, one of
9. drm-backend.so
10. fbdev-backend.so
11. headless-backend.so
12. wayland-backend.so
13. x11-backend.so
14. --shell=MODULE Shell module, defaults to desktop-shell.so
15. -S, --socket=NAME Name of socket to listen on
16. -i, --idle-time=SECS Idle time in seconds
17. --modules Load the comma-separated list of modules
18. --log=FILE Log to the given file
19. -c, --config=FILE Config file to load, defaults to weston.ini
20. --no-config Do not read weston.ini
21. -h, --help This help message
22.
23. 如果选择使用drm-backend.so的子选项:
24.
25. --connector=ID Bring up only this connector
26. --seat=SEAT The seat that weston should run on
27. --tty=TTY The tty to use
28. --use-pixman Use the pixman (CPU) renderer
29. --current-mode Prefer current KMS mode over EDID preferred mode
30.
31. 如果选择使用fbdev-backend.so的子选项:
32.
33. --tty=TTY The tty to use
34. --device=DEVICE The framebuffer device to use
35.
36. 如果选择使用headless-backend.so的子选项:
37.
38. --width=WIDTH Width of memory surface
39. --height=HEIGHT Height of memory surface
40. --transform=TR The output transformation, TR is one of:
41. normal 90 180 270 flipped flipped-90 flipped-180 flipped-270
42. --use-pixman Use the pixman (CPU) renderer (default: no rendering)
43. --no-outputs Do not create any virtual outputs
44.
45. 如果选择使用wayland-backend.so的子选项:
46.
47. --width=WIDTH Width of Wayland surface
48. --height=HEIGHT Height of Wayland surface
49. --scale=SCALE Scale factor of output
50. --fullscreen Run in fullscreen mode
51. --use-pixman Use the pixman (CPU) renderer
52. --output-count=COUNT Create multiple outputs
53. --sprawl Create one fullscreen output for every parent output
54. --display=DISPLAY Wayland display to connect to
55.
56. 如果选择使用x11-backend.so的子选项:
57.
58. --width=WIDTH Width of X window
59. --height=HEIGHT Height of X window
60. --scale=SCALE Scale factor of output
61. --fullscreen Run in fullscreen mode
62. --use-pixman Use the pixman (CPU) renderer
63. --output-count=COUNT Create multiple outputs
64. --no-input Dont create input devices
参考资料
https://www.cnblogs.com/danmiao/p/9993142.html
https://blog.csdn.net/SwTesting/article/details/81698986
https://www.secjuice.com/wayland-vs-xorg/
https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)
https://blog.csdn.net/garybrother/article/details/5764710
http://manpages.ubuntu.com/manpages/xenial/man1/weston.1.html#xwayland
https://blog.csdn.net/wojiuguowei/article/details/79201845
https://blog.csdn.net/jinzhuojun/article/details/47290707
http://manpages.ubuntu.com/manpages/bionic/man5/weston.ini.5.html
http://manpages.ubuntu.com/manpages/bionic/man5/weston.ini.5.html