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