Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Auto merge of #70 - paulrouget:glutinUpdate, r=mbrubeck
Browse files Browse the repository at this point in the history
Glutin update

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/glutin/70)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Mar 4, 2016
2 parents 99febe6 + 985733d commit 0ae49fe
Show file tree
Hide file tree
Showing 32 changed files with 222 additions and 73 deletions.
23 changes: 17 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "servo-glutin"
version = "0.4.9"
authors = ["tomaka <pierre.krieger1708@gmail.com>"]
version = "0.4.10"
authors = ["The glutin contributors, Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "Cross-platform OpenGL context provider."
keywords = ["windowing", "opengl"]
license = "Apache-2.0"
Expand All @@ -26,9 +26,6 @@ shared_library = "0.1.0"
gl_generator = "0.4"
khronos_api = "1.0"

[dev-dependencies]
clock_ticks = "0.1.0"

[target.arm-linux-androideabi.dependencies.android_glue]
version = "0.1"

Expand All @@ -50,7 +47,7 @@ objc = "0.1.8"
[target.x86_64-apple-darwin.dependencies]
objc = "0.1.8"
cgl = "0.1"
cocoa = "0.2"
cocoa = "0.2.4"
core-foundation = "0"
core-graphics = "0"

Expand Down Expand Up @@ -93,6 +90,13 @@ wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.3"

[target.i586-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.3"

[target.x86_64-unknown-linux-gnu.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
Expand Down Expand Up @@ -134,3 +138,10 @@ wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.3"

[target.x86_64-unknown-openbsd.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.3"
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn main() {
"1.5", "core", &mut file).unwrap();
}

if target.contains("linux") || target.contains("dragonfly") || target.contains("freebsd") {
if target.contains("linux") || target.contains("dragonfly") || target.contains("freebsd") || target.contains("openbsd") {
let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap();
gl_generator::generate_bindings(gl_generator::StructGenerator,
gl_generator::registry::Ns::Glx,
Expand Down
4 changes: 2 additions & 2 deletions examples/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ pub fn load(window: &glutin::Window) -> Context {

unsafe {
let vs = gl.CreateShader(gl::VERTEX_SHADER);
gl.ShaderSource(vs, 1, [VS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
gl.ShaderSource(vs, 1, [VS_SRC.as_ptr() as *const _].as_ptr(), ptr::null());
gl.CompileShader(vs);

let fs = gl.CreateShader(gl::FRAGMENT_SHADER);
gl.ShaderSource(fs, 1, [FS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
gl.ShaderSource(fs, 1, [FS_SRC.as_ptr() as *const _].as_ptr(), ptr::null());
gl.CompileShader(fs);

let program = gl.CreateProgram();
Expand Down
12 changes: 10 additions & 2 deletions src/api/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl MonitorId {
}
}

#[derive(Default)]
pub struct PlatformSpecificWindowBuilderAttributes;
#[derive(Default)]
pub struct PlatformSpecificHeadlessBuilderAttributes;

pub struct PollEventsIterator<'a> {
window: &'a Window,
}
Expand Down Expand Up @@ -116,7 +121,8 @@ impl<'a> Iterator for WaitEventsIterator<'a> {

impl Window {
pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
opengl: &GlAttributes<&Window>, _: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window, CreationError>
{
use std::{mem, ptr};

Expand Down Expand Up @@ -302,7 +308,9 @@ pub struct HeadlessContext(EglContext);
impl HeadlessContext {
/// See the docs in the crate root file.
pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
opengl: &GlAttributes<&HeadlessContext>,
_: &PlatformSpecificHeadlessBuilderAttributes)
-> Result<HeadlessContext, CreationError>
{
let opengl = opengl.clone().map_sharing(|c| &c.0);
let context = try!(EglContext::new(egl::ffi::egl::Egl, pf_reqs, &opengl,
Expand Down
2 changes: 1 addition & 1 deletion src/api/caca/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(any(target_os = "linux", target_os = "freebsd"))]
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
#![allow(unused_variables, dead_code)]

use libc;
Expand Down
7 changes: 6 additions & 1 deletion src/api/cocoa/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use cocoa::appkit::*;
use PixelFormat;
use api::cocoa::helpers;

#[derive(Default)]
pub struct PlatformSpecificHeadlessBuilderAttributes;

pub struct HeadlessContext {
width: u32,
height: u32,
Expand All @@ -21,7 +24,9 @@ pub struct HeadlessContext {

impl HeadlessContext {
pub fn new((width, height): (u32, u32), pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
opengl: &GlAttributes<&HeadlessContext>,
_: &PlatformSpecificHeadlessBuilderAttributes)
-> Result<HeadlessContext, CreationError>
{
let context = unsafe {

Expand Down
36 changes: 23 additions & 13 deletions src/api/cocoa/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg(target_os = "macos")]

pub use self::headless::HeadlessContext;

use {CreationError, Event, MouseCursor, CursorState};
use CreationError::OsError;
use libc;
Expand Down Expand Up @@ -44,12 +42,14 @@ use std::sync::Mutex;
use std::ascii::AsciiExt;
use std::ops::Deref;

use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed, Focused};
use events::ElementState::{Pressed, Released};
use events::MouseButton;
use events;
use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput};
use events::Event::{MouseWheel, Closed, Focused, TouchpadPressure};
use events::{self, MouseButton, TouchPhase};

pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
pub use self::headless::HeadlessContext;
pub use self::headless::PlatformSpecificHeadlessBuilderAttributes;

mod monitor;
mod event;
Expand Down Expand Up @@ -179,6 +179,9 @@ impl Drop for WindowDelegate {
}
}

#[derive(Default)]
pub struct PlatformSpecificWindowBuilderAttributes;

pub struct Window {
view: IdRef,
window: IdRef,
Expand Down Expand Up @@ -222,7 +225,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {
let event: Option<Event>;
unsafe {
let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
NSAnyEventMask.bits(),
NSAnyEventMask.bits() | NSEventMaskPressure.bits(),
NSDate::distantPast(nil),
NSDefaultRunLoopMode,
YES);
Expand All @@ -247,7 +250,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
let event: Option<Event>;
unsafe {
let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
NSAnyEventMask.bits(),
NSAnyEventMask.bits() | NSEventMaskPressure.bits(),
NSDate::distantFuture(nil),
NSDefaultRunLoopMode,
YES);
Expand All @@ -264,7 +267,8 @@ impl<'a> Iterator for WaitEventsIterator<'a> {

impl Window {
pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
opengl: &GlAttributes<&Window>, _: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window, CreationError>
{
if opengl.sharing.is_some() {
unimplemented!()
Expand Down Expand Up @@ -836,7 +840,7 @@ impl Clone for IdRef {
unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
if nsevent == nil { return None; }

let event_type = msg_send![nsevent, type];
let event_type = nsevent.eventType();
NSApp().sendEvent_(if let NSKeyDown = event_type { nil } else { nsevent });

match event_type {
Expand Down Expand Up @@ -867,9 +871,7 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
let received_c_str = nsevent.characters().UTF8String();
let received_str = CStr::from_ptr(received_c_str);
for received_char in from_utf8(received_str.to_bytes()).unwrap().chars() {
if received_char.is_ascii() {
events.push_back(ReceivedCharacter(received_char));
}
events.push_back(ReceivedCharacter(received_char));
}

let vkey = event::vkeycode_to_element(NSEvent::keyCode(nsevent));
Expand Down Expand Up @@ -919,7 +921,15 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
LineDelta(scale_factor * nsevent.scrollingDeltaX() as f32,
scale_factor * nsevent.scrollingDeltaY() as f32)
};
Some(MouseWheel(delta))
let phase = match nsevent.phase() {
NSEventPhaseMayBegin | NSEventPhaseBegan => TouchPhase::Started,
NSEventPhaseEnded => TouchPhase::Ended,
_ => TouchPhase::Moved,
};
Some(MouseWheel(delta, phase))
},
NSEventTypePressure => {
Some(TouchpadPressure(nsevent.pressure(), nsevent.stage()))
},
_ => { None },
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/dlopen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
#![allow(dead_code)]

use std::os::raw::{c_void, c_char, c_int};
Expand Down
2 changes: 1 addition & 1 deletion src/api/egl/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ pub type EGLNativeWindowType = winapi::HWND;
pub type EGLNativeWindowType = *const libc::c_void;
#[cfg(target_os = "android")]
pub type EGLNativeWindowType = *const libc::c_void;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
pub type EGLNativeWindowType = *const libc::c_void;
2 changes: 1 addition & 1 deletion src/api/egl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(any(target_os = "windows", target_os = "linux", target_os = "android",
target_os = "dragonfly", target_os = "freebsd"))]
target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
#![allow(unused_variables)]

use ContextError;
Expand Down
39 changes: 31 additions & 8 deletions src/api/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

use std::ffi::CString;
use libc;
use {Event, BuilderAttribs, CreationError, MouseCursor};
use Api;
use PixelFormat;
use Event;
use CreationError;
use ContextError;
use CursorState;
use GlAttributes;
use GlContext;
use MouseCursor;
use PixelFormat;
use PixelFormatRequirements;
use WindowAttributes;

use std::collections::VecDeque;

Expand Down Expand Up @@ -52,6 +58,7 @@ impl WindowProxy {
}
}

#[derive(Clone)]
pub struct MonitorId;

#[inline]
Expand All @@ -72,14 +79,21 @@ impl MonitorId {
Some("Canvas".to_owned())
}

#[inline]
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
::native_monitor::NativeMonitorId::Unavailable
}

#[inline]
pub fn get_dimensions(&self) -> (u32, u32) {
unimplemented!()
}
}

impl Window {
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
{
// getting the default values of attributes
let mut attributes = unsafe {
use std::mem;
Expand Down Expand Up @@ -198,14 +212,23 @@ impl Window {
}

#[inline]
pub fn set_cursor(&self, _cursor: MouseCursor) {
unimplemented!()
pub fn set_cursor(&self, cursor: MouseCursor) {
}

#[inline]
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
Ok(())
}

#[inline]
pub fn hidpi_factor(&self) -> f32 {
1.0
}

#[inline]
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
Ok(())
}
}

impl GlContext for Window {
Expand All @@ -222,11 +245,11 @@ impl GlContext for Window {
}

fn get_proc_address(&self, addr: &str) -> *const () {
let addr = CString::new(addr.as_bytes()).unwrap();
let addr = addr.as_ptr();
let addr = CString::new(addr).unwrap();

unsafe {
ffi::emscripten_GetProcAddress(addr) as *const _
// FIXME: if `as_ptr()` is used, then wrong data is passed to emscripten
ffi::emscripten_GetProcAddress(addr.into_raw() as *const _) as *const _
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/glx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]

use ContextError;
use CreationError;
Expand Down
6 changes: 5 additions & 1 deletion src/api/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,14 @@ impl MonitorId {
}
}

#[derive(Default)]
pub struct PlatformSpecificWindowBuilderAttributes;

impl Window {

pub fn new(builder: &WindowAttributes, _: &PixelFormatRequirements, _: &GlAttributes<&Window>) -> Result<Window, CreationError> {
pub fn new(builder: &WindowAttributes, _: &PixelFormatRequirements, _: &GlAttributes<&Window>,
_: &PlatformSpecificWindowBuilderAttributes) -> Result<Window, CreationError>
{
unsafe {
if setjmp(mem::transmute(&mut jmpbuf)) != 0 {
let app: id = msg_send![Class::get("UIApplication").unwrap(), sharedApplication];
Expand Down
2 changes: 1 addition & 1 deletion src/api/osmesa/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]

extern crate osmesa_sys;

Expand Down
Loading

0 comments on commit 0ae49fe

Please sign in to comment.