diff --git a/glutin/src/api/egl/display.rs b/glutin/src/api/egl/display.rs index 3cc47653bb..5ac0778114 100644 --- a/glutin/src/api/egl/display.rs +++ b/glutin/src/api/egl/display.rs @@ -259,38 +259,37 @@ impl Display { let extensions = CLIENT_EXTENSIONS.get().unwrap(); let mut attrs = Vec::::with_capacity(5); - let (platform, display) = match display { - RawDisplayHandle::Wayland(handle) - if extensions.contains("EGL_KHR_platform_wayland") => - { - (egl::PLATFORM_WAYLAND_KHR, handle.display.as_ptr()) - }, - RawDisplayHandle::Xlib(handle) if extensions.contains("EGL_KHR_platform_x11") => { - attrs.push(egl::PLATFORM_X11_SCREEN_KHR as EGLAttrib); - attrs.push(handle.screen as EGLAttrib); - ( - egl::PLATFORM_X11_KHR, - handle.display.map_or(egl::DEFAULT_DISPLAY as *mut _, |d| d.as_ptr()), - ) - }, - RawDisplayHandle::Gbm(handle) if extensions.contains("EGL_KHR_platform_gbm") => { - (egl::PLATFORM_GBM_KHR, handle.gbm_device.as_ptr()) - }, - RawDisplayHandle::Drm(_) => { - return Err(ErrorKind::NotSupported( + let (platform, display) = + match display { + RawDisplayHandle::Wayland(handle) + if extensions.contains("EGL_KHR_platform_wayland") => + { + (egl::PLATFORM_WAYLAND_KHR, handle.display.as_ptr()) + }, + RawDisplayHandle::Xlib(handle) if extensions.contains("EGL_KHR_platform_x11") => { + attrs.push(egl::PLATFORM_X11_SCREEN_KHR as EGLAttrib); + attrs.push(handle.screen as EGLAttrib); + ( + egl::PLATFORM_X11_KHR, + handle.display.map_or(egl::DEFAULT_DISPLAY as *mut _, |d| d.as_ptr()), + ) + }, + RawDisplayHandle::Gbm(handle) if extensions.contains("EGL_KHR_platform_gbm") => { + (egl::PLATFORM_GBM_KHR, handle.gbm_device.as_ptr()) + }, + RawDisplayHandle::Drm(_) => return Err(ErrorKind::NotSupported( "`DrmDisplayHandle` must be used with `egl::display::Display::with_device()`", ) - .into()) - }, - RawDisplayHandle::Android(_) if extensions.contains("EGL_KHR_platform_android") => { - (egl::PLATFORM_ANDROID_KHR, egl::DEFAULT_DISPLAY as *mut _) - }, - _ => { - return Err( - ErrorKind::NotSupported("provided display handle is not supported").into() - ) - }, - }; + .into()), + RawDisplayHandle::Android(_) if extensions.contains("EGL_KHR_platform_android") => { + (egl::PLATFORM_ANDROID_KHR, egl::DEFAULT_DISPLAY as *mut _) + }, + _ => { + return Err( + ErrorKind::NotSupported("provided display handle is not supported").into() + ) + }, + }; // Push at the end so we can pop it on failure let mut has_display_reference = extensions.contains("EGL_KHR_display_reference"); @@ -430,24 +429,23 @@ impl Display { } fn get_display(egl: &Egl, display: RawDisplayHandle) -> Result { - let display = match display { - RawDisplayHandle::Gbm(handle) => handle.gbm_device.as_ptr(), - RawDisplayHandle::Drm(_) => { - return Err(ErrorKind::NotSupported( + let display = + match display { + RawDisplayHandle::Gbm(handle) => handle.gbm_device.as_ptr(), + RawDisplayHandle::Drm(_) => return Err(ErrorKind::NotSupported( "`DrmDisplayHandle` must be used with `egl::display::Display::with_device()`", ) - .into()) - }, - RawDisplayHandle::Xlib(XlibDisplayHandle { display, .. }) => { - display.map_or(egl::DEFAULT_DISPLAY as *mut _, |d| d.as_ptr()) - }, - RawDisplayHandle::Android(_) => egl::DEFAULT_DISPLAY as *mut _, - _ => { - return Err( - ErrorKind::NotSupported("provided display handle is not supported").into() - ) - }, - }; + .into()), + RawDisplayHandle::Xlib(XlibDisplayHandle { display, .. }) => { + display.map_or(egl::DEFAULT_DISPLAY as *mut _, |d| d.as_ptr()) + }, + RawDisplayHandle::Android(_) => egl::DEFAULT_DISPLAY as *mut _, + _ => { + return Err( + ErrorKind::NotSupported("provided display handle is not supported").into() + ) + }, + }; let display = unsafe { egl.GetDisplay(display) }; Self::check_display_error(display).map(EglDisplay::Legacy) diff --git a/glutin/src/api/wgl/context.rs b/glutin/src/api/wgl/context.rs index 22458bc5ce..26819adde1 100644 --- a/glutin/src/api/wgl/context.rs +++ b/glutin/src/api/wgl/context.rs @@ -22,9 +22,9 @@ use crate::prelude::*; use crate::private::Sealed; use crate::surface::SurfaceTypeTrait; -use super::{config::Config, surface::WGLSurface}; use super::display::Display; use super::surface::Surface; +use super::{config::Config, surface::WGLSurface}; impl Display { pub(crate) unsafe fn create_context( @@ -388,7 +388,7 @@ impl ContextInner { fn make_current(&self, surface: &Surface) -> Result<()> { unsafe { let hdc = match surface.raw { - WGLSurface::Window(_, hdc) => hdc as _, + WGLSurface::Window(_, hdc) => hdc as _, WGLSurface::PBuffer(_, hdc) => hdc as _, }; diff --git a/glutin/src/api/wgl/surface.rs b/glutin/src/api/wgl/surface.rs index 4770f507a2..d685a23cea 100644 --- a/glutin/src/api/wgl/surface.rs +++ b/glutin/src/api/wgl/surface.rs @@ -1,12 +1,15 @@ //! A wrapper around `HWND` used for GL operations. -use std::{fmt, mem}; use std::io::Error as IoError; use std::marker::PhantomData; use std::num::NonZeroU32; use std::os::raw::c_int; +use std::{fmt, mem}; -use glutin_wgl_sys::{wgl::types::GLenum, wgl_extra::{self, types::HPBUFFEREXT}}; +use glutin_wgl_sys::{ + wgl::types::GLenum, + wgl_extra::{self, types::HPBUFFEREXT}, +}; use raw_window_handle::RawWindowHandle; use windows_sys::Win32::Foundation::{HWND, RECT}; use windows_sys::Win32::Graphics::{Gdi as gdi, OpenGL as gl}; @@ -53,19 +56,25 @@ impl Display { let (hbuf, hdc) = match self.inner.wgl_extra { Some(extra) if extra.CreatePbufferARB.is_loaded() => unsafe { - let hbuf = extra.CreatePbufferARB(hdc as _, config.inner.pixel_format_index, width, height, attrs.as_ptr()); + let hbuf = extra.CreatePbufferARB( + hdc as _, + config.inner.pixel_format_index, + width, + height, + attrs.as_ptr(), + ); let hdc = extra.GetPbufferDCARB(hbuf); (hbuf, hdc) }, - _ => { - return Err( - ErrorKind::NotSupported("pbuffer extensions are not supported").into() - ) - }, + _ => return Err(ErrorKind::NotSupported("pbuffer extensions are not supported").into()), }; - let surface = - Surface { display: self.clone(), config: config.clone(), raw: WGLSurface::PBuffer(hbuf, hdc), _ty: PhantomData }; + let surface = Surface { + display: self.clone(), + config: config.clone(), + raw: WGLSurface::PBuffer(hbuf, hdc), + _ty: PhantomData, + }; Ok(surface) } @@ -89,8 +98,12 @@ impl Display { let hdc = unsafe { gdi::GetDC(hwnd) }; - let surface = - Surface { display: self.clone(), config: config.clone(), raw: WGLSurface::Window(hwnd, hdc), _ty: PhantomData }; + let surface = Surface { + display: self.clone(), + config: config.clone(), + raw: WGLSurface::Window(hwnd, hdc), + _ty: PhantomData, + }; Ok(surface) } @@ -142,7 +155,7 @@ impl Drop for Surface { match self.raw { WGLSurface::Window(hwnd, hdc) => { gdi::ReleaseDC(hwnd, hdc); - } + }, WGLSurface::PBuffer(hbuf, hdc) => { if let Some(extra) = self.display.inner.wgl_extra { extra.ReleasePbufferDCARB(hbuf, hdc); @@ -172,8 +185,8 @@ impl GlSurface for Surface { Some((rect.right - rect.left) as u32) } }, - WGLSurface::PBuffer(_, _) => { - unsafe { Some(self.raw_attribute(wgl_extra::PBUFFER_WIDTH_ARB) as _) } + WGLSurface::PBuffer(_, _) => unsafe { + Some(self.raw_attribute(wgl_extra::PBUFFER_WIDTH_ARB) as _) }, } } @@ -188,8 +201,8 @@ impl GlSurface for Surface { Some((rect.bottom - rect.top) as u32) } }, - WGLSurface::PBuffer(_, _) => { - unsafe { Some(self.raw_attribute(wgl_extra::PBUFFER_HEIGHT_ARB) as _) } + WGLSurface::PBuffer(_, _) => unsafe { + Some(self.raw_attribute(wgl_extra::PBUFFER_HEIGHT_ARB) as _) }, } } @@ -202,7 +215,7 @@ impl GlSurface for Surface { unsafe { let hdc = match self.raw { WGLSurface::Window(_, hdc) => hdc as _, - WGLSurface::PBuffer(_, hdc) => hdc as _ + WGLSurface::PBuffer(_, hdc) => hdc as _, }; if gl::SwapBuffers(hdc) == 0 {