mirror of
https://github.com/servo/servo.git
synced 2025-09-29 16:19:14 +01:00
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:
parent
92dd54b1ec
commit
ebb12cb298
25 changed files with 481 additions and 414 deletions
|
@ -12,6 +12,7 @@ use crossbeam_channel::Sender;
|
|||
use embedder_traits::{AnimationState, EventLoopWaker, TouchEventResult};
|
||||
use log::warn;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use rustc_hash::FxHashMap;
|
||||
use smallvec::SmallVec;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use webrender_api::{DocumentId, FontVariation};
|
||||
|
@ -87,8 +88,6 @@ pub enum CompositorMsg {
|
|||
RemoveWebView(WebViewId),
|
||||
/// Script has handled a touch event, and either prevented or allowed default actions.
|
||||
TouchEventProcessed(WebViewId, TouchEventResult),
|
||||
/// A reply to the compositor asking if the output image is stable.
|
||||
IsReadyToSaveImageReply(bool),
|
||||
/// Set whether to use less resources by stopping animations.
|
||||
SetThrottled(WebViewId, PipelineId, bool),
|
||||
/// WebRender has produced a new frame. This message informs the compositor that
|
||||
|
@ -100,8 +99,6 @@ pub enum CompositorMsg {
|
|||
/// they have fully shut it down, to avoid recreating it due to any subsequent
|
||||
/// messages.
|
||||
PipelineExited(WebViewId, PipelineId, PipelineExitSource),
|
||||
/// The load of a page has completed
|
||||
LoadComplete(WebViewId),
|
||||
/// Inform WebRender of the existence of this pipeline.
|
||||
SendInitialTransaction(WebRenderPipelineId),
|
||||
/// Perform a scroll operation.
|
||||
|
@ -163,6 +160,9 @@ pub enum CompositorMsg {
|
|||
CollectMemoryReport(ReportsChan),
|
||||
/// A top-level frame has parsed a viewport metatag and is sending the new constraints.
|
||||
Viewport(WebViewId, ViewportDescription),
|
||||
/// Let the compositor know that the given WebView is ready to have a screenshot taken
|
||||
/// after the given pipeline's epochs have been rendered.
|
||||
ScreenshotReadinessReponse(WebViewId, FxHashMap<PipelineId, Epoch>),
|
||||
}
|
||||
|
||||
impl Debug for CompositorMsg {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1063,6 +1063,15 @@ pub enum JavaScriptEvaluationError {
|
|||
SerializationError,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
pub enum ScreenshotCaptureError {
|
||||
/// The screenshot request failed to read the screenshot image from the `WebView`'s
|
||||
/// `RenderingContext`.
|
||||
CouldNotReadImage,
|
||||
/// The WebView that this screenshot request was made for no longer exists.
|
||||
WebViewDoesNotExist,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub struct RgbColor {
|
||||
pub red: u8,
|
||||
|
|
|
@ -267,6 +267,10 @@ pub enum ScriptThreadMessage {
|
|||
NoLongerWaitingOnAsychronousImageUpdates(PipelineId),
|
||||
/// Forward a keyboard scroll operation from an `<iframe>` to a parent pipeline.
|
||||
ForwardKeyboardScroll(PipelineId, KeyboardScroll),
|
||||
/// Request readiness for a screenshot from the given pipeline. The pipeline will
|
||||
/// respond when it is ready to take the screenshot or will not be able to take it
|
||||
/// in the future.
|
||||
RequestScreenshotReadiness(PipelineId),
|
||||
}
|
||||
|
||||
impl fmt::Debug for ScriptThreadMessage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue