Auto merge of #13382 - glennw:headless, r=larsbergstrom

Add OSMesa headless mode, run WPT against Webrender.

<!-- 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/13382)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-27 21:46:13 -05:00 committed by GitHub
commit c7e1a575a5
164 changed files with 2095 additions and 458 deletions

View file

@ -7,15 +7,87 @@ use canvas_traits::{FromLayoutMsg, byte_swap};
use euclid::size::Size2D;
use gleam::gl;
use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory};
use offscreen_gl_context::{ColorAttachmentType, GLContext, GLLimits, GLContextAttributes, NativeGLContext};
use offscreen_gl_context::{ColorAttachmentType, GLContext, GLLimits};
use offscreen_gl_context::{GLContextAttributes, NativeGLContext, OSMesaContext};
use std::borrow::ToOwned;
use std::sync::mpsc::channel;
use util::opts;
use util::thread::spawn_named;
use webrender_traits;
enum GLContextWrapper {
Native(GLContext<NativeGLContext>),
OSMesa(GLContext<OSMesaContext>),
}
impl GLContextWrapper {
fn new(size: Size2D<i32>,
attributes: GLContextAttributes) -> Result<GLContextWrapper, &'static str> {
if opts::get().should_use_osmesa() {
let ctx = GLContext::<OSMesaContext>::new(size,
attributes,
ColorAttachmentType::Texture,
None);
ctx.map(GLContextWrapper::OSMesa)
} else {
let ctx = GLContext::<NativeGLContext>::new(size,
attributes,
ColorAttachmentType::Texture,
None);
ctx.map(GLContextWrapper::Native)
}
}
pub fn get_limits(&self) -> GLLimits {
match *self {
GLContextWrapper::Native(ref ctx) => {
ctx.borrow_limits().clone()
}
GLContextWrapper::OSMesa(ref ctx) => {
ctx.borrow_limits().clone()
}
}
}
fn resize(&mut self, size: Size2D<i32>) -> Result<Size2D<i32>, &'static str> {
match *self {
GLContextWrapper::Native(ref mut ctx) => {
try!(ctx.resize(size));
Ok(ctx.borrow_draw_buffer().unwrap().size())
}
GLContextWrapper::OSMesa(ref mut ctx) => {
try!(ctx.resize(size));
Ok(ctx.borrow_draw_buffer().unwrap().size())
}
}
}
pub fn make_current(&self) {
match *self {
GLContextWrapper::Native(ref ctx) => {
ctx.make_current().unwrap();
}
GLContextWrapper::OSMesa(ref ctx) => {
ctx.make_current().unwrap();
}
}
}
pub fn apply_command(&self, cmd: webrender_traits::WebGLCommand) {
match *self {
GLContextWrapper::Native(ref ctx) => {
cmd.apply(ctx);
}
GLContextWrapper::OSMesa(ref ctx) => {
cmd.apply(ctx);
}
}
}
}
enum WebGLPaintTaskData {
WebRender(webrender_traits::RenderApi, webrender_traits::WebGLContextId),
Readback(GLContext<NativeGLContext>, (Option<(webrender_traits::RenderApi, webrender_traits::ImageKey)>)),
Readback(GLContextWrapper, (Option<(webrender_traits::RenderApi, webrender_traits::ImageKey)>)),
}
pub struct WebGLPaintThread {
@ -27,8 +99,8 @@ fn create_readback_painter(size: Size2D<i32>,
attrs: GLContextAttributes,
webrender_api: Option<webrender_traits::RenderApi>)
-> Result<(WebGLPaintThread, GLLimits), String> {
let context = try!(GLContext::<NativeGLContext>::new(size, attrs, ColorAttachmentType::Texture, None));
let limits = context.borrow_limits().clone();
let context = try!(GLContextWrapper::new(size, attrs));
let limits = context.get_limits();
let webrender_api_and_image_key = webrender_api.map(|wr| {
let key = wr.alloc_image();
(wr, key)
@ -73,7 +145,7 @@ impl WebGLPaintThread {
api.send_webgl_command(id, message);
}
WebGLPaintTaskData::Readback(ref ctx, _) => {
message.apply(ctx);
ctx.apply_command(message);
}
}
}
@ -174,8 +246,7 @@ impl WebGLPaintThread {
WebGLPaintTaskData::Readback(ref mut context, _) => {
if size.width > self.size.width ||
size.height > self.size.height {
try!(context.resize(size));
self.size = context.borrow_draw_buffer().unwrap().size();
self.size = try!(context.resize(size));
} else {
self.size = size;
unsafe { gl::Scissor(0, 0, size.width, size.height); }
@ -191,7 +262,7 @@ impl WebGLPaintThread {
fn init(&mut self) {
if let WebGLPaintTaskData::Readback(ref context, _) = self.data {
context.make_current().unwrap();
context.make_current();
}
}
}

View file

@ -85,22 +85,14 @@ partial interface Element {
DOMRectList getClientRects();
DOMRect getBoundingClientRect();
[Func="::script_can_initiate_scroll"]
void scroll(optional ScrollToOptions options);
[Func="::script_can_initiate_scroll"]
void scroll(unrestricted double x, unrestricted double y);
[Func="::script_can_initiate_scroll"]
void scrollTo(optional ScrollToOptions options);
[Func="::script_can_initiate_scroll"]
void scrollTo(unrestricted double x, unrestricted double y);
[Func="::script_can_initiate_scroll"]
void scrollBy(optional ScrollToOptions options);
[Func="::script_can_initiate_scroll"]
void scrollBy(unrestricted double x, unrestricted double y);
[Func="::script_can_initiate_scroll"]
attribute unrestricted double scrollTop;
[Func="::script_can_initiate_scroll"]
attribute unrestricted double scrollLeft;
readonly attribute long scrollWidth;
readonly attribute long scrollHeight;

View file

@ -138,17 +138,11 @@ partial interface Window {
readonly attribute long pageXOffset;
readonly attribute long scrollY;
readonly attribute long pageYOffset;
[Func="::script_can_initiate_scroll"]
void scroll(optional ScrollToOptions options);
[Func="::script_can_initiate_scroll"]
void scroll(unrestricted double x, unrestricted double y);
[Func="::script_can_initiate_scroll"]
void scrollTo(optional ScrollToOptions options);
[Func="::script_can_initiate_scroll"]
void scrollTo(unrestricted double x, unrestricted double y);
[Func="::script_can_initiate_scroll"]
void scrollBy(optional ScrollToOptions options);
[Func="::script_can_initiate_scroll"]
void scrollBy(unrestricted double x, unrestricted double y);
// client

View file

@ -114,10 +114,8 @@ mod webdriver_handlers;
use dom::bindings::codegen::RegisterBindings;
use dom::bindings::proxyhandler;
use js::jsapi::{Handle, JSContext, JSObject};
use script_traits::SWManagerSenders;
use serviceworker_manager::ServiceWorkerManager;
use util::opts;
#[cfg(target_os = "linux")]
#[allow(unsafe_code)]
@ -175,13 +173,3 @@ pub fn init(sw_senders: SWManagerSenders) {
perform_platform_specific_initialization();
}
/// FIXME(pcwalton): Currently WebRender cannot handle DOM-initiated scrolls. Remove this when it
/// can. See PR #11680 for details.
///
/// This function is only marked `unsafe` because the `[Func=foo]` WebIDL attribute requires it. It
/// shouldn't actually do anything unsafe.
#[allow(unsafe_code)]
pub unsafe fn script_can_initiate_scroll(_: *mut JSContext, _: Handle<*mut JSObject>) -> bool {
!opts::get().use_webrender
}

View file

@ -235,7 +235,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)",
@ -369,7 +369,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)",
@ -902,6 +902,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)",
@ -1617,7 +1619,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)",
@ -1626,6 +1628,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)",
]
@ -1704,9 +1707,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)",
@ -1971,7 +1987,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)",
@ -2055,7 +2071,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)",
@ -2180,7 +2196,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)",
@ -2645,7 +2661,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)",
@ -2661,7 +2677,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)",
@ -2670,7 +2686,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)",
@ -2679,7 +2695,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)",
]
@ -2902,7 +2918,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"
@ -2911,7 +2927,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"

