Skip to content

Commit

Permalink
Auto merge of #20315 - kwonoj:feat-webrender-capture, r=jdm
Browse files Browse the repository at this point in the history
feat(window): bind hotkey to trigger capture event

<!-- Please describe your changes on the following line: -->
Relates to #20295.

This PR intends to expose additional hotkey to window to allow capture webrender. Internally it adds one new `WindowEvent::CaptureWebRender` for those purpose. I took some liberty to make some decisions around which need to be reviewed & updated in PR.

- `Ctrl-shift-3` is binded to hotkey to follow described in Gecko's behavior. Is it good to go?
- Maybe do not need to create new event `CaptureWebRender` but reuse `ToggleWebRenderDebug`, having additional `WebRenderDebugOption` values?
: This sounds more right path for me, but `capture` isn't really `toggle` behavior to include capture into it.
- Capturing will create `capture_webrender` in cwd, creates new folder inside each time new capture stored
: Maybe it'd better to expose new cmdline args allow overrides, or some better way else. I took the simple approach to generate path without asking for it.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20295 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
- This change has manually verified on local machines (mac, windows, linux).

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/20315)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Mar 16, 2018
2 parents f5c1f51 + ee637dc commit 1ae5715
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
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

0 comments on commit 1ae5715

Please sign in to comment.