Skip to content

Commit 946a925

Browse files
authored
disable dma buf on wayland linux (#4957)
* disable dma buf on linux * allow configuring
1 parent 1e48093 commit 946a925

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/desktop/src/app.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub(crate) struct App {
3232
pub(crate) control_flow: ControlFlow,
3333
pub(crate) is_visible_before_start: bool,
3434
pub(crate) exit_on_last_window_close: bool,
35+
pub(crate) disable_dma_buf_on_wayland: bool,
3536
pub(crate) webviews: HashMap<WindowId, WebviewInstance>,
3637
pub(crate) float_all: bool,
3738
pub(crate) show_devtools: bool,
@@ -61,6 +62,7 @@ impl App {
6162

6263
let app = Self {
6364
exit_on_last_window_close: cfg.exit_on_last_window_close,
65+
disable_dma_buf_on_wayland: cfg.disable_dma_buf_on_wayland,
6466
is_visible_before_start: true,
6567
webviews: HashMap::new(),
6668
control_flow: ControlFlow::Wait,
@@ -101,6 +103,9 @@ impl App {
101103
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
102104
app.connect_preserve_window_state_handler();
103105

106+
// Make sure to disable DMA buffer rendering on Linux Wayland sessions
107+
app.disable_dma_buf();
108+
104109
(event_loop, app)
105110
}
106111

@@ -609,6 +614,28 @@ impl App {
609614
});
610615
}
611616
}
617+
618+
/// Disable DMA buffer rendering on Linux Wayland sessions to avoid bugs with WebKitGTK
619+
fn disable_dma_buf(&self) {
620+
if cfg!(target_os = "linux") && self.disable_dma_buf_on_wayland {
621+
static INIT: std::sync::Once = std::sync::Once::new();
622+
INIT.call_once(|| {
623+
if std::path::Path::new("/dev/dri").exists()
624+
&& std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland"
625+
{
626+
// Gnome Webkit is currently buggy under Wayland and KDE, so we will run it with XWayland mode.
627+
// See: https://github.com/DioxusLabs/dioxus/issues/3667
628+
unsafe {
629+
// Disable explicit sync for NVIDIA drivers on Linux when using Way
630+
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
631+
}
632+
}
633+
unsafe {
634+
std::env::set_var("GDK_BACKEND", "x11");
635+
}
636+
});
637+
}
638+
}
612639
}
613640

614641
#[derive(Debug, serde::Serialize, serde::Deserialize)]

packages/desktop/src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub struct Config {
6767
pub(crate) window_close_behavior: WindowCloseBehaviour,
6868
pub(crate) custom_event_handler: Option<CustomEventHandler>,
6969
pub(crate) disable_file_drop_handler: bool,
70+
pub(crate) disable_dma_buf_on_wayland: bool,
7071
pub(crate) additional_windows_args: Option<String>,
7172

7273
#[allow(clippy::type_complexity)]
@@ -118,6 +119,7 @@ impl Config {
118119
window_close_behavior: WindowCloseBehaviour::WindowCloses,
119120
custom_event_handler: None,
120121
disable_file_drop_handler: false,
122+
disable_dma_buf_on_wayland: true,
121123
on_window: None,
122124
additional_windows_args: None,
123125
}
@@ -315,6 +317,15 @@ impl Config {
315317
self
316318
}
317319

320+
/// Set whether or not DMA-BUF usage should be disabled on Wayland.
321+
///
322+
/// Defaults to true to avoid issues on some systems. If you want to enable DMA-BUF usage, set this to false.
323+
/// See <https://github.com/DioxusLabs/dioxus/issues/4528#issuecomment-3476430611>
324+
pub fn with_disable_dma_buf_on_wayland(mut self, disable: bool) -> Self {
325+
self.disable_dma_buf_on_wayland = disable;
326+
self
327+
}
328+
318329
/// Add additional windows only launch arguments for webview2
319330
pub fn with_windows_browser_args(mut self, additional_args: impl ToString) -> Self {
320331
self.additional_windows_args = Some(additional_args.to_string());

0 commit comments

Comments
 (0)