Skip to content

Commit

Permalink
Merge pull request rust-windowing#62 from ecoal95/servo-merge
Browse files Browse the repository at this point in the history
Merge from glutin upstream
  • Loading branch information
SimonSapin committed Jan 16, 2016
2 parents 8d02133 + dd2f2d6 commit 7ef1cb7
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 46 deletions.
23 changes: 7 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "servo-glutin"
version = "0.4.6"
version = "0.4.7"
authors = ["tomaka <pierre.krieger1708@gmail.com>"]
description = "Cross-plaform OpenGL context provider."
keywords = ["windowing", "opengl"]
Expand All @@ -18,7 +18,6 @@ default = []
headless = []

[dependencies]
gl_common = "0.1.0"
lazy_static = "0.1.10"
libc = "0.2"
shared_library = "0.1.0"
Expand Down Expand Up @@ -92,47 +91,39 @@ osmesa-sys = "0.0.5"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"
x11-dl = "~2.3"

[target.x86_64-unknown-linux-gnu.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"
x11-dl = "~2.3"

[target.arm-unknown-linux-gnueabihf.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"
x11-dl = "~2.3"

[target.aarch64-unknown-linux-gnu.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"
x11-dl = "~2.3"

[target.x86_64-unknown-dragonfly.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"
x11-dl = "~2.3"

[target.x86_64-unknown-freebsd.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"

[target.i686-unknown-linux-gnu.dependencies.x11]
version = "2.2"
features = ["xlib", "xf86vmode", "xcursor"]

[target.x86_64-unknown-linux-gnu.dependencies.x11]
version = "2.2"
features = ["xlib", "xf86vmode", "xcursor"]
x11-dl = "~2.3"
12 changes: 6 additions & 6 deletions src/api/egl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ unsafe fn choose_fbconfig(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDisp
out.push(ffi::egl::RGB_BUFFER as c_int);
}

if egl_version >= &(1, 3) {
out.push(ffi::egl::SURFACE_TYPE as c_int);
out.push((ffi::egl::WINDOW_BIT | ffi::egl::PBUFFER_BIT) as c_int);
}
out.push(ffi::egl::SURFACE_TYPE as c_int);
// TODO: Some versions of Mesa report a BAD_ATTRIBUTE error
// if we ask for PBUFFER_BIT as well as WINDOW_BIT
out.push((ffi::egl::WINDOW_BIT) as c_int);

match (api, version) {
(Api::OpenGlEs, Some((3, _))) => {
Expand All @@ -495,7 +495,7 @@ unsafe fn choose_fbconfig(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDisp
}
},
(Api::OpenGlEs, _) => unimplemented!(),
(Api::OpenGl, Some((1, _))) => {
(Api::OpenGl, _) => {
if egl_version < &(1, 3) { return Err(CreationError::NoAvailablePixelFormat); }
out.push(ffi::egl::RENDERABLE_TYPE as c_int);
out.push(ffi::egl::OPENGL_BIT as c_int);
Expand Down Expand Up @@ -561,7 +561,7 @@ unsafe fn choose_fbconfig(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDisp
},
}

out.push(0);
out.push(ffi::egl::NONE as c_int);
out
};

Expand Down
13 changes: 7 additions & 6 deletions src/api/glx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) ->

impl Context {
pub fn new<'a>(glx: ffi::glx::Glx, xlib: &ffi::Xlib, pf_reqs: &PixelFormatRequirements,
opengl: &'a GlAttributes<&'a Context>, display: *mut ffi::Display)
-> Result<ContextPrototype<'a>, CreationError>
opengl: &'a GlAttributes<&'a Context>, display: *mut ffi::Display,
screen_id: libc::c_int) -> Result<ContextPrototype<'a>, CreationError>
{
// This is completely ridiculous, but VirtualBox's OpenGL driver needs some call handled by
// *it* (i.e. not Mesa) to occur before anything else can happen. That is because
Expand All @@ -55,14 +55,14 @@ impl Context {

// loading the list of extensions
let extensions = unsafe {
let extensions = glx.QueryExtensionsString(display as *mut _, 0); // FIXME: screen number
let extensions = glx.QueryExtensionsString(display as *mut _, screen_id);
let extensions = CStr::from_ptr(extensions).to_bytes().to_vec();
String::from_utf8(extensions).unwrap()
};

// finding the pixel format we want
let (fb_config, pixel_format) = unsafe {
try!(choose_fbconfig(&glx, &extensions, xlib, display, pf_reqs)
try!(choose_fbconfig(&glx, &extensions, xlib, display, screen_id, pf_reqs)
.map_err(|_| CreationError::NoAvailablePixelFormat))
};

Expand Down Expand Up @@ -355,7 +355,8 @@ fn create_context(glx: &ffi::glx::Glx, extra_functions: &ffi::glx_extra::Glx, ex

/// Enumerates all available FBConfigs
unsafe fn choose_fbconfig(glx: &ffi::glx::Glx, extensions: &str, xlib: &ffi::Xlib,
display: *mut ffi::Display, reqs: &PixelFormatRequirements)
display: *mut ffi::Display, screen_id: libc::c_int,
reqs: &PixelFormatRequirements)
-> Result<(ffi::glx::types::GLXFBConfig, PixelFormat), ()>
{
let descriptor = {
Expand Down Expand Up @@ -459,7 +460,7 @@ unsafe fn choose_fbconfig(glx: &ffi::glx::Glx, extensions: &str, xlib: &ffi::Xli
// calling glXChooseFBConfig
let fb_config = {
let mut num_configs = 1;
let result = glx.ChooseFBConfig(display as *mut _, 0, descriptor.as_ptr(),
let result = glx.ChooseFBConfig(display as *mut _, screen_id, descriptor.as_ptr(),
&mut num_configs);
if result.is_null() { return Err(()); }
if num_configs == 0 { return Err(()); }
Expand Down
10 changes: 5 additions & 5 deletions src/api/wgl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ unsafe fn choose_native_pixel_format(hdc: winapi::HDC, reqs: &PixelFormatRequire
nVersion: 1,
dwFlags: {
let f1 = match reqs.double_buffer {
None => winapi::PFD_DOUBLEBUFFER_DONTCARE,
None => winapi::PFD_DOUBLEBUFFER, // Should be PFD_DOUBLEBUFFER_DONTCARE after you can choose
Some(true) => winapi::PFD_DOUBLEBUFFER,
Some(false) => 0,
};
Expand Down Expand Up @@ -541,10 +541,10 @@ unsafe fn choose_arb_pixel_format(extra: &gl::wgl_extra::Wgl, extensions: &str,
out.push(stencil as c_int);
}

if let Some(double_buffer) = reqs.double_buffer {
out.push(gl::wgl_extra::DOUBLE_BUFFER_ARB as c_int);
out.push(if double_buffer { 1 } else { 0 });
}
// Prefer double buffering if unspecified (probably shouldn't once you can choose)
let double_buffer = reqs.double_buffer.unwrap_or(true);
out.push(gl::wgl_extra::DOUBLE_BUFFER_ARB as c_int);
out.push(if double_buffer { 1 } else { 0 });

if let Some(multisampling) = reqs.multisampling {
if extensions.split(' ').find(|&i| i == "WGL_ARB_multisample").is_some() {
Expand Down
8 changes: 6 additions & 2 deletions src/api/x11/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl XInputEventHandler {
for axis_id in 0..axis_state.mask_len {
if ffi::XIMaskIsSet(&mask, axis_id) {
let axis_value = unsafe{*axis_state.values.offset(axis_count)};
let delta = calc_scroll_deltas(event_data, axis_id, axis_value, &self.axis_list,
let delta = calc_scroll_deltas(event_data, axis_id, axis_value, &self.axis_list,
&mut self.current_state.axis_values);
scroll_delta.0 += delta.0;
scroll_delta.1 += delta.1;
Expand Down Expand Up @@ -314,7 +314,11 @@ fn read_input_axis_info(display: &Arc<XConnection>) -> Vec<Axis> {
}
}
}


unsafe {
(display.xinput2.XIFreeDeviceInfo)(devices);
}

axis_list
}

Expand Down
33 changes: 23 additions & 10 deletions src/api/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::sync::atomic::AtomicBool;
use std::collections::VecDeque;
use std::sync::{Arc, Mutex};
use std::os::raw::c_long;
use std::thread;
use std::time::Duration;

use Api;
use ContextError;
Expand Down Expand Up @@ -366,7 +368,7 @@ impl Window {
// GLX should be preferred over EGL, otherwise crashes may occur
// on X11 – issue #314
if let Some(ref glx) = display.glx {
Prototype::Glx(try!(GlxContext::new(glx.clone(), &display.xlib, pf_reqs, &builder_clone_opengl_glx, display.display)))
Prototype::Glx(try!(GlxContext::new(glx.clone(), &display.xlib, pf_reqs, &builder_clone_opengl_glx, display.display, screen_id)))
} else if let Some(ref egl) = display.egl {
Prototype::Egl(try!(EglContext::new(egl.clone(), pf_reqs, &builder_clone_opengl_egl, egl::NativeDisplay::X11(Some(display.display as *const _)))))
} else {
Expand Down Expand Up @@ -648,15 +650,26 @@ impl Window {
let ref x_window: &XWindow = window.x.borrow();

// XSetInputFocus generates an error if the window is not visible,
// therefore we call XSync before to make sure it's the case
(display.xlib.XSync)(display.display, 0);
(display.xlib.XSetInputFocus)(
display.display,
x_window.window,
ffi::RevertToParent,
ffi::CurrentTime
);
display.check_errors().expect("Failed to call XSetInputFocus");
// therefore we wait until it's the case.
loop {
let mut window_attributes = mem::uninitialized();
(display.xlib.XGetWindowAttributes)(display.display, x_window.window, &mut window_attributes);
display.check_errors().expect("Failed to call XGetWindowAttributes");

if window_attributes.map_state == ffi::IsViewable {
(display.xlib.XSetInputFocus)(
display.display,
x_window.window,
ffi::RevertToParent,
ffi::CurrentTime
);
display.check_errors().expect("Failed to call XSetInputFocus");
break;
}

// Wait about a frame to avoid too-busy waiting
thread::sleep(Duration::from_millis(16));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl Default for PixelFormatRequirements {
alpha_bits: Some(8),
depth_bits: Some(24),
stencil_bits: Some(8),
double_buffer: Some(true),
double_buffer: None,
multisampling: None,
stereoscopy: false,
srgb: false,
Expand Down

0 comments on commit 7ef1cb7

Please sign in to comment.