Skip to content
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

Add a way to retrieve the EGL display #1082

Merged
merged 2 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added NetBSD support.
- **Breaking:** Removed `new_shared` function from `Context` and `GlWindow`, in favor of `new`.
- Added `build` method to `ContextBuilder`.
- Added `get_egl_display` method to `GlContextExt` trait and its implementation for platforms.
- Removed minimum supported Rust version guarantee.

# Version 0.19.0 (2018-11-09)
Expand Down
5 changes: 5 additions & 0 deletions src/api/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,9 @@ impl Context {
pub unsafe fn raw_handle(&self) -> egl::ffi::EGLContext {
self.0.egl_context.raw_handle()
}

#[inline]
pub unsafe fn get_egl_display(&self) -> egl::ffi::EGLDisplay {
self.0.egl_context.get_egl_display()
}
}
1 change: 1 addition & 0 deletions src/api/egl/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
extern crate winapi;

pub use self::egl::types::EGLContext;
pub use self::egl::types::EGLDisplay;

use libc;

Expand Down
5 changes: 5 additions & 0 deletions src/api/egl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ impl Context {
self.context
}

#[inline]
pub unsafe fn get_egl_display(&self) -> ffi::egl::types::EGLDisplay {
self.display
}

// Handle Android Life Cycle.
// Android has started the activity or sent it to foreground.
// Create a new surface and attach it to the recreated ANativeWindow.
Expand Down
5 changes: 5 additions & 0 deletions src/api/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,9 @@ impl GlContextExt for Context {
unsafe fn raw_handle(&self) -> Self::Handle {
self.eagl_context as *mut c_void
}

#[inline]
unsafe fn get_egl_display(&self) -> Option<*const c_void> {
None
}
}
7 changes: 7 additions & 0 deletions src/os/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ pub use api::egl::ffi::EGLContext;
use Context;
use os::GlContextExt;

use std::os::raw;

impl GlContextExt for Context {
type Handle = EGLContext;

#[inline]
unsafe fn raw_handle(&self) -> Self::Handle {
self.context.raw_handle()
}

#[inline]
unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> {
Some(self.context.get_egl_display())
}
}
5 changes: 5 additions & 0 deletions src/os/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ impl GlContextExt for Context {
unsafe fn raw_handle(&self) -> Self::Handle {
self.context.raw_handle()
}

#[inline]
unsafe fn get_egl_display(&self) -> Option<*const c_void> {
None
}
}
9 changes: 9 additions & 0 deletions src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ pub mod macos;
pub mod unix;
pub mod windows;

use std::os::raw;

/// Platform-specific extensions for OpenGL contexts.
pub trait GlContextExt {
/// Raw context handle.
type Handle;

/// Returns the raw context handle.
unsafe fn raw_handle(&self) -> Self::Handle;

/// Returns a pointer to the `EGLDisplay` object of EGL that is used by this context.
///
/// Return `None` if the context doesn't use EGL.
//
// The pointer will become invalid when the glutin `GlContext` is destroyed.
unsafe fn get_egl_display(&self) -> Option<*const raw::c_void>;
}
7 changes: 7 additions & 0 deletions src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ pub use winit::os::unix::WindowExt;
use Context;
use os::GlContextExt;

use std::os::raw;

impl GlContextExt for Context {
type Handle = RawHandle;

#[inline]
unsafe fn raw_handle(&self) -> Self::Handle {
self.context.raw_handle()
}

#[inline]
unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> {
self.context.get_egl_display()
}
}
7 changes: 7 additions & 0 deletions src/os/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub use winit::os::windows::{DeviceIdExt, MonitorIdExt, WindowBuilderExt, Window
pub use api::egl::ffi::EGLContext;
pub use platform::RawHandle;

use std::os::raw;

use os::GlContextExt;
use Context;

Expand All @@ -16,4 +18,9 @@ impl GlContextExt for Context {
unsafe fn raw_handle(&self) -> Self::Handle {
self.context.raw_handle()
}

#[inline]
unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> {
self.context.get_egl_display()
}
}
14 changes: 14 additions & 0 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod wayland;
mod x11;
use api::osmesa;

use std::os::raw;

/// Context handles available on Unix-like platforms.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -213,4 +214,17 @@ impl Context {
Context::OsMesa(ref ctxt) => RawHandle::Egl(ctxt.raw_handle()),
}
}

#[inline]
pub unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> {
match *self {
Context::WindowedX11(ref ctxt) | Context::HeadlessX11(_, ref ctxt) => {
ctxt.get_egl_display()
}
Context::WindowedWayland(ref ctxt) | Context::HeadlessWayland(_, ref ctxt) => {
ctxt.get_egl_display()
}
_ => None,
}
}
}
6 changes: 6 additions & 0 deletions src/platform/linux/wayland.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;
use std::ffi::CString;
use std::os::raw;
use winit;
use winit::os::unix::WindowExt;
use {ContextError, CreationError, GlAttributes, PixelFormat, PixelFormatRequirements};
Expand Down Expand Up @@ -90,4 +91,9 @@ impl Context {
pub unsafe fn raw_handle(&self) -> ffi::EGLContext {
self.context.raw_handle()
}

#[inline]
pub unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> {
Some(self.context.get_egl_display())
}
}
9 changes: 9 additions & 0 deletions src/platform/linux/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use winit::os::unix::x11::{XError, XNotSupported, XConnection};

use std::{mem, ptr, fmt, error};
use std::ffi::CString;
use std::os::raw;
use std::sync::Arc;

use winit;
Expand Down Expand Up @@ -297,4 +298,12 @@ impl Context {
pub unsafe fn raw_handle(&self) -> &GlContext {
&self.context
}

#[inline]
pub unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> {
match self.context {
GlContext::Egl(ref ctxt) => Some(ctxt.get_egl_display()),
_ => None,
}
}
}
11 changes: 11 additions & 0 deletions src/platform/windows/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(target_os = "windows")]

use std::os::raw;
use std::ptr;

use winapi::shared::windef::HWND;
Expand Down Expand Up @@ -187,4 +188,14 @@ impl Context {
| Context::EglPbuffer(ref c) => RawHandle::Egl(c.raw_handle()),
}
}

#[inline]
pub unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> {
match *self {
Context::Egl(ref c)
| Context::HiddenWindowEgl(_, ref c)
| Context::EglPbuffer(ref c) => Some(c.get_egl_display()),
_ => None,
}
}
}