Make WindowBuilder Send + Sync

Window builder is always accessed by winit on the thread event loop
is on, thus it's safe to mark the data it gets as `Send + Sync`.
Each unsafe object is marked individually as `Send + Sync` instead
of just implementing `Send` and `Sync` for the whole builder.
This commit is contained in:
Kirill Chibisov 2023-10-17 04:54:12 +04:00 committed by GitHub
parent 3ad64fb811
commit 801fddbfcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 72 additions and 47 deletions

View file

@ -295,7 +295,7 @@ impl WinitWindow {
trace_scope!("WinitWindow::new");
let this = autoreleasepool(|_| {
let screen = match attrs.fullscreen.clone().map(Into::into) {
let screen = match attrs.fullscreen.0.clone().map(Into::into) {
Some(Fullscreen::Borderless(Some(monitor)))
| Some(Fullscreen::Exclusive(VideoMode { monitor, .. })) => {
monitor.ns_screen().or_else(NSScreen::main)
@ -449,7 +449,7 @@ impl WinitWindow {
.ok_or_else(|| os_error!(OsError::CreationError("Couldn't create `NSWindow`")))?;
#[cfg(feature = "rwh_06")]
match attrs.parent_window {
match attrs.parent_window.0 {
Some(rwh_06::RawWindowHandle::AppKit(handle)) => {
// SAFETY: Caller ensures the pointer is valid or NULL
// Unwrap is fine, since the pointer comes from `NonNull`.
@ -520,14 +520,14 @@ impl WinitWindow {
}
}
let delegate = WinitWindowDelegate::new(&this, attrs.fullscreen.is_some());
let delegate = WinitWindowDelegate::new(&this, attrs.fullscreen.0.is_some());
// XXX Send `Focused(false)` right after creating the window delegate, so we won't
// obscure the real focused events on the startup.
delegate.queue_event(WindowEvent::Focused(false));
// Set fullscreen mode after we setup everything
this.set_fullscreen(attrs.fullscreen.map(Into::into));
this.set_fullscreen(attrs.fullscreen.0.map(Into::into));
// Setting the window as key has to happen *after* we set the fullscreen
// state, since otherwise we'll briefly see the window at normal size