Auto merge of #24310 - ceyusa:clean-display-glutin, r=ferjm

Clean up gating and order of getting display/glcontext from glutin

This patch simply simplify the OS gating for getting display and gl
context from glutin since it is only used for a linux, mac and not
UWP-based windows.

Also, in linux tries to fetch the wayland display and don't rely
on EGLDisplay because it might bring problems in servo/media.
Nonetheless it is required to compile render-unix in servo-media
with feature 'gl-wayland'

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because no functional changes, just clean ups

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24310)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-10-02 05:56:49 -04:00 committed by GitHub
commit b6df281b80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 76 deletions

View file

@ -85,13 +85,7 @@ impl GlContext {
pub fn raw_context(&self) -> RawContext { pub fn raw_context(&self) -> RawContext {
match self { match self {
GlContext::Current(c) => { GlContext::Current(c) => {
#[cfg(any( #[cfg(target_os = "linux")]
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
{ {
use glutin::os::unix::RawHandle; use glutin::os::unix::RawHandle;
@ -114,23 +108,14 @@ impl GlContext {
} }
} }
#[cfg(target_os = "android")] // @TODO(victor): https://github.com/rust-windowing/glutin/pull/1221
{ // https://github.com/servo/media/pull/315
let raw_handle = unsafe { c.raw_handle() };
return RawContext::Egl(raw_handle as usize);
}
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
return unimplemented!(); // @TODO(victor): RawContext::Cocoa in servo-media return unimplemented!();
#[cfg(not(any( #[cfg(not(any(
target_os = "linux", target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "windows", target_os = "windows",
target_os = "android",
target_os = "macos", target_os = "macos",
)))] )))]
unimplemented!() unimplemented!()

View file

@ -14,6 +14,8 @@ use gleam::gl;
use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use glutin::os::macos::{ActivationPolicy, WindowBuilderExt}; use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
#[cfg(target_os = "linux")]
use glutin::os::unix::WindowExt;
use glutin::Api; use glutin::Api;
#[cfg(any(target_os = "linux", target_os = "windows"))] #[cfg(any(target_os = "linux", target_os = "windows"))]
use glutin::Icon; use glutin::Icon;
@ -609,10 +611,10 @@ impl WindowMethods for Window {
fn get_gl_context(&self) -> PlayerGLContext { fn get_gl_context(&self) -> PlayerGLContext {
if pref!(media.glvideo.enabled) { if pref!(media.glvideo.enabled) {
self.gl_context.borrow().raw_context() return self.gl_context.borrow().raw_context();
} else {
PlayerGLContext::Unknown
} }
return PlayerGLContext::Unknown;
} }
fn get_native_display(&self) -> NativeDisplay { fn get_native_display(&self) -> NativeDisplay {
@ -620,63 +622,25 @@ impl WindowMethods for Window {
return NativeDisplay::Unknown; return NativeDisplay::Unknown;
} }
#[cfg(any( #[cfg(target_os = "linux")]
target_os = "linux", {
target_os = "dragonfly", if let Some(display) = self.gl_context.borrow().window().get_wayland_display() {
target_os = "freebsd", return NativeDisplay::Wayland(display as usize);
target_os = "netbsd", } else if let Some(display) =
target_os = "openbsd", self.gl_context.borrow().window().get_xlib_display()
target_os = "windows", {
target_os = "android", return NativeDisplay::X11(display as usize);
))]
let native_display = {
if let Some(display) = self.gl_context.borrow().egl_display() {
NativeDisplay::Egl(display as usize)
} else {
#[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() {
NativeDisplay::Wayland(display as usize)
} else if let Some(display) =
self.gl_context.borrow().window().get_xlib_display()
{
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
} }
}; }
#[cfg(not(any( #[cfg(any(target_os = "linux", target_os = "windows"))]
target_os = "linux", {
target_os = "dragonfly", if let Some(display) = self.gl_context.borrow().egl_display() {
target_os = "freebsd", return NativeDisplay::Egl(display as usize);
target_os = "netbsd", }
target_os = "openbsd", }
target_os = "windows",
target_os = "android",
)))]
let native_display = NativeDisplay::Unknown;
native_display NativeDisplay::Unknown
} }
fn get_gl_api(&self) -> GlApi { fn get_gl_api(&self) -> GlApi {