Skip to content

Commit 2c564aa

Browse files
desktop mac os fixup
Co-authored-by: Dennis Kobert <[email protected]>
1 parent 5acf50c commit 2c564aa

File tree

14 files changed

+220
-185
lines changed

14 files changed

+220
-185
lines changed

Cargo.lock

Lines changed: 16 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ members = [
2828
"proc-macros",
2929
]
3030
default-members = [
31-
"desktop",
32-
"desktop/wrapper",
3331
"editor",
3432
"frontend/wasm",
3533
"libraries/dyn-any",

desktop/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ gpu = ["graphite-desktop-wrapper/gpu"]
1818
accelerated_paint = ["accelerated_paint_dmabuf", "accelerated_paint_d3d11", "accelerated_paint_iosurface"]
1919
accelerated_paint_dmabuf = ["libc", "ash"]
2020
accelerated_paint_d3d11 = ["windows", "ash"]
21-
accelerated_paint_iosurface = ["objc2-io-surface", "objc2-metal", "core-foundation"]
21+
accelerated_paint_iosurface = ["metal", "objc", "core-foundation"]
2222

2323
[dependencies]
2424
# Local dependencies
@@ -66,9 +66,9 @@ windows = { version = "0.58.0", features = [
6666

6767
# macOS-specific dependencies
6868
[target.'cfg(target_os = "macos")'.dependencies]
69-
objc2-io-surface = { version = "0.3", optional = true }
70-
objc2-metal = { version = "0.3", optional = true }
71-
core-foundation = { version = "0.9", optional = true }
69+
metal = { version = "0.31.0", optional = true }
70+
objc = { version = "0.2", optional = true }
71+
core-foundation = { version = "0.10", optional = true }
7272

7373
# Linux-specific dependencies
7474
[target.'cfg(target_os = "linux")'.dependencies]

desktop/src/cef/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(not(target_os = "macos"))]
12
mod multithreaded;
23
mod singlethreaded;
34

desktop/src/cef/context/builder.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::PathBuf;
1+
use std::path::{Path, PathBuf};
22

33
use cef::args::Args;
44
use cef::sys::{CEF_API_VERSION_LAST, cef_resultcode_t};
@@ -25,12 +25,23 @@ unsafe impl<H: CefEventHandler> Send for CefContextBuilder<H> {}
2525

2626
impl<H: CefEventHandler> CefContextBuilder<H> {
2727
pub(crate) fn new() -> Self {
28+
Self::new_inner(false)
29+
}
30+
31+
pub(crate) fn new_helper() -> Self {
32+
Self::new_inner(true)
33+
}
34+
35+
fn new_inner(helper: bool) -> Self {
2836
#[cfg(target_os = "macos")]
2937
let _loader = {
30-
let loader = library_loader::LibraryLoader::new(&std::env::current_exe().unwrap(), false);
38+
let loader = cef::library_loader::LibraryLoader::new(&std::env::current_exe().unwrap(), helper);
3139
assert!(loader.load());
3240
loader
3341
};
42+
#[cfg(not(target_os = "macos"))]
43+
let _ = helper;
44+
3445
let _ = api_hash(CEF_API_VERSION_LAST, 0);
3546

3647
let args = Args::new();
@@ -62,17 +73,29 @@ impl<H: CefEventHandler> CefContextBuilder<H> {
6273
}
6374
}
6475

76+
fn common_settings(instance_dir: &Path) -> Settings {
77+
Settings {
78+
windowless_rendering_enabled: 1,
79+
root_cache_path: instance_dir.to_str().map(CefString::from).unwrap(),
80+
cache_path: CefString::from(""),
81+
disable_signal_handlers: 1,
82+
..Default::default()
83+
}
84+
}
85+
6586
#[cfg(target_os = "macos")]
6687
pub(crate) fn initialize(self, event_handler: H, disable_gpu_acceleration: bool) -> Result<impl CefContext, InitError> {
6788
let instance_dir = create_instance_dir();
6889

90+
let exe = std::env::current_exe().expect("cannot get current exe path");
91+
let app_root = exe.parent().and_then(|p| p.parent()).expect("bad path structure").parent().expect("bad path structure");
92+
6993
let settings = Settings {
70-
windowless_rendering_enabled: 1,
94+
main_bundle_path: CefString::from(app_root.to_str().unwrap()),
7195
multi_threaded_message_loop: 0,
7296
external_message_pump: 1,
73-
root_cache_path: instance_dir.to_str().map(CefString::from).unwrap(),
74-
cache_path: CefString::from(""),
75-
..Default::default()
97+
no_sandbox: 1, // GPU helper crashes when running with sandbox
98+
..Self::common_settings(&instance_dir)
7699
};
77100

78101
self.initialize_inner(&event_handler, settings)?;
@@ -85,11 +108,8 @@ impl<H: CefEventHandler> CefContextBuilder<H> {
85108
let instance_dir = create_instance_dir();
86109

87110
let settings = Settings {
88-
windowless_rendering_enabled: 1,
89111
multi_threaded_message_loop: 1,
90-
root_cache_path: instance_dir.to_str().map(CefString::from).unwrap(),
91-
cache_path: CefString::from(""),
92-
..Default::default()
112+
..Self::common_settings(&instance_dir)
93113
};
94114

95115
self.initialize_inner(&event_handler, settings)?;

desktop/src/cef/internal.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ mod scheme_handler_factory;
1313
mod display_handler;
1414

1515
pub(super) mod render_handler;
16+
17+
#[cfg(not(target_os = "macos"))]
1618
pub(super) mod task;
1719

1820
pub(super) use browser_process_app::BrowserProcessAppImpl;

desktop/src/cef/internal/browser_process_app.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ impl<H: CefEventHandler + Clone> ImplApp for BrowserProcessAppImpl<H> {
6666
cmd.append_switch_with_value(Some(&CefString::from("ozone-platform")), Some(&CefString::from("wayland")));
6767
}
6868
}
69+
70+
#[cfg(target_os = "macos")]
71+
{
72+
// Hide user prompt asking for keychain access
73+
cmd.append_switch(Some(&CefString::from("use-mock-keychain")));
74+
}
6975
}
7076
}
7177

desktop/src/cef/internal/display_handler.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ impl<H: CefEventHandler> DisplayHandlerImpl<H> {
1919
}
2020
}
2121

22+
#[cfg(not(target_os = "macos"))]
23+
type CefCursorHandle = cef::CursorHandle;
24+
#[cfg(target_os = "macos")]
25+
type CefCursorHandle = *mut u8;
26+
2227
impl<H: CefEventHandler> ImplDisplayHandler for DisplayHandlerImpl<H> {
23-
fn on_cursor_change(&self, _browser: Option<&mut cef::Browser>, _cursor: cef::CursorHandle, cursor_type: cef::CursorType, _custom_cursor_info: Option<&cef::CursorInfo>) -> ::std::os::raw::c_int {
28+
fn on_cursor_change(&self, _browser: Option<&mut cef::Browser>, _cursor: CefCursorHandle, cursor_type: cef::CursorType, _custom_cursor_info: Option<&cef::CursorInfo>) -> ::std::os::raw::c_int {
2429
let cursor = match cursor_type.into() {
2530
CT_POINTER => CursorIcon::Default,
2631
CT_CROSS => CursorIcon::Crosshair,

desktop/src/cef/texture_import/common.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Common utilities and traits for texture import across platforms
22
33
use crate::cef::texture_import::*;
4-
use ash::vk;
54
use cef::sys::cef_color_type_t;
65
use wgpu::Device;
76

@@ -20,10 +19,10 @@ pub mod format {
2019

2120
#[cfg(not(target_os = "macos"))]
2221
/// Convert CEF color type to Vulkan format
23-
pub fn cef_to_vulkan(format: cef_color_type_t) -> Result<vk::Format, TextureImportError> {
22+
pub fn cef_to_vulkan(format: cef_color_type_t) -> Result<ash::vk::Format, TextureImportError> {
2423
match format {
25-
cef_color_type_t::CEF_COLOR_TYPE_BGRA_8888 => Ok(vk::Format::B8G8R8A8_UNORM),
26-
cef_color_type_t::CEF_COLOR_TYPE_RGBA_8888 => Ok(vk::Format::R8G8B8A8_UNORM),
24+
cef_color_type_t::CEF_COLOR_TYPE_BGRA_8888 => Ok(ash::vk::Format::B8G8R8A8_UNORM),
25+
cef_color_type_t::CEF_COLOR_TYPE_RGBA_8888 => Ok(ash::vk::Format::R8G8B8A8_UNORM),
2726
_ => Err(TextureImportError::UnsupportedFormat { format }),
2827
}
2928
}
@@ -63,16 +62,17 @@ pub mod texture {
6362
}
6463

6564
/// Common Vulkan utilities
65+
#[cfg(not(target_os = "macos"))]
6666
pub mod vulkan {
6767
use super::*;
68+
use ash::vk;
6869

6970
/// Find a suitable memory type index for Vulkan allocation
7071
pub fn find_memory_type_index(type_filter: u32, properties: vk::MemoryPropertyFlags, mem_properties: &vk::PhysicalDeviceMemoryProperties) -> Option<u32> {
7172
(0..mem_properties.memory_type_count).find(|&i| (type_filter & (1 << i)) != 0 && mem_properties.memory_types[i as usize].property_flags.contains(properties))
7273
}
7374

7475
/// Check if the wgpu device is using Vulkan backend
75-
#[cfg(not(target_os = "macos"))]
7676
pub fn is_vulkan_backend(device: &Device) -> bool {
7777
use wgpu::hal::api;
7878
let mut is_vulkan = false;

0 commit comments

Comments
 (0)