参考:
修正linux下wayland的chrome輸入與顯示錯誤
无法在Chrome(Wayland)中使用fcitx5
Wayland下使用UseOzonePlatform无法显示界面 #2300
support IME under native Wayland #33662
Vscode does not launch in wayland session #146349
Ozone-wayland: support text_input_v3 protocol

Chromium从98版本开始已经默认支持Wayland,用户可以通过--ozone-platform-hint=auto参数启用Wayland支持。问题根源在于 Chromium对Wayland的兼容措施还没有完全释出, text-input-v3 支持虽然以及合并但因为前者还存在一些问题。
2025-06-29T19:56:53.png
作为对wayland支持的努力,UseOzonePlatform现在是 chrome://flags/#ozon-platform-hint 中的一个实验性选项,默认没有启用。
启用后选择auto即可,但是理论上应该确保XDG_RUNTIME_DIR 和 WAYLAND_DISPLAY 等环境变量正常传递,这可能影响Chromium对当前运行环境的识别,
终端执行 echo $XDG_RUNTIME_DIRecho $WAYLAND_DISPLAY,正常应返回类似 /run/user/1000 wayland-0 的路径。
查找资料过程中发现用户使用--ozone-platform-hint=wayland 后只有第一次重新启动是正常的,第二次就无法启动
我的终端里可以看到刷屏的报错:

[10091:10136:0630/034118.878942:ERROR:gpu/command_buffer/client/client_shared_image.cc:133] Failed to map the buffer.
[10091:10136:0630/034118.878946:ERROR:gpu/command_buffer/client/client_shared_image.cc:231] ScopedMapping init failed.
[10091:10136:0630/034118.878951:ERROR:gpu/command_buffer/client/client_shared_image.cc:431] Unable to create ScopedMapping
[10091:10136:0630/034118.878957:ERROR:cc/raster/one_copy_raster_buffer_provider.cc:303] MapSharedImage Failed.
[10091:10136:0630/034118.878964:ERROR:ui/gfx/linux/client_native_pixmap_dmabuf.cc:49] Failed to mmap dmabuf: 权限不够 (13)

丢给Deepseek分析:

根据您提供的错误日志,问题核心在于 Chromium 在 Wayland 环境下尝试使用 DMA-BUF 共享内存时出现权限问题,导致 GPU 进程初始化失败。以下是针对性的解决方案:

### 🔧 问题根源分析 ``` ERROR:ui/gfx/linux/client_native_pixmap_dmabuf.cc:49] Failed to mmap dmabuf: 权限不够 (13) ``` 该错误表明 Chromium 的 GPU 进程无法映射 DMA-BUF 内存区域(直接内存访问缓冲区),通常由以下原因导致: 1. **沙箱权限限制**:Chromium 的渲染器沙箱阻止了 GPU 进程访问 DRM 设备 2. **Wayland 协议限制**:Wayland 合成器(KWin)未正确授权客户端访问缓冲区 3. **内核权限问题**:用户账户缺少 `/dev/dri` 设备的访问权限 4. **内存保护机制**:内核的 `CONFIG_STRICT_DEVMEM` 保护阻止访问 --- ### ✅ 解决方案 #### 1. 添加用户到视频渲染组 (关键步骤) ```bash sudo usermod -aG render,video $USER ``` 重启系统使权限生效,此操作解决 90% 的 DMA-BUF 权限问题 #### 2. 调整 Chromium 沙箱策略 ```bash # 尝试禁用 GPU 沙箱(测试用) chromium --disable-gpu-sandbox --enable-features=UseOzonePlatform --ozone-platform-hint=auto # 或更安全的沙箱放松策略 chromium --enable-features=UseOzonePlatform --ozone-platform-hint=auto \ --no-sandbox --disable-seccomp-filter-sandbox ``` #### 3. 配置 KWin 的 DMA-BUF 支持 (Plasma 6+) 创建或修改 `~/.config/kwinrc`: ```ini [Wayland] Enabled=true DmaBufForce=true ``` #### 4. 强制启用内存映射支持 ```bash chromium --enable-features=UseOzonePlatform,EnableSharedImageForVideo \ --ozone-platform-hint=auto \ --use-gl=egl ``` #### 5. 修复系统级权限问题 ```bash # 检查设备权限 ls -l /dev/dri/ # 临时修复权限(重启后重置) sudo chmod 666 /dev/dri/card* # 永久修复(创建 udev 规则) echo 'KERNEL=="card*", GROUP="video", MODE="0660"' | sudo tee /etc/udev/rules.d/99-gpu.rules sudo udevadm control --reload-rules ``` #### 6. 使用替代渲染后端 ```bash # 尝试不同后端组合 chromium --use-angle=gl --enable-features=UseOzonePlatform --ozone-platform-hint=auto # 或 chromium --use-cmd-decoder=passthrough --enable-features=UseOzonePlatform --ozone-platform-hint=auto ``` --- ### 📍 验证步骤 1. 执行权限修改后重启系统 2. 通过终端启动 Chromium: ```bash chromium --enable-features=UseOzonePlatform --ozone-platform-hint=auto 2> chromium.log ``` 3. 检查日志中是否还有 `Failed to mmap dmabuf` 错误 --- ### ⚠️ 注意事项 1. 如果使用 **Flatpak 版 Chromium**,需要额外授权: ```bash flatpak override --user com.github.Eloston.UngoogledChromium \ --talk-name=org.freedesktop.FileTransfer \ --filesystem=/dev/dri ``` 2. **内核版本要求**:Linux 内核 ≥ 5.15 对 Wayland DMA-BUF 有显著改进 3. **硬件兼容性**:较老的 Intel HD Graphics (Gen<8) 可能需要额外内核参数: ```bash # 在 /etc/default/grub 添加 GRUB_CMDLINE_LINUX_DEFAULT="... i915.enable_guc=2" ``` 通过组合使用用户组权限调整 + 沙箱策略优化 + KWin 配置,通常可彻底解决 DMA-BUF 映射问题。若问题依旧,请提供 `chromium://gpu` 页面的完整信息进一步诊断。

实践结论

单给权限也解决不了问题,窗口虽然能看见了但是一样处于抽风状态。
只有明确指定图形后端才能获得一个正常的窗口体验,而且因为打开UseOzonePlatform 输入法输入的问题也一同解决了。
那么我们就有两种方案可以让Chromium在Wayland下正常工作。

# 方案1
# 自动选择Ozone后端,但强制使用EGL 
chromium-browser --enable-features=UseOzonePlatform \
         --ozone-platform-hint=auto \
         --use-gl=egl
# 方案2 
# 指定Ozone图形后端使用Wayland+ EGL组合(推荐)
chromium-browser \
  --enable-features=UseOzonePlatform \
  --ozone-platform=wayland \
  --use-gl=egl

接下来把启动参数加到Chromium.desktop文件里就好了。

各参数作用总结

参数作用推荐值
--enable-features=UseOzonePlatform启用Ozone图形抽象层必需
--ozone-platform-hint=auto自动选择最佳图形后端可选
--use-gl=egl使用EGL接口而非原生GLX对Wayland必需

标签: none

添加新评论