style: Remove the Mutex from new_animations_sender by moving it to the local StyleContext.

As a follow-up, we could move all the data living under a mutex in the
SharedLayoutContext only in order to create the local context to the same place.

This should increase animation performance when there are multiple animations in
one page that happen to be on different threads.
This commit is contained in:
Emilio Cobos Álvarez 2016-06-29 20:04:30 -07:00
parent 5478e605ae
commit 203d2a62c2
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
15 changed files with 166 additions and 134 deletions

View file

@ -22,7 +22,7 @@ use std::ptr;
use std::slice;
use std::str::from_utf8_unchecked;
use std::sync::{Arc, Mutex};
use style::context::ReflowGoal;
use style::context::{LocalStyleContextCreationInfo, ReflowGoal};
use style::dom::{TDocument, TElement, TNode};
use style::error_reporting::StdoutErrorReporter;
use style::parallel;
@ -77,7 +77,7 @@ pub extern "C" fn Servo_Initialize() -> () {
fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
debug_assert!(node.is_element() || node.is_text_node());
let data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) };
let per_doc_data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) };
// Force the creation of our lazily-constructed initial computed values on
// the main thread, since it's not safe to call elsewhere.
@ -88,24 +88,28 @@ fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
// along in startup than the sensible place to call Servo_Initialize.
GeckoComputedValues::initial_values();
let _needs_dirtying = Arc::get_mut(&mut data.stylist).unwrap()
.update(&data.stylesheets, data.stylesheets_changed);
data.stylesheets_changed = false;
let _needs_dirtying = Arc::get_mut(&mut per_doc_data.stylist).unwrap()
.update(&per_doc_data.stylesheets,
per_doc_data.stylesheets_changed);
per_doc_data.stylesheets_changed = false;
let local_context_data =
LocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
let shared_style_context = SharedStyleContext {
viewport_size: Size2D::new(Au(0), Au(0)),
screen_size_changed: false,
generation: 0,
goal: ReflowGoal::ForScriptQuery,
stylist: data.stylist.clone(),
new_animations_sender: Mutex::new(data.new_animations_sender.clone()),
running_animations: data.running_animations.clone(),
expired_animations: data.expired_animations.clone(),
stylist: per_doc_data.stylist.clone(),
running_animations: per_doc_data.running_animations.clone(),
expired_animations: per_doc_data.expired_animations.clone(),
error_reporter: Box::new(StdoutErrorReporter),
local_context_creation_data: Mutex::new(local_context_data),
};
if node.is_dirty() || node.has_dirty_descendants() {
parallel::traverse_dom::<GeckoNode, RecalcStyleOnly>(node, &shared_style_context, &mut data.work_queue);
parallel::traverse_dom::<GeckoNode, RecalcStyleOnly>(node, &shared_style_context, &mut per_doc_data.work_queue);
}
}