Skip to content

Commit

Permalink
Implement get_egl_display() for GlContextExt trait
Browse files Browse the repository at this point in the history
Fixes: #1078
  • Loading branch information
ceyusa committed Dec 5, 2018
1 parent 1ad6560 commit 22d2f75
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 0 deletions.
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) -> *mut c_void {
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,
}
}
}

0 comments on commit 22d2f75

Please sign in to comment.