Skip to content
Merged
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
54 changes: 31 additions & 23 deletions blade-graphics/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ impl super::Context {
};
window_ptr
}
Rwh::OhosNdk(handle) => handle.native_window.as_ptr(),
other => {
panic!("Unable to connect with RWH {:?}", other);
}
Expand All @@ -386,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)) {
if cfg!(any(
target_os = "android",
target_os = "macos",
windows,
target_env = "ohos"
)) {
egl::BACK_BUFFER
} else {
egl::SINGLE_BUFFER
Expand All @@ -413,25 +419,23 @@ 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::<egl::EGL1_5>() {
Some(egl) => {
let attributes_usize = attributes
.into_iter()
.map(|v| v as usize)
.collect::<Vec<_>>();
unsafe {
egl.create_platform_window_surface(
inner.egl.display,
inner.egl.config,
native_window_ptr,
&attributes_usize,
)
.unwrap()
}
}
_ => unsafe {
// Careful, we can still be in 1.4 version even if `upcast` succeeds
let surface_window = match inner.egl.instance.upcast::<egl::EGL1_5>() {
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
.egl
.instance
Expand All @@ -442,8 +446,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 {
Expand Down Expand Up @@ -853,7 +861,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 _][..],
Expand Down
Loading