disable dma buf on wayland linux (#4957)

* disable dma buf on linux

* allow configuring
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-12-04 15:18:13 -08:00
1 parent 1e48093e22
commit 946a925f41
2 files changed
+38

No files matched your search

+27
View File
@@ -32,6 +32,7 @@ pub(crate) struct App {
pub(crate) control_flow: ControlFlow,
pub(crate) is_visible_before_start: bool,
pub(crate) exit_on_last_window_close: bool,
pub(crate) disable_dma_buf_on_wayland: bool,
pub(crate) webviews: HashMap<WindowId, WebviewInstance>,
pub(crate) float_all: bool,
pub(crate) show_devtools: bool,
@@ -61,6 +62,7 @@ impl App {
let app = Self {
exit_on_last_window_close: cfg.exit_on_last_window_close,
disable_dma_buf_on_wayland: cfg.disable_dma_buf_on_wayland,
is_visible_before_start: true,
webviews: HashMap::new(),
control_flow: ControlFlow::Wait,
@@ -101,6 +103,9 @@ impl App {
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
app.connect_preserve_window_state_handler();
// Make sure to disable DMA buffer rendering on Linux Wayland sessions
app.disable_dma_buf();
(event_loop, app)
}
@@ -609,6 +614,28 @@ impl App {
});
}
}
/// Disable DMA buffer rendering on Linux Wayland sessions to avoid bugs with WebKitGTK
fn disable_dma_buf(&self) {
if cfg!(target_os = "linux") && self.disable_dma_buf_on_wayland {
static INIT: std::sync::Once = std::sync::Once::new();
INIT.call_once(|| {
if std::path::Path::new("/dev/dri").exists()
&& std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland"
{
// Gnome Webkit is currently buggy under Wayland and KDE, so we will run it with XWayland mode.
// See: https://github.com/DioxusLabs/dioxus/issues/3667
unsafe {
// Disable explicit sync for NVIDIA drivers on Linux when using Way
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
}
}
unsafe {
std::env::set_var("GDK_BACKEND", "x11");
}
});
}
}
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
+11
View File
@@ -67,6 +67,7 @@ pub struct Config {
pub(crate) window_close_behavior: WindowCloseBehaviour,
pub(crate) custom_event_handler: Option<CustomEventHandler>,
pub(crate) disable_file_drop_handler: bool,
pub(crate) disable_dma_buf_on_wayland: bool,
pub(crate) additional_windows_args: Option<String>,
#[allow(clippy::type_complexity)]
@@ -118,6 +119,7 @@ impl Config {
window_close_behavior: WindowCloseBehaviour::WindowCloses,
custom_event_handler: None,
disable_file_drop_handler: false,
disable_dma_buf_on_wayland: true,
on_window: None,
additional_windows_args: None,
}
@@ -315,6 +317,15 @@ impl Config {
self
}
/// Set whether or not DMA-BUF usage should be disabled on Wayland.
///
/// Defaults to true to avoid issues on some systems. If you want to enable DMA-BUF usage, set this to false.
/// See <https://github.com/DioxusLabs/dioxus/issues/4528#issuecomment-3476430611>
pub fn with_disable_dma_buf_on_wayland(mut self, disable: bool) -> Self {
self.disable_dma_buf_on_wayland = disable;
self
}
/// Add additional windows only launch arguments for webview2
pub fn with_windows_browser_args(mut self, additional_args: impl ToString) -> Self {
self.additional_windows_args = Some(additional_args.to_string());