mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #17965 - emilio:rebuild-not, r=heycam
stylo: Avoid recreating the stylist in RebuildAllStyleData. Bug: 1386602 Reviewed-by: heycam MozReview-Commit-ID: 31G9BLgqEmm <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17965) <!-- Reviewable:end -->
This commit is contained in:
commit
8b5a356c57
3 changed files with 24 additions and 34 deletions
|
@ -1934,12 +1934,12 @@ extern "C" {
|
||||||
pub fn Servo_StyleSet_Clear(set: RawServoStyleSetBorrowed);
|
pub fn Servo_StyleSet_Clear(set: RawServoStyleSetBorrowed);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_RebuildData(set: RawServoStyleSetBorrowed);
|
pub fn Servo_StyleSet_RebuildCachedData(set: RawServoStyleSetBorrowed);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_MediumFeaturesChanged(set: RawServoStyleSetBorrowed,
|
pub fn Servo_StyleSet_MediumFeaturesChanged(set: RawServoStyleSetBorrowed,
|
||||||
viewport_changed: bool)
|
viewport_units_used:
|
||||||
-> nsRestyleHint;
|
*mut bool) -> bool;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_CompatModeChanged(raw_data:
|
pub fn Servo_StyleSet_CompatModeChanged(raw_data:
|
||||||
|
|
|
@ -42,7 +42,6 @@ pub struct Device {
|
||||||
/// here is fine.
|
/// here is fine.
|
||||||
pres_context: RawGeckoPresContextOwned,
|
pres_context: RawGeckoPresContextOwned,
|
||||||
default_values: Arc<ComputedValues>,
|
default_values: Arc<ComputedValues>,
|
||||||
viewport_override: Option<ViewportConstraints>,
|
|
||||||
/// The font size of the root element
|
/// The font size of the root element
|
||||||
/// This is set when computing the style of the root
|
/// This is set when computing the style of the root
|
||||||
/// element, and used for rem units in other elements.
|
/// element, and used for rem units in other elements.
|
||||||
|
@ -70,7 +69,6 @@ impl Device {
|
||||||
Device {
|
Device {
|
||||||
pres_context: pres_context,
|
pres_context: pres_context,
|
||||||
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
|
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
|
||||||
viewport_override: None,
|
|
||||||
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
||||||
used_root_font_size: AtomicBool::new(false),
|
used_root_font_size: AtomicBool::new(false),
|
||||||
used_viewport_size: AtomicBool::new(false),
|
used_viewport_size: AtomicBool::new(false),
|
||||||
|
@ -79,9 +77,11 @@ impl Device {
|
||||||
|
|
||||||
/// Tells the device that a new viewport rule has been found, and stores the
|
/// Tells the device that a new viewport rule has been found, and stores the
|
||||||
/// relevant viewport constraints.
|
/// relevant viewport constraints.
|
||||||
pub fn account_for_viewport_rule(&mut self,
|
pub fn account_for_viewport_rule(
|
||||||
constraints: &ViewportConstraints) {
|
&mut self,
|
||||||
self.viewport_override = Some(constraints.clone());
|
_constraints: &ViewportConstraints
|
||||||
|
) {
|
||||||
|
unreachable!("Gecko doesn't support @viewport");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the default computed values as a reference, in order to match
|
/// Returns the default computed values as a reference, in order to match
|
||||||
|
@ -113,9 +113,12 @@ impl Device {
|
||||||
|
|
||||||
/// Recreates the default computed values.
|
/// Recreates the default computed values.
|
||||||
pub fn reset_computed_values(&mut self) {
|
pub fn reset_computed_values(&mut self) {
|
||||||
// NB: A following stylesheet flush will populate this if appropriate.
|
|
||||||
self.viewport_override = None;
|
|
||||||
self.default_values = ComputedValues::default_values(self.pres_context());
|
self.default_values = ComputedValues::default_values(self.pres_context());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rebuild all the cached data.
|
||||||
|
pub fn rebuild_cached_data(&mut self) {
|
||||||
|
self.reset_computed_values();
|
||||||
self.used_root_font_size.store(false, Ordering::Relaxed);
|
self.used_root_font_size.store(false, Ordering::Relaxed);
|
||||||
self.used_viewport_size.store(false, Ordering::Relaxed);
|
self.used_viewport_size.store(false, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
@ -130,8 +133,6 @@ impl Device {
|
||||||
/// This includes the viewport override from `@viewport` rules, and also the
|
/// This includes the viewport override from `@viewport` rules, and also the
|
||||||
/// default computed values.
|
/// default computed values.
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
// NB: A following stylesheet flush will populate this if appropriate.
|
|
||||||
self.viewport_override = None;
|
|
||||||
self.reset_computed_values();
|
self.reset_computed_values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,14 +154,11 @@ impl Device {
|
||||||
/// Returns the current viewport size in app units.
|
/// Returns the current viewport size in app units.
|
||||||
pub fn au_viewport_size(&self) -> Size2D<Au> {
|
pub fn au_viewport_size(&self) -> Size2D<Au> {
|
||||||
self.used_viewport_size.store(true, Ordering::Relaxed);
|
self.used_viewport_size.store(true, Ordering::Relaxed);
|
||||||
self.viewport_override.as_ref().map(|v| {
|
unsafe {
|
||||||
Size2D::new(Au::from_f32_px(v.size.width),
|
|
||||||
Au::from_f32_px(v.size.height))
|
|
||||||
}).unwrap_or_else(|| unsafe {
|
|
||||||
// TODO(emilio): Need to take into account scrollbars.
|
// TODO(emilio): Need to take into account scrollbars.
|
||||||
let area = &self.pres_context().mVisibleArea;
|
let area = &self.pres_context().mVisibleArea;
|
||||||
Size2D::new(Au(area.width), Au(area.height))
|
Size2D::new(Au(area.width), Au(area.height))
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether we ever looked up the viewport size of the Device.
|
/// Returns whether we ever looked up the viewport size of the Device.
|
||||||
|
|
|
@ -850,8 +850,8 @@ pub extern "C" fn Servo_StyleSet_AppendStyleSheet(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
|
pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
|
||||||
raw_data: RawServoStyleSetBorrowed,
|
raw_data: RawServoStyleSetBorrowed,
|
||||||
viewport_changed: bool,
|
viewport_units_used: *mut bool,
|
||||||
) -> nsRestyleHint {
|
) -> bool {
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
let guard = global_style_data.shared_lock.read();
|
let guard = global_style_data.shared_lock.read();
|
||||||
|
|
||||||
|
@ -867,19 +867,16 @@ pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
|
||||||
// less often.
|
// less often.
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
|
|
||||||
let viewport_units_used = data.stylist.device().used_viewport_size();
|
unsafe {
|
||||||
|
*viewport_units_used = data.stylist.device().used_viewport_size();
|
||||||
|
}
|
||||||
data.stylist.device_mut().reset_computed_values();
|
data.stylist.device_mut().reset_computed_values();
|
||||||
let rules_changed = data.stylist.media_features_change_changed_style(
|
let rules_changed = data.stylist.media_features_change_changed_style(
|
||||||
data.stylesheets.iter(),
|
data.stylesheets.iter(),
|
||||||
&guard,
|
&guard,
|
||||||
);
|
);
|
||||||
if rules_changed {
|
|
||||||
structs::nsRestyleHint_eRestyle_Subtree
|
rules_changed
|
||||||
} else if viewport_changed && viewport_units_used {
|
|
||||||
structs::nsRestyleHint_eRestyle_ForceDescendants
|
|
||||||
} else {
|
|
||||||
nsRestyleHint(0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1852,14 +1849,9 @@ pub extern "C" fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextOwned)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_RebuildData(raw_data: RawServoStyleSetBorrowed) {
|
pub extern "C" fn Servo_StyleSet_RebuildCachedData(raw_data: RawServoStyleSetBorrowed) {
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
||||||
let guard = global_style_data.shared_lock.read();
|
|
||||||
|
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
data.stylist.device_mut().reset();
|
data.stylist.device_mut().rebuild_cached_data();
|
||||||
data.stylesheets.force_dirty();
|
|
||||||
data.flush_stylesheets::<GeckoElement>(&guard, None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue