Render PRD sites in real viewport
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
use std::{env, num::ParseIntError, path::PathBuf, thread, time::Duration};
|
||||
use std::{
|
||||
env,
|
||||
num::ParseIntError,
|
||||
path::PathBuf,
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use ely_domain::{ProfileId, TabId, UrlText};
|
||||
use ely_servo_host::{
|
||||
@@ -10,6 +16,7 @@ use thiserror::Error;
|
||||
|
||||
const WAIT_ITERATIONS: usize = 5_000;
|
||||
const WAIT_INTERVAL: Duration = Duration::from_millis(2);
|
||||
const RENDER_TIMEOUT: Duration = Duration::from_secs(20);
|
||||
|
||||
fn main() -> Result<(), SidecarError> {
|
||||
match parse_command(env::args())? {
|
||||
@@ -175,7 +182,12 @@ fn wait_for_frame(
|
||||
webview_id: &ely_domain::WebViewId,
|
||||
url: &str,
|
||||
) -> Result<WebViewSnapshot, SidecarError> {
|
||||
let started_at = Instant::now();
|
||||
for _ in 0..WAIT_ITERATIONS {
|
||||
if started_at.elapsed() >= RENDER_TIMEOUT {
|
||||
break;
|
||||
}
|
||||
|
||||
host.tick();
|
||||
let snapshot = host.snapshot(webview_id)?;
|
||||
if snapshot.has_pending_frame() {
|
||||
@@ -210,6 +222,7 @@ struct SnapshotReport {
|
||||
rgba_byte_count: usize,
|
||||
opaque_pixel_count: u64,
|
||||
non_white_pixel_count: u64,
|
||||
content_pixel_count: u64,
|
||||
sample_hash: u64,
|
||||
}
|
||||
|
||||
@@ -231,6 +244,7 @@ impl SnapshotReport {
|
||||
rgba_byte_count: frame.rgba_bytes().len(),
|
||||
opaque_pixel_count: frame.opaque_pixel_count(),
|
||||
non_white_pixel_count: frame.non_white_pixel_count(),
|
||||
content_pixel_count: frame.content_pixel_count(),
|
||||
sample_hash: frame.sample_hash(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ pub struct RenderedFrameSummary {
|
||||
height: u32,
|
||||
opaque_pixel_count: u64,
|
||||
non_white_pixel_count: u64,
|
||||
content_pixel_count: u64,
|
||||
sample_hash: u64,
|
||||
}
|
||||
|
||||
@@ -25,6 +26,7 @@ impl RenderedFrameSummary {
|
||||
pub fn from_rgba_bytes(width: u32, height: u32, rgba_bytes: &[u8]) -> Self {
|
||||
let mut opaque_pixel_count = 0;
|
||||
let mut non_white_pixel_count = 0;
|
||||
let mut content_pixel_count = 0;
|
||||
let mut sample_hash = 0xcbf29ce484222325_u64;
|
||||
|
||||
for (index, pixel) in rgba_bytes.chunks_exact(4).enumerate() {
|
||||
@@ -35,6 +37,9 @@ impl RenderedFrameSummary {
|
||||
if alpha > 0 && (red < 245 || green < 245 || blue < 245) {
|
||||
non_white_pixel_count += 1;
|
||||
}
|
||||
if alpha > 0 && (red < 220 || green < 220 || blue < 220) {
|
||||
content_pixel_count += 1;
|
||||
}
|
||||
if index % 97 == 0 {
|
||||
for byte in pixel {
|
||||
sample_hash ^= u64::from(*byte);
|
||||
@@ -43,7 +48,14 @@ impl RenderedFrameSummary {
|
||||
}
|
||||
}
|
||||
|
||||
Self { width, height, opaque_pixel_count, non_white_pixel_count, sample_hash }
|
||||
Self {
|
||||
width,
|
||||
height,
|
||||
opaque_pixel_count,
|
||||
non_white_pixel_count,
|
||||
content_pixel_count,
|
||||
sample_hash,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -66,6 +78,11 @@ impl RenderedFrameSummary {
|
||||
self.non_white_pixel_count
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn content_pixel_count(&self) -> u64 {
|
||||
self.content_pixel_count
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sample_hash(&self) -> u64 {
|
||||
self.sample_hash
|
||||
@@ -117,6 +134,11 @@ impl RenderedFrame {
|
||||
self.summary.non_white_pixel_count()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn content_pixel_count(&self) -> u64 {
|
||||
self.summary.content_pixel_count()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sample_hash(&self) -> u64 {
|
||||
self.summary.sample_hash()
|
||||
|
||||
Reference in New Issue
Block a user