Skip to content

Commit

Permalink
ohos: dynamically link eglGetNativeClientBufferANDROID
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
  • Loading branch information
jschwe committed Aug 29, 2024
1 parent 1fa8b3a commit d7dd2f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
18 changes: 18 additions & 0 deletions src/platform/egl/ohos_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#![allow(non_snake_case)]
#![allow(unused)]

use std::ffi::c_void;

/// From `eglext.h` on OpenHarmony.
pub(crate) const EGL_NATIVE_BUFFER_OHOS: u32 = 0x34E1;

use crate::egl::types::EGLClientBuffer;

#[repr(C)]
pub struct NativeWindow {
_unused: [u8; 0],
Expand Down Expand Up @@ -46,6 +53,17 @@ extern "C" {
) -> i32;
}

#[link(name = "EGL")]
extern "C" {
/// Get the native Client buffer
///
/// The extension function `eglGetNativeClientBufferANDROID` is available starting with OpenHarmony 5.0.
/// Its availability is documented here: https://docs.openharmony.cn/pages/v5.0/en/application-dev/reference/native-lib/egl-symbol.md
/// However it is not available in `EGL_EXTENSION_FUNCTIONS`, since `eglGetProcAddress()` does not find
/// the function and returns NULL.
pub(crate) fn eglGetNativeClientBufferANDROID(buffer: *const c_void) -> EGLClientBuffer;
}

// Bindings to `native_buffer` components we use. Official Documentation:
// https://docs.openharmony.cn/pages/v5.0/en/application-dev/graphics/native-buffer-guidelines.md

Expand Down
14 changes: 3 additions & 11 deletions src/platform/egl/surface/ohos_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use crate::egl::types::{EGLSurface, EGLint};
use crate::gl;
use crate::gl::types::{GLenum, GLuint};
use crate::gl_utils;
use crate::platform::egl::ohos_ffi::{eglGetNativeClientBufferANDROID, EGL_NATIVE_BUFFER_OHOS};
use crate::platform::generic;
use crate::platform::generic::egl::device::EGL_FUNCTIONS;
use crate::platform::generic::egl::ffi::EGLImageKHR;
use crate::platform::generic::egl::ffi::EGL_EXTENSION_FUNCTIONS;
use crate::platform::generic::egl::ffi::EGL_IMAGE_PRESERVED_KHR;
use crate::platform::generic::egl::ffi::EGL_NATIVE_BUFFER_ANDROID;
use crate::platform::generic::egl::ffi::EGL_NO_IMAGE_KHR;
use crate::renderbuffers::Renderbuffers;
use crate::{Error, SurfaceAccess, SurfaceID, SurfaceInfo, SurfaceType};
Expand Down Expand Up @@ -252,14 +252,6 @@ impl Device {
_: &Context,
hardware_buffer: *mut OH_NativeBuffer,
) -> EGLImageKHR {
// Get the native client buffer.
// Note: `eglGetNativeClientBufferANDROID` is available starting with OpenHarmony 5.0.
// Its availability is documented here: https://docs.openharmony.cn/pages/v5.0/en/application-dev/reference/native-lib/egl-symbol.md
let eglGetNativeClientBufferANDROID =
EGL_EXTENSION_FUNCTIONS.GetNativeClientBufferANDROID.expect(
"Where's the `EGL_ANDROID_get_native_client_buffer` \
extension?",
);
let client_buffer = eglGetNativeClientBufferANDROID(hardware_buffer as *const _);
assert!(!client_buffer.is_null());

Expand All @@ -273,8 +265,8 @@ impl Device {
let egl_image = (EGL_EXTENSION_FUNCTIONS.CreateImageKHR)(
self.egl_display,
egl::NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID,
client_buffer,
EGL_NATIVE_BUFFER_OHOS,
client_buffer.cast_mut().cast(),
egl_image_attributes.as_ptr(),
);
assert_ne!(egl_image, EGL_NO_IMAGE_KHR);
Expand Down

0 comments on commit d7dd2f7

Please sign in to comment.