diff --git a/.gitignore b/.gitignore index 4461cbc942..c7da511384 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target/ .DS_Store *~ #*# +glutin_examples/dist diff --git a/CHANGELOG.md b/CHANGELOG.md index ef55ffb894..107967aafa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - **Breaking:** Added `make_current_surfaceless(self)` for `{Possibly,Not}CurrentGlContext`. +- Added OpenHarmony support for `glutin-winit`. # Version 0.32.2 diff --git a/README.md b/README.md index 2473be5e29..0d4643ebdd 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,20 @@ and start the app using: ```console $ cargo apk r -p glutin_examples --example android ``` + +### OpenHarmony/HarmonyNext + +Be sure to handle OpenHarmony's lifecycle correctly when using a `winit` window +by only creating a GL surface after `winit` raises `Event::Resumed`, and +destroy it again upon receiving `Event::Suspended`. See this in action in the +[`ohos.rs` example](./glutin_examples/examples/ohos.rs). + +To compile and run the OpenHarmony example on your device, +install [`ohrs`](https://crates.io/crates/ohrs) +and start the app using: + +```console +$ ohrs build --arch aarch -- -p glutin_examples --example ohos +``` + +Then copy the `$PWD/dist/arm64-v8a/libohos.so` into your OpenHarmony or HarmonyNext project. diff --git a/glutin-winit/Cargo.toml b/glutin-winit/Cargo.toml index a27cd8ef77..54d58acf09 100644 --- a/glutin-winit/Cargo.toml +++ b/glutin-winit/Cargo.toml @@ -21,7 +21,11 @@ wayland = ["glutin/wayland", "winit/wayland"] [dependencies] glutin = { version = "0.32.0", path = "../glutin", default-features = false } raw-window-handle = "0.6" -winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] } +# winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] } +winit = { git = "https://github.com/richerfu/winit.git", branch = "feat-ohos-3x", default-features = false, features = [ + "rwh_06", +] } +# winit = {path = "../../winit", default-features = false, features = ["rwh_06"]} [build-dependencies] cfg_aliases = "0.2.1" diff --git a/glutin-winit/build.rs b/glutin-winit/build.rs index 32078de541..5dd734fdcd 100644 --- a/glutin-winit/build.rs +++ b/glutin-winit/build.rs @@ -6,12 +6,13 @@ fn main() { // Setup alias to reduce `cfg` boilerplate. cfg_aliases! { // Systems. + ohos_platform: { target_env = "ohos" }, android_platform: { target_os = "android" }, wasm_platform: { target_family = "wasm" }, macos_platform: { target_os = "macos" }, ios_platform: { target_os = "ios" }, apple: { any(ios_platform, macos_platform) }, - free_unix: { all(unix, not(apple), not(android_platform)) }, + free_unix: { all(unix, not(apple), not(android_platform), not(ohos_platform)) }, // Native displays. x11_platform: { all(feature = "x11", free_unix, not(wasm_platform)) }, diff --git a/glutin_examples/Cargo.toml b/glutin_examples/Cargo.toml index 4ff9927a18..24534ff0a3 100644 --- a/glutin_examples/Cargo.toml +++ b/glutin_examples/Cargo.toml @@ -23,11 +23,26 @@ glutin = { path = "../glutin", default-features = false } glutin-winit = { path = "../glutin-winit", default-features = false } png = { version = "0.17.6", optional = true } raw-window-handle = "0.6" -winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] } +# winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] } +winit = { git = "https://github.com/richerfu/winit.git", branch = "feat-ohos-30", default-features = false, features = [ + "rwh_06", +] } drm = { version = "0.12", optional = true } [target.'cfg(target_os = "android")'.dependencies] -winit = { version = "0.30.0", default-features = false, features = ["android-native-activity", "rwh_06"] } +# winit = { version = "0.30.0", default-features = false, features = ["android-native-activity", "rwh_06"] } +winit = { git = "https://github.com/richerfu/winit.git", branch = "feat-ohos-30", default-features = false, features = [ + "rwh_06", + "android-native-activity" +] } + +[target.'cfg(target_env = "ohos")'.dependencies] +openharmony-ability = { version = "0.0.2" } +openharmony-ability-derive = { version = "0.0.1" } +winit = { git = "https://github.com/richerfu/winit.git", branch = "feat-ohos-30", default-features = false, features = [ + "rwh_06", +] } +napi-ohos = {version = "1.0", features = ["napi8", "async"]} [build-dependencies] gl_generator = "0.14" @@ -37,6 +52,10 @@ cfg_aliases = "0.2.1" name = "android" crate-type = ["cdylib"] +[[example]] +name = "ohos" +crate-type = ["cdylib"] + [[example]] name = "egl_device" required-features = ["egl"] diff --git a/glutin_examples/build.rs b/glutin_examples/build.rs index 2fbd6cc476..b7b3e11ec8 100644 --- a/glutin_examples/build.rs +++ b/glutin_examples/build.rs @@ -12,11 +12,12 @@ fn main() { cfg_aliases! { // Systems. android_platform: { target_os = "android" }, + ohos_platform: { target_env = "ohos" }, wasm_platform: { target_family = "wasm" }, macos_platform: { target_os = "macos" }, ios_platform: { target_os = "ios" }, apple: { any(ios_platform, macos_platform) }, - free_unix: { all(unix, not(apple), not(android_platform)) }, + free_unix: { all(unix, not(apple), not(android_platform), not(ohos_platform)) }, // Native displays. x11_platform: { all(feature = "x11", free_unix, not(wasm_platform)) }, diff --git a/glutin_examples/examples/ohos.rs b/glutin_examples/examples/ohos.rs new file mode 100644 index 0000000000..fd59e8562d --- /dev/null +++ b/glutin_examples/examples/ohos.rs @@ -0,0 +1,14 @@ +#![cfg(ohos_platform)] + +use openharmony_ability::OpenHarmonyApp; +use openharmony_ability_derive::ability; + +use winit::event_loop::EventLoop; +use winit::platform::ohos::EventLoopBuilderExtOpenHarmony; + +#[ability] +pub fn openharmony(openharmony_app: OpenHarmonyApp) { + let a = openharmony_app.clone(); + let event_loop = EventLoop::builder().with_openharmony_app(a).build().unwrap(); + glutin_examples::main(event_loop).unwrap() +} diff --git a/glutin_examples/src/lib.rs b/glutin_examples/src/lib.rs index e5b75e17bf..e04583592d 100644 --- a/glutin_examples/src/lib.rs +++ b/glutin_examples/src/lib.rs @@ -21,6 +21,9 @@ use glutin::surface::{Surface, SwapInterval, WindowSurface}; use glutin_winit::{DisplayBuilder, GlWindow}; +#[cfg(target_env = "ohos")] +use winit::platform::ohos::EventLoopExtOpenHarmony; + pub mod gl { #![allow(clippy::all)] include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs")); @@ -42,10 +45,21 @@ pub fn main(event_loop: winit::event_loop::EventLoop<()>) -> Result<(), Box