Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add openharmony support #1702

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added `Device::drm_device_node_path()` and `Device::drm_render_device_node_path()` getters to EGL via `EGL_EXT_device_drm`.
- Added support for `DrmDisplayHandle` in EGL's `Display::with_device()` using `EGL_DRM_MASTER_FD_EXT` from `EGL_EXT_device_drm`.
- Properly set up OpenGL-specific stuff on the `NSView`, instead of relying on Winit to do it.
- Added `OpenHarmony` platform support with EGL.

# Version 0.32.0

Expand Down
2 changes: 1 addition & 1 deletion glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wayland = ["wayland-sys", "egl"]
bitflags = "2.2.1"
libloading = { version = "0.8.0", optional = true }
once_cell = "1.13"
raw-window-handle = "0.6"
raw-window-handle = "0.6.2"

[target.'cfg(windows)'.dependencies]
glutin_egl_sys = { version = "0.7.0", path = "../glutin_egl_sys", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion glutin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ fn main() {
cfg_aliases! {
// Systems.
android_platform: { target_os = "android" },
ohos_platform: { target_env = "ohos" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glutin's CI is quite extensive. @richerfu would you be up for adding one or two ohos target triples to our CI with the egl feature, so that we can always build-test this functionality and make sure this target environment is not accidentally broken in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenHarmony currently has no environment to directly run cargo test, and all code testing is forcibly dependent on real machines. So there is no way to do some testing or verification in the CI environment for the time being. According to official news, this capability will be supported as early as Q1 2025.

Copy link
Member

@MarijnS95 MarijnS95 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richerfu I don't think we need run-time tests, just build-testing (i.e. cargo check/build/clippy) is enough for now to at least guarantee a minimum level of source compatibility. We can incrementally move towards testing on real machines if that possibility is provided.

For example, this works for me:

$ rustup target add x86_64-unknown-linux-ohos
$ cargo clippy --all-features --target x86_64-unknown-linux-ohos -p glutin

And if I make a silly change, like commenting out a Self::Ohos match arm, the compiler/CI could complain that the ohos target no longer even compiles:

$ cargo clippy --all-features --target x86_64-unknown-linux-ohos -p glutin
error[E0004]: non-exhaustive patterns: `api::egl::surface::NativeWindow::Ohos(_)` not covered
   --> glutin/src/api/egl/surface.rs:541:15
    |
541 |         match *self {
    |               ^^^^^ pattern `api::egl::surface::NativeWindow::Ohos(_)` not covered
    |
note: `api::egl::surface::NativeWindow` defined here
   --> glutin/src/api/egl/surface.rs:446:6
    |
446 | enum NativeWindow {
    |      ^^^^^^^^^^^^
...
460 |     Ohos(*mut ffi::c_void),
    |     ---- not covered
    = note: the matched value is of type `api::egl::surface::NativeWindow`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
    |
541 ~         match *self {
542 +             api::egl::surface::NativeWindow::Ohos(_) => todo!(),
543 +         }
    |

For more information about this error, try `rustc --explain E0004`.
error: could not compile `glutin` (lib) due to 1 previous error

(Which may be useful if we edit some code elsewhere or add new match blocks in the future, etc..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i'll try to add some code and upgrade CI config later.

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)) },
Expand Down
4 changes: 3 additions & 1 deletion glutin/src/api/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ impl Display {
RawDisplayHandle::Xlib(XlibDisplayHandle { display, .. }) => {
display.map_or(egl::DEFAULT_DISPLAY as *mut _, |d| d.as_ptr())
},
RawDisplayHandle::Android(_) => egl::DEFAULT_DISPLAY as *mut _,
RawDisplayHandle::Android(_) | RawDisplayHandle::Ohos(_) => {
egl::DEFAULT_DISPLAY as *mut _
},
_ => {
return Err(
ErrorKind::NotSupported("provided display handle is not supported").into()
Expand Down
11 changes: 11 additions & 0 deletions glutin/src/api/egl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ enum NativeWindow {
#[cfg(android_platform)]
Android(*mut ffi::c_void),

#[cfg(ohos_platform)]
Ohos(*mut ffi::c_void),

#[cfg(windows)]
Win32(isize),

Expand Down Expand Up @@ -498,6 +501,10 @@ impl NativeWindow {
RawWindowHandle::AndroidNdk(window_handle) => {
Self::Android(window_handle.a_native_window.as_ptr())
},
#[cfg(ohos_platform)]
RawWindowHandle::OhosNdk(window_handle) => {
Self::Ohos(window_handle.native_window.as_ptr())
},
#[cfg(windows)]
RawWindowHandle::Win32(window_handle) => Self::Win32(window_handle.hwnd.get() as _),
#[cfg(free_unix)]
Expand Down Expand Up @@ -542,6 +549,8 @@ impl NativeWindow {
Self::Win32(hwnd) => hwnd,
#[cfg(android_platform)]
Self::Android(a_native_window) => a_native_window,
#[cfg(ohos_platform)]
Self::Ohos(native_window) => native_window,
#[cfg(free_unix)]
Self::Gbm(gbm_surface) => gbm_surface,
}
Expand Down Expand Up @@ -573,6 +582,8 @@ impl NativeWindow {
Self::Win32(hwnd) => *hwnd as *const ffi::c_void as *mut _,
#[cfg(android_platform)]
Self::Android(a_native_window) => *a_native_window,
#[cfg(ohos_platform)]
Self::Ohos(native_window) => *native_window,
#[cfg(free_unix)]
Self::Gbm(gbm_surface) => *gbm_surface,
}
Expand Down
Loading