Allow platform references to be sent to background threads

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Nathan Sobo
2021-06-07 17:35:27 -06:00
co-authored by Max Brunsfeld
parent ebbe517bfa
commit 6daddf5146
5 changed files with 17 additions and 13 deletions
+3 -3
View File
@@ -12,15 +12,15 @@ use cocoa::base::{BOOL, NO, YES};
pub use dispatcher::Dispatcher;
pub use fonts::FontSystem;
use platform::{MacMainThreadPlatform, MacPlatform};
use std::rc::Rc;
use std::{rc::Rc, sync::Arc};
use window::Window;
pub(crate) fn main_thread_platform() -> Rc<dyn super::MainThreadPlatform> {
Rc::new(MacMainThreadPlatform::default())
}
pub(crate) fn platform() -> Rc<dyn super::Platform> {
Rc::new(MacPlatform::new())
pub(crate) fn platform() -> Arc<dyn super::Platform> {
Arc::new(MacPlatform::new())
}
trait BoolExt {
+3
View File
@@ -329,6 +329,9 @@ impl MacPlatform {
}
}
unsafe impl Send for MacPlatform {}
unsafe impl Sync for MacPlatform {}
impl platform::Platform for MacPlatform {
fn dispatcher(&self) -> Arc<dyn platform::Dispatcher> {
self.dispatcher.clone()
+4 -3
View File
@@ -1,4 +1,5 @@
use crate::ClipboardItem;
use parking_lot::Mutex;
use pathfinder_geometry::vector::Vector2F;
use std::{
any::Any,
@@ -11,7 +12,7 @@ use std::{
pub(crate) struct Platform {
dispatcher: Arc<dyn super::Dispatcher>,
fonts: Arc<dyn super::FontSystem>,
current_clipboard_item: RefCell<Option<ClipboardItem>>,
current_clipboard_item: Mutex<Option<ClipboardItem>>,
}
#[derive(Default)]
@@ -114,11 +115,11 @@ impl super::Platform for Platform {
fn quit(&self) {}
fn write_to_clipboard(&self, item: ClipboardItem) {
*self.current_clipboard_item.borrow_mut() = Some(item);
*self.current_clipboard_item.lock() = Some(item);
}
fn read_from_clipboard(&self) -> Option<ClipboardItem> {
self.current_clipboard_item.borrow().clone()
self.current_clipboard_item.lock().clone()
}
}