windows rwh 0.6 (untested)
This commit is contained in:
parent
e51b4dd832
commit
4e6e9737f1
|
@ -84,10 +84,6 @@ impl GlContext {
|
||||||
return Err(GlError::InvalidWindowHandle);
|
return Err(GlError::InvalidWindowHandle);
|
||||||
};
|
};
|
||||||
|
|
||||||
if handle.hwnd.is_null() {
|
|
||||||
return Err(GlError::InvalidWindowHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create temporary window and context to load function pointers
|
// Create temporary window and context to load function pointers
|
||||||
|
|
||||||
let class_name_str = format!("raw-gl-context-window-{}", uuid::Uuid::new_v4().to_simple());
|
let class_name_str = format!("raw-gl-context-window-{}", uuid::Uuid::new_v4().to_simple());
|
||||||
|
@ -195,7 +191,7 @@ impl GlContext {
|
||||||
|
|
||||||
// Create actual context
|
// Create actual context
|
||||||
|
|
||||||
let hwnd = handle.hwnd as HWND;
|
let hwnd = handle.hwnd.get() as HWND;
|
||||||
|
|
||||||
let hdc = GetDC(hwnd);
|
let hdc = GetDC(hwnd);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ use winapi::um::winuser::{
|
||||||
use std::cell::{Cell, Ref, RefCell, RefMut};
|
use std::cell::{Cell, Ref, RefCell, RefMut};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::ffi::{c_void, OsStr};
|
use std::ffi::{c_void, OsStr};
|
||||||
|
use std::num::NonZeroIsize;
|
||||||
use std::os::windows::ffi::OsStrExt;
|
use std::os::windows::ffi::OsStrExt;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -86,15 +87,12 @@ impl WindowHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
if let Some(hwnd) = self.hwnd {
|
self.hwnd
|
||||||
let mut handle = Win32WindowHandle::empty();
|
.and_then(|hwnd| NonZeroIsize::new(hwnd as isize))
|
||||||
handle.hwnd = hwnd as *mut c_void;
|
.ok_or(raw_window_handle::HandleError::Unavailable)
|
||||||
|
.map(|v| Win32WindowHandle::new(v))
|
||||||
RawWindowHandle::Win32(handle)
|
.map(|v| RawWindowHandle::Win32(v))
|
||||||
} else {
|
|
||||||
RawWindowHandle::Win32(Win32WindowHandle::empty())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,7 +589,7 @@ impl Window<'_> {
|
||||||
B: Send + 'static,
|
B: Send + 'static,
|
||||||
{
|
{
|
||||||
let parent = match parent.raw_window_handle() {
|
let parent = match parent.raw_window_handle() {
|
||||||
RawWindowHandle::Win32(h) => h.hwnd as HWND,
|
Ok(RawWindowHandle::Win32(h)) => h.hwnd.get() as HWND,
|
||||||
h => panic!("unsupported parent handle {:?}", h),
|
h => panic!("unsupported parent handle {:?}", h),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -688,9 +686,11 @@ impl Window<'_> {
|
||||||
|
|
||||||
#[cfg(feature = "opengl")]
|
#[cfg(feature = "opengl")]
|
||||||
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 handle = NonZeroIsize::new(hwnd as isize)
|
||||||
handle.hwnd = hwnd as *mut c_void;
|
.ok_or(raw_window_handle::HandleError::Unavailable)
|
||||||
let handle = RawWindowHandle::Win32(handle);
|
.map(|v| Win32WindowHandle::new(v))
|
||||||
|
.map(|v| RawWindowHandle::Win32(v))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
|
GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
|
||||||
});
|
});
|
||||||
|
@ -827,17 +827,17 @@ impl Window<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for Window<'_> {
|
unsafe impl HasRawWindowHandle for Window<'_> {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
let mut handle = Win32WindowHandle::empty();
|
NonZeroIsize::new(self.state.hwnd as isize)
|
||||||
handle.hwnd = self.state.hwnd as *mut c_void;
|
.ok_or(raw_window_handle::HandleError::Unavailable)
|
||||||
|
.map(|v| Win32WindowHandle::new(v))
|
||||||
RawWindowHandle::Win32(handle)
|
.map(|v| RawWindowHandle::Win32(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawDisplayHandle for Window<'_> {
|
unsafe impl HasRawDisplayHandle for Window<'_> {
|
||||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
fn raw_display_handle(&self) -> Result<RawDisplayHandle, raw_window_handle::HandleError> {
|
||||||
RawDisplayHandle::Windows(WindowsDisplayHandle::empty())
|
Ok(RawDisplayHandle::Windows(WindowsDisplayHandle::new()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue