Replace RwLock<StyleRule> with Locked<StyleRule>

This commit is contained in:
Simon Sapin 2017-03-18 00:47:08 +01:00
parent 57724e5a37
commit aeffca2a59
33 changed files with 279 additions and 334 deletions

View file

@ -114,8 +114,9 @@ use style::error_reporting::StdoutErrorReporter;
use style::logical_geometry::LogicalPoint;
use style::media_queries::{Device, MediaType};
use style::parser::ParserContextExtraData;
use style::servo::AUTHOR_SHARED_LOCK;
use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW};
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard};
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ReadGuards};
use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets};
use style::stylist::Stylist;
use style::thread_state;
@ -215,7 +216,7 @@ pub struct LayoutThread {
WebRenderImageInfo,
BuildHasherDefault<FnvHasher>>>>,
// Webrender interface.
/// Webrender interface.
webrender_api: webrender_traits::RenderApi,
/// The timer object to control the timing of the animations. This should
@ -498,16 +499,18 @@ impl LayoutThread {
}
// Create a layout context for use in building display lists, hit testing, &c.
fn build_layout_context(&self,
rw_data: &LayoutThreadData,
request_images: bool)
-> LayoutContext {
fn build_layout_context<'a>(&self,
guards: ReadGuards<'a>,
rw_data: &LayoutThreadData,
request_images: bool)
-> LayoutContext<'a> {
let thread_local_style_context_creation_data =
ThreadLocalStyleContextCreationInfo::new(self.new_animations_sender.clone());
LayoutContext {
style_context: SharedStyleContext {
stylist: rw_data.stylist.clone(),
guards: guards,
running_animations: self.running_animations.clone(),
expired_animations: self.expired_animations.clone(),
error_reporter: Box::new(self.error_reporter.clone()),
@ -941,7 +944,6 @@ impl LayoutThread {
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let document = unsafe { ServoLayoutNode::new(&data.document) };
let document = document.as_document().unwrap();
let style_guard = document.style_shared_lock().read();
self.quirks_mode = Some(document.quirks_mode());
// FIXME(pcwalton): Combine `ReflowGoal` and `ReflowQueryType`. Then remove this assert.
@ -1017,9 +1019,11 @@ impl LayoutThread {
Au::from_f32_px(initial_viewport.height));
// Calculate the actual viewport as per DEVICE-ADAPT § 6
let author_guard = document.style_shared_lock().read();
let device = Device::new(MediaType::Screen, initial_viewport);
Arc::get_mut(&mut rw_data.stylist).unwrap()
.set_device(device, &style_guard, &data.document_stylesheets);
.set_device(device, &author_guard, &data.document_stylesheets);
self.viewport_size =
rw_data.stylist.viewport_constraints().map_or(current_screen_size, |constraints| {
@ -1063,10 +1067,16 @@ impl LayoutThread {
}
// If the entire flow tree is invalid, then it will be reflowed anyhow.
let ua_stylesheets = &*UA_STYLESHEETS;
let ua_or_user_guard = ua_stylesheets.shared_lock.read();
let guards = ReadGuards {
author: &author_guard,
ua_or_user: &ua_or_user_guard,
};
let needs_dirtying = Arc::get_mut(&mut rw_data.stylist).unwrap().update(
&data.document_stylesheets,
&style_guard,
Some(&*UA_STYLESHEETS),
&guards,
Some(ua_stylesheets),
data.stylesheets_changed);
let needs_reflow = viewport_size_changed && !needs_dirtying;
if needs_dirtying {
@ -1113,7 +1123,7 @@ impl LayoutThread {
}
// Create a layout context for use throughout the following passes.
let mut layout_context = self.build_layout_context(&*rw_data, true);
let mut layout_context = self.build_layout_context(guards.clone(), &*rw_data, true);
// NB: Type inference falls apart here for some reason, so we need to be very verbose. :-(
let traversal_driver = if self.parallel_flag && self.parallel_traversal.is_some() {
@ -1172,7 +1182,7 @@ impl LayoutThread {
}
if opts::get().dump_rule_tree {
layout_context.style_context.stylist.rule_tree.dump_stdout();
layout_context.style_context.stylist.rule_tree.dump_stdout(&guards);
}
// GC the rule tree if some heuristics are met.
@ -1341,7 +1351,13 @@ impl LayoutThread {
page_clip_rect: max_rect(),
};
let mut layout_context = self.build_layout_context(&*rw_data, false);
let author_guard = AUTHOR_SHARED_LOCK.read();
let ua_or_user_guard = UA_STYLESHEETS.shared_lock.read();
let guards = ReadGuards {
author: &author_guard,
ua_or_user: &ua_or_user_guard,
};
let mut layout_context = self.build_layout_context(guards, &*rw_data, false);
if let Some(mut root_flow) = self.root_flow.clone() {
// Perform an abbreviated style recalc that operates without access to the DOM.