Add more raw context handler for glutin port

This commit is contained in:
Víctor Manuel Jáquez Leal 2019-06-17 11:46:24 +02:00 committed by Fernando Jiménez Moreno
parent 6e2ee394c9
commit eb3857237c
2 changed files with 61 additions and 13 deletions

View file

@ -77,30 +77,53 @@ impl GlContext {
pub fn raw_context(&self) -> RawContext { pub fn raw_context(&self) -> RawContext {
match self { match self {
GlContext::Current(c) => { GlContext::Current(c) => {
let raw_handle = unsafe { c.raw_handle() };
#[cfg(any( #[cfg(any(
target_os = "linux", target_os = "linux",
target_os = "dragonfly", target_os = "dragonfly",
target_os = "freebsd", target_os = "freebsd",
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd" target_os = "openbsd",
))] ))]
{ {
use glutin::os::unix::RawHandle; use glutin::os::unix::RawHandle;
let raw_handle = unsafe { c.raw_handle() };
return match raw_handle { return match raw_handle {
RawHandle::Egl(handle) => RawContext::Egl(handle as usize), RawHandle::Egl(handle) => RawContext::Egl(handle as usize),
RawHandle::Glx(handle) => RawContext::Glx(handle as usize), RawHandle::Glx(handle) => RawContext::Glx(handle as usize),
}; };
} }
#[cfg(target_os = "windows")]
{
use glutin::os::windows::RawHandle;
let raw_handle = unsafe { c.raw_handle() };
return match raw_handle {
RawHandle::Egl(handle) => RawContext::Egl(handle as usize),
// @TODO(victor): RawContext::Wgl in servo-media
RawHandle::Wgl(_) => unimplemented!(),
}
}
#[cfg(target_os = "android")]
{
let raw_handle = unsafe { c.raw_handle() };
return RawContext::Egl(raw_handle as usize);
}
#[cfg(target_os = "macos")]
return unimplemeneted!(); // @TODO(victor): RawContext::Cocoa in servo-media
#[cfg(not(any( #[cfg(not(any(
target_os = "linux", target_os = "linux",
target_os = "dragonfly", target_os = "dragonfly",
target_os = "freebsd", target_os = "freebsd",
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd" target_os = "openbsd",
target_os = "windows",
target_os = "android",
target_os = "macos",
)))] )))]
unimplemented!() unimplemented!()
} }
@ -111,6 +134,7 @@ impl GlContext {
GlContext::None => unreachable!(), GlContext::None => unreachable!(),
} }
} }
pub fn egl_display(&self) -> Option<*const raw::c_void> { pub fn egl_display(&self) -> Option<*const raw::c_void> {
match self { match self {
GlContext::Current(c) => unsafe { c.get_egl_display() }, GlContext::Current(c) => unsafe { c.get_egl_display() },

View file

@ -544,21 +544,43 @@ impl WindowMethods for Window {
target_os = "dragonfly", target_os = "dragonfly",
target_os = "freebsd", target_os = "freebsd",
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd" target_os = "openbsd",
target_os = "windows",
target_os = "android",
))] ))]
let native_display = { let native_display = {
if let Some(display) = self.gl_context.borrow().egl_display() { if let Some(display) = self.gl_context.borrow().egl_display() {
NativeDisplay::Egl(display as usize) NativeDisplay::Egl(display as usize)
} else { } else {
use glutin::os::unix::WindowExt; #[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
{
use glutin::os::unix::WindowExt;
if let Some(display) = self.gl_context.borrow().window().get_wayland_display() { if let Some(display) = self.gl_context.borrow().window().get_wayland_display() {
NativeDisplay::Wayland(display as usize) NativeDisplay::Wayland(display as usize)
} else if let Some(display) = self.gl_context.borrow().window().get_xlib_display() { } else if let Some(display) =
NativeDisplay::X11(display as usize) self.gl_context.borrow().window().get_xlib_display()
} else { {
NativeDisplay::Unknown NativeDisplay::X11(display as usize)
} else {
NativeDisplay::Unknown
}
} }
#[cfg(not(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
)))]
NativeDisplay::Unknown
} }
}; };
@ -567,7 +589,9 @@ impl WindowMethods for Window {
target_os = "dragonfly", target_os = "dragonfly",
target_os = "freebsd", target_os = "freebsd",
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd" target_os = "openbsd",
target_os = "windows",
target_os = "android",
)))] )))]
let native_display = NativeDisplay::Unknown; let native_display = NativeDisplay::Unknown;