From 365feab3e553e984db3aeacf44457780b5daf09f Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 28 Apr 2024 17:18:43 +0200 Subject: [PATCH] Add Display interface for EGL/GLX --- glutin-winit/src/lib.rs | 2 +- glutin/src/api/egl/display.rs | 5 +++++ glutin/src/api/egl/mod.rs | 6 ++---- glutin/src/api/glx/display.rs | 5 +++++ glutin/src/api/glx/mod.rs | 4 +++- glutin/src/lib.rs | 2 +- glutin_examples/examples/egl_device.rs | 2 +- glutin_examples/examples/switch_render_thread.rs | 6 +++--- glutin_examples/src/lib.rs | 2 +- 9 files changed, 22 insertions(+), 12 deletions(-) diff --git a/glutin-winit/src/lib.rs b/glutin-winit/src/lib.rs index d0af719047..cb3b2cd8f9 100644 --- a/glutin-winit/src/lib.rs +++ b/glutin-winit/src/lib.rs @@ -6,7 +6,7 @@ #![deny(clippy::all)] #![deny(missing_debug_implementations)] #![deny(missing_docs)] -#![cfg_attr(feature = "cargo-clippy", deny(warnings))] +#![cfg_attr(clippy, deny(warnings))] mod window; diff --git a/glutin/src/api/egl/display.rs b/glutin/src/api/egl/display.rs index ea64ba66b2..d43e99366a 100644 --- a/glutin/src/api/egl/display.rs +++ b/glutin/src/api/egl/display.rs @@ -212,6 +212,11 @@ impl Display { Device::from_ptr(self.inner.egl, device) } + /// Get a reference to the initialized EGL API. + pub fn egl(&self) -> &'static Egl { + self.inner.egl + } + /// Terminate the EGL display. /// /// When the display is managed by glutin with the diff --git a/glutin/src/api/egl/mod.rs b/glutin/src/api/egl/mod.rs index 8d45c32cb1..3f6534771c 100644 --- a/glutin/src/api/egl/mod.rs +++ b/glutin/src/api/egl/mod.rs @@ -28,8 +28,7 @@ pub mod device; pub mod display; pub mod surface; -/// TODO -pub static EGL: Lazy> = Lazy::new(|| { +pub(crate) static EGL: Lazy> = Lazy::new(|| { #[cfg(windows)] let paths = ["libEGL.dll", "atioglxx.dll"]; @@ -42,8 +41,7 @@ pub static EGL: Lazy> = Lazy::new(|| { type EglGetProcAddress = unsafe extern "C" fn(*const ffi::c_void) -> *const ffi::c_void; static EGL_GET_PROC_ADDRESS: OnceCell> = OnceCell::new(); -/// TODO -#[allow(private_interfaces)] +/// EGL interface. #[allow(missing_debug_implementations)] pub struct Egl(pub SymWrapper); diff --git a/glutin/src/api/glx/display.rs b/glutin/src/api/glx/display.rs index 1cdf96d191..f808dfd4a8 100644 --- a/glutin/src/api/glx/display.rs +++ b/glutin/src/api/glx/display.rs @@ -113,6 +113,11 @@ impl Display { Ok(Self { inner }) } + /// Get a reference to the initialized GLX API. + pub fn glx(&self) -> &'static Glx { + self.inner.glx + } + fn extract_display_features( extensions: &HashSet<&'static str>, version: Version, diff --git a/glutin/src/api/glx/mod.rs b/glutin/src/api/glx/mod.rs index d90b0f5095..ccaba62974 100644 --- a/glutin/src/api/glx/mod.rs +++ b/glutin/src/api/glx/mod.rs @@ -58,7 +58,9 @@ static GLX_EXTRA: Lazy> = Lazy::new(|| { Some(GlxExtra::new(glx)) }); -pub(crate) struct Glx(pub SymWrapper); +/// GLX interface. +#[allow(missing_debug_implementations)] +pub struct Glx(pub SymWrapper); unsafe impl Sync for Glx {} unsafe impl Send for Glx {} diff --git a/glutin/src/lib.rs b/glutin/src/lib.rs index 1f6d51fa20..5fa6481bbb 100644 --- a/glutin/src/lib.rs +++ b/glutin/src/lib.rs @@ -17,7 +17,7 @@ #![deny(clippy::all)] #![deny(missing_debug_implementations)] #![deny(missing_docs)] -#![cfg_attr(feature = "cargo-clippy", deny(warnings))] +#![cfg_attr(clippy, deny(warnings))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] #[cfg(all(not(egl_backend), not(glx_backend), not(wgl_backend), not(cgl_backend)))] diff --git a/glutin_examples/examples/egl_device.rs b/glutin_examples/examples/egl_device.rs index 89c9f1a4f6..191eb657eb 100644 --- a/glutin_examples/examples/egl_device.rs +++ b/glutin_examples/examples/egl_device.rs @@ -112,7 +112,7 @@ mod example { } let path = Path::new(IMG_PATH); - let file = OpenOptions::new().write(true).create(true).open(path).unwrap(); + let file = OpenOptions::new().write(true).truncate(true).open(path).unwrap(); let mut encoder = png::Encoder::new(file, 1280, 720); encoder.set_depth(png::BitDepth::Eight); diff --git a/glutin_examples/examples/switch_render_thread.rs b/glutin_examples/examples/switch_render_thread.rs index 672f04f369..87b71a0b5f 100644 --- a/glutin_examples/examples/switch_render_thread.rs +++ b/glutin_examples/examples/switch_render_thread.rs @@ -8,11 +8,11 @@ use glutin::config::ConfigTemplateBuilder; use glutin::context::{ContextAttributesBuilder, PossiblyCurrentContext}; use glutin::display::GetGlDisplay; use glutin::error::{Error as GlutinError, ErrorKind}; -use glutin::prelude::{NotCurrentGlContext, PossiblyCurrentGlContext, *}; -use glutin::surface::{GlSurface, Surface, WindowSurface}; +use glutin::prelude::*; +use glutin::surface::{Surface, WindowSurface}; use glutin_examples::gl::types::GLfloat; use glutin_examples::{gl_config_picker, Renderer}; -use glutin_winit::{self, DisplayBuilder, GlWindow}; +use glutin_winit::{DisplayBuilder, GlWindow}; use raw_window_handle::HasRawWindowHandle; use winit::dpi::PhysicalSize; use winit::event::{ElementState, Event, WindowEvent}; diff --git a/glutin_examples/src/lib.rs b/glutin_examples/src/lib.rs index 1c1c0bd7e0..126ceb0768 100644 --- a/glutin_examples/src/lib.rs +++ b/glutin_examples/src/lib.rs @@ -15,7 +15,7 @@ use glutin::display::GetGlDisplay; use glutin::prelude::*; use glutin::surface::SwapInterval; -use glutin_winit::{self, DisplayBuilder, GlWindow}; +use glutin_winit::{DisplayBuilder, GlWindow}; pub mod gl { #![allow(clippy::all)]