Auto merge of #23288 - paulrouget:glutin-21, r=jdm

Glutin 0.21

Fix #23189

Depends on #23233

Dependencies update:
- https://github.com/servo/rust-webvr/pull/73
- https://github.com/servo/skia/pull/172
- https://github.com/servo/rust-glx/pull/23
- https://github.com/servo/rust-offscreen-rendering-context/pull/134

<!-- 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/23288)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-05-22 10:02:14 -04:00 committed by GitHub
commit a911b82e27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 625 additions and 351 deletions

789
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -30,5 +30,5 @@ lazy_static = "1.0"
mach = "0.2.3"
[target.'cfg(all(target_os = "linux", not(any(target_arch = "arm", target_arch = "aarch64"))))'.dependencies]
nix = "~0.11.0"
nix = "0.13"
unwind-sys = "0.1.1"

View file

@ -21,7 +21,7 @@ compositing = {path = "../compositing"}
cssparser = "0.25"
euclid = "0.19"
fnv = "1.0"
gleam = "0.6.4"
gleam = "0.6.7"
half = "1"
ipc-channel = "0.11"
log = "0.4"

View file

@ -33,7 +33,7 @@ msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.2"
ordered-float = "1.0"
parking_lot = "0.6"
parking_lot = "0.7"
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
rayon = "1"

View file

@ -36,7 +36,7 @@ malloc_size_of = { path = "../malloc_size_of" }
metrics = {path = "../metrics"}
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
parking_lot = "0.6"
parking_lot = "0.7"
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
rayon = "1"

View file

@ -79,7 +79,7 @@ mime_guess = "2.0.0-alpha.6"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.2"
parking_lot = "0.6"
parking_lot = "0.7"
phf = "0.7.18"
pixels = {path = "../pixels"}
profile_traits = {path = "../profile_traits"}

View file

@ -53,7 +53,7 @@ num-traits = "0.2"
num-derive = "0.2"
ordered-float = "1.0"
owning_ref = "0.4"
parking_lot = "0.6"
parking_lot = "0.7"
precomputed-hash = "0.1.1"
rayon = "1"
selectors = { path = "../selectors" }

View file

@ -22,7 +22,7 @@ gleam = "0.6"
ipc-channel = "0.11"
log = "0.4"
msg = {path = "../msg"}
rust-webvr = {version = "=0.11.0", features = ["openvr", "vrexternal"]}
rust-webvr = {version = "0.11", features = ["openvr", "vrexternal"]}
script_traits = {path = "../script_traits"}
servo_config = {path = "../config"}
webvr_traits = {path = "../webvr_traits" }

View file

@ -13,5 +13,5 @@ path = "lib.rs"
[dependencies]
ipc-channel = "0.11"
msg = {path = "../msg"}
rust-webvr-api = {version = "=0.11.0", features = ["ipc"]}
rust-webvr-api = {version = "0.11", features = ["ipc"]}
serde = "1.0"

View file

@ -46,13 +46,13 @@ bitflags = "1.0"
crossbeam-channel = "0.3"
euclid = "0.19"
gleam = "0.6"
glutin = "0.19"
glutin = "0.21.0"
keyboard-types = "0.4.3"
lazy_static = "1"
libservo = {path = "../../components/servo"}
libc = "0.2"
log = "0.4"
rust-webvr = { version = "=0.11.0", features = ["glwindow"] }
rust-webvr = { version = "0.11", features = ["glwindow"] }
tinyfiledialogs = "3.0"
[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]

65
ports/glutin/context.rs Normal file
View file

