配置 Ubuntu 21.04 以支持 Wayland 和 Flutter 桌面
从带有 NVIDIA 驱动程序的 X11 迁移到 Wayland 可能需要更多配置
Ubuntu 21.04 宣传 Flutter 和 Wayland
在 4 月 22日,Ubuntu 21.04 发布 并大肆宣传“Wayland 和 Flutter 提供更流畅的图形和简洁美观的、以设计为主导的跨平台开发”。由于我经常使用 Flutter 2.0,包括桌面上的 Flutter,我决定将我的 Ubuntu 20.04 工作站升级到 21.04,使用 do_release_upgrade -d
。大多数人无需添加 -d
以进行开发版本。请先尝试不使用 -d
。虽然我在 4 月 25 日(在 21.04 公开发布后)进行了升级,但我需要在我的系统中添加 -d
。
我首先升级到 20.10,然后升级到 21.04。虽然升级所有不同的组件花了一些时间,但升级进行得很顺利。
切换到 Wayland 的问题
虽然我可以登录 gdm3,但看起来我使用的是 x11 而不是 Wayland。
$ echo $XDG_SESSION_TYPE
将返回 x11,而不是预期的 wayland。
此外,我在登录屏幕上没有看到齿轮图标来选择 Ubuntu Wayland 和 X.org。 在 21.04 上,Wayland 似乎是默认设置,并且只是在登录屏幕的齿轮上称为 ubuntu。升级后,齿轮甚至没有出现。
解决问题
gdm3 custom.conf
最初,我以为可以通过修改/etc/gdm3/custom.conf来解决问题。
有一个很好的注释,例如注释掉 WaylandEnable=false
将导致启用 Wayland。
# GDM configuration storage
#
# See /usr/share/gdm/gdm.schemas for a list of available options.
[daemon]
# Uncomment the line below to force the login screen to use Xorg
# WaylandEnable=false
# Enabling automatic login
# AutomaticLoginEnable = true
# AutomaticLogin = user1
在注释掉 WaylandEnable=false
之后,我重新启动了计算机,但我仍然无法使 Wayland 工作。
gdm udev 规则
即使在我清除了所有 nvidia 驱动程序文件之后,我仍然无法启用 Wayland。然后我编辑了/usr/lib/udev/rules.d/61-gdm.rules并注释掉了对 DRIVER=="nvidia"
的检查。
cd /usr/lib/udev/rules.d/
$ sudo vi 61-gdm.rules
# disable Wayland on Hi1710 chipsets
ATTR{vendor}=="0x19e5", ATTR{device}=="0x1711", RUN+="/usr/libexec/gdm-disable-wayland"
# disable Wayland when using the proprietary nvidia driver
# DRIVER=="nvidia", RUN+="/usr/libexec/gdm-disable-wayland"
# disable Wayland if modesetting is disabled
IMPORT{cmdline}="nomodeset", RUN+="/usr/libexec/gdm-disable-wayland"
重新启动系统后,我能够切换到 Wayland。
现在,检查 XDG_SESSION_TYPE
显示的是预期的 wayland。
测试 Flutter 桌面
我启用 Wayland 的全部目标是测试 Canonical 首席执行官 Mark Shuttleworth 在 Ubuntu 21.04 公告中宣传的 Flutter 桌面。
我创建了一个名为 desk
的示例项目。我使用自动化的 dart migrate 命令开始使用 Dart 2.12.0 和 Flutter 2.0 的健全空安全。
$ flutter create --platforms=linux desk
cd desk
dart migrate --apply-changes
flutter run
默认的桌面应用程序在 Linux 上运行良好。
接下来,我测试了一个更复杂的应用程序,用于 RICOH THETA 360 相机,该相机最初是在 Windows 上构建的。
该应用程序使用大约 8MB 大小的 23MP 360 度图像。该应用程序可以运行,并且可以导航 360 度图像。但是,在 Windows 10 上的图形性能感觉稍微流畅一些。
我运行的是带有 X.org 驱动程序的 NVIDIA GTX 950Ti 和 Intel i7-6800K CPU。
NVIDIA 470 Linux 驱动程序应该具有更多 Wayland 支持。但是,它目前不可用。我没有测试 2021 年 5 月 18 日发布的 465.31 版本。
OBS 屏幕共享
2021 年 6 月初发布的 OBS 27 增加了对 Wayland 屏幕捕获的支持。 下面的测试是在 2021 年 6 月 11 日发布的 OBS 27.0.1 上完成的。
屏幕捕获应使用 PipeWire
。
摘要
构建 Flutter Linux 桌面应用程序可与 Wayland 一起使用。 但是,我最初看不到任何性能或图形方面的提升。 我打算继续将 Wayland 与 Flutter 一起使用,并计划密切关注 NVIDIA 驱动程序的未来硬件加速改进的状况。
更新到 21.10 Impish Indri
在 /usr/lib/dev/rules/d/61-gdm.rules 中
# disable wayland if nvidia-drm modeset is not enabled
ATTR{parameters/modeset}!="Y", GOTO="gdm_disable_wayland"
# disable wayland for nvidia drivers versions lower than 470
ATTR{version}=="4[0-6][0-9].*|[0-3][0-9][0-9].*|[0-9][0-9].*|[0-9].*",
GOTO="gdm_disable_wayland"
GOTO="gdm_prefer_xorg"
LABEL="gdm_nvidia_drm_end"
GOTO="gdm_end"
Wayland 未在 21.10 的首次启动时出现
显式指定 nvidia-drm.modeset
编辑 /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nvidia-drm.modeset=1"
运行 sudo update-grub
重新启动计算机。
Wayland 现在可与 NVIDIA 驱动程序一起使用
$ echo $XDG_SESSION_TYPE
wayland
nvidia-smi
Wed Oct 6 17:46:37 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.63.01 Driver Version: 470.63.01 CUDA Version: 11.4 |
|-------------------------------+----------------------+----------------------+
使用 30fps 的 4K 视频测试 Flutter 桌面。
$ flutter run -d linux
Launching lib/main.dart on Linux in debug mode...
Building Linux application...
Syncing files to device Linux...
Flutter 桌面应用程序运行良好!
运行 Flutter 2.5.2 和 Dart 2.14.3。
到目前为止,体验非常好。 :-)
历史
- 2021 年 4 月 27日:初始版本
- 2021 年 6 月 14日:添加了有关 OBS 27 的信息
- 2021 年 10 月 6日:使用 NVIDIA 驱动程序 470 升级到 Ubuntu 21.10 Impish Indri