traversal_flags.rs (2827B)
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 5 //! Flags that control the traversal process. 6 //! 7 //! We CamelCase rather than UPPER_CASING so that we can grep for the same 8 //! strings across gecko and servo. 9 #![allow(non_upper_case_globals)] 10 11 bitflags! { 12 /// Flags that control the traversal process. 13 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 14 pub struct TraversalFlags: u32 { 15 /// Traverse only elements for animation restyles. 16 const AnimationOnly = 1 << 0; 17 /// Traverse and update all elements with CSS animations since 18 /// @keyframes rules may have changed. Triggered by CSS rule changes. 19 const ForCSSRuleChanges = 1 << 1; 20 /// The final animation-only traversal, which shouldn't really care about other 21 /// style changes anymore. 22 const FinalAnimationTraversal = 1 << 2; 23 /// Allows the traversal to run in parallel if there are sufficient cores on 24 /// the machine. 25 const ParallelTraversal = 1 << 7; 26 /// Flush throttled animations. By default, we only update throttled animations 27 /// when we have other non-throttled work to do. With this flag, we 28 /// unconditionally tick and process them. 29 const FlushThrottledAnimations = 1 << 8; 30 31 } 32 } 33 34 /// Asserts that all TraversalFlags flags have a matching ServoTraversalFlags value in gecko. 35 #[cfg(feature = "gecko")] 36 #[inline] 37 pub fn assert_traversal_flags_match() { 38 use crate::gecko_bindings::structs; 39 40 macro_rules! check_traversal_flags { 41 ( $( $a:ident => $b:path ),*, ) => { 42 if cfg!(debug_assertions) { 43 let mut modes = TraversalFlags::all(); 44 $( 45 assert_eq!(structs::$a as usize, $b.bits() as usize, stringify!($b)); 46 modes.remove($b); 47 )* 48 assert_eq!(modes, TraversalFlags::empty(), "all TraversalFlags bits should have an assertion"); 49 } 50 } 51 } 52 53 check_traversal_flags! { 54 ServoTraversalFlags_AnimationOnly => TraversalFlags::AnimationOnly, 55 ServoTraversalFlags_ForCSSRuleChanges => TraversalFlags::ForCSSRuleChanges, 56 ServoTraversalFlags_FinalAnimationTraversal => TraversalFlags::FinalAnimationTraversal, 57 ServoTraversalFlags_ParallelTraversal => TraversalFlags::ParallelTraversal, 58 ServoTraversalFlags_FlushThrottledAnimations => TraversalFlags::FlushThrottledAnimations, 59 } 60 } 61 62 impl TraversalFlags { 63 /// Returns true if the traversal is for animation-only restyles. 64 #[inline] 65 pub fn for_animation_only(&self) -> bool { 66 self.contains(TraversalFlags::AnimationOnly) 67 } 68 }