@ -0,0 +1,65 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use glutin::{WindowedContext, NotCurrent, PossiblyCurrent};
pub enum GlContext {
Current(WindowedContext<PossiblyCurrent>),
NotCurrent(WindowedContext<NotCurrent>),
// Used a temporary value as we switch from Current to NotCurrent.
None,
}
impl GlContext {
pub fn window(&self) -> &glutin::Window {
match self {
GlContext::Current(c) => c.window(),
GlContext::NotCurrent(c) => c.window(),
GlContext::None => unreachable!(),
}
}
pub fn make_current(&mut self) {
*self = match std::mem::replace(self, GlContext::None) {
GlContext::Current(c) => {
warn!("Making an already current context current");
GlContext::Current(c)
},
GlContext::NotCurrent(c) => {
let c = unsafe {
c.make_current().expect("Couldn't make window current")
};
GlContext::Current(c)
}
GlContext::None => unreachable!(),
}
}
pub fn make_not_current(&mut self) {
*self = match std::mem::replace(self, GlContext::None) {
GlContext::Current(c) => {
let c = unsafe {
c.make_not_current().expect("Couldn't make window not current")
};
GlContext::NotCurrent(c)
},
GlContext::NotCurrent(c) => {
warn!("Making an already not current context not current");
GlContext::NotCurrent(c)
}
GlContext::None => unreachable!(),
}
}
pub fn swap_buffers(&self) {
match self {
GlContext::Current(c) => {
if let Err(err) = c.swap_buffers() {
warn!("Failed to swap window buffers ({}).", err);
}
},
GlContext::NotCurrent(_) => {
error!("Context is not current. Forgot to call prepare_for_composite?");
},
GlContext::None => unreachable!(),
};
}
}

View file

