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 servo_base::Epoch;
11use servo_base::id::{ContainerTimingID, LCPCandidateID, PipelineId};
12use style_traits::CSSPixel;
13use webrender_api::Epoch as WebRenderEpoch;
14use webrender_api::units::DevicePixel;
15
16use crate::painter::PaintMetricState;
17use crate::web_content_animation::PipelineAnimations;
18
19pub(crate) struct PipelineDetails {
20    /// The pipeline associated with this PipelineDetails object.
21    pub pipeline: Option<CompositionPipeline>,
22
23    /// The id of the parent pipeline, if any.
24    pub parent_pipeline_id: Option<PipelineId>,
25
26    /// The ids of the child pipelines for this pipeline.
27    pub children: Vec<PipelineId>,
28
29    /// Whether animations are running
30    pub animations_running: bool,
31
32    /// Whether there are animation callbacks
33    pub animation_callbacks_running: bool,
34
35    /// Whether to use less resources by stopping animations.
36    pub throttled: bool,
37
38    /// The `Paint`-side [ScrollTree]. This is used to allow finding and scrolling
39    /// nodes in `Paint` before forwarding new offsets to WebRender.
40    pub scroll_tree: ScrollTree,
41
42    /// The paint metric status of the first paint.
43    pub first_paint_metric: PaintMetricState,
44
45    /// The paint metric status of the first contentful paint.
46    pub first_contentful_paint_metric: PaintMetricState,
47
48    /// LCP candidates waiting to be presented, in order by [WebRenderEpoch]
49    pub lcp_candidates: VecDeque<(WebRenderEpoch, (LCPCandidateID, usize), PaintTimingInfo)>,
50
51    /// Container Timing updates waiting to be presented, in order by [WebRenderEpoch].
52    pub container_timing_candidates: VecDeque<(WebRenderEpoch, Vec<ContainerTimingID>)>,
53
54    /// The CSS pixel to device pixel scale of the viewport of this pipeline, including
55    /// page zoom, but not including any pinch zoom amount. This is used to detect
56    /// situations where the current display list is for an old scale.
57    pub viewport_scale: Option<Scale<f32, CSSPixel, DevicePixel>>,
58
59    /// Which parts of Servo have reported that this `Pipeline` has exited. Only when all
60    /// have done so will it be discarded.
61    pub exited: PipelineExitSource,
62
63    /// The [`Epoch`] of the latest display list received for this `Pipeline` or `None` if no
64    /// display list has been received.
65    pub display_list_epoch: Option<Epoch>,
66
67    /// Paint-driven animations associated with this [`PipelineDetails`]. Currently only text caret
68    /// is handled this way.
69    ///
70    /// Note: This does not manage animations and transitions from CSS or for user input
71    /// interaction.
72    pub animations: PipelineAnimations,
73}
74
75impl PipelineDetails {
76    pub(crate) fn animation_callbacks_running(&self) -> bool {
77        self.animation_callbacks_running
78    }
79
80    pub(crate) fn animating(&self) -> bool {
81        !self.throttled && (self.animation_callbacks_running || self.animations_running)
82    }
83}
84
85impl PipelineDetails {
86    pub(crate) fn new() -> PipelineDetails {
87        PipelineDetails {
88            pipeline: None,
89            parent_pipeline_id: None,
90            children: Default::default(),
91            viewport_scale: None,
92            animations_running: false,
93            animation_callbacks_running: false,
94            throttled: false,
95            scroll_tree: ScrollTree::default(),
96            first_paint_metric: PaintMetricState::Waiting,
97            first_contentful_paint_metric: PaintMetricState::Waiting,
98            lcp_candidates: VecDeque::new(),
99            container_timing_candidates: VecDeque::new(),
100            exited: PipelineExitSource::empty(),
101            display_list_epoch: None,
102            animations: Default::default(),
103        }
104    }
105
106    pub(crate) fn install_new_scroll_tree(&mut self, new_scroll_tree: ScrollTree) {
107        let old_scroll_offsets = self.scroll_tree.scroll_offsets();
108        self.scroll_tree = new_scroll_tree;
109        self.scroll_tree.set_all_scroll_offsets(&old_scroll_offsets);
110    }
111}