mirror of
https://github.com/servo/servo.git
synced 2025-08-18 11:55:39 +01:00
Introduce and use Scoped TLS.
It turns out that it's problematic to embed ThreadLocalStyleContext within LayoutContext, because parameterizing the former on TElement (which we do in the next patch) infects all the traversal stuff with the trait parameters, which we don't really want. In general, it probably makes sense to use separate scoped TLS types for the separate DOM and Flow tree passes, so we can add a different ScopedTLS type for the Flow pass if we ever need it. We also reorder the |scope| and |shared| parameters in parallel.rs, because it aligns more with the order in style/parallel.rs. I did this when I was adding a TLS parameter to all these functions, which I realized we don't need for now.
This commit is contained in:
parent
8f7f62f810
commit
c5f01fe3b8
16 changed files with 212 additions and 205 deletions
|
@ -17,11 +17,11 @@ use std::ptr;
|
|||
use std::sync::{Arc, Mutex};
|
||||
use style::arc_ptr_eq;
|
||||
use style::atomic_refcell::AtomicRefMut;
|
||||
use style::context::{ThreadLocalStyleContextCreationInfo, QuirksMode, ReflowGoal, SharedStyleContext, StyleContext};
|
||||
use style::context::{QuirksMode, ReflowGoal, SharedStyleContext, StyleContext};
|
||||
use style::context::{ThreadLocalStyleContext, ThreadLocalStyleContextCreationInfo};
|
||||
use style::data::{ElementData, RestyleData};
|
||||
use style::dom::{ShowSubtreeData, TElement, TNode};
|
||||
use style::error_reporting::StdoutErrorReporter;
|
||||
use style::gecko::context::clear_local_context;
|
||||
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
||||
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
||||
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
|
||||
|
@ -88,12 +88,6 @@ pub extern "C" fn Servo_Initialize() -> () {
|
|||
pub extern "C" fn Servo_Shutdown() -> () {
|
||||
// Destroy our default computed values.
|
||||
unsafe { ComputedValues::shutdown(); }
|
||||
|
||||
// In general, ThreadLocalStyleContexts will get destroyed when the worker thread
|
||||
// is joined and the TLS is dropped. However, under some configurations we
|
||||
// may do sequential style computation on the main thread, so we need to be
|
||||
// sure to clear the main thread TLS entry as well.
|
||||
clear_local_context();
|
||||
}
|
||||
|
||||
fn create_shared_context(mut per_doc_data: &mut AtomicRefMut<PerDocumentStyleDataImpl>) -> SharedStyleContext {
|
||||
|
@ -875,22 +869,19 @@ pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
|
|||
let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
let shared_style_context = create_shared_context(&mut per_doc_data);
|
||||
let traversal = RecalcStyleOnly::new(shared_style_context);
|
||||
let tlc = traversal.create_or_get_thread_local_context();
|
||||
|
||||
let mut traversal_data = PerLevelTraversalData {
|
||||
current_dom_depth: None,
|
||||
};
|
||||
|
||||
let mut tlc = ThreadLocalStyleContext::new(traversal.shared_context());
|
||||
let context = StyleContext {
|
||||
shared: traversal.shared_context(),
|
||||
thread_local: &*tlc,
|
||||
thread_local: &mut tlc,
|
||||
};
|
||||
|
||||
recalc_style_at(&traversal, &mut traversal_data, &context, element, &mut data);
|
||||
|
||||
// We don't want to keep any cached style around after this one-off style resolution.
|
||||
tlc.style_sharing_candidate_cache.borrow_mut().clear();
|
||||
|
||||
// The element was either unstyled or needed restyle. If it was unstyled, it may have
|
||||
// additional unstyled children that subsequent traversals won't find now that the style
|
||||
// on this element is up-to-date. Mark dirty descendants in that case.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue