Skip to main content

paint/
pipeline_details.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::collections::VecDeque;
6
7use euclid::Scale;
8use paint_api::display_list::{PaintTimingInfo, ScrollTree};
9use paint_api::{CompositionPipeline, PipelineExitSource};
10use rustc_hash::FxHashMap;
11use servo_base::Epoch;
12use servo_base::id::{ContainerTimingID, LCPCandidateID, PipelineId, ScrollTreeNodeId};
13use style_traits::CSSPixel;
14use webrender_api::units::{DevicePixel, LayoutRect};
15use webrender_api::{Epoch as WebRenderEpoch, PipelineId as WebRenderPipelineId};
16
17use crate::painter::PaintMetricState;
18use crate::web_content_animation::PipelineAnimations;
19
20pub(crate) struct PipelineDetails {
21    /// The pipeline associated with this PipelineDetails object.
22    pub pipeline: Option<CompositionPipeline>,
23
24    /// The id of the parent pipeline, if any.
25    pub parent_pipeline_id: Option<PipelineId>,
26
27    /// The ids of the child pipelines for this pipeline.
28    pub children: Vec<PipelineId>,
29
30    /// A map of `<iframe>` [`PipelineId`]s to their rectangle and containing [`ScrollTreeNodeId`].
31    /// This can be used to translate from coordinates within an `<iframe>` to root WebView
32    /// coordinates.
33    pub iframes: FxHashMap<WebRenderPipelineId, (ScrollTreeNodeId, LayoutRect)>,
34
35    /// Whether animations are running
36    pub animations_running: bool,
37
38    /// Whether there are animation callbacks
39    pub animation_callbacks_running: bool,
40
41    /// Whether to use less resources by stopping animations.
42    pub throttled: bool,
43
44    /// The `Paint`-side [ScrollTree]. This is used to allow finding and scrolling
45    /// nodes in `Paint` before forwarding new offsets to WebRender.
46    pub scroll_tree: ScrollTree,
47
48    /// The paint metric status of the first paint.
49    pub first_paint_metric: PaintMetricState,
50
51    /// The paint metric status of the first contentful paint.
52    pub first_contentful_paint_metric: PaintMetricState,
53
54    /// LCP candidates waiting to be presented, in order by [WebRenderEpoch]
55    pub lcp_candidates: VecDeque<(WebRenderEpoch, (LCPCandidateID, usize), PaintTimingInfo)>,
56
57    /// Container Timing updates waiting to be presented, in order by [WebRenderEpoch].
58    pub container_timing_candidates: VecDeque<(WebRenderEpoch, Vec<ContainerTimingID>)>,
59
60    /// The CSS pixel to device pixel scale of the viewport of this pipeline, including
61    /// page zoom, but not including any pinch zoom amount. This is used to detect
62    /// situations where the current display list is for an old scale.
63    pub viewport_scale: Option<Scale<f32, CSSPixel, DevicePixel>>,
64
65    /// Which parts of Servo have reported that this `Pipeline` has exited. Only when all
66    /// have done so will it be discarded.
67    pub exited: PipelineExitSource,
68
69    /// The [`Epoch`] of the latest display list received for this `Pipeline` or `None` if no
70    /// display list has been received.
71    pub display_list_epoch: Option<Epoch>,
72
73    /// Paint-driven animations associated with this [`PipelineDetails`]. Currently only text caret
74    /// is handled this way.
75    ///
76    /// Note: This does not manage animations and transitions from CSS or for user input
77    /// interaction.
78    pub animations: PipelineAnimations,
79}
80
81impl PipelineDetails {
82    pub(crate) fn animation_callbacks_running(&self) -> bool {
83        self.animation_callbacks_running
84    }
85
86    pub(crate) fn animating(&self) -> bool {
87        !self.throttled && (self.animation_callbacks_running || self.animations_running)
88    }
89}
90
91impl PipelineDetails {
92    pub(crate) fn new() -> PipelineDetails {
93        PipelineDetails {
94            pipeline: None,
95            parent_pipeline_id: None,
96            children: Default::default(),
97            iframes: Default::default(),
98            viewport_scale: None,
99            animations_running: false,
100            animation_callbacks_running: false,
101            throttled: false,
102            scroll_tree: ScrollTree::default(),
103            first_paint_metric: PaintMetricState::Waiting,
104            first_contentful_paint_metric: PaintMetricState::Waiting,
105            lcp_candidates: VecDeque::new(),
106            container_timing_candidates: VecDeque::new(),
107            exited: PipelineExitSource::empty(),
108            display_list_epoch: None,
109            animations: Default::default(),
110        }
111    }
112
113    pub(crate) fn install_new_scroll_tree_and_iframes(
114        &mut self,
115        new_scroll_tree: ScrollTree,
116        iframes: FxHashMap<WebRenderPipelineId, (ScrollTreeNodeId, LayoutRect)>,
117    ) {
118        let old_scroll_offsets = self.scroll_tree.scroll_offsets();
119        self.scroll_tree = new_scroll_tree;
120        self.scroll_tree.set_all_scroll_offsets(&old_scroll_offsets);
121        self.iframes = iframes;
122    }
123}