mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +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
|
@ -6,9 +6,8 @@ use atomic_refcell::AtomicRefCell;
|
|||
use context::{SharedStyleContext, StyleContext, ThreadLocalStyleContext};
|
||||
use data::ElementData;
|
||||
use dom::{NodeInfo, TNode};
|
||||
use gecko::context::create_or_get_local_context;
|
||||
use gecko::wrapper::{GeckoElement, GeckoNode};
|
||||
use std::rc::Rc; use traversal::{DomTraversal, PerLevelTraversalData, recalc_style_at};
|
||||
use traversal::{DomTraversal, PerLevelTraversalData, recalc_style_at};
|
||||
|
||||
pub struct RecalcStyleOnly {
|
||||
shared: SharedStyleContext,
|
||||
|
@ -25,20 +24,22 @@ impl RecalcStyleOnly {
|
|||
impl<'ln> DomTraversal<GeckoNode<'ln>> for RecalcStyleOnly {
|
||||
type ThreadLocalContext = ThreadLocalStyleContext;
|
||||
|
||||
fn process_preorder(&self, node: GeckoNode<'ln>, traversal_data: &mut PerLevelTraversalData) {
|
||||
fn process_preorder(&self, traversal_data: &mut PerLevelTraversalData,
|
||||
thread_local: &mut ThreadLocalStyleContext,
|
||||
node: GeckoNode<'ln>)
|
||||
{
|
||||
if node.is_element() {
|
||||
let el = node.as_element().unwrap();
|
||||
let mut data = unsafe { el.ensure_data() }.borrow_mut();
|
||||
let tlc = self.create_or_get_thread_local_context();
|
||||
let context = StyleContext {
|
||||
let mut context = StyleContext {
|
||||
shared: &self.shared,
|
||||
thread_local: &*tlc,
|
||||
thread_local: thread_local,
|
||||
};
|
||||
recalc_style_at(self, traversal_data, &context, el, &mut data);
|
||||
recalc_style_at(self, traversal_data, &mut context, el, &mut data);
|
||||
}
|
||||
}
|
||||
|
||||
fn process_postorder(&self, _: GeckoNode<'ln>) {
|
||||
fn process_postorder(&self, _: &mut ThreadLocalStyleContext, _: GeckoNode<'ln>) {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
|
@ -57,7 +58,7 @@ impl<'ln> DomTraversal<GeckoNode<'ln>> for RecalcStyleOnly {
|
|||
&self.shared
|
||||
}
|
||||
|
||||
fn create_or_get_thread_local_context(&self) -> Rc<ThreadLocalStyleContext> {
|
||||
create_or_get_local_context(&self.shared)
|
||||
fn create_thread_local_context(&self) -> ThreadLocalStyleContext {
|
||||
ThreadLocalStyleContext::new(&self.shared)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue