1
0
Fork 0

Replace uses of Arc with Rc in Windows impl

Everything is single threaded so there's no need to use Arcs.
This commit is contained in:
Robbert van der Helm 2022-11-30 18:25:05 +01:00
parent c5867b6af6
commit b8a5867436

View file

@ -21,8 +21,8 @@ use std::ffi::{c_void, OsStr};
use std::marker::PhantomData; use std::marker::PhantomData;
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::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle}; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle};
@ -61,7 +61,7 @@ const WIN_FRAME_TIMER: usize = 4242;
pub struct WindowHandle { pub struct WindowHandle {
hwnd: Option<HWND>, hwnd: Option<HWND>,
is_open: Arc<AtomicBool>, is_open: Rc<AtomicBool>,
// Ensure handle is !Send // Ensure handle is !Send
_phantom: PhantomData<*mut ()>, _phantom: PhantomData<*mut ()>,
@ -95,16 +95,16 @@ unsafe impl HasRawWindowHandle for WindowHandle {
} }
struct ParentHandle { struct ParentHandle {
is_open: Arc<AtomicBool>, is_open: Rc<AtomicBool>,
} }
impl ParentHandle { impl ParentHandle {
pub fn new(hwnd: HWND) -> (Self, WindowHandle) { pub fn new(hwnd: HWND) -> (Self, WindowHandle) {
let is_open = Arc::new(AtomicBool::new(true)); let is_open = Rc::new(AtomicBool::new(true));
let handle = WindowHandle { let handle = WindowHandle {
hwnd: Some(hwnd), hwnd: Some(hwnd),
is_open: Arc::clone(&is_open), is_open: Rc::clone(&is_open),
_phantom: PhantomData::default(), _phantom: PhantomData::default(),
}; };
@ -400,7 +400,7 @@ struct WindowState {
dw_style: u32, dw_style: u32,
#[cfg(feature = "opengl")] #[cfg(feature = "opengl")]
gl_context: Arc<Option<GlContext>>, gl_context: Rc<Option<GlContext>>,
} }
impl WindowState { impl WindowState {
@ -419,7 +419,7 @@ pub struct Window {
hwnd: HWND, hwnd: HWND,
#[cfg(feature = "opengl")] #[cfg(feature = "opengl")]
gl_context: Arc<Option<GlContext>>, gl_context: Rc<Option<GlContext>>,
} }
impl Window { impl Window {
@ -538,7 +538,7 @@ impl Window {
// todo: manage error ^ // todo: manage error ^
#[cfg(feature = "opengl")] #[cfg(feature = "opengl")]
let gl_context: Arc<Option<GlContext>> = Arc::new(options.gl_config.map(|gl_config| { let gl_context: Rc<Option<GlContext>> = Rc::new(options.gl_config.map(|gl_config| {
let mut handle = Win32Handle::empty(); let mut handle = Win32Handle::empty();
handle.hwnd = hwnd as *mut c_void; handle.hwnd = hwnd as *mut c_void;
let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Win32(handle) }; let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Win32(handle) };