Skip to content

egl: support grabbing current context and display#1741

Open
Supreeeme wants to merge 3 commits intorust-windowing:masterfrom
Supreeeme:egl-current-context-display
Open

egl: support grabbing current context and display#1741
Supreeeme wants to merge 3 commits intorust-windowing:masterfrom
Supreeeme:egl-current-context-display

Conversation

@Supreeeme
Copy link
Copy Markdown

@Supreeeme Supreeeme commented Jan 7, 2026

  • Tested on all platforms changed
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

Open questions:

  • I'm not sure about the error handling when grabbing the current context.
  • I'm also not sure about the error handling when parsing the Display version, though it seems like it'd be a driver bug for that to fail.

@Supreeeme Supreeeme force-pushed the egl-current-context-display branch from 09dddec to 05184a3 Compare January 7, 2026 06:38
@Supreeeme Supreeeme force-pushed the egl-current-context-display branch from 05184a3 to 19bb537 Compare January 9, 2026 04:36
Copy link
Copy Markdown
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

In general, if you want to add raw contexts we need to have borrow and owned ways of taking it, and for dropping part, we must just track on creation + in drop how we got the object, in case it was borrowed, we should just ignore dropping.

I'm fine with having it just for EGL.

Comment on lines +191 to +212
let display = unsafe { egl.GetCurrentDisplay() };
let version = unsafe { egl.QueryString(display, egl::VERSION as EGLint) };
if version.is_null() {
return Err(ErrorKind::BadDisplay.into());
}
// Version string is "<major>.<minor> <vendor info>"
let version = unsafe { CStr::from_ptr(version) }.to_string_lossy();
let (major, rest) = version.split_once('.').unwrap();
let major: u8 = major.parse().unwrap();
let minor = rest.split(' ').next().unwrap();
let minor: u8 = minor.parse().unwrap();
let version = Version::new(major, minor);

let display_extensions = get_extensions(egl, display);
let features = Self::extract_display_features(&display_extensions, version);
let inner = Arc::new(DisplayInner {
egl,
raw: EglDisplay::Ext(display),
_native_display: None,
version,
display_extensions,
features,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should follow display creation logic to some extent, I think.

fn raw_context(&self) -> RawContext {
*self
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It was missing intentionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants