mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
commit
93f4581c08
|
@ -6,7 +6,7 @@ extern crate android_glue;
|
||||||
|
|
||||||
extern crate glutin;
|
extern crate glutin;
|
||||||
|
|
||||||
use std::thread::Thread;
|
use std::thread;
|
||||||
|
|
||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
|
@ -22,15 +22,15 @@ fn main() {
|
||||||
let window2 = glutin::Window::new().unwrap();
|
let window2 = glutin::Window::new().unwrap();
|
||||||
let window3 = glutin::Window::new().unwrap();
|
let window3 = glutin::Window::new().unwrap();
|
||||||
|
|
||||||
let t1 = Thread::scoped(move || {
|
let t1 = thread::scoped(move || {
|
||||||
run(window1, (0.0, 1.0, 0.0, 1.0));
|
run(window1, (0.0, 1.0, 0.0, 1.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
let t2 = Thread::scoped(move || {
|
let t2 = thread::scoped(move || {
|
||||||
run(window2, (0.0, 0.0, 1.0, 1.0));
|
run(window2, (0.0, 0.0, 1.0, 1.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
let t3 = Thread::scoped(move || {
|
let t3 = thread::scoped(move || {
|
||||||
run(window3, (1.0, 0.0, 0.0, 1.0));
|
run(window3, (1.0, 0.0, 0.0, 1.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#![cfg(feature = "window")]
|
#![cfg(feature = "window")]
|
||||||
|
|
||||||
|
use std::ffi::CStr;
|
||||||
use glutin;
|
use glutin;
|
||||||
|
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
|
@ -21,8 +22,8 @@ pub fn load(window: &glutin::Window) -> Context {
|
||||||
let gl = gl::Gl::load(window);
|
let gl = gl::Gl::load(window);
|
||||||
|
|
||||||
let version = unsafe {
|
let version = unsafe {
|
||||||
use std::ffi;
|
let data = CStr::from_ptr(gl.GetString(gl::VERSION) as *const i8).to_bytes().to_vec();
|
||||||
String::from_utf8(ffi::c_str_to_bytes(&(gl.GetString(gl::VERSION) as *const i8)).to_vec()).unwrap()
|
String::from_utf8(data).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("OpenGL version {}", version);
|
println!("OpenGL version {}", version);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(collections, unsafe_destructor, os, core, std_misc, alloc)]
|
#![feature(collections, unsafe_destructor, core, std_misc, alloc)]
|
||||||
#![unstable]
|
#![unstable]
|
||||||
|
|
||||||
//! The purpose of this library is to provide an OpenGL context on as many
|
//! The purpose of this library is to provide an OpenGL context on as many
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::rc::Rc;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::{
|
use std::sync::{Arc, Mutex};
|
||||||
Arc,
|
|
||||||
Mutex
|
|
||||||
};
|
|
||||||
|
|
||||||
use CursorState;
|
use CursorState;
|
||||||
use Event;
|
use Event;
|
||||||
|
@ -232,16 +228,12 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
if let Ok(cursor_state) = cstash.cursor_state.lock() {
|
if let Ok(cursor_state) = cstash.cursor_state.lock() {
|
||||||
match *cursor_state {
|
match *cursor_state {
|
||||||
CursorState::Normal => {
|
CursorState::Normal => {
|
||||||
unsafe {
|
user32::SetCursor(user32::LoadCursorW(
|
||||||
user32::SetCursor(user32::LoadCursorW(
|
ptr::null_mut(),
|
||||||
ptr::null_mut(),
|
winapi::IDC_ARROW));
|
||||||
winapi::IDC_ARROW));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
CursorState::Grab | CursorState::Hide => {
|
CursorState::Grab | CursorState::Hide => {
|
||||||
unsafe {
|
user32::SetCursor(ptr::null_mut());
|
||||||
user32::SetCursor(ptr::null_mut());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{
|
use std::sync::{Arc, Mutex};
|
||||||
Arc,
|
use std::io;
|
||||||
Mutex
|
|
||||||
};
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::os;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use super::callback;
|
use super::callback;
|
||||||
|
@ -41,7 +38,7 @@ pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<C
|
||||||
-> Result<Window, CreationError>
|
-> Result<Window, CreationError>
|
||||||
{
|
{
|
||||||
// initializing variables to be sent to the task
|
// initializing variables to be sent to the task
|
||||||
let title = builder.title.as_slice().utf16_units()
|
let title = builder.title.utf16_units()
|
||||||
.chain(Some(0).into_iter()).collect::<Vec<u16>>(); // title to utf16
|
.chain(Some(0).into_iter()).collect::<Vec<u16>>(); // title to utf16
|
||||||
|
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
@ -125,13 +122,13 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
|
|
||||||
if handle.is_null() {
|
if handle.is_null() {
|
||||||
return Err(OsError(format!("CreateWindowEx function failed: {}",
|
return Err(OsError(format!("CreateWindowEx function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
let hdc = user32::GetDC(handle);
|
let hdc = user32::GetDC(handle);
|
||||||
if hdc.is_null() {
|
if hdc.is_null() {
|
||||||
let err = Err(OsError(format!("GetDC function failed: {}",
|
let err = Err(OsError(format!("GetDC function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,13 +188,13 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
|
|
||||||
if handle.is_null() {
|
if handle.is_null() {
|
||||||
return Err(OsError(format!("CreateWindowEx function failed: {}",
|
return Err(OsError(format!("CreateWindowEx function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
let hdc = user32::GetDC(handle);
|
let hdc = user32::GetDC(handle);
|
||||||
if hdc.is_null() {
|
if hdc.is_null() {
|
||||||
return Err(OsError(format!("GetDC function failed: {}",
|
return Err(OsError(format!("GetDC function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowWrapper(handle, hdc)
|
WindowWrapper(handle, hdc)
|
||||||
|
@ -377,7 +374,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
|
|
||||||
Some(extra_functions.CreateContextAttribsARB(hdc.1 as *const libc::c_void,
|
Some(extra_functions.CreateContextAttribsARB(hdc.1 as *const libc::c_void,
|
||||||
share as *const libc::c_void,
|
share as *const libc::c_void,
|
||||||
attributes.as_slice().as_ptr()))
|
attributes.as_ptr()))
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -399,7 +396,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
|
|
||||||
if ctxt.is_null() {
|
if ctxt.is_null() {
|
||||||
return Err(OsError(format!("OpenGL context creation failed: {}",
|
return Err(OsError(format!("OpenGL context creation failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ContextWrapper(ctxt as winapi::HGLRC))
|
Ok(ContextWrapper(ctxt as winapi::HGLRC))
|
||||||
|
@ -506,12 +503,12 @@ unsafe fn set_pixel_format(hdc: &WindowWrapper, id: libc::c_int) -> Result<(), C
|
||||||
as winapi::UINT, &mut output) == 0
|
as winapi::UINT, &mut output) == 0
|
||||||
{
|
{
|
||||||
return Err(OsError(format!("DescribePixelFormat function failed: {}",
|
return Err(OsError(format!("DescribePixelFormat function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
if gdi32::SetPixelFormat(hdc.1, id, &output) == 0 {
|
if gdi32::SetPixelFormat(hdc.1, id, &output) == 0 {
|
||||||
return Err(OsError(format!("SetPixelFormat function failed: {}",
|
return Err(OsError(format!("SetPixelFormat function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -525,7 +522,7 @@ unsafe fn load_opengl32_dll() -> Result<winapi::HMODULE, CreationError> {
|
||||||
|
|
||||||
if lib.is_null() {
|
if lib.is_null() {
|
||||||
return Err(OsError(format!("LoadLibrary function failed: {}",
|
return Err(OsError(format!("LoadLibrary function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(lib)
|
Ok(lib)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::os;
|
use std::io;
|
||||||
|
|
||||||
use libc;
|
use libc;
|
||||||
use winapi;
|
use winapi;
|
||||||
|
@ -30,7 +30,7 @@ impl<'a, 'b> CurrentContextGuard<'a, 'b> {
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
return Err(CreationError::OsError(format!("wglMakeCurrent function failed: {}",
|
return Err(CreationError::OsError(format!("wglMakeCurrent function failed: {}",
|
||||||
os::error_string(os::errno()))));
|
format!("{}", io::Error::last_os_error()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CurrentContextGuard {
|
Ok(CurrentContextGuard {
|
||||||
|
|
|
@ -5,12 +5,6 @@ use libc;
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
use super::ffi;
|
use super::ffi;
|
||||||
|
|
||||||
fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) -> T {
|
|
||||||
use std::ffi::CString;
|
|
||||||
let c_str = CString::from_slice(s.as_bytes());
|
|
||||||
f(c_str.as_ptr())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct HeadlessContext {
|
pub struct HeadlessContext {
|
||||||
context: ffi::OSMesaContext,
|
context: ffi::OSMesaContext,
|
||||||
buffer: Vec<u32>,
|
buffer: Vec<u32>,
|
||||||
|
@ -53,9 +47,9 @@ impl HeadlessContext {
|
||||||
|
|
||||||
pub fn get_proc_address(&self, addr: &str) -> *const () {
|
pub fn get_proc_address(&self, addr: &str) -> *const () {
|
||||||
unsafe {
|
unsafe {
|
||||||
with_c_str(addr, |s| {
|
use std::ffi::CString;
|
||||||
ffi::OSMesaGetProcAddress(mem::transmute(s)) as *const ()
|
let c_str = CString::new(addr.as_bytes().to_vec()).unwrap();
|
||||||
})
|
ffi::OSMesaGetProcAddress(mem::transmute(c_str.as_ptr())) as *const ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn ensure_thread_init() {
|
||||||
|
|
||||||
fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) -> T {
|
fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) -> T {
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
let c_str = CString::from_slice(s.as_bytes());
|
let c_str = CString::new(s.as_bytes().to_vec()).unwrap();
|
||||||
f(c_str.as_ptr())
|
f(c_str.as_ptr())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,7 +778,7 @@ impl Window {
|
||||||
MouseCursor::AllScroll | MouseCursor::ZoomIn |
|
MouseCursor::AllScroll | MouseCursor::ZoomIn |
|
||||||
MouseCursor::ZoomOut => "left_ptr",
|
MouseCursor::ZoomOut => "left_ptr",
|
||||||
};
|
};
|
||||||
let c_string = CString::from_slice(cursor_name.as_bytes());
|
let c_string = CString::new(cursor_name.as_bytes().to_vec()).unwrap();
|
||||||
let xcursor = ffi::XcursorLibraryLoadCursor(self.x.display, c_string.as_ptr());
|
let xcursor = ffi::XcursorLibraryLoadCursor(self.x.display, c_string.as_ptr());
|
||||||
ffi::XDefineCursor (self.x.display, self.x.window, xcursor);
|
ffi::XDefineCursor (self.x.display, self.x.window, xcursor);
|
||||||
ffi::XFlush(self.x.display);
|
ffi::XFlush(self.x.display);
|
||||||
|
|
Loading…
Reference in a new issue