-
Notifications
You must be signed in to change notification settings - Fork 73
Fix GLES/EGL surface creation on older Mesa (Linux) #331
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
Open
guillaug
wants to merge
1
commit into
kvark:main
Choose a base branch
from
guillaug:fix/gles-egl-linux-compat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,6 +348,31 @@ impl super::Context { | |
| } else if let Some(egl1_5) = egl.upcast::<egl::EGL1_5>() { | ||
| if let Some(state) = try_create_gbm_display(egl1_5, &client_extensions) { | ||
| (state.0, Some(state.1)) | ||
| } else if std::env::var("WAYLAND_DISPLAY").is_ok() | ||
| && (client_extensions.contains("EGL_KHR_platform_wayland") | ||
| || client_extensions.contains("EGL_EXT_platform_wayland")) | ||
| { | ||
| log::info!("Using Wayland EGL platform"); | ||
| let d = egl1_5 | ||
| .get_platform_display( | ||
| EGL_PLATFORM_WAYLAND_KHR, | ||
| egl::DEFAULT_DISPLAY as *mut _, | ||
| &[egl::ATTRIB_NONE], | ||
| ) | ||
| .unwrap(); | ||
| (d, None) | ||
| } else if client_extensions.contains("EGL_KHR_platform_x11") | ||
| || client_extensions.contains("EGL_EXT_platform_x11") | ||
| { | ||
| log::info!("Using X11 EGL platform"); | ||
| let d = egl1_5 | ||
| .get_platform_display( | ||
| EGL_PLATFORM_X11_KHR, | ||
| egl::DEFAULT_DISPLAY as *mut _, | ||
| &[egl::ATTRIB_NONE], | ||
| ) | ||
| .unwrap(); | ||
| (d, None) | ||
| } else if client_extensions.contains("EGL_MESA_platform_surfaceless") { | ||
| log::info!("Using surfaceless platform"); | ||
| let d = egl1_5 | ||
|
|
@@ -691,7 +716,7 @@ impl super::Context { | |
| ) { | ||
| use raw_window_handle::RawWindowHandle as Rwh; | ||
|
|
||
| let (mut temp_xlib_handle, mut temp_xcb_handle); | ||
| let mut temp_xlib_handle; | ||
| let mut new_wl_window = None; | ||
| #[allow(trivial_casts)] | ||
| let native_window_ptr = match surface.platform.window_handle { | ||
|
|
@@ -700,10 +725,7 @@ impl super::Context { | |
| temp_xlib_handle = handle.window; | ||
| &mut temp_xlib_handle as *mut _ as *mut ffi::c_void | ||
| } | ||
| Rwh::Xcb(handle) => { | ||
| temp_xcb_handle = handle.window; | ||
| &mut temp_xcb_handle as *mut _ as *mut ffi::c_void | ||
| } | ||
| Rwh::Xcb(handle) => handle.window.get() as usize as *mut ffi::c_void, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch! |
||
| Rwh::AndroidNdk(handle) => handle.a_native_window.as_ptr(), | ||
| Rwh::Wayland(handle) => unsafe { | ||
| let wl_egl_window_create: libloading::Symbol<WlEglWindowCreateFun> = surface | ||
|
|
@@ -753,16 +775,9 @@ impl super::Context { | |
|
|
||
| let mut attributes = vec![ | ||
| egl::RENDER_BUFFER, | ||
| if cfg!(any( | ||
| target_os = "android", | ||
| target_os = "macos", | ||
| windows, | ||
| target_env = "ohos" | ||
| )) { | ||
| egl::BACK_BUFFER | ||
| } else { | ||
| egl::SINGLE_BUFFER | ||
| }, | ||
| // Use BACK_BUFFER unconditionally: some Mesa drivers reject | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to use BACK_BUFFER pessimistically on the main path where DMA-BUF is in effect. |
||
| // EGL_SINGLE_BUFFER with BadAlloc on window surfaces. | ||
| egl::BACK_BUFFER, | ||
| ]; | ||
| match inner.egl.srgb_kind { | ||
| SrgbFrameBufferKind::None => {} | ||
|
|
@@ -852,7 +867,7 @@ impl super::Context { | |
| pres_egl_context.shared_display = true; | ||
|
|
||
| // Create the window surface on the presentation display | ||
| let (mut temp_xlib_handle, mut temp_xcb_handle); | ||
| let mut temp_xlib_handle; | ||
| let mut new_wl_window = None; | ||
| #[allow(trivial_casts)] | ||
| let native_window_ptr = match surface.platform.window_handle { | ||
|
|
@@ -861,10 +876,7 @@ impl super::Context { | |
| temp_xlib_handle = handle.window; | ||
| &mut temp_xlib_handle as *mut _ as *mut ffi::c_void | ||
| } | ||
| Rwh::Xcb(handle) => { | ||
| temp_xcb_handle = handle.window; | ||
| &mut temp_xcb_handle as *mut _ as *mut ffi::c_void | ||
| } | ||
| Rwh::Xcb(handle) => handle.window.get() as usize as *mut ffi::c_void, | ||
| Rwh::Wayland(handle) => unsafe { | ||
| let wl_egl_window_create: libloading::Symbol<WlEglWindowCreateFun> = surface | ||
| .platform | ||
|
|
@@ -886,7 +898,7 @@ impl super::Context { | |
| } | ||
| }; | ||
|
|
||
| let mut attributes = vec![egl::RENDER_BUFFER, egl::SINGLE_BUFFER]; | ||
| let mut attributes = vec![egl::RENDER_BUFFER, egl::BACK_BUFFER]; | ||
| match pres_egl_context.srgb_kind { | ||
| SrgbFrameBufferKind::None => {} | ||
| SrgbFrameBufferKind::Core | SrgbFrameBufferKind::Khr => { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check X11 before wayland, otherwise this would potentially fail on XWayland.
Perhaps don't check wayland at all? If you are running wayland, chances are your platform already supports EGL-1.5