libservo: Add a WebView::take_screenshot() API and use it for reftests

Co-authored-by: Delan Azabani <dazabani@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-09-26 09:24:24 +02:00
parent 92dd54b1ec
commit ebb12cb298
25 changed files with 481 additions and 414 deletions

View file

@ -501,6 +501,16 @@ pub enum KeyboardScroll {
End,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum ScreenshotReadinessResponse {
/// The Pipeline associated with this response, is ready for a screenshot at the
/// provided [`Epoch`].
Ready(Epoch),
/// The Pipeline associated with this response is no longer active and should be
/// ignored for the purposes of the screenshot.
NoLongerActive,
}
/// Messages from the script to the constellation.
#[derive(Deserialize, IntoStaticStr, Serialize)]
pub enum ScriptToConstellationMessage {
@ -641,8 +651,6 @@ pub enum ScriptToConstellationMessage {
ActivateDocument,
/// Set the document state for a pipeline (used by screenshot / reftests)
SetDocumentState(DocumentState),
/// Update the layout epoch in the constellation (used by screenshot / reftests).
SetLayoutEpoch(Epoch, IpcSender<bool>),
/// Update the pipeline Url, which can change after redirections.
SetFinalUrl(ServoUrl),
/// Script has handled a touch event, and either prevented or allowed default actions.
@ -688,6 +696,8 @@ pub enum ScriptToConstellationMessage {
WebDriverInputComplete(WebDriverMessageId),
/// Forward a keyboard scroll operation from an `<iframe>` to a parent pipeline.
ForwardKeyboardScroll(PipelineId, KeyboardScroll),
/// Notify the Constellation of the screenshot readiness of a given pipeline.
RespondToScreenshotReadinessRequest(ScreenshotReadinessResponse),
}
impl fmt::Debug for ScriptToConstellationMessage {

View file

@ -15,7 +15,6 @@ use std::collections::VecDeque;
use std::fmt;
use std::time::Duration;
use base::Epoch;
use base::cross_process_instant::CrossProcessInstant;
use base::id::{MessagePortId, PipelineId, WebViewId};
use embedder_traits::{
@ -41,8 +40,6 @@ use webrender_api::{ExternalScrollId, ImageKey};
pub enum EmbedderToConstellationMessage {
/// Exit the constellation.
Exit,
/// Query the constellation to see if the current compositor output is stable
IsReadyToSaveImage(FxHashMap<PipelineId, Epoch>),
/// Whether to allow script to navigate.
AllowNavigationResponse(PipelineId, bool),
/// Request to load a page.
@ -109,6 +106,9 @@ pub enum EmbedderToConstellationMessage {
SetWebDriverResponseSender(IpcSender<WebDriverCommandResponse>),
/// A set of preferences were updated with the given new values.
PreferencesUpdated(Vec<(&'static str, PrefValue)>),
/// Request preparation for a screenshot of the given WebView. The Constellation will
/// send a message to the Embedder when the screenshot is ready to be taken.
RequestScreenshotReadiness(WebViewId),
}
/// A description of a paint metric that is sent from the Servo renderer to the