View file

@ -147,6 +147,12 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
}
};
let renderer_kind = if opts::get().should_use_osmesa() {
webrender_traits::RendererKind::OSMesa
} else {
webrender_traits::RendererKind::Native
};
let (webrender, webrender_sender) =
webrender::Renderer::new(webrender::RendererOptions {
device_pixel_ratio: device_pixel_ratio,
@ -158,6 +164,7 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
enable_recording: false,
precache_shaders: opts.precache_shaders,
enable_scrollbars: opts.output_file.is_none(),
renderer_kind: renderer_kind,
});
(Some(webrender), Some(webrender_sender))
} else {

View file

@ -791,8 +791,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
!PREFS.get("shell.native-titlebar.enabled").as_boolean().unwrap();
let use_webrender =
(PREFS.get("gfx.webrender.enabled").as_boolean().unwrap() || opt_match.opt_present("w")) &&
!opt_match.opt_present("z");
PREFS.get("gfx.webrender.enabled").as_boolean().unwrap() || opt_match.opt_present("w");
let render_api = match opt_match.opt_str("G") {
Some(ref ga) if ga == "gl" => RenderApi::GL,
@ -944,3 +943,9 @@ pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<Url, ()> {
Err(_) => Err(()),
}
}
impl Opts {
pub fn should_use_osmesa(&self) -> bool {
self.headless
}
}