@ -9,7 +9,6 @@ use crate::events_loop::EventsLoop;
use gleam::gl;
use glutin;
use glutin::dpi::LogicalSize;
use glutin::{ContextBuilder, GlWindow};
use rust_webvr::GlWindowVRService;
use servo::compositing::windowing::EmbedderMethods;
use servo::embedder_traits::EventLoopWaker;
@ -52,14 +51,13 @@ impl EmbedderMethods for EmbedderCallbacks {
.with_dimensions(size)
.with_visibility(false)
.with_multitouch();
let context_builder = ContextBuilder::new()
let context = glutin::ContextBuilder::new()
.with_gl(app::gl_version())
.with_vsync(false); // Assume the browser vsync is the same as the test VR window vsync
let gl_window =
GlWindow::new(window_builder, context_builder, &*self.events_loop.borrow().as_winit())
.expect("Failed to create window.");
.with_vsync(false) // Assume the browser vsync is the same as the test VR window vsync
.build_windowed(window_builder, &*self.events_loop.borrow().as_winit())
.expect("Failed to create window.");
let gl = self.gl.clone();
let (service, heartbeat) = GlWindowVRService::new(name, gl_window, gl);
let (service, heartbeat) = GlWindowVRService::new(name, context, gl);
services.register(Box::new(service));
heartbeats.push(Box::new(heartbeat));

View file

@ -5,6 +5,7 @@
//! A glutin window implementation.
use crate::app;
use crate::context::GlContext;
use crate::keyutils::keyboard_event_from_winit;
use crate::window_trait::{WindowPortsMethods, LINE_HEIGHT};
use euclid::{TypedPoint2D, TypedScale, TypedSize2D, TypedVector2D};
@ -14,7 +15,7 @@ use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use glutin::Icon;
use glutin::{Api, ContextBuilder, GlContext, GlWindow};
use glutin::Api;
use glutin::{ElementState, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use image;
@ -53,7 +54,7 @@ fn builder_with_platform_options(builder: glutin::WindowBuilder) -> glutin::Wind
}
pub struct Window {
gl_window: GlWindow,
gl_context: RefCell<GlContext>,
screen_size: TypedSize2D<u32, DeviceIndependentPixel>,
inner_size: Cell<TypedSize2D<u32, DeviceIndependentPixel>>,
mouse_down_button: Cell<Option<glutin::MouseButton>>,
@ -106,7 +107,7 @@ impl Window {
window_builder = builder_with_platform_options(window_builder);
let mut context_builder = ContextBuilder::new()
let mut context_builder = glutin::ContextBuilder::new()
.with_gl(app::gl_version())
.with_vsync(opts.enable_vsync);
@ -114,21 +115,19 @@ impl Window {
context_builder = context_builder.with_multisampling(MULTISAMPLES)
}
let glutin_window = GlWindow::new(window_builder, context_builder, &events_loop)
let context = context_builder
.build_windowed(window_builder, &events_loop)
.expect("Failed to create window.");
#[cfg(any(target_os = "linux", target_os = "windows"))]
{
let icon_bytes = include_bytes!("../../resources/servo64.png");
glutin_window.set_window_icon(Some(load_icon(icon_bytes)));
context.window().set_window_icon(Some(load_icon(icon_bytes)));
}
unsafe {
glutin_window
.context()
.make_current()
.expect("Couldn't make window current");
}
let context = unsafe {
context.make_current().expect("Couldn't make window current")
};
let primary_monitor = events_loop.get_primary_monitor();
@ -138,19 +137,20 @@ impl Window {
} = primary_monitor.get_dimensions();
let screen_size = TypedSize2D::new(screen_width as u32, screen_height as u32);
// TODO(ajeffrey): can this fail?
let LogicalSize { width, height } = glutin_window
let LogicalSize { width, height } = context
.window()
.get_inner_size()
.expect("Failed to get window inner size.");
let inner_size = TypedSize2D::new(width as u32, height as u32);
glutin_window.show();
context.window().show();
let gl = match glutin_window.context().get_api() {
let gl = match context.get_api() {
Api::OpenGl => unsafe {
gl::GlFns::load_with(|s| glutin_window.get_proc_address(s) as *const _)
gl::GlFns::load_with(|s| context.get_proc_address(s) as *const _)
},
Api::OpenGlEs => unsafe {
gl::GlesFns::load_with(|s| glutin_window.get_proc_address(s) as *const _)
gl::GlesFns::load_with(|s| context.get_proc_address(s) as *const _)
},
Api::WebGl => unreachable!("webgl is unsupported"),
};
@ -159,8 +159,12 @@ impl Window {
gl.clear(gl::COLOR_BUFFER_BIT);
gl.finish();
let mut context = GlContext::Current(context);
context.make_not_current();
let window = Window {
gl_window: glutin_window,
gl_context: RefCell::new(context),
event_queue: RefCell::new(vec![]),
mouse_down_button: Cell::new(None),
mouse_down_point: Cell::new(TypedPoint2D::new(0, 0)),
@ -263,7 +267,7 @@ impl Window {
}
fn device_hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
TypedScale::new(self.gl_window.get_hidpi_factor() as f32)
TypedScale::new(self.gl_context.borrow().window().get_hidpi_factor() as f32)
}
fn servo_hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
@ -289,31 +293,33 @@ impl WindowPortsMethods for Window {
fn page_height(&self) -> f32 {
let dpr = self.servo_hidpi_factor();
let size = self
.gl_window
.gl_context
.borrow()
.window()
.get_inner_size()
.expect("Failed to get window inner size.");
size.height as f32 * dpr.get()
}
fn set_title(&self, title: &str) {
self.gl_window.set_title(title);
self.gl_context.borrow().window().set_title(title);
}
fn set_inner_size(&self, size: DeviceIntSize) {
let size = size.to_f32() / self.device_hidpi_factor();
self.gl_window
self.gl_context.borrow_mut().window()
.set_inner_size(LogicalSize::new(size.width.into(), size.height.into()))
}
fn set_position(&self, point: DeviceIntPoint) {
let point = point.to_f32() / self.device_hidpi_factor();
self.gl_window
self.gl_context.borrow_mut().window()
.set_position(LogicalPosition::new(point.x.into(), point.y.into()))
}
fn set_fullscreen(&self, state: bool) {
if self.fullscreen.get() != state {
self.gl_window
self.gl_context.borrow_mut().window()
.set_fullscreen(Some(self.primary_monitor.clone()));
}
self.fullscreen.set(state);
@ -363,7 +369,7 @@ impl WindowPortsMethods for Window {
Cursor::ZoomOut => MouseCursor::ZoomOut,
_ => MouseCursor::Default,
};
self.gl_window.set_cursor(winit_cursor);
self.gl_context.borrow_mut().window().set_cursor(winit_cursor);
}
fn is_animating(&self) -> bool {
@ -371,7 +377,7 @@ impl WindowPortsMethods for Window {
}
fn id(&self) -> Option<glutin::WindowId> {
Some(self.gl_window.id())
Some(self.gl_context.borrow().window().id())
}
fn winit_event_to_servo_event(&self, event: glutin::WindowEvent) {
@ -435,10 +441,7 @@ impl WindowPortsMethods for Window {
self.event_queue.borrow_mut().push(WindowEvent::Quit);
},
glutin::WindowEvent::Resized(size) => {
// size is DeviceIndependentPixel.
// gl_window.resize() takes DevicePixel.
let size = size.to_physical(self.device_hidpi_factor().get() as f64);
self.gl_window.resize(size);
self.gl_context.borrow_mut().window().set_inner_size(size);
// window.set_inner_size() takes DeviceIndependentPixel.
let (width, height) = size.into();
let new_size = TypedSize2D::new(width, height);
@ -461,11 +464,15 @@ impl WindowMethods for Window {
// TODO(ajeffrey): can this fail?
let dpr = self.device_hidpi_factor();
let LogicalSize { width, height } = self
.gl_window
.gl_context
.borrow()
.window()
.get_outer_size()
.expect("Failed to get window outer size.");
let LogicalPosition { x, y } = self
.gl_window
.gl_context
.borrow()
.window()
.get_position()
.unwrap_or(LogicalPosition::new(0., 0.));
let win_size = (TypedSize2D::new(width as f32, height as f32) * dpr).to_i32();
@ -473,7 +480,9 @@ impl WindowMethods for Window {
let screen = (self.screen_size.to_f32() * dpr).to_i32();
let LogicalSize { width, height } = self
.gl_window
.gl_context
.borrow()
.window()
.get_inner_size()
.expect("Failed to get window inner size.");
let inner_size = (TypedSize2D::new(width as f32, height as f32) * dpr).to_i32();
@ -492,9 +501,8 @@ impl WindowMethods for Window {
}
fn present(&self) {
if let Err(err) = self.gl_window.swap_buffers() {
warn!("Failed to swap window buffers ({}).", err);
}
self.gl_context.borrow().swap_buffers();
self.gl_context.borrow_mut().make_not_current();
}
fn set_animation_state(&self, state: AnimationState) {
@ -502,9 +510,7 @@ impl WindowMethods for Window {
}
fn prepare_for_composite(&self) -> bool {
if let Err(err) = unsafe { self.gl_window.context().make_current() } {
warn!("Couldn't make window current: {}", err);
}
self.gl_context.borrow_mut().make_current();
true
}
}

View file

@ -12,6 +12,7 @@ extern crate sig;
mod app;
mod browser;
mod context;
mod embedder;
mod events_loop;
mod headed_window;

View file

@ -23,7 +23,7 @@ winapi = "0.3.2"
libloading = "0.5"
[build-dependencies]
gl_generator = "0.10"
gl_generator = "0.11"
[features]
default = ["unstable", "default-except-unstable"]

View file

@ -40,7 +40,10 @@ packages = [
"crossbeam-utils",
"digest",
"generic-array",
"gl_generator", # https://github.com/servo/servo/pull/23288#issuecomment-494687746
"nix", # https://github.com/servo/servo/issues/23189#issuecomment-487512605
"rand",
"rand_core",
"unicase",
"winapi",
]

View file

@ -15,7 +15,7 @@ app_units = "0.7"
cssparser = "0.25"
euclid = "0.19"
html5ever = "0.23"
parking_lot = "0.6"
parking_lot = "0.7"
rayon = "1"
serde_json = "1.0"
selectors = {path = "../../../components/selectors"}