diff --git a/.gitignore b/.gitignore index 9dde417c9c99..35b7815ab7e3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ Servo.app .config.mk.last /glfw +capture_webrender/ # Editors diff --git a/Cargo.lock b/Cargo.lock index 63096eaceb0a..ae1ca42f20e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2352,6 +2352,14 @@ name = "regex-syntax" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ron" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rust-webvr" version = "0.9.10" @@ -3492,6 +3500,8 @@ dependencies = [ "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "plane-split 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ron 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "thread_profiler 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3893,6 +3903,7 @@ dependencies = [ "checksum ref_slice 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "825740057197b7d43025e7faf6477eaabc03434e153233da02d1f44602f71527" "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" +"checksum ron 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "da06feaa07f69125ab9ddc769b11de29090122170b402547f64b86fe16ebc399" "checksum rust-webvr 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "9629ce5b5c3cda05259d225e639851daf39c55c170358d3056205dd205deaab2" "checksum rust-webvr-api 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "712e22ba3c03a7075b40842ae91029a0ab96a81f95e97c0cf623800ec0cbac07" "checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index 88cd1c479770..736fef8a57d2 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -27,5 +27,5 @@ servo_geometry = {path = "../geometry"} servo_url = {path = "../url"} style_traits = {path = "../style_traits"} time = "0.1.17" -webrender = {git = "https://github.com/servo/webrender"} +webrender = {git = "https://github.com/servo/webrender", features = ["capture"]} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 027151af9b4a..88a3dc6b5eff 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -23,6 +23,7 @@ use script_traits::CompositorEvent::{MouseMoveEvent, MouseButtonEvent, TouchEven use servo_config::opts; use servo_geometry::DeviceIndependentPixel; use std::collections::HashMap; +use std::env; use std::fs::File; use std::rc::Rc; use std::sync::mpsc::Sender; @@ -30,7 +31,7 @@ use std::time::{Duration, Instant}; use style_traits::{CSSPixel, DevicePixel, PinchZoomFactor}; use style_traits::cursor::CursorKind; use style_traits::viewport::ViewportConstraints; -use time::{precise_time_ns, precise_time_s}; +use time::{now, precise_time_ns, precise_time_s}; use touch::{TouchHandler, TouchAction}; use webrender; use webrender_api::{self, DeviceUintRect, DeviceUintSize, HitTestFlags, HitTestResult}; @@ -1530,6 +1531,17 @@ impl IOCompositor { txn.generate_frame(); self.webrender_api.send_transaction(self.webrender_document, txn); } + + pub fn capture_webrender(&mut self) { + match env::current_dir() { + Ok(current_dir) => { + let capture_id = now().to_timespec().sec.to_string(); + let capture_path = current_dir.join("capture_webrender").join(capture_id); + self.webrender_api.save_capture(capture_path, webrender_api::CaptureBits::all()); + }, + Err(err) => println!("could not locate path to save captures: {:?}", err) + } + } } /// Why we performed a composite. This is used for debugging. diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 473e85fcb07a..0426f0317bf1 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -84,6 +84,8 @@ pub enum WindowEvent { SelectBrowser(TopLevelBrowsingContextId), /// Toggles a debug flag in WebRender ToggleWebRenderDebug(WebRenderDebugOption), + /// Capture current WebRender + CaptureWebRender, } impl Debug for WindowEvent { @@ -108,6 +110,7 @@ impl Debug for WindowEvent { WindowEvent::CloseBrowser(..) => write!(f, "CloseBrowser"), WindowEvent::SelectBrowser(..) => write!(f, "SelectBrowser"), WindowEvent::ToggleWebRenderDebug(..) => write!(f, "ToggleWebRenderDebug"), + WindowEvent::CaptureWebRender => write!(f, "CaptureWebRender"), } } } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 45b6af50c89e..f5ebed9f04d9 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -333,6 +333,10 @@ impl Servo where Window: WindowMethods + 'static { self.compositor.toggle_webrender_debug(option); } + WindowEvent::CaptureWebRender => { + self.compositor.capture_webrender(); + } + WindowEvent::NewBrowser(url, response_chan) => { let msg = ConstellationMsg::NewBrowser(url, response_chan); if let Err(e) = self.constellation_chan.send(msg) { diff --git a/ports/servo/glutin_app/window.rs b/ports/servo/glutin_app/window.rs index a243d32e4c84..542715a85edb 100644 --- a/ports/servo/glutin_app/window.rs +++ b/ports/servo/glutin_app/window.rs @@ -1230,6 +1230,9 @@ impl WindowMethods for Window { self.event_queue.borrow_mut().push(WindowEvent::Quit); } } + (_, Some('3'), _) => if mods ^ KeyModifiers::CONTROL == KeyModifiers::SHIFT { + self.event_queue.borrow_mut().push(WindowEvent::CaptureWebRender); + } (KeyModifiers::CONTROL, None, Key::F10) => { let event = WindowEvent::ToggleWebRenderDebug(WebRenderDebugOption::RenderTargetDebug); self.event_queue.borrow_mut().push(event);