Add Servo site compatibility frame smoke

This commit is contained in:
2026-05-08 12:08:57 -04:00
parent b4355d0f82
commit 5f0773a043
5 changed files with 223 additions and 20 deletions
+114
View File
@@ -11,6 +11,118 @@ pub enum WebViewState {
Crashed,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RenderedFrameSummary {
width: u32,
height: u32,
opaque_pixel_count: u64,
non_white_pixel_count: u64,
sample_hash: u64,
}
impl RenderedFrameSummary {
#[must_use]
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 sample_hash = 0xcbf29ce484222325_u64;
for (index, pixel) in rgba_bytes.chunks_exact(4).enumerate() {
let [red, green, blue, alpha] = [pixel[0], pixel[1], pixel[2], pixel[3]];
if alpha > 0 {
opaque_pixel_count += 1;
}
if alpha > 0 && (red < 245 || green < 245 || blue < 245) {
non_white_pixel_count += 1;
}
if index % 97 == 0 {
for byte in pixel {
sample_hash ^= u64::from(*byte);
sample_hash = sample_hash.wrapping_mul(0x100000001b3);
}
}
}
Self { width, height, opaque_pixel_count, non_white_pixel_count, sample_hash }
}
#[must_use]
pub fn width(&self) -> u32 {
self.width
}
#[must_use]
pub fn height(&self) -> u32 {
self.height
}
#[must_use]
pub fn opaque_pixel_count(&self) -> u64 {
self.opaque_pixel_count
}
#[must_use]
pub fn non_white_pixel_count(&self) -> u64 {
self.non_white_pixel_count
}
#[must_use]
pub fn sample_hash(&self) -> u64 {
self.sample_hash
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RenderedFrame {
width: u32,
height: u32,
rgba_bytes: Vec<u8>,
summary: RenderedFrameSummary,
}
impl RenderedFrame {
#[must_use]
pub fn from_rgba_bytes(width: u32, height: u32, rgba_bytes: Vec<u8>) -> Self {
let summary = RenderedFrameSummary::from_rgba_bytes(width, height, &rgba_bytes);
Self { width, height, rgba_bytes, summary }
}
#[must_use]
pub fn width(&self) -> u32 {
self.width
}
#[must_use]
pub fn height(&self) -> u32 {
self.height
}
#[must_use]
pub fn rgba_bytes(&self) -> &[u8] {
&self.rgba_bytes
}
#[must_use]
pub fn summary(&self) -> &RenderedFrameSummary {
&self.summary
}
#[must_use]
pub fn opaque_pixel_count(&self) -> u64 {
self.summary.opaque_pixel_count()
}
#[must_use]
pub fn non_white_pixel_count(&self) -> u64 {
self.summary.non_white_pixel_count()
}
#[must_use]
pub fn sample_hash(&self) -> u64 {
self.summary.sample_hash()
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WebViewSnapshot {
webview_id: WebViewId,
@@ -116,4 +228,6 @@ pub trait ServoHost {
fn tick(&mut self) -> bool;
fn paint(&mut self, webview_id: &WebViewId) -> Result<(), ServoHostError>;
fn last_rendered_frame(&self) -> Result<RenderedFrame, ServoHostError>;
}