Remove RawWindowHandleWrapper (#156)
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.
This commit is contained in:
parent
3ecc88f9fc
commit
348bc9fe61
|
@ -1,7 +1,7 @@
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
use raw_window_handle::RawWindowHandle;
|
||||||
|
|
||||||
use cocoa::appkit::{
|
use cocoa::appkit::{
|
||||||
NSOpenGLContext, NSOpenGLContextParameter, NSOpenGLPFAAccelerated, NSOpenGLPFAAlphaSize,
|
NSOpenGLContext, NSOpenGLContextParameter, NSOpenGLPFAAccelerated, NSOpenGLPFAAlphaSize,
|
||||||
|
@ -28,10 +28,8 @@ pub struct GlContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlContext {
|
impl GlContext {
|
||||||
pub unsafe fn create(
|
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
|
||||||
parent: &impl HasRawWindowHandle, config: GlConfig,
|
let handle = if let RawWindowHandle::AppKit(handle) = parent {
|
||||||
) -> Result<GlContext, GlError> {
|
|
||||||
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
|
|
||||||
handle
|
handle
|
||||||
} else {
|
} else {
|
||||||
return Err(GlError::InvalidWindowHandle);
|
return Err(GlError::InvalidWindowHandle);
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
// On X11 creating the context is a two step process
|
// On X11 creating the context is a two step process
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
use raw_window_handle::HasRawWindowHandle;
|
use raw_window_handle::RawWindowHandle;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
mod win;
|
mod win;
|
||||||
|
@ -77,7 +77,7 @@ pub struct GlContext {
|
||||||
impl GlContext {
|
impl GlContext {
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
pub(crate) unsafe fn create(
|
pub(crate) unsafe fn create(
|
||||||
parent: &impl HasRawWindowHandle, config: GlConfig,
|
parent: &RawWindowHandle, config: GlConfig,
|
||||||
) -> Result<GlContext, GlError> {
|
) -> Result<GlContext, GlError> {
|
||||||
platform::GlContext::create(parent, config)
|
platform::GlContext::create(parent, config)
|
||||||
.map(|context| GlContext { context, phantom: PhantomData })
|
.map(|context| GlContext { context, phantom: PhantomData })
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::ffi::{c_void, CString, OsStr};
|
use std::ffi::{c_void, CString, OsStr};
|
||||||
use std::os::windows::ffi::OsStrExt;
|
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::minwindef::{HINSTANCE, HMODULE};
|
||||||
use winapi::shared::ntdef::WCHAR;
|
use winapi::shared::ntdef::WCHAR;
|
||||||
|
@ -77,10 +77,8 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlContext {
|
impl GlContext {
|
||||||
pub unsafe fn create(
|
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
|
||||||
parent: &impl HasRawWindowHandle, config: GlConfig,
|
let handle = if let RawWindowHandle::Win32(handle) = parent {
|
||||||
) -> Result<GlContext, GlError> {
|
|
||||||
let handle = if let RawWindowHandle::Win32(handle) = parent.raw_window_handle() {
|
|
||||||
handle
|
handle
|
||||||
} else {
|
} else {
|
||||||
return Err(GlError::InvalidWindowHandle);
|
return Err(GlError::InvalidWindowHandle);
|
||||||
|
|
|
@ -31,10 +31,7 @@ use super::keyboard::KeyboardState;
|
||||||
use super::view::{create_view, BASEVIEW_STATE_IVAR};
|
use super::view::{create_view, BASEVIEW_STATE_IVAR};
|
||||||
|
|
||||||
#[cfg(feature = "opengl")]
|
#[cfg(feature = "opengl")]
|
||||||
use crate::{
|
use crate::gl::{GlConfig, GlContext};
|
||||||
gl::{GlConfig, GlContext},
|
|
||||||
window::RawWindowHandleWrapper,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct WindowHandle {
|
pub struct WindowHandle {
|
||||||
raw_window_handle: Option<RawWindowHandle>,
|
raw_window_handle: Option<RawWindowHandle>,
|
||||||
|
@ -313,7 +310,7 @@ impl Window {
|
||||||
let mut handle = AppKitWindowHandle::empty();
|
let mut handle = AppKitWindowHandle::empty();
|
||||||
handle.ns_window = ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
|
handle.ns_window = ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
|
||||||
handle.ns_view = ns_view 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") }
|
unsafe { GlContext::create(&handle, config).expect("Could not create OpenGL context") }
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ use super::drop_target::DropTarget;
|
||||||
use super::keyboard::KeyboardState;
|
use super::keyboard::KeyboardState;
|
||||||
|
|
||||||
#[cfg(feature = "opengl")]
|
#[cfg(feature = "opengl")]
|
||||||
use crate::{gl::GlContext, window::RawWindowHandleWrapper};
|
use crate::gl::GlContext;
|
||||||
|
|
||||||
unsafe fn generate_guid() -> String {
|
unsafe fn generate_guid() -> String {
|
||||||
let mut guid: GUID = std::mem::zeroed();
|
let mut guid: GUID = std::mem::zeroed();
|
||||||
|
@ -655,7 +655,7 @@ impl Window<'_> {
|
||||||
let gl_context: Option<GlContext> = options.gl_config.map(|gl_config| {
|
let gl_context: Option<GlContext> = options.gl_config.map(|gl_config| {
|
||||||
let mut handle = Win32WindowHandle::empty();
|
let mut handle = Win32WindowHandle::empty();
|
||||||
handle.hwnd = hwnd as *mut c_void;
|
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")
|
GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,12 +21,6 @@ pub struct WindowHandle {
|
||||||
phantom: PhantomData<*mut ()>,
|
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 {
|
impl WindowHandle {
|
||||||
fn new(window_handle: platform::WindowHandle) -> Self {
|
fn new(window_handle: platform::WindowHandle) -> Self {
|
||||||
Self { window_handle, phantom: PhantomData::default() }
|
Self { window_handle, phantom: PhantomData::default() }
|
||||||
|
@ -126,9 +120,3 @@ unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
||||||
self.window.raw_display_handle()
|
self.window.raw_display_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for RawWindowHandleWrapper {
|
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
|
||||||
self.handle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue