mirror of
https://github.com/servo/servo.git
synced 2025-08-14 18:05:36 +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
|
@ -1,27 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use context::{SharedStyleContext, ThreadLocalStyleContext};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
thread_local!(static LOCAL_CONTEXT_KEY: RefCell<Option<Rc<ThreadLocalStyleContext>>> = RefCell::new(None));
|
||||
|
||||
// Keep this implementation in sync with the one in components/layout/context.rs.
|
||||
pub fn create_or_get_local_context(shared: &SharedStyleContext) -> Rc<ThreadLocalStyleContext> {
|
||||
LOCAL_CONTEXT_KEY.with(|r| {
|
||||
let mut r = r.borrow_mut();
|
||||
if let Some(context) = r.clone() {
|
||||
context
|
||||
} else {
|
||||
let context = Rc::new(ThreadLocalStyleContext::new(&shared.local_context_creation_data.lock().unwrap()));
|
||||
*r = Some(context.clone());
|
||||
context
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn clear_local_context() {
|
||||
LOCAL_CONTEXT_KEY.with(|r| *r.borrow_mut() = None);
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
pub mod context;
|
||||
pub mod data;
|
||||
pub mod restyle_damage;
|
||||
pub mod snapshot;
|
||||
|
|
|
@ -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