Bug 1567173 - WR Rawtest comparisons r=gw

Differential Revision: https://phabricator.services.mozilla.com/D38499

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dzmitry Malyshau 2019-07-18 20:30:00 +00:00
Родитель 8002be2a0d
Коммит 54f5b4cbf0
2 изменённых файлов: 49 добавлений и 14 удалений

Просмотреть файл

@ -2,14 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use crate::{WindowWrapper, NotifierEvent};
use crate::blob;
use euclid::{point2, size2, rect};
use std::sync::Arc;
use std::sync::atomic::{AtomicIsize, Ordering};
use std::sync::mpsc::Receiver;
use webrender::api::*;
use webrender::api::units::*;
use crate::{WindowWrapper, NotifierEvent};
use crate::blob;
use crate::reftest::{ReftestImage, ReftestImageComparison};
use crate::wrench::Wrench;
pub struct RawtestHarness<'a> {
@ -53,6 +54,41 @@ impl<'a> RawtestHarness<'a> {
self.wrench.renderer.read_pixels_rgba8(window_rect)
}
fn compare_pixels(&self, reference: Vec<u8>, test: Vec<u8>, size: FramebufferIntSize) {
let size = DeviceIntSize::new(size.width, size.height);
let reference = ReftestImage {
data: reference,
size,
};
let test = ReftestImage {
data: test,
size,
};
match reference.compare(&test) {
ReftestImageComparison::Equal => {}
ReftestImageComparison::NotEqual { max_difference, count_different } => {
let t = "rawtest";
println!(
"{} | {} | {}: {}, {}: {}",
"REFTEST TEST-UNEXPECTED-FAIL",
t,
"image comparison, max difference",
max_difference,
"number of differing pixels",
count_different
);
println!("REFTEST IMAGE 1 (TEST): {}", test.create_data_uri());
println!(
"REFTEST IMAGE 2 (REFERENCE): {}",
reference.create_data_uri()
);
println!("REFTEST TEST-END | {}", t);
panic!();
}
}
}
fn submit_dl(
&mut self,
epoch: &mut Epoch,
@ -574,7 +610,7 @@ impl<'a> RawtestHarness<'a> {
let pixels = self.render_and_get_pixels(window_rect);
assert!(pixels == original_pixels);
self.compare_pixels(original_pixels, pixels, window_rect.size);
// Leaving a tiled blob image in the resource cache
// confuses the `test_capture`. TODO: remove this
@ -667,7 +703,6 @@ impl<'a> RawtestHarness<'a> {
// use png;
// png::save_flipped("out1.png", &pixels_first, window_rect.size);
// png::save_flipped("out2.png", &pixels_second, window_rect.size);
assert!(pixels_first != pixels_second);
// cleanup
@ -905,8 +940,8 @@ impl<'a> RawtestHarness<'a> {
self.submit_dl(&mut epoch, layout_size, builder, &txn.resource_updates);
let pixels_third = self.render_and_get_pixels(window_rect);
assert!(pixels_first == pixels_second);
assert!(pixels_first != pixels_third);
self.compare_pixels(pixels_first, pixels_second, window_rect.size);
}
// Ensures that content doing a save-restore produces the same results as not
@ -1012,7 +1047,7 @@ impl<'a> RawtestHarness<'a> {
let first = do_test(false);
let second = do_test(true);
assert_eq!(first, second);
self.compare_pixels(first, second, window_rect.size);
}
// regression test for #2769
@ -1141,7 +1176,7 @@ impl<'a> RawtestHarness<'a> {
// 5. render the built frame and compare
let pixels1 = self.render_and_get_pixels(window_rect);
assert!(pixels0 == pixels1);
self.compare_pixels(pixels0.clone(), pixels1, window_rect.size);
// 6. rebuild the scene and compare again
let mut txn = Transaction::new();
@ -1149,7 +1184,7 @@ impl<'a> RawtestHarness<'a> {
txn.generate_frame();
self.wrench.api.send_transaction(captured.document_id, txn);
let pixels2 = self.render_and_get_pixels(window_rect);
assert!(pixels0 == pixels2);
self.compare_pixels(pixels0, pixels2, window_rect.size);
}
fn test_zero_height_window(&mut self) {

Просмотреть файл

@ -114,11 +114,11 @@ impl Display for Reftest {
}
}
struct ReftestImage {
data: Vec<u8>,
size: DeviceIntSize,
pub struct ReftestImage {
pub data: Vec<u8>,
pub size: DeviceIntSize,
}
enum ReftestImageComparison {
pub enum ReftestImageComparison {
Equal,
NotEqual {
max_difference: usize,
@ -127,7 +127,7 @@ enum ReftestImageComparison {
}
impl ReftestImage {
fn compare(&self, other: &ReftestImage) -> ReftestImageComparison {
pub fn compare(&self, other: &ReftestImage) -> ReftestImageComparison {
assert_eq!(self.size, other.size);
assert_eq!(self.data.len(), other.data.len());
assert_eq!(self.data.len() % 4, 0);
@ -158,7 +158,7 @@ impl ReftestImage {
}
}
fn create_data_uri(mut self) -> String {
pub fn create_data_uri(mut self) -> String {
let width = self.size.width;
let height = self.size.height;