Auto merge of #18499 - heycam:rule-cache, r=emilio

Rule cache

<!-- Please describe your changes on the following line: -->
This adds a TLS-based cache reset styles structs keyed off rule nodes.  Reviewed in https://bugzilla.mozilla.org/show_bug.cgi?id=1367635 by me and Emilio.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2017-09-14 04:28:50 -05:00 committed by GitHub
commit 874cb0d9df
21 changed files with 471 additions and 35 deletions

View file

@ -866,6 +866,10 @@ impl ToComputedValue for specified::MozLength {
MozLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context))
}
specified::MozLength::ExtremumLength(ref ext) => {
debug_assert!(context.for_non_inherited_property.is_some(),
"should check whether we're a non-inherited property");
context.rule_cache_conditions.borrow_mut()
.set_writing_mode_dependency(context.builder.writing_mode);
MozLength::ExtremumLength(ext.clone())
}
}

View file

@ -11,10 +11,12 @@ use font_metrics::FontMetricsProvider;
use media_queries::Device;
#[cfg(feature = "gecko")]
use properties;
use properties::{ComputedValues, StyleBuilder};
use properties::{ComputedValues, LonghandId, StyleBuilder};
use rule_cache::RuleCacheConditions;
#[cfg(feature = "servo")]
use servo_url::ServoUrl;
use std::{f32, fmt};
use std::cell::RefCell;
#[cfg(feature = "servo")]
use std::sync::Arc;
use style_traits::ToCss;
@ -116,6 +118,17 @@ pub struct Context<'a> {
/// This is used to allow certain properties to generate out-of-range
/// values, which SMIL allows.
pub for_smil_animation: bool,
/// The property we are computing a value for, if it is a non-inherited
/// property. None if we are computed a value for an inherited property
/// or not computing for a property at all (e.g. in a media query
/// evaluation).
pub for_non_inherited_property: Option<LonghandId>,
/// The conditions to cache a rule node on the rule cache.
///
/// FIXME(emilio): Drop the refcell.
pub rule_cache_conditions: RefCell<&'a mut RuleCacheConditions>,
}
impl<'a> Context<'a> {

View file

@ -249,18 +249,36 @@ fn convert_nscolor_to_computedcolor(color: nscolor) -> ComputedColor {
impl ToComputedValue for Color {
type ComputedValue = ComputedColor;
fn to_computed_value(&self, _context: &Context) -> ComputedColor {
fn to_computed_value(&self, context: &Context) -> ComputedColor {
match *self {
Color::CurrentColor => ComputedColor::currentcolor(),
Color::CurrentColor => {
if let Some(longhand) = context.for_non_inherited_property {
if longhand.stores_complex_colors_lossily() {
context.rule_cache_conditions.borrow_mut()
.set_uncacheable();
}
}
ComputedColor::currentcolor()
}
Color::Numeric { ref parsed, .. } => ComputedColor::rgba(*parsed),
Color::Complex(ref complex) => *complex,
Color::Complex(ref complex) => {
if complex.foreground_ratio != 0 {
if let Some(longhand) = context.for_non_inherited_property {
if longhand.stores_complex_colors_lossily() {
context.rule_cache_conditions.borrow_mut()
.set_uncacheable();
}
}
}
*complex
}
#[cfg(feature = "gecko")]
Color::System(system) =>
convert_nscolor_to_computedcolor(system.to_computed_value(_context)),
convert_nscolor_to_computedcolor(system.to_computed_value(context)),
#[cfg(feature = "gecko")]
Color::Special(special) => {
use self::gecko::SpecialColorKeyword as Keyword;
let pres_context = _context.device().pres_context();
let pres_context = context.device().pres_context();
convert_nscolor_to_computedcolor(match special {
Keyword::MozDefaultColor => pres_context.mDefaultColor,
Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor,
@ -274,7 +292,7 @@ impl ToComputedValue for Color {
use dom::TElement;
use gecko::wrapper::GeckoElement;
use gecko_bindings::bindings::Gecko_GetBody;
let pres_context = _context.device().pres_context();
let pres_context = context.device().pres_context();
let body = unsafe { Gecko_GetBody(pres_context) }.map(GeckoElement);
let data = body.as_ref().and_then(|wrap| wrap.borrow_data());
if let Some(data) = data {

View file

@ -132,9 +132,18 @@ impl FontRelativeLength {
match *self {
FontRelativeLength::Em(length) => {
if !matches!(base_size, FontBaseSize::InheritedStyle) {
context.rule_cache_conditions.borrow_mut()
.set_font_size_dependency(
reference_font_size.into()
);
}
(reference_font_size, length)
},
FontRelativeLength::Ex(length) => {
if context.for_non_inherited_property.is_some() {
context.rule_cache_conditions.borrow_mut().set_uncacheable();
}
let reference_size = match query_font_metrics(context, reference_font_size) {
FontMetricsQueryResult::Available(metrics) => {
metrics.x_height
@ -152,6 +161,9 @@ impl FontRelativeLength {
(reference_size, length)
},
FontRelativeLength::Ch(length) => {
if context.for_non_inherited_property.is_some() {
context.rule_cache_conditions.borrow_mut().set_uncacheable();
}
let reference_size = match query_font_metrics(context, reference_font_size) {
FontMetricsQueryResult::Available(metrics) => {
metrics.zero_advance_measure