mirror of
https://github.com/servo/servo.git
synced 2025-09-10 15:08:21 +01:00
Add OSMesa headless mode, run WPT against Webrender, update tests.
This commit is contained in:
parent
06bb57bdcb
commit
cdb69d4423
164 changed files with 2095 additions and 458 deletions
44
ports/cef/Cargo.lock
generated
44
ports/cef/Cargo.lock
generated
|
@ -208,7 +208,7 @@ dependencies = [
|
|||
"ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"plugins 0.0.1",
|
||||
"util 0.0.1",
|
||||
"webrender_traits 0.5.1 (git+https://github.com/servo/webrender)",
|
||||
|
@ -326,7 +326,7 @@ dependencies = [
|
|||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"offscreen_gl_context 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"plugins 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -809,6 +809,8 @@ dependencies = [
|
|||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"osmesa-src 12.0.1 (git+https://github.com/servo/osmesa-src)",
|
||||
"osmesa-sys 0.1.2 (git+https://github.com/daggerbot/osmesa-rs)",
|
||||
"script_traits 0.0.1",
|
||||
"servo-egl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"servo-glutin 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1488,7 +1490,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "offscreen_gl_context"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1497,6 +1499,7 @@ dependencies = [
|
|||
"gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"x11 2.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -1575,9 +1578,22 @@ dependencies = [
|
|||
"unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "osmesa-src"
|
||||
version = "12.0.1"
|
||||
source = "git+https://github.com/servo/osmesa-src#aaccb7b7acdbcd54708db6530cea4177642cf64c"
|
||||
|
||||
[[package]]
|
||||
name = "osmesa-sys"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = "git+https://github.com/daggerbot/osmesa-rs#7ef7ebc612302794e7ed3bd068c93b70950218a1"
|
||||
dependencies = [
|
||||
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "osmesa-sys"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1822,7 +1838,7 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"phf_macros 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1896,7 +1912,7 @@ dependencies = [
|
|||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"offscreen_gl_context 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"plugins 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2063,7 +2079,7 @@ dependencies = [
|
|||
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"osmesa-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2505,7 +2521,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "webrender"
|
||||
version = "0.5.1"
|
||||
source = "git+https://github.com/servo/webrender#58b9e983a5e74ac1670fcf67f9c2ba68740ab2cc"
|
||||
source = "git+https://github.com/servo/webrender#cf945d15c71c757c6694b40a38fd7cfef1a2f827"
|
||||
dependencies = [
|
||||
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2521,7 +2537,7 @@ dependencies = [
|
|||
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"webrender_traits 0.5.1 (git+https://github.com/servo/webrender)",
|
||||
|
@ -2530,7 +2546,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "webrender_traits"
|
||||
version = "0.5.1"
|
||||
source = "git+https://github.com/servo/webrender#58b9e983a5e74ac1670fcf67f9c2ba68740ab2cc"
|
||||
source = "git+https://github.com/servo/webrender#cf945d15c71c757c6694b40a38fd7cfef1a2f827"
|
||||
dependencies = [
|
||||
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2539,7 +2555,7 @@ dependencies = [
|
|||
"gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -2756,7 +2772,7 @@ dependencies = [
|
|||
"checksum num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "cee7e88156f3f9e19bdd598f8d6c9db7bf4078f99f8381f43a55b09648d1a6e3"
|
||||
"checksum objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7c9311aa5acd7bee14476afa0f0557f564e9d0d61218a8b833d9b1f871fa5fba"
|
||||
"checksum odds 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "f3701cfdec1676e319ad37ff96c31de39df8c92006032976153366f52693bf40"
|
||||
"checksum offscreen_gl_context 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0860b03349dd951ade7f4fdb1f6724a76a3750b094a760d2aeee1af1d4706400"
|
||||
"checksum offscreen_gl_context 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ffcda42bebbbbee2b403bc46d8ea85e0dcf25b5242592bde6eae7788d67cd655"
|
||||
"checksum ogg 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "426d8dc59cdd206be1925461087350385c0a02f291d87625829c6d08e72b457b"
|
||||
"checksum ogg_metadata 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e755cc735fa6faa709cb23048433d9201d6caa85fa96215386ccdd5e9b40ad01"
|
||||
"checksum open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c228597177bc4a6876e278f7c7948ac033bfcb4d163ccdd5a009557c8fe5fa1e"
|
||||
|
@ -2765,7 +2781,9 @@ dependencies = [
|
|||
"checksum openssl-sys-extras 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)" = "11c5e1dba7d3d03d80f045bf0d60111dc69213b67651e7c889527a3badabb9fa"
|
||||
"checksum openssl-verify 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ed86cce894f6b0ed4572e21eb34026f1dc8869cb9ee3869029131bc8c3feb2d"
|
||||
"checksum ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cc511538298611a79d5a4ddfbb75315b866d942ed26a00bdc3590795c68b7279"
|
||||
"checksum osmesa-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b0040392971435cdab6bb52f0d4dc2fbb959c90b4263bec33af6ef092f8f828d"
|
||||
"checksum osmesa-src 12.0.1 (git+https://github.com/servo/osmesa-src)" = "<none>"
|
||||
"checksum osmesa-sys 0.1.2 (git+https://github.com/daggerbot/osmesa-rs)" = "<none>"
|
||||
"checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b"
|
||||
"checksum phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)" = "52c875926de24c01b5b69153eaa258b57920a39b44bbce8ef1f2052a6c5a6a1a"
|
||||
"checksum phf_codegen 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0a8912c2cc0ea2e8ae70388ec0af9a445e7ab37b3c9cc61f059c2b34db8ed50b"
|
||||
"checksum phf_generator 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)" = "04b5ea825e28cb6efd89d9133b129b2003b45a221aeda025509b125b00ecb7c4"
|
||||
|
|
|
@ -23,6 +23,9 @@ style_traits = {path = "../../components/style_traits"}
|
|||
url = {version = "1.2", features = ["heap_size"]}
|
||||
util = {path = "../../components/util"}
|
||||
|
||||
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
|
||||
osmesa-sys = {git = "https://github.com/daggerbot/osmesa-rs"}
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
x11 = "2.0.0"
|
||||
|
||||
|
@ -33,3 +36,9 @@ servo-egl = "0.2"
|
|||
winapi = "0.2"
|
||||
user32-sys = "0.2"
|
||||
gdi32-sys = "0.2"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
osmesa-src = {git = "https://github.com/servo/osmesa-src"}
|
||||
|
||||
[target.x86_64-unknown-linux-gnu.dependencies]
|
||||
osmesa-src = {git = "https://github.com/servo/osmesa-src"}
|
||||
|
|
|
@ -17,6 +17,7 @@ extern crate layers;
|
|||
#[macro_use] extern crate log;
|
||||
extern crate msg;
|
||||
extern crate net_traits;
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))] extern crate osmesa_sys;
|
||||
extern crate script_traits;
|
||||
extern crate style_traits;
|
||||
extern crate url;
|
||||
|
|
|
@ -24,10 +24,17 @@ use layers::platform::surface::NativeDisplay;
|
|||
use msg::constellation_msg::{self, Key};
|
||||
use msg::constellation_msg::{ALT, CONTROL, KeyState, NONE, SHIFT, SUPER};
|
||||
use net_traits::net_error_list::NetError;
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
use osmesa_sys;
|
||||
use script_traits::{TouchEventType, TouchpadPressurePhase};
|
||||
use std::cell::{Cell, RefCell};
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
use std::ffi::CString;
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
use std::mem;
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{Sender, channel};
|
||||
use style_traits::cursor::Cursor;
|
||||
|
@ -91,9 +98,88 @@ fn builder_with_platform_options(builder: glutin::WindowBuilder) -> glutin::Wind
|
|||
builder
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
struct HeadlessContext {
|
||||
width: u32,
|
||||
height: u32,
|
||||
_context: osmesa_sys::OSMesaContext,
|
||||
_buffer: Vec<u32>,
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
struct HeadlessContext {
|
||||
width: u32,
|
||||
height: u32,
|
||||
}
|
||||
|
||||
impl HeadlessContext {
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
fn new(width: u32, height: u32) -> HeadlessContext {
|
||||
let mut attribs = Vec::new();
|
||||
|
||||
attribs.push(osmesa_sys::OSMESA_PROFILE);
|
||||
attribs.push(osmesa_sys::OSMESA_CORE_PROFILE);
|
||||
attribs.push(osmesa_sys::OSMESA_CONTEXT_MAJOR_VERSION);
|
||||
attribs.push(3);
|
||||
attribs.push(osmesa_sys::OSMESA_CONTEXT_MINOR_VERSION);
|
||||
attribs.push(3);
|
||||
attribs.push(0);
|
||||
|
||||
let context = unsafe {
|
||||
osmesa_sys::OSMesaCreateContextAttribs(attribs.as_ptr(), ptr::null_mut())
|
||||
};
|
||||
|
||||
assert!(!context.is_null());
|
||||
|
||||
let mut buffer = vec![0; (width * height) as usize];
|
||||
|
||||
unsafe {
|
||||
let ret = osmesa_sys::OSMesaMakeCurrent(context,
|
||||
buffer.as_mut_ptr() as *mut _,
|
||||
gl::UNSIGNED_BYTE,
|
||||
width as i32,
|
||||
height as i32);
|
||||
assert!(ret != 0);
|
||||
};
|
||||
|
||||
HeadlessContext {
|
||||
width: width,
|
||||
height: height,
|
||||
_context: context,
|
||||
_buffer: buffer,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
fn new(width: u32, height: u32) -> HeadlessContext {
|
||||
HeadlessContext {
|
||||
width: width,
|
||||
height: height,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
fn get_proc_address(s: &str) -> *const c_void {
|
||||
let c_str = CString::new(s).expect("Unable to create CString");
|
||||
unsafe {
|
||||
mem::transmute(osmesa_sys::OSMesaGetProcAddress(c_str.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
fn get_proc_address(_: &str) -> *const c_void {
|
||||
ptr::null() as *const _
|
||||
}
|
||||
}
|
||||
|
||||
enum WindowKind {
|
||||
Window(glutin::Window),
|
||||
Headless(HeadlessContext),
|
||||
}
|
||||
|
||||
/// The type of a window.
|
||||
pub struct Window {
|
||||
window: glutin::Window,
|
||||
kind: WindowKind,
|
||||
|
||||
mouse_down_button: Cell<Option<glutin::MouseButton>>,
|
||||
mouse_down_point: Cell<Point2D<i32>>,
|
||||
|
@ -139,43 +225,55 @@ impl Window {
|
|||
// #9996.
|
||||
let visible = is_foreground && !opts::get().no_native_titlebar;
|
||||
|
||||
let window_kind = if opts::get().headless {
|
||||
WindowKind::Headless(HeadlessContext::new(width, height))
|
||||
} else {
|
||||
let mut builder =
|
||||
glutin::WindowBuilder::new().with_title("Servo".to_string())
|
||||
.with_decorations(!opts::get().no_native_titlebar)
|
||||
.with_transparency(opts::get().no_native_titlebar)
|
||||
.with_dimensions(width, height)
|
||||
.with_gl(Window::gl_version())
|
||||
.with_visibility(visible)
|
||||
.with_parent(parent)
|
||||
.with_multitouch();
|
||||
|
||||
let mut builder =
|
||||
glutin::WindowBuilder::new().with_title("Servo".to_string())
|
||||
.with_decorations(!opts::get().no_native_titlebar)
|
||||
.with_transparency(opts::get().no_native_titlebar)
|
||||
.with_dimensions(width, height)
|
||||
.with_gl(Window::gl_version())
|
||||
.with_visibility(visible)
|
||||
.with_parent(parent)
|
||||
.with_multitouch();
|
||||
if let Ok(mut icon_path) = resource_files::resources_dir_path() {
|
||||
icon_path.push("servo.png");
|
||||
builder = builder.with_icon(icon_path);
|
||||
}
|
||||
|
||||
if opts::get().enable_vsync {
|
||||
builder = builder.with_vsync();
|
||||
}
|
||||
|
||||
if let Ok(mut icon_path) = resource_files::resources_dir_path() {
|
||||
icon_path.push("servo.png");
|
||||
builder = builder.with_icon(icon_path);
|
||||
if opts::get().use_msaa {
|
||||
builder = builder.with_multisampling(MULTISAMPLES)
|
||||
}
|
||||
|
||||
builder = builder_with_platform_options(builder);
|
||||
|
||||
let mut glutin_window = builder.build().expect("Failed to create window.");
|
||||
|
||||
unsafe { glutin_window.make_current().expect("Failed to make context current!") }
|
||||
|
||||
glutin_window.set_window_resize_callback(Some(Window::nested_window_resize as fn(u32, u32)));
|
||||
|
||||
WindowKind::Window(glutin_window)
|
||||
};
|
||||
|
||||
Window::load_gl_functions(&window_kind);
|
||||
|
||||
if opts::get().headless {
|
||||
// Print some information about the headless renderer that
|
||||
// can be useful in diagnosing CI failures on build machines.
|
||||
println!("{}", gl::get_string(gl::VENDOR));
|
||||
println!("{}", gl::get_string(gl::RENDERER));
|
||||
println!("{}", gl::get_string(gl::VERSION));
|
||||
}
|
||||
|
||||
if opts::get().enable_vsync {
|
||||
builder = builder.with_vsync();
|
||||
}
|
||||
|
||||
if opts::get().use_msaa {
|
||||
builder = builder.with_multisampling(MULTISAMPLES)
|
||||
}
|
||||
|
||||
builder = builder_with_platform_options(builder);
|
||||
|
||||
let mut glutin_window = builder.build().expect("Failed to create window.");
|
||||
|
||||
unsafe { glutin_window.make_current().expect("Failed to make context current!") }
|
||||
|
||||
glutin_window.set_window_resize_callback(Some(Window::nested_window_resize as fn(u32, u32)));
|
||||
|
||||
Window::load_gl_functions(&glutin_window);
|
||||
|
||||
let window = Window {
|
||||
window: glutin_window,
|
||||
kind: window_kind,
|
||||
event_queue: RefCell::new(vec!()),
|
||||
mouse_down_button: Cell::new(None),
|
||||
mouse_down_point: Cell::new(Point2D::new(0, 0)),
|
||||
|
@ -197,7 +295,14 @@ impl Window {
|
|||
}
|
||||
|
||||
pub fn platform_window(&self) -> glutin::WindowID {
|
||||
unsafe { glutin::WindowID::new(self.window.platform_window()) }
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
unsafe { glutin::WindowID::new(window.platform_window()) }
|
||||
}
|
||||
WindowKind::Headless(..) => {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn nested_window_resize(width: u32, height: u32) {
|
||||
|
@ -233,12 +338,21 @@ impl Window {
|
|||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn load_gl_functions(window: &glutin::Window) {
|
||||
gl::load_with(|s| window.get_proc_address(s) as *const c_void);
|
||||
fn load_gl_functions(window_kind: &WindowKind) {
|
||||
match window_kind {
|
||||
&WindowKind::Window(ref window) => {
|
||||
gl::load_with(|s| window.get_proc_address(s) as *const c_void);
|
||||
}
|
||||
&WindowKind::Headless(..) => {
|
||||
gl::load_with(|s| {
|
||||
HeadlessContext::get_proc_address(s)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn load_gl_functions(_: &glutin::Window) {
|
||||
fn load_gl_functions(_: &WindowKind) {
|
||||
}
|
||||
|
||||
fn handle_window_event(&self, event: glutin::Event) -> bool {
|
||||
|
@ -417,23 +531,30 @@ impl Window {
|
|||
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
fn handle_next_event(&self) -> bool {
|
||||
let event = match self.window.wait_events().next() {
|
||||
None => {
|
||||
warn!("Window event stream closed.");
|
||||
return false;
|
||||
},
|
||||
Some(event) => event,
|
||||
};
|
||||
let mut close = self.handle_window_event(event);
|
||||
if !close {
|
||||
while let Some(event) = self.window.poll_events().next() {
|
||||
if self.handle_window_event(event) {
|
||||
close = true;
|
||||
break
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
let event = match window.wait_events().next() {
|
||||
None => {
|
||||
warn!("Window event stream closed.");
|
||||
return false;
|
||||
},
|
||||
Some(event) => event,
|
||||
};
|
||||
let mut close = self.handle_window_event(event);
|
||||
if !close {
|
||||
while let Some(event) = window.poll_events().next() {
|
||||
if self.handle_window_event(event) {
|
||||
close = true;
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
close
|
||||
}
|
||||
WindowKind::Headless(..) => {
|
||||
false
|
||||
}
|
||||
}
|
||||
close
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
|
@ -445,23 +566,30 @@ impl Window {
|
|||
// because it doesn't call X11 functions from another thread, so doesn't
|
||||
// hit the same issues explained below.
|
||||
if opts::get().use_webrender {
|
||||
let event = match self.window.wait_events().next() {
|
||||
None => {
|
||||
warn!("Window event stream closed.");
|
||||
return false;
|
||||
},
|
||||
Some(event) => event,
|
||||
};
|
||||
let mut close = self.handle_window_event(event);
|
||||
if !close {
|
||||
while let Some(event) = self.window.poll_events().next() {
|
||||
if self.handle_window_event(event) {
|
||||
close = true;
|
||||
break
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
let event = match window.wait_events().next() {
|
||||
None => {
|
||||
warn!("Window event stream closed.");
|
||||
return false;
|
||||
},
|
||||
Some(event) => event,
|
||||
};
|
||||
let mut close = self.handle_window_event(event);
|
||||
if !close {
|
||||
while let Some(event) = window.poll_events().next() {
|
||||
if self.handle_window_event(event) {
|
||||
close = true;
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
close
|
||||
}
|
||||
WindowKind::Headless(..) => {
|
||||
false
|
||||
}
|
||||
}
|
||||
close
|
||||
} else {
|
||||
// TODO(gw): This is an awful hack to work around the
|
||||
// broken way we currently call X11 from multiple threads.
|
||||
|
@ -480,14 +608,21 @@ impl Window {
|
|||
//
|
||||
// See https://github.com/servo/servo/issues/5780
|
||||
//
|
||||
let first_event = self.window.poll_events().next();
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
let first_event = window.poll_events().next();
|
||||
|
||||
match first_event {
|
||||
Some(event) => {
|
||||
self.handle_window_event(event)
|
||||
match first_event {
|
||||
Some(event) => {
|
||||
self.handle_window_event(event)
|
||||
}
|
||||
None => {
|
||||
thread::sleep(Duration::from_millis(16));
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
thread::sleep(Duration::from_millis(16));
|
||||
WindowKind::Headless(..) => {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -504,8 +639,13 @@ impl Window {
|
|||
// polling so that we don't block on a GUI event
|
||||
// such as mouse click.
|
||||
if opts::get().output_file.is_some() || opts::get().exit_after_load || opts::get().headless {
|
||||
while let Some(event) = self.window.poll_events().next() {
|
||||
close_event = self.handle_window_event(event) || close_event;
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
while let Some(event) = window.poll_events().next() {
|
||||
close_event = self.handle_window_event(event) || close_event;
|
||||
}
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
}
|
||||
} else {
|
||||
close_event = self.handle_next_event();
|
||||
|
@ -671,44 +811,89 @@ fn create_window_proxy(_: &Window) -> Option<glutin::WindowProxy> {
|
|||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn create_window_proxy(window: &Window) -> Option<glutin::WindowProxy> {
|
||||
Some(window.window.create_window_proxy())
|
||||
match window.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
Some(window.create_window_proxy())
|
||||
}
|
||||
WindowKind::Headless(..) => {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WindowMethods for Window {
|
||||
fn framebuffer_size(&self) -> TypedSize2D<u32, DevicePixel> {
|
||||
let scale_factor = self.window.hidpi_factor() as u32;
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (width, height) = self.window.get_inner_size().expect("Failed to get window inner size.");
|
||||
TypedSize2D::new(width * scale_factor, height * scale_factor)
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
let scale_factor = window.hidpi_factor() as u32;
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (width, height) = window.get_inner_size().expect("Failed to get window inner size.");
|
||||
TypedSize2D::new(width * scale_factor, height * scale_factor)
|
||||
}
|
||||
WindowKind::Headless(ref context) => {
|
||||
TypedSize2D::new(context.width, context.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size(&self) -> TypedSize2D<f32, ScreenPx> {
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (width, height) = self.window.get_inner_size().expect("Failed to get window inner size.");
|
||||
TypedSize2D::new(width as f32, height as f32)
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (width, height) = window.get_inner_size().expect("Failed to get window inner size.");
|
||||
TypedSize2D::new(width as f32, height as f32)
|
||||
}
|
||||
WindowKind::Headless(ref context) => {
|
||||
TypedSize2D::new(context.width as f32, context.height as f32)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn client_window(&self) -> (Size2D<u32>, Point2D<i32>) {
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (width, height) = self.window.get_outer_size().expect("Failed to get window outer size.");
|
||||
let size = Size2D::new(width, height);
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (x, y) = self.window.get_position().expect("Failed to get window position.");
|
||||
let origin = Point2D::new(x as i32, y as i32);
|
||||
(size, origin)
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (width, height) = window.get_outer_size().expect("Failed to get window outer size.");
|
||||
let size = Size2D::new(width, height);
|
||||
// TODO(ajeffrey): can this fail?
|
||||
let (x, y) = window.get_position().expect("Failed to get window position.");
|
||||
let origin = Point2D::new(x as i32, y as i32);
|
||||
(size, origin)
|
||||
}
|
||||
WindowKind::Headless(ref context) => {
|
||||
let size = TypedSize2D::new(context.width, context.height);
|
||||
(size, Point2D::zero())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn set_inner_size(&self, size: Size2D<u32>) {
|
||||
self.window.set_inner_size(size.width as u32, size.height as u32)
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
window.set_inner_size(size.width as u32, size.height as u32)
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_position(&self, point: Point2D<i32>) {
|
||||
self.window.set_position(point.x, point.y)
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
window.set_position(point.x, point.y)
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn present(&self) {
|
||||
if let Err(err) = self.window.swap_buffers() {
|
||||
warn!("Failed to swap window buffers ({}).", err);
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
if let Err(err) = window.swap_buffers() {
|
||||
warn!("Failed to swap window buffers ({}).", err);
|
||||
}
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -727,7 +912,14 @@ impl WindowMethods for Window {
|
|||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel> {
|
||||
ScaleFactor::new(self.window.hidpi_factor())
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
ScaleFactor::new(window.hidpi_factor())
|
||||
}
|
||||
WindowKind::Headless(..) => {
|
||||
ScaleFactor::new(1.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
|
@ -738,18 +930,23 @@ impl WindowMethods for Window {
|
|||
}
|
||||
|
||||
fn set_page_title(&self, title: Option<String>) {
|
||||
let fallback_title: String = if let Some(ref current_url) = *self.current_url.borrow() {
|
||||
current_url.to_string()
|
||||
} else {
|
||||
String::from("Untitled")
|
||||
};
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
let fallback_title: String = if let Some(ref current_url) = *self.current_url.borrow() {
|
||||
current_url.to_string()
|
||||
} else {
|
||||
String::from("Untitled")
|
||||
};
|
||||
|
||||
let title = match title {
|
||||
Some(ref title) if title.len() > 0 => &**title,
|
||||
_ => &fallback_title,
|
||||
};
|
||||
let title = format!("{} - Servo", title);
|
||||
self.window.set_title(&title);
|
||||
let title = match title {
|
||||
Some(ref title) if title.len() > 0 => &**title,
|
||||
_ => &fallback_title,
|
||||
};
|
||||
let title = format!("{} - Servo", title);
|
||||
window.set_title(&title);
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_page_url(&self, url: Url) {
|
||||
|
@ -764,7 +961,12 @@ impl WindowMethods for Window {
|
|||
|
||||
fn load_end(&self, _: bool, _: bool, root: bool) {
|
||||
if root && opts::get().no_native_titlebar {
|
||||
self.window.show()
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
window.show();
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -776,46 +978,51 @@ impl WindowMethods for Window {
|
|||
|
||||
/// Has no effect on Android.
|
||||
fn set_cursor(&self, c: Cursor) {
|
||||
use glutin::MouseCursor;
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
use glutin::MouseCursor;
|
||||
|
||||
let glutin_cursor = match c {
|
||||
Cursor::None => MouseCursor::NoneCursor,
|
||||
Cursor::Default => MouseCursor::Default,
|
||||
Cursor::Pointer => MouseCursor::Hand,
|
||||
Cursor::ContextMenu => MouseCursor::ContextMenu,
|
||||
Cursor::Help => MouseCursor::Help,
|
||||
Cursor::Progress => MouseCursor::Progress,
|
||||
Cursor::Wait => MouseCursor::Wait,
|
||||
Cursor::Cell => MouseCursor::Cell,
|
||||
Cursor::Crosshair => MouseCursor::Crosshair,
|
||||
Cursor::Text => MouseCursor::Text,
|
||||
Cursor::VerticalText => MouseCursor::VerticalText,
|
||||
Cursor::Alias => MouseCursor::Alias,
|
||||
Cursor::Copy => MouseCursor::Copy,
|
||||
Cursor::Move => MouseCursor::Move,
|
||||
Cursor::NoDrop => MouseCursor::NoDrop,
|
||||
Cursor::NotAllowed => MouseCursor::NotAllowed,
|
||||
Cursor::Grab => MouseCursor::Grab,
|
||||
Cursor::Grabbing => MouseCursor::Grabbing,
|
||||
Cursor::EResize => MouseCursor::EResize,
|
||||
Cursor::NResize => MouseCursor::NResize,
|
||||
Cursor::NeResize => MouseCursor::NeResize,
|
||||
Cursor::NwResize => MouseCursor::NwResize,
|
||||
Cursor::SResize => MouseCursor::SResize,
|
||||
Cursor::SeResize => MouseCursor::SeResize,
|
||||
Cursor::SwResize => MouseCursor::SwResize,
|
||||
Cursor::WResize => MouseCursor::WResize,
|
||||
Cursor::EwResize => MouseCursor::EwResize,
|
||||
Cursor::NsResize => MouseCursor::NsResize,
|
||||
Cursor::NeswResize => MouseCursor::NeswResize,
|
||||
Cursor::NwseResize => MouseCursor::NwseResize,
|
||||
Cursor::ColResize => MouseCursor::ColResize,
|
||||
Cursor::RowResize => MouseCursor::RowResize,
|
||||
Cursor::AllScroll => MouseCursor::AllScroll,
|
||||
Cursor::ZoomIn => MouseCursor::ZoomIn,
|
||||
Cursor::ZoomOut => MouseCursor::ZoomOut,
|
||||
};
|
||||
self.window.set_cursor(glutin_cursor);
|
||||
let glutin_cursor = match c {
|
||||
Cursor::None => MouseCursor::NoneCursor,
|
||||
Cursor::Default => MouseCursor::Default,
|
||||
Cursor::Pointer => MouseCursor::Hand,
|
||||
Cursor::ContextMenu => MouseCursor::ContextMenu,
|
||||
Cursor::Help => MouseCursor::Help,
|
||||
Cursor::Progress => MouseCursor::Progress,
|
||||
Cursor::Wait => MouseCursor::Wait,
|
||||
Cursor::Cell => MouseCursor::Cell,
|
||||
Cursor::Crosshair => MouseCursor::Crosshair,
|
||||
Cursor::Text => MouseCursor::Text,
|
||||
Cursor::VerticalText => MouseCursor::VerticalText,
|
||||
Cursor::Alias => MouseCursor::Alias,
|
||||
Cursor::Copy => MouseCursor::Copy,
|
||||
Cursor::Move => MouseCursor::Move,
|
||||
Cursor::NoDrop => MouseCursor::NoDrop,
|
||||
Cursor::NotAllowed => MouseCursor::NotAllowed,
|
||||
Cursor::Grab => MouseCursor::Grab,
|
||||
Cursor::Grabbing => MouseCursor::Grabbing,
|
||||
Cursor::EResize => MouseCursor::EResize,
|
||||
Cursor::NResize => MouseCursor::NResize,
|
||||
Cursor::NeResize => MouseCursor::NeResize,
|
||||
Cursor::NwResize => MouseCursor::NwResize,
|
||||
Cursor::SResize => MouseCursor::SResize,
|
||||
Cursor::SeResize => MouseCursor::SeResize,
|
||||
Cursor::SwResize => MouseCursor::SwResize,
|
||||
Cursor::WResize => MouseCursor::WResize,
|
||||
Cursor::EwResize => MouseCursor::EwResize,
|
||||
Cursor::NsResize => MouseCursor::NsResize,
|
||||
Cursor::NeswResize => MouseCursor::NeswResize,
|
||||
Cursor::NwseResize => MouseCursor::NwseResize,
|
||||
Cursor::ColResize => MouseCursor::ColResize,
|
||||
Cursor::RowResize => MouseCursor::RowResize,
|
||||
Cursor::AllScroll => MouseCursor::AllScroll,
|
||||
Cursor::ZoomIn => MouseCursor::ZoomIn,
|
||||
Cursor::ZoomOut => MouseCursor::ZoomOut,
|
||||
};
|
||||
window.set_cursor(glutin_cursor);
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_favicon(&self, _: Url) {
|
||||
|
@ -831,7 +1038,14 @@ impl WindowMethods for Window {
|
|||
unsafe {
|
||||
match opts::get().render_api {
|
||||
RenderApi::GL => {
|
||||
NativeDisplay::new(self.window.platform_display() as *mut xlib::Display)
|
||||
match self.kind {
|
||||
WindowKind::Window(ref window) => {
|
||||
NativeDisplay::new(window.platform_display() as *mut xlib::Display)
|
||||
}
|
||||
WindowKind::Headless(..) => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
},
|
||||
RenderApi::ES2 => {
|
||||
NativeDisplay::new_egl_display()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue