Skip to content

Commit

Permalink
expose context and display from adapter and device for egl hal
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Jul 8, 2022
1 parent 94c065c commit 0b57522
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Bottom level categories:
#### Hal

- Allow access to queue family index in Vulkan hal by @i509VCB in [#2859](https://github.com/gfx-rs/wgpu/pull/2859)
- Allow access to the EGLDisplay and EGLContext pointer in Gles hal Adapter and Device by @i509VCB in [#2860](https://github.com/gfx-rs/wgpu/pull/2860)

### Documentation
- Update present_mode docs as most of them don't automatically fall back to Fifo anymore. by @Elabajaba in [#2855](https://github.com/gfx-rs/wgpu/pull/2855)
Expand Down
42 changes: 41 additions & 1 deletion wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
#[derive(Clone, Debug)]
struct EglContext {
instance: Arc<EglInstance>,
version: (i32, i32),
display: egl::Display,
raw: egl::Context,
pbuffer: Option<egl::Surface>,
Expand Down Expand Up @@ -315,7 +316,34 @@ impl AdapterContext {
self.egl.is_some()
}

#[cfg(feature = "renderdoc")]
/// Returns a GL or an EGL extension function.
///
/// Always returns [`None`] if the adapter was externally created.
///
/// # Safety
///
/// - The returned function is only valid for the lifetime of this adapter context and any devices which
/// use the adapter context.
pub unsafe fn get_proc_address(&self, proc_name: &str) -> Option<extern "C" fn()> {
self.egl
.as_ref()
.and_then(|egl| egl.instance.get_proc_address(proc_name))
}

/// Returns the EGLDisplay corresponding to the adapter context.
///
/// Returns [`None`] if the adapter was externally created.
pub fn raw_display(&self) -> Option<&egl::Display> {
self.egl.as_ref().map(|egl| &egl.display)
}

/// Returns the EGL version the adapter context was created with.
///
/// Returns [`None`] if the adapter was externally created.
pub fn egl_version(&self) -> Option<(i32, i32)> {
self.egl.as_ref().map(|egl| egl.version)
}

pub fn raw_context(&self) -> *mut raw::c_void {
match self.egl {
Some(ref egl) => egl.raw.as_ptr(),
Expand Down Expand Up @@ -535,6 +563,7 @@ impl Inner {
display,
raw: context,
pbuffer,
version,
},
version,
supports_native_window,
Expand Down Expand Up @@ -881,6 +910,17 @@ impl super::Adapter {
egl: None,
})
}

pub fn adapter_context(&self) -> &AdapterContext {
&self.shared.context
}
}

impl super::Device {
/// Returns the underlying EGL context.
pub fn context(&self) -> &AdapterContext {
&self.shared.context
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 0b57522

Please sign in to comment.