From 82d6ad4616547e7228798971463d12934837c6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Fri, 26 Jul 2024 01:40:49 +0800 Subject: [PATCH] Make `CosmicTextSystem` Linux-only (#14728) Since `WindowsDispatcher` requires a minimum Windows version of Windows 10 Fall Creators Update (10.0.16299), and the `alacritty_terminal` dependency relies on conPTY, an API introduced in the same version, additionally, `DirectWriteTextSystem` also relies on Windows 10 Fall Creators Update (10.0.16299), so it seems reasonable to make `CosmicTextSystem` Linux-only. And we can use `DirectWriteTextSystem` on the Windows platform exclusively. I hope this approach makes sense. Release Notes: - N/A --- crates/gpui/src/platform.rs | 8 -------- crates/gpui/src/platform/cosmic_text.rs | 3 --- crates/gpui/src/platform/linux.rs | 2 ++ .../platform/{cosmic_text => linux}/text_system.rs | 3 --- crates/gpui/src/platform/test/platform.rs | 2 +- crates/gpui/src/platform/windows/direct_write.rs | 10 +++++----- crates/gpui/src/platform/windows/platform.rs | 11 +++-------- 7 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 crates/gpui/src/platform/cosmic_text.rs rename crates/gpui/src/platform/{cosmic_text => linux}/text_system.rs (99%) diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 7946a71d6d..45de306ad2 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -4,9 +4,6 @@ mod app_menu; mod keystroke; -#[cfg(not(target_os = "macos"))] -mod cosmic_text; - #[cfg(target_os = "linux")] mod linux; @@ -51,8 +48,6 @@ use uuid::Uuid; pub use app_menu::*; pub use keystroke::*; -#[cfg(not(target_os = "macos"))] -pub(crate) use cosmic_text::*; #[cfg(target_os = "linux")] pub(crate) use linux::*; #[cfg(target_os = "macos")] @@ -105,7 +100,6 @@ pub fn guess_compositor() -> &'static str { } } -// todo("windows") #[cfg(target_os = "windows")] pub(crate) fn current_platform(_headless: bool) -> Rc { Rc::new(WindowsPlatform::new()) @@ -413,8 +407,6 @@ pub(crate) trait PlatformTextSystem: Send + Sync { raster_bounds: Bounds, ) -> Result<(Size, Vec)>; fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout; - #[cfg(target_os = "windows")] - fn destroy(&self); } #[derive(PartialEq, Eq, Hash, Clone)] diff --git a/crates/gpui/src/platform/cosmic_text.rs b/crates/gpui/src/platform/cosmic_text.rs deleted file mode 100644 index f7a54b65ba..0000000000 --- a/crates/gpui/src/platform/cosmic_text.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod text_system; - -pub(crate) use text_system::*; diff --git a/crates/gpui/src/platform/linux.rs b/crates/gpui/src/platform/linux.rs index fe2f08296c..cfba4b4907 100644 --- a/crates/gpui/src/platform/linux.rs +++ b/crates/gpui/src/platform/linux.rs @@ -1,6 +1,7 @@ mod dispatcher; mod headless; mod platform; +mod text_system; mod wayland; mod x11; mod xdg_desktop_portal; @@ -8,5 +9,6 @@ mod xdg_desktop_portal; pub(crate) use dispatcher::*; pub(crate) use headless::*; pub(crate) use platform::*; +pub(crate) use text_system::*; pub(crate) use wayland::*; pub(crate) use x11::*; diff --git a/crates/gpui/src/platform/cosmic_text/text_system.rs b/crates/gpui/src/platform/linux/text_system.rs similarity index 99% rename from crates/gpui/src/platform/cosmic_text/text_system.rs rename to crates/gpui/src/platform/linux/text_system.rs index 0735804858..dc7bf6ca5f 100644 --- a/crates/gpui/src/platform/cosmic_text/text_system.rs +++ b/crates/gpui/src/platform/linux/text_system.rs @@ -177,9 +177,6 @@ impl PlatformTextSystem for CosmicTextSystem { fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout { self.0.write().layout_line(text, font_size, runs) } - - #[cfg(target_os = "windows")] - fn destroy(&self) {} } impl CosmicTextSystemState { diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index 0483953028..d26317f50e 100644 --- a/crates/gpui/src/platform/test/platform.rs +++ b/crates/gpui/src/platform/test/platform.rs @@ -49,7 +49,7 @@ impl TestPlatform { let text_system = Arc::new(crate::platform::mac::MacTextSystem::new()); #[cfg(target_os = "linux")] - let text_system = Arc::new(crate::platform::cosmic_text::CosmicTextSystem::new()); + let text_system = Arc::new(crate::platform::linux::CosmicTextSystem::new()); #[cfg(target_os = "windows")] let text_system = Arc::new(crate::platform::windows::DirectWriteTextSystem::new().unwrap()); diff --git a/crates/gpui/src/platform/windows/direct_write.rs b/crates/gpui/src/platform/windows/direct_write.rs index f721834c7c..912dee7893 100644 --- a/crates/gpui/src/platform/windows/direct_write.rs +++ b/crates/gpui/src/platform/windows/direct_write.rs @@ -171,6 +171,11 @@ impl DirectWriteTextSystem { font_id_by_identifier: HashMap::default(), }))) } + + pub(crate) fn destroy(&self) { + let mut lock = self.0.write(); + unsafe { ManuallyDrop::drop(&mut lock.components.bitmap_factory) }; + } } impl PlatformTextSystem for DirectWriteTextSystem { @@ -239,11 +244,6 @@ impl PlatformTextSystem for DirectWriteTextSystem { ..Default::default() }) } - - fn destroy(&self) { - let mut lock = self.0.write(); - unsafe { ManuallyDrop::drop(&mut lock.components.bitmap_factory) }; - } } impl DirectWriteState { diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 3b2f5095e2..6dbe14ffed 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -49,7 +49,7 @@ pub(crate) struct WindowsPlatform { icon: HICON, background_executor: BackgroundExecutor, foreground_executor: ForegroundExecutor, - text_system: Arc, + text_system: Arc, clipboard_hash_format: u32, clipboard_metadata_format: u32, } @@ -90,13 +90,8 @@ impl WindowsPlatform { let dispatcher = Arc::new(WindowsDispatcher::new()); let background_executor = BackgroundExecutor::new(dispatcher.clone()); let foreground_executor = ForegroundExecutor::new(dispatcher); - let text_system = if let Some(direct_write) = DirectWriteTextSystem::new().log_err() { - log::info!("Using direct write text system."); - Arc::new(direct_write) as Arc - } else { - log::info!("Using cosmic text system."); - Arc::new(CosmicTextSystem::new()) as Arc - }; + let text_system = + Arc::new(DirectWriteTextSystem::new().expect("Error creating DirectWriteTextSystem")); let icon = load_icon().unwrap_or_default(); let state = RefCell::new(WindowsPlatformState::new()); let raw_window_handles = RwLock::new(SmallVec::new());