Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SK83RJOSH committed Sep 19, 2024
1 parent 6f987dd commit 838424a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 66 deletions.
90 changes: 44 additions & 46 deletions glutin/src/api/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,38 +259,37 @@ impl Display {
let extensions = CLIENT_EXTENSIONS.get().unwrap();

let mut attrs = Vec::<EGLAttrib>::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");
Expand Down Expand Up @@ -430,24 +429,23 @@ impl Display {
}

fn get_display(egl: &Egl, display: RawDisplayHandle) -> Result<EglDisplay> {
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)
Expand Down
4 changes: 2 additions & 2 deletions glutin/src/api/wgl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -388,7 +388,7 @@ impl ContextInner {
fn make_current<T: SurfaceTypeTrait>(&self, surface: &Surface<T>) -> Result<()> {
unsafe {
let hdc = match surface.raw {
WGLSurface::Window(_, hdc) => hdc as _,
WGLSurface::Window(_, hdc) => hdc as _,
WGLSurface::PBuffer(_, hdc) => hdc as _,
};

Expand Down
49 changes: 31 additions & 18 deletions glutin/src/api/wgl/surface.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -142,7 +155,7 @@ impl<T: SurfaceTypeTrait> Drop for Surface<T> {
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);
Expand Down Expand Up @@ -172,8 +185,8 @@ impl<T: SurfaceTypeTrait> GlSurface<T> for Surface<T> {
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 _)
},
}
}
Expand All @@ -188,8 +201,8 @@ impl<T: SurfaceTypeTrait> GlSurface<T> for Surface<T> {
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 _)
},
}
}
Expand All @@ -202,7 +215,7 @@ impl<T: SurfaceTypeTrait> GlSurface<T> for Surface<T> {
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 {
Expand Down

0 comments on commit 838424a

Please sign in to comment.