From 678aa5427167d7ca05ccf1070bf8005b19506788 Mon Sep 17 00:00:00 2001 From: richerfu Date: Thu, 15 Jan 2026 20:00:05 +0800 Subject: [PATCH 1/5] feat(blade-graphics): gles support ohos platform --- blade-graphics/src/gles/egl.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blade-graphics/src/gles/egl.rs b/blade-graphics/src/gles/egl.rs index 683d38d3..7e7b836b 100644 --- a/blade-graphics/src/gles/egl.rs +++ b/blade-graphics/src/gles/egl.rs @@ -362,7 +362,8 @@ impl super::Context { layer as *mut ffi::c_void }; window_ptr - } + }, + Rwh::OhosNdk(handle) => handle.native_window.as_ptr(), other => { panic!("Unable to connect with RWH {:?}", other); } From bafd9e35a651c8af1873245d626233f62d24e43a Mon Sep 17 00:00:00 2001 From: richerfu Date: Mon, 19 Jan 2026 16:16:17 +0800 Subject: [PATCH 2/5] feat(blade-graphics): gles support ohos platform --- blade-graphics/src/gles/egl.rs | 60 +++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/blade-graphics/src/gles/egl.rs b/blade-graphics/src/gles/egl.rs index 7e7b836b..66fba2ff 100644 --- a/blade-graphics/src/gles/egl.rs +++ b/blade-graphics/src/gles/egl.rs @@ -362,7 +362,7 @@ impl super::Context { layer as *mut ffi::c_void }; window_ptr - }, + } Rwh::OhosNdk(handle) => handle.native_window.as_ptr(), other => { panic!("Unable to connect with RWH {:?}", other); @@ -414,25 +414,43 @@ impl super::Context { crate::ColorSpace::Srgb => crate::TextureFormat::Rgba8Unorm, }; - surface.platform.swapchain = Some(Swapchain { - // Careful, we can still be in 1.4 version even if `upcast` succeeds - surface: match inner.egl.instance.upcast::() { - Some(egl) => { - let attributes_usize = attributes - .into_iter() - .map(|v| v as usize) - .collect::>(); + // Careful, we can still be in 1.4 version even if `upcast` succeeds + let surface_window = match inner.egl.instance.upcast::() { + Some(egl1_5) => { + // ohos can upcast to 1.5 but it will return nullptr with create_platform_window_surface. + // And using 1.4 succeed. + if cfg!(target_env = "ohos") { unsafe { - egl.create_platform_window_surface( - inner.egl.display, - inner.egl.config, - native_window_ptr, - &attributes_usize, - ) - .unwrap() + inner + .egl + .instance + .create_window_surface( + inner.egl.display, + inner.egl.config, + native_window_ptr, + Some(&attributes), + ) + .unwrap() + } + } else { + // Use platform window surface for EGL 1.5 (except on ohos) + let attributes_usize: Vec = + attributes.iter().map(|&v| v as usize).collect(); + unsafe { + egl1_5 + .create_platform_window_surface( + inner.egl.display, + inner.egl.config, + native_window_ptr, + &attributes_usize, + ) + .unwrap() } } - _ => unsafe { + } + None => { + // Fallback to standard window surface for ohos or non-EGL1.5 + unsafe { inner .egl .instance @@ -443,8 +461,12 @@ impl super::Context { Some(&attributes), ) .unwrap() - }, - }, + } + } + }; + + surface.platform.swapchain = Some(Swapchain { + surface: surface_window, extent: config.size, info: crate::SurfaceInfo { format, alpha }, swap_interval: match config.display_sync { From d9c0464f87ff6a72ac5dd6c1430f91a739da3811 Mon Sep 17 00:00:00 2001 From: richerfu Date: Wed, 21 Jan 2026 15:34:52 +0800 Subject: [PATCH 3/5] fix(blade-graphics): ohos gles feature error --- blade-graphics/src/gles/egl.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blade-graphics/src/gles/egl.rs b/blade-graphics/src/gles/egl.rs index 66fba2ff..3f159141 100644 --- a/blade-graphics/src/gles/egl.rs +++ b/blade-graphics/src/gles/egl.rs @@ -387,7 +387,7 @@ impl super::Context { // We don't want any of the buffering done by the driver, because we // manage a swapchain on our side. // Some drivers just fail on surface creation seeing `EGL_SINGLE_BUFFER`. - if cfg!(any(target_os = "android", target_os = "macos", windows)) { + if cfg!(any(target_os = "android", target_os = "macos", windows, target_env = "ohos")) { egl::BACK_BUFFER } else { egl::SINGLE_BUFFER @@ -876,7 +876,7 @@ fn choose_config( ][..], ), ("presentation", &[egl::SURFACE_TYPE, egl::WINDOW_BIT][..]), - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_env = "ohos")))] ( "native-render", &[egl::NATIVE_RENDERABLE, egl::TRUE as _][..], From 15f10023e32e364519a25092f22708abeb846666 Mon Sep 17 00:00:00 2001 From: richerfu Date: Sat, 24 Jan 2026 13:15:37 +0800 Subject: [PATCH 4/5] fix: format code --- blade-graphics/src/gles/egl.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blade-graphics/src/gles/egl.rs b/blade-graphics/src/gles/egl.rs index 3f159141..d03092c3 100644 --- a/blade-graphics/src/gles/egl.rs +++ b/blade-graphics/src/gles/egl.rs @@ -387,7 +387,12 @@ impl super::Context { // We don't want any of the buffering done by the driver, because we // manage a swapchain on our side. // Some drivers just fail on surface creation seeing `EGL_SINGLE_BUFFER`. - if cfg!(any(target_os = "android", target_os = "macos", windows, target_env = "ohos")) { + if cfg!(any( + target_os = "android", + target_os = "macos", + windows, + target_env = "ohos" + )) { egl::BACK_BUFFER } else { egl::SINGLE_BUFFER From d07bad17e2138487dc1c0234653c7568ce689aa0 Mon Sep 17 00:00:00 2001 From: richerfu Date: Sun, 25 Jan 2026 10:37:34 +0800 Subject: [PATCH 5/5] fix: simplify code --- blade-graphics/src/gles/egl.rs | 46 ++++++++++------------------------ 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/blade-graphics/src/gles/egl.rs b/blade-graphics/src/gles/egl.rs index d03092c3..336524ce 100644 --- a/blade-graphics/src/gles/egl.rs +++ b/blade-graphics/src/gles/egl.rs @@ -421,39 +421,19 @@ impl super::Context { // Careful, we can still be in 1.4 version even if `upcast` succeeds let surface_window = match inner.egl.instance.upcast::() { - Some(egl1_5) => { - // ohos can upcast to 1.5 but it will return nullptr with create_platform_window_surface. - // And using 1.4 succeed. - if cfg!(target_env = "ohos") { - unsafe { - inner - .egl - .instance - .create_window_surface( - inner.egl.display, - inner.egl.config, - native_window_ptr, - Some(&attributes), - ) - .unwrap() - } - } else { - // Use platform window surface for EGL 1.5 (except on ohos) - let attributes_usize: Vec = - attributes.iter().map(|&v| v as usize).collect(); - unsafe { - egl1_5 - .create_platform_window_surface( - inner.egl.display, - inner.egl.config, - native_window_ptr, - &attributes_usize, - ) - .unwrap() - } - } - } - None => { + Some(egl1_5) if !cfg!(target_env = "ohos") => unsafe { + inner + .egl + .instance + .create_window_surface( + inner.egl.display, + inner.egl.config, + native_window_ptr, + Some(&attributes), + ) + .unwrap() + }, + _ => { // Fallback to standard window surface for ohos or non-EGL1.5 unsafe { inner