diff --git a/Cargo.lock b/Cargo.lock index 6c3431dca..0a2da8d54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -624,6 +624,24 @@ dependencies = [ "web-sys", ] +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "convert_case" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baaaa0ecca5b51987b9423ccdc971514dd8b0bb7b4060b983d3664dad3f1f89f" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -790,18 +808,69 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" +[[package]] +name = "ctor" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ffc71fcdcdb40d6f087edddf7f8f1f8f79e6cf922f555a9ee8779752d4819bd" +dependencies = [ + "ctor-proc-macro", + "dtor", +] + [[package]] name = "ctor-lite" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f791803201ab277ace03903de1594460708d2d54df6053f2d9e82f592b19e3b" +[[package]] +name = "ctor-proc-macro" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52560adf09603e58c9a7ee1fe1dcb95a16927b17c127f0ac02d6e768a0e25bc1" + [[package]] name = "cursor-icon" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" +[[package]] +name = "darling" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "data-url" version = "0.3.2" @@ -857,9 +926,8 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dpi" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" +version = "0.1.1" +source = "git+https://github.com/richerfu/winit.git?branch=feat-ohos-3x#21f89eb278c418948ba3c68c504d833e88c4aeab" [[package]] name = "drm" @@ -900,6 +968,21 @@ dependencies = [ "linux-raw-sys 0.6.5", ] +[[package]] +name = "dtor" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404d02eeb088a82cfd873006cb713fe411306c7d182c344905e101fb1167d301" +dependencies = [ + "dtor-proc-macro", +] + +[[package]] +name = "dtor-proc-macro" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f678cf4a922c215c63e0de95eb1ff08a958a81d47e485cf9da1e27bf6305cfa5" + [[package]] name = "dyn-clone" version = "1.0.20" @@ -954,7 +1037,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.0", + "windows-sys 0.60.2", ] [[package]] @@ -1578,6 +1661,12 @@ dependencies = [ "rayon", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "image" version = "0.25.8" @@ -2149,6 +2238,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "napi-build-ohos" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c26abeb82d299258244202546ce4b8098e9991b0a8d5514abe5f56d4fb1d48c" + +[[package]] +name = "napi-derive-backend-ohos" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86f96f92eb3dba447ebc023ac5e16b0a92406d6df938bf3be566b604ea6646a" +dependencies = [ + "convert_case 0.8.0", + "proc-macro2", + "quote", + "semver", + "syn", +] + +[[package]] +name = "napi-derive-ohos" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2ebc6e95ff9cb26e669693315116913fcfdbd1cf4dd50463f046ef8c440937" +dependencies = [ + "convert_case 0.8.0", + "ctor", + "napi-derive-backend-ohos", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "napi-ohos" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c507895644c3334483daeb9612cfe3fd2d433408edcb9f3449bccd7c3e357db0" +dependencies = [ + "bitflags 2.9.4", + "ctor", + "napi-build-ohos", + "napi-sys-ohos", + "nohash-hasher", + "rustc-hash 2.1.1", +] + +[[package]] +name = "napi-sys-ohos" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96d2ad26866a761c5cf9432200bb3e5190e222a12c2e4494a0c23f7c45c6964" +dependencies = [ + "libloading", +] + [[package]] name = "native_webgl" version = "0.6.0" @@ -2196,6 +2341,12 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + [[package]] name = "notify" version = "8.2.0" @@ -2548,6 +2699,112 @@ dependencies = [ "memchr", ] +[[package]] +name = "ohos-arkui-binding" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "731d879cf95234bbd12e525bdce7da6475a6786a86dd2362fac0f3cfca760373" +dependencies = [ + "bitflags 2.9.4", + "napi-ohos", + "napi-sys-ohos", + "ohos-arkui-sys", + "ohos-xcomponent-binding", + "ohos-xcomponent-sys", + "ohos_enum_macro 0.0.2", +] + +[[package]] +name = "ohos-arkui-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a19176486bbe46d33830aca4213b07bb46c745200118e57106639db4962e1c3" +dependencies = [ + "napi-sys-ohos", +] + +[[package]] +name = "ohos-display-binding" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157fe09232fd0af55ed9207d30b47a5f5ff7f84a0673a3b47f65acb7bbc9b8a9" +dependencies = [ + "ohos-display-sys", + "ohos_enum_macro 0.0.1", +] + +[[package]] +name = "ohos-display-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9e1bba4d94159d0a65f1b4e748c148d4bce7930912c424522693f1837dad77" + +[[package]] +name = "ohos-ime-binding" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bed52a087eacd3ea07de5258ca7574276431b17d4c0464ed7f7f57a5fa99bd48" +dependencies = [ + "ohos-input-method-sys", + "ohos_enum_macro 0.0.1", +] + +[[package]] +name = "ohos-input-method-sys" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e95bb83d997b0d7f1d04e9b2ba8874a1bd8e89dc5e88d0852a4390f8b44b0703" + +[[package]] +name = "ohos-xcomponent-binding" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f99c43b17408bb43ae53832a7b929dc6a359685f914624e82fec0a52e9d6ac" +dependencies = [ + "napi-derive-ohos", + "napi-ohos", + "napi-sys-ohos", + "ohos-display-binding", + "ohos-xcomponent-sys", + "ohos_enum_macro 0.0.2", + "raw-window-handle", +] + +[[package]] +name = "ohos-xcomponent-sys" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5613209329ff61bc8695871ef985d57fc59ea4d55263e2c2395d8810d063575e" +dependencies = [ + "ohos-arkui-sys", +] + +[[package]] +name = "ohos_enum_macro" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0ee769776099c824423d1686e21b5fd13b464d374d60f7cc25c48c1c836ede1" +dependencies = [ + "convert_case 0.6.0", + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "ohos_enum_macro" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4bacd60b52be93024c446f27645d795ab71eb2243bb4c5d87b6238a35341fbd" +dependencies = [ + "convert_case 0.6.0", + "proc-macro2", + "quote", + "regex", + "syn", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -2566,6 +2823,32 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" +[[package]] +name = "openharmony-ability" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b68b0a56a8968f31a85024951451a2bb084ecdf08814e77011b47fb957478c7e" +dependencies = [ + "napi-derive-ohos", + "napi-ohos", + "ohos-arkui-binding", + "ohos-display-binding", + "ohos-ime-binding", + "ohos-xcomponent-binding", +] + +[[package]] +name = "openharmony-ability-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da80e8fd70a5f6ebf88a804f969e299672ec6f39b259afcd5d39d23c12f12227" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "orbclient" version = "0.3.48" @@ -3100,7 +3383,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.0", + "windows-sys 0.60.2", ] [[package]] @@ -3557,7 +3840,7 @@ dependencies = [ "getrandom", "once_cell", "rustix 1.1.2", - "windows-sys 0.61.0", + "windows-sys 0.60.2", ] [[package]] @@ -4783,7 +5066,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.0", + "windows-sys 0.60.2", ] [[package]] @@ -5148,9 +5431,8 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winit" -version = "0.30.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66d4b9ed69c4009f6321f762d6e61ad8a2389cd431b97cb1e146812e9e6c732" +version = "0.30.9" +source = "git+https://github.com/richerfu/winit.git?branch=feat-ohos-3x#21f89eb278c418948ba3c68c504d833e88c4aeab" dependencies = [ "ahash", "android-activity", @@ -5173,6 +5455,8 @@ dependencies = [ "objc2-app-kit", "objc2-foundation 0.2.2", "objc2-ui-kit", + "openharmony-ability", + "openharmony-ability-derive", "orbclient", "percent-encoding", "pin-project", @@ -5227,7 +5511,11 @@ dependencies = [ "jni", "kurbo 0.12.0", "log", + "napi-derive-ohos", + "napi-ohos", "notify-debouncer-full", + "openharmony-ability", + "openharmony-ability-derive", "pollster", "profiling", "scenes", diff --git a/Cargo.toml b/Cargo.toml index f7fb4a077..7d6120f10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -138,7 +138,7 @@ anyhow = "1.0.98" pollster = "0.4.0" web-time = "1.1.0" wgpu-profiler = "0.25.0" -winit = "0.30.10" +winit = { git = "https://github.com/richerfu/winit.git", branch = "feat-ohos-3x" } scenes = { path = "examples/scenes" } svg = "0.18.0" criterion = { version = "0.5.1", default-features = false } diff --git a/examples/scenes/src/lib.rs b/examples/scenes/src/lib.rs index fa5bacf1d..7ddacac8b 100644 --- a/examples/scenes/src/lib.rs +++ b/examples/scenes/src/lib.rs @@ -95,9 +95,9 @@ impl Arguments { // directory. // TODO: Upload the assets directory on Android // Therefore, only render the `test_scenes` (including one SVG example) - #[cfg(any(target_arch = "wasm32", target_os = "android"))] + #[cfg(any(target_arch = "wasm32", target_os = "android", target_env = "ohos"))] return Ok(Some(test_scenes())); - #[cfg(not(any(target_arch = "wasm32", target_os = "android")))] + #[cfg(not(any(target_arch = "wasm32", target_os = "android", target_env = "ohos")))] if self.test_scenes { Ok(test_scenes()) } else if let Some(svgs) = &self.svgs { diff --git a/examples/simple/Cargo.toml b/examples/simple/Cargo.toml index b9ded0135..96df8a27d 100644 --- a/examples/simple/Cargo.toml +++ b/examples/simple/Cargo.toml @@ -15,4 +15,4 @@ workspace = true vello = { version = "0.6.0", path = "../../vello" } anyhow = "1.0.98" pollster = "0.4.0" -winit = "0.30.10" +winit = { workspace = true } diff --git a/examples/with_winit/Cargo.toml b/examples/with_winit/Cargo.toml index 08c631562..6bb2bf132 100644 --- a/examples/with_winit/Cargo.toml +++ b/examples/with_winit/Cargo.toml @@ -50,11 +50,16 @@ kurbo = { workspace = true, optional = true, default-features = true } # We use android_logger on Android env_logger = "0.11.8" -[target.'cfg(not(any(target_arch = "wasm32", target_os = "android")))'.dependencies] +[target.'cfg(not(any(target_arch = "wasm32", target_os = "android", target_env = "ohos")))'.dependencies] vello = { workspace = true, features = ["hot_reload"] } vello_shaders = { workspace = true, features = ["compile"] } notify-debouncer-full = "0.5.0" +[target.'cfg(target_env = "ohos")'.dependencies] +openharmony-ability = "0.3" +openharmony-ability-derive = "0.3" +napi-ohos = "1.1" +napi-derive-ohos = "1.1" [target.'cfg(target_os = "android")'.dependencies] winit = { workspace = true, features = ["android-native-activity"] } diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index 49f0412e5..cc01a8af3 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -46,7 +46,7 @@ use winit::window::{Window, WindowAttributes}; use vello::wgpu::{self, PipelineCache}; -#[cfg(not(any(target_arch = "wasm32", target_os = "android")))] +#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_env = "ohos")))] mod hot_reload; mod minimal_pipeline_cache; mod multi_touch; @@ -106,12 +106,12 @@ struct RenderState { window: Arc, } -#[cfg(not(target_os = "android"))] +#[cfg(not(any(target_os = "android", target_env = "ohos")))] // TODO: Make this set configurable through the command line // Alternatively, load anti-aliasing shaders on demand/asynchronously const AA_CONFIGS: [AaConfig; 3] = [AaConfig::Area, AaConfig::Msaa8, AaConfig::Msaa16]; -#[cfg(target_os = "android")] +#[cfg(any(target_os = "android", target_env = "ohos"))] // Hard code to only one on Android whilst we are working on startup speed const AA_CONFIGS: [AaConfig; 1] = [AaConfig::Area]; @@ -691,8 +691,8 @@ impl ApplicationHandler for VelloApp { } fn user_event(&mut self, _event_loop: &winit::event_loop::ActiveEventLoop, event: UserEvent) { + #[cfg(not(any(target_arch = "wasm32", target_os = "android", target_env = "ohos")))] match event { - #[cfg(not(any(target_arch = "wasm32", target_os = "android")))] UserEvent::HotReload => { let Some(render_state) = &mut self.state else { return; @@ -863,6 +863,13 @@ fn run( cache_data, }; + #[cfg(target_env = "ohos")] + { + let app = Box::leak(Box::new(app)); + event_loop.run_app(app).expect("run to completion"); + } + + #[cfg(not(target_env = "ohos"))] event_loop.run_app(&mut app).expect("run to completion"); } @@ -897,7 +904,7 @@ fn window_attributes() -> WindowAttributes { #[derive(Debug)] enum UserEvent { - #[cfg(not(any(target_arch = "wasm32", target_os = "android")))] + #[cfg(not(any(target_arch = "wasm32", target_os = "android", target_env = "ohos")))] HotReload, } @@ -923,7 +930,7 @@ fn display_error_message() -> Option<()> { } /// Entry point. -#[cfg(not(target_os = "android"))] +#[cfg(not(any(target_os = "android", target_env = "ohos")))] pub fn main() -> anyhow::Result<()> { // TODO: initializing both env_logger and console_logger fails on wasm. // Figure out a more principled approach. @@ -1074,3 +1081,24 @@ fn test_kurbo_schemars_with_peniko() { #[expect(unused_qualifications)] let _: PhantomData = PhantomData::; } + +#[cfg(target_env = "ohos")] +use openharmony_ability::OpenHarmonyApp; +#[cfg(target_env = "ohos")] +use winit::platform::ohos::EventLoopBuilderExtOpenHarmony; +#[cfg(target_env = "ohos")] +use openharmony_ability_derive::ability; + +#[cfg(target_env = "ohos")] +#[ability] +pub fn openharmony_main(app: OpenHarmonyApp) { + let event_loop = EventLoop::with_user_event() + .with_openharmony_app(app) + .build() + .expect("Required to continue"); + let args = parse_arguments(); + let scenes = args.args.select_scene_set().unwrap().unwrap(); + let render_cx = RenderContext::new(); + + run(event_loop, args, scenes, render_cx); +} diff --git a/examples/with_winit/src/main.rs b/examples/with_winit/src/main.rs index 9a3642573..50089517d 100644 --- a/examples/with_winit/src/main.rs +++ b/examples/with_winit/src/main.rs @@ -6,10 +6,10 @@ use anyhow::Result; fn main() -> Result<()> { - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_env = "ohos")))] { with_winit::main() } - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_env = "ohos"))] unreachable!() }