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::{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    /// The CSS pixel to device pixel scale of the viewport of this pipeline, including
52    /// page zoom, but not including any pinch zoom amount. This is used to detect
53    /// situations where the current display list is for an old scale.
54    pub viewport_scale: Option<Scale<f32, CSSPixel, DevicePixel>>,
55
56    /// Which parts of Servo have reported that this `Pipeline` has exited. Only when all
57    /// have done so will it be discarded.
58    pub exited: PipelineExitSource,
59
60    /// The [`Epoch`] of the latest display list received for this `Pipeline` or `None` if no
61    /// display list has been received.
62    pub display_list_epoch: Option<Epoch>,
63
64    /// Paint-driven animations associated with this [`PipelineDetails`]. Currently only text caret
65    /// is handled this way.
66    ///
67    /// Note: This does not manage animations and transitions from CSS or for user input
68    /// interaction.
69    pub animations: PipelineAnimations,
70}
71
72impl PipelineDetails {
73    pub(crate) fn animation_callbacks_running(&self) -> bool {
74        self.animation_callbacks_running
75    }
76
77    pub(crate) fn animating(&self) -> bool {
78        !self.throttled && (self.animation_callbacks_running || self.animations_running)
79    }
80}
81
82impl PipelineDetails {
83    pub(crate) fn new() -> PipelineDetails {
84        PipelineDetails {
85            pipeline: None,
86            parent_pipeline_id: None,
87            children: Default::default(),
88            viewport_scale: None,
89            animations_running: false,
90            animation_callbacks_running: false,
91            throttled: false,
92            scroll_tree: ScrollTree::default(),
93            first_paint_metric: PaintMetricState::Waiting,
94            first_contentful_paint_metric: PaintMetricState::Waiting,
95            lcp_candidates: VecDeque::new(),
96            exited: PipelineExitSource::empty(),
97            display_list_epoch: None,
98            animations: Default::default(),
99        }
100    }
101
102    pub(crate) fn install_new_scroll_tree(&mut self, new_scroll_tree: ScrollTree) {
103        let old_scroll_offsets = self.scroll_tree.scroll_offsets();
104        self.scroll_tree = new_scroll_tree;
105        self.scroll_tree.set_all_scroll_offsets(&old_scroll_offsets);
106    }
107}