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