-
Notifications
You must be signed in to change notification settings - Fork 296
Wrench Reftests #695
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
Merged
+157
−3
Merged
Wrench Reftests #695
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
root: | ||
items: | ||
- | ||
bounds: [0, 0, 95, 88] | ||
type: rect | ||
color: green |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
root: | ||
items: | ||
- | ||
bounds: [0, 0, 95, 88] | ||
items: | ||
- | ||
bounds: [9, 9, 10, 10] | ||
type: rect | ||
color: blue | ||
type: stacking_context |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
root: | ||
items: | ||
- | ||
bounds: [0, 0, 95, 88] | ||
clip: | ||
image_mask: | ||
image: "mask.png" | ||
rect: [0, 0, 35, 35] | ||
repeat: false | ||
rect: [0, 0, 95, 88] | ||
items: | ||
- | ||
bounds: [0, 0, 95, 88] | ||
type: rect | ||
color: blue | ||
type: stacking_context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
== mask.yaml mask-ref.yaml | ||
!= mask.yaml green.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,5 @@ subcommands: | |
help: The input binary file or directory | ||
required: true | ||
index: 1 | ||
- reftest: | ||
about: run reftests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use std::io::BufReader; | ||
use std::io::BufRead; | ||
use std::fs::File; | ||
use wrench::{Wrench, WrenchThing}; | ||
use std::path::Path; | ||
use gleam::gl; | ||
use std::sync::mpsc::{channel, Sender, Receiver}; | ||
|
||
use yaml_frame_reader::YamlFrameReader; | ||
use webrender_traits::*; | ||
|
||
use WindowWrapper; | ||
|
||
pub enum ReftestOp { | ||
Equal, | ||
NotEqual, | ||
} | ||
|
||
pub struct Reftest<'a> { | ||
op: ReftestOp, | ||
test: &'a Path, | ||
reference: &'a Path, | ||
} | ||
|
||
pub fn parse_reftests<F>(filename: &str, mut runner: F) | ||
where F: FnMut(Reftest) | ||
{ | ||
let manifest = Path::new(filename); | ||
let dir = manifest.parent().unwrap(); | ||
let f = File::open(manifest).unwrap(); | ||
let file = BufReader::new(&f); | ||
for line in file.lines() { | ||
let l = line.unwrap(); | ||
|
||
// strip the comments | ||
let s = &l[0..l.find("#").unwrap_or(l.len())]; | ||
let s = s.trim(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a simpler way, possibly, is: |
||
if s.len() == 0 { | ||
continue; | ||
} | ||
|
||
let mut items = s.split_whitespace(); | ||
let kind = match items.next() { | ||
Some("==") => ReftestOp::Equal, | ||
Some("!=") => ReftestOp::NotEqual, | ||
_ => panic!(), | ||
}; | ||
let test = dir.join(items.next().unwrap()); | ||
let reference = dir.join(items.next().unwrap()); | ||
runner(Reftest { | ||
op: kind, | ||
test: test.as_path(), | ||
reference: reference.as_path(), | ||
}); | ||
} | ||
|
||
} | ||
|
||
|
||
fn render_yaml(wrench: &mut Wrench, | ||
window: &mut WindowWrapper, | ||
filename: &Path, | ||
rx: &Receiver<()>) | ||
-> Vec<u8> { | ||
let mut reader = YamlFrameReader::new(filename); | ||
reader.do_frame(wrench); | ||
// wait for the frame | ||
rx.recv().unwrap(); | ||
wrench.render(); | ||
|
||
let size = window.get_inner_size(); | ||
let pixels = gl::read_pixels(0, | ||
0, | ||
size.0 as gl::GLsizei, | ||
size.1 as gl::GLsizei, | ||
gl::RGBA, | ||
gl::UNSIGNED_BYTE); | ||
window.swap_buffers(); | ||
pixels | ||
} | ||
|
||
pub fn run_reftests(wrench: &mut Wrench, window: &mut WindowWrapper, filename: &str) { | ||
// setup a notifier so we can wait for frames to be finished | ||
struct Notifier { | ||
tx: Sender<()>, | ||
}; | ||
impl RenderNotifier for Notifier { | ||
fn new_frame_ready(&mut self) { | ||
self.tx.send(()).unwrap(); | ||
} | ||
fn new_scroll_frame_ready(&mut self, _composite_needed: bool) {} | ||
fn pipeline_size_changed(&mut self, _: PipelineId, _: Option<LayoutSize>) {} | ||
} | ||
let (tx, rx) = channel(); | ||
wrench.renderer.set_render_notifier(Box::new(Notifier { tx: tx })); | ||
|
||
parse_reftests(filename, |t: Reftest| { | ||
println!("{} {}", t.test.display(), t.reference.display()); | ||
let test = render_yaml(wrench, window, t.test, &rx); | ||
let reference = render_yaml(wrench, window, t.reference, &rx); | ||
match t.op { | ||
ReftestOp::Equal => assert!(test == reference), | ||
ReftestOp::NotEqual => assert!(test != reference), | ||
} | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-conventional formatting here (and in other function definitions)