tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mod.rs (4445B)


      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 http://mozilla.org/MPL/2.0/. */
      4 
      5 //! Invalidation tracking and dirty region management
      6 //!
      7 //! This module contains types and logic for tracking dirty regions and
      8 //! dependencies used to determine what needs to be redrawn each frame.
      9 
     10 pub mod compare;
     11 pub mod quadtree;
     12 pub mod cached_surface;
     13 
     14 use api::units::*;
     15 use crate::spatial_tree::{SpatialTree, SpatialNodeIndex};
     16 use crate::space::SpaceMapper;
     17 use crate::util::MaxRect;
     18 
     19 /// Represents the dirty region of a tile cache picture, relative to a
     20 /// "visibility" spatial node. At the moment the visibility node is
     21 /// world space, but the plan is to switch to raster space.
     22 ///
     23 /// The plan is to move away from these world space representation and
     24 /// compute dirty regions in raster space instead.
     25 #[derive(Clone)]
     26 pub struct DirtyRegion {
     27    /// The overall dirty rect, a combination of dirty_rects
     28    pub combined: VisRect,
     29 
     30    /// The corrdinate space used to do clipping, visibility, and
     31    /// dirty rect calculations.
     32    pub visibility_spatial_node: SpatialNodeIndex,
     33    /// Spatial node of the picture this region represents.
     34    local_spatial_node: SpatialNodeIndex,
     35 }
     36 
     37 impl DirtyRegion {
     38    /// Construct a new dirty region tracker.
     39    pub fn new(
     40        visibility_spatial_node: SpatialNodeIndex,
     41        local_spatial_node: SpatialNodeIndex,
     42    ) -> Self {
     43        DirtyRegion {
     44            combined: VisRect::zero(),
     45            visibility_spatial_node,
     46            local_spatial_node,
     47        }
     48    }
     49 
     50    /// Reset the dirty regions back to empty
     51    pub fn reset(
     52        &mut self,
     53        visibility_spatial_node: SpatialNodeIndex,
     54        local_spatial_node: SpatialNodeIndex,
     55    ) {
     56        self.combined = VisRect::zero();
     57        self.visibility_spatial_node = visibility_spatial_node;
     58        self.local_spatial_node = local_spatial_node;
     59    }
     60 
     61    /// Add a dirty region to the tracker. Returns the visibility mask that corresponds to
     62    /// this region in the tracker.
     63    pub fn add_dirty_region(
     64        &mut self,
     65        rect_in_pic_space: PictureRect,
     66        spatial_tree: &SpatialTree,
     67    ) {
     68        let map_pic_to_raster = SpaceMapper::new_with_target(
     69            self.visibility_spatial_node,
     70            self.local_spatial_node,
     71            VisRect::max_rect(),
     72            spatial_tree,
     73        );
     74 
     75        let raster_rect = map_pic_to_raster
     76            .map(&rect_in_pic_space)
     77            .expect("bug");
     78 
     79        // Include this in the overall dirty rect
     80        self.combined = self.combined.union(&raster_rect);
     81    }
     82 }
     83 
     84 /// Debugging information about why a tile was invalidated
     85 #[derive(Debug,Clone)]
     86 #[cfg_attr(feature = "capture", derive(Serialize))]
     87 #[cfg_attr(feature = "replay", derive(Deserialize))]
     88 pub enum InvalidationReason {
     89    /// The background color changed
     90    BackgroundColor,
     91    /// The opaque state of the backing native surface changed
     92    SurfaceOpacityChanged,
     93    /// There was no backing texture (evicted or never rendered)
     94    NoTexture,
     95    /// There was no backing native surface (never rendered, or recreated)
     96    NoSurface,
     97    /// The primitive count in the dependency list was different
     98    PrimCount,
     99    /// The content of one of the primitives was different
    100    Content,
    101    // The compositor type changed
    102    CompositorKindChanged,
    103    // The valid region of the tile changed
    104    ValidRectChanged,
    105    // The overall scale of the picture cache changed
    106    ScaleChanged,
    107    // The content of the sampling surface changed
    108    SurfaceContentChanged,
    109 }
    110 
    111 /// The result of a primitive dependency comparison. Size is a u8
    112 /// since this is a hot path in the code, and keeping the data small
    113 /// is a performance win.
    114 #[derive(Debug, Copy, Clone, PartialEq)]
    115 #[cfg_attr(feature = "capture", derive(Serialize))]
    116 #[cfg_attr(feature = "replay", derive(Deserialize))]
    117 #[repr(u8)]
    118 pub enum PrimitiveCompareResult {
    119    /// Primitives match
    120    Equal,
    121    /// Something in the PrimitiveDescriptor was different
    122    Descriptor,
    123    /// The clip node content or spatial node changed
    124    Clip,
    125    /// The value of the transform changed
    126    Transform,
    127    /// An image dependency was dirty
    128    Image,
    129    /// The value of an opacity binding changed
    130    OpacityBinding,
    131    /// The value of a color binding changed
    132    ColorBinding,
    133 }