Skip to content

Commit

Permalink
remove RawWindowHandleWrapper
Browse files Browse the repository at this point in the history
RawWindowHandleWrapper is only necessary since GlContext::create takes an `impl
HasRawWindowHandle` argument, but GlContext::create is an internal unsafe API
and it is can just take a RawWindowHandle directly.
  • Loading branch information
micahrj committed Dec 12, 2023
1 parent 3ecc88f commit 4b7bf6c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 31 deletions.
8 changes: 3 additions & 5 deletions src/gl/macos.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::c_void;
use std::str::FromStr;

use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::RawWindowHandle;

use cocoa::appkit::{
NSOpenGLContext, NSOpenGLContextParameter, NSOpenGLPFAAccelerated, NSOpenGLPFAAlphaSize,
Expand All @@ -28,10 +28,8 @@ pub struct GlContext {
}

impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::AppKit(handle) = parent {
handle
} else {
return Err(GlError::InvalidWindowHandle);
Expand Down
4 changes: 2 additions & 2 deletions src/gl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;

// On X11 creating the context is a two step process
#[cfg(not(target_os = "linux"))]
use raw_window_handle::HasRawWindowHandle;
use raw_window_handle::RawWindowHandle;

#[cfg(target_os = "windows")]
mod win;
Expand Down Expand Up @@ -77,7 +77,7 @@ pub struct GlContext {
impl GlContext {
#[cfg(not(target_os = "linux"))]
pub(crate) unsafe fn create(
parent: &impl HasRawWindowHandle, config: GlConfig,
parent: &RawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
platform::GlContext::create(parent, config)
.map(|context| GlContext { context, phantom: PhantomData })
Expand Down
8 changes: 3 additions & 5 deletions src/gl/win.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::{c_void, CString, OsStr};
use std::os::windows::ffi::OsStrExt;

use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::RawWindowHandle;

use winapi::shared::minwindef::{HINSTANCE, HMODULE};
use winapi::shared::ntdef::WCHAR;
Expand Down Expand Up @@ -77,10 +77,8 @@ extern "C" {
}

impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::Win32(handle) = parent.raw_window_handle() {
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::Win32(handle) = parent {
handle
} else {
return Err(GlError::InvalidWindowHandle);
Expand Down
7 changes: 2 additions & 5 deletions src/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ use super::keyboard::KeyboardState;
use super::view::{create_view, BASEVIEW_STATE_IVAR};

#[cfg(feature = "opengl")]
use crate::{
gl::{GlConfig, GlContext},
window::RawWindowHandleWrapper,
};
use crate::gl::{GlConfig, GlContext};

pub struct WindowHandle {
raw_window_handle: Option<RawWindowHandle>,
Expand Down Expand Up @@ -313,7 +310,7 @@ impl Window {
let mut handle = AppKitWindowHandle::empty();
handle.ns_window = ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
handle.ns_view = ns_view as *mut c_void;
let handle = RawWindowHandleWrapper { handle: RawWindowHandle::AppKit(handle) };
let handle = RawWindowHandle::AppKit(handle);

unsafe { GlContext::create(&handle, config).expect("Could not create OpenGL context") }
}
Expand Down
4 changes: 2 additions & 2 deletions src/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use super::drop_target::DropTarget;
use super::keyboard::KeyboardState;

#[cfg(feature = "opengl")]
use crate::{gl::GlContext, window::RawWindowHandleWrapper};
use crate::gl::GlContext;

unsafe fn generate_guid() -> String {
let mut guid: GUID = std::mem::zeroed();
Expand Down Expand Up @@ -655,7 +655,7 @@ impl Window<'_> {
let gl_context: Option<GlContext> = options.gl_config.map(|gl_config| {
let mut handle = Win32WindowHandle::empty();
handle.hwnd = hwnd as *mut c_void;
let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Win32(handle) };
let handle = RawWindowHandle::Win32(handle);

GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
});
Expand Down
12 changes: 0 additions & 12 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ pub struct WindowHandle {
phantom: PhantomData<*mut ()>,
}

/// Quick wrapper to satisfy [HasRawWindowHandle], because of course a raw window handle wouldn't
/// have a raw window handle, that would be silly.
pub(crate) struct RawWindowHandleWrapper {
pub handle: RawWindowHandle,
}

impl WindowHandle {
fn new(window_handle: platform::WindowHandle) -> Self {
Self { window_handle, phantom: PhantomData::default() }
Expand Down Expand Up @@ -126,9 +120,3 @@ unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
self.window.raw_display_handle()
}
}

unsafe impl HasRawWindowHandle for RawWindowHandleWrapper {
fn raw_window_handle(&self) -> RawWindowHandle {
self.handle
}
}

0 comments on commit 4b7bf6c

Please sign in to comment.