Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(window): bind hotkey to trigger capture event #20315

Merged
merged 3 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Servo.app
.config.mk.last
/glfw
capture_webrender/

# Editors

Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/compositing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
14 changes: 13 additions & 1 deletion components/compositing/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ 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;
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};
Expand Down Expand Up @@ -1530,6 +1531,17 @@ impl<Window: WindowMethods> IOCompositor<Window> {
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.
Expand Down
3 changes: 3 additions & 0 deletions components/compositing/windowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions components/servo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ impl<Window> Servo<Window> 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) {
Expand Down
3 changes: 3 additions & 0 deletions ports/servo/glutin_app/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down