From cfb0fe6a17254eef20abe2584f975ab9f4dc26a4 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 20 Jun 2024 10:49:14 +0200 Subject: [PATCH] examples: Add Windows support to `glupload` WGL does not have the concept of a `Display` connection, presumably because there's always only one compositor active. All interop and sharing is happening from the `Context` afterwards. After all `glutin` doesn't have a pointer inside `RawDisplay::Wgl`, and upstream `gstreamer` code creates a dummy display on Win32. WINRT is not taken into account & tested yet. Part-of: --- Cargo.lock | 11 +++++++++++ ci/run_windows_tests.ps1 | 2 +- examples/Cargo.toml | 5 +++-- examples/src/glupload.rs | 10 +++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35b382a78..82b5bcabf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -776,12 +776,14 @@ dependencies = [ "dispatch", "glutin_egl_sys", "glutin_glx_sys", + "glutin_wgl_sys", "icrate", "libloading", "objc2", "once_cell", "raw-window-handle", "wayland-sys", + "windows-sys 0.48.0", "x11-dl", ] @@ -817,6 +819,15 @@ dependencies = [ "x11-dl", ] +[[package]] +name = "glutin_wgl_sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8098adac955faa2d31079b65dc48841251f69efd3ac25477903fc424362ead" +dependencies = [ + "gl_generator", +] + [[package]] name = "gobject-sys" version = "0.20.0" diff --git a/ci/run_windows_tests.ps1 b/ci/run_windows_tests.ps1 index f3f45fffe..faf9a1a74 100644 --- a/ci/run_windows_tests.ps1 +++ b/ci/run_windows_tests.ps1 @@ -54,7 +54,7 @@ foreach($features in $features_matrix) { if ($env:LocalFeatures -and ($env:LocalFeatures -ne '--no-default-features')) { if ($crate -eq 'examples') { # FIXME: We can do --all-features for examples once we have gtk3 installed in the image - $env:LocalFeatures = "--features=rtsp-server,rtsp-server-record,pango-cairo,overlay-composition,gst-play,gst-player,ges,image,cairo-rs,gst-video/v1_18,windows" + $env:LocalFeatures = "--features=rtsp-server,rtsp-server-record,pango-cairo,overlay-composition,gst-play,gst-player,ges,image,cairo-rs,gst-video/v1_18,windows,gl" } if ($crate -eq 'tutorials') { diff --git a/examples/Cargo.toml b/examples/Cargo.toml index cb14d0230..567530603 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -30,8 +30,9 @@ byte-slice-cast = "1" cairo-rs = { workspace = true, features=["use_glib"], optional = true } derive_more = "0.99.5" futures = "0.3" -glutin = { version = "0.31", optional = true, default-features = false } -glutin-winit = { version = "0.4", optional = true, default-features = false } +# Since there's nothing Windows-specific to enable on gstreamer-rs, unconditionally enable glutin's WGL backend +glutin = { version = "0.31", optional = true, default-features = false, features = ["wgl"] } +glutin-winit = { version = "0.4", optional = true, default-features = false, features = ["wgl"] } image = { version = "0.24", optional = true, default-features = false, features = ["png", "jpeg"] } memfd = { version = "0.6", optional = true } memmap2 = { version = "0.9", optional = true } diff --git a/examples/src/glupload.rs b/examples/src/glupload.rs index 730245608..9d64b3117 100644 --- a/examples/src/glupload.rs +++ b/examples/src/glupload.rs @@ -434,8 +434,8 @@ impl App { println!("Using raw GL context {:?}", raw_gl_context); - #[cfg(not(target_os = "linux"))] - compile_error!("This example only has Linux support"); + #[cfg(not(any(target_os = "linux", windows)))] + compile_error!("This example only has Linux and Windows support"); let api = App::map_gl_api(gl_config.api()); @@ -449,7 +449,6 @@ impl App { unsafe { gst_gl_egl::GLDisplayEGL::with_egl_display(egl_display as usize) } .context("Failed to create GLDisplayEGL from raw `EGLDisplay`")? .upcast::(); - (egl_context as usize, gl_display, gst_gl::GLPlatform::EGL) } #[cfg(feature = "gst-gl-x11")] @@ -463,6 +462,11 @@ impl App { .upcast::(); (glx_context as usize, gl_display, gst_gl::GLPlatform::GLX) } + #[cfg(windows)] + (glutin::display::RawDisplay::Wgl, glutin::context::RawContext::Wgl(wgl_context)) => { + let gl_display = gst_gl::GLDisplay::new(); + (wgl_context as usize, gl_display, gst_gl::GLPlatform::WGL) + } #[allow(unreachable_patterns)] handler => anyhow::bail!("Unsupported platform: {handler:?}."), };