Bug 1474959 part 1 - Have StyleBuilder return a UniqueArc. r?emilio
MozReview-Commit-ID: CzMTxtZtRsP
--- a/servo/components/style/animation.rs
+++ b/servo/components/style/animation.rs
@@ -507,17 +507,17 @@ where
/* visited_style = */ None,
font_metrics_provider,
CascadeFlags::empty(),
context.quirks_mode(),
/* rule_cache = */ None,
&mut Default::default(),
/* element = */ None,
);
- computed
+ computed.shareable()
},
}
}
/// Triggers animations for a given node looking at the animation property
/// values.
pub fn maybe_start_animations<E>(
element: E,
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -47,17 +47,17 @@ use gecko::values::convert_rgba_to_nscol
use gecko::values::GeckoStyleCoordConvertible;
use gecko::values::round_border_to_device_pixels;
use logical_geometry::WritingMode;
use media_queries::Device;
use properties::computed_value_flags::*;
use properties::longhands;
use rule_tree::StrongRuleNode;
use selector_parser::PseudoElement;
-use servo_arc::{Arc, RawOffsetArc};
+use servo_arc::{Arc, RawOffsetArc, UniqueArc};
use std::marker::PhantomData;
use std::mem::{forget, uninitialized, transmute, zeroed};
use std::{cmp, ops, ptr};
use values::{self, CustomIdent, Either, KeyframesName, None_};
use values::computed::{NonNegativeLength, Percentage, TransitionProperty};
use values::computed::font::FontSize;
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
use values::computed::outline::OutlineStyle;
@@ -88,17 +88,17 @@ impl ComputedValues {
custom_properties: Option<Arc<CustomPropertiesMap>>,
writing_mode: WritingMode,
flags: ComputedValueFlags,
rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>,
% for style_struct in data.style_structs:
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
- ) -> Arc<Self> {
+ ) -> UniqueArc<Self> {
ComputedValuesInner::new(
custom_properties,
writing_mode,
flags,
rules,
visited_style,
% for style_struct in data.style_structs:
${style_struct.ident},
@@ -115,17 +115,17 @@ impl ComputedValues {
/* custom_properties = */ None,
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
ComputedValueFlags::empty(),
/* rules = */ None,
/* visited_style = */ None,
% for style_struct in data.style_structs:
style_structs::${style_struct.name}::default(pres_context),
% endfor
- ).to_outer(pres_context, None, None)
+ ).to_outer(pres_context, None, None).shareable()
}
pub fn pseudo(&self) -> Option<PseudoElement> {
let atom = (self.0).mPseudoTag.mRawPtr;
if atom.is_null() {
return None;
}
@@ -219,35 +219,35 @@ impl ComputedValuesInner {
}
}
fn to_outer(
self,
pres_context: RawGeckoPresContextBorrowed,
parent: ParentComputedStyleInfo,
info: Option<PseudoInfo>
- ) -> Arc<ComputedValues> {
+ ) -> UniqueArc<ComputedValues> {
let (tag, ty) = if let Some(info) = info {
info
} else {
(ptr::null_mut(), structs::CSSPseudoElementType::NotPseudo)
};
unsafe { self.to_outer_helper(pres_context, parent, ty, tag) }
}
unsafe fn to_outer_helper(
self,
pres_context: bindings::RawGeckoPresContextBorrowed,
parent: ParentComputedStyleInfo,
pseudo_ty: structs::CSSPseudoElementType,
pseudo_tag: *mut structs::nsAtom
- ) -> Arc<ComputedValues> {
+ ) -> UniqueArc<ComputedValues> {
let arc = {
- let arc: Arc<ComputedValues> = Arc::new(uninitialized());
+ let arc: UniqueArc<ComputedValues> = UniqueArc::new(uninitialized());
bindings::Gecko_ComputedStyle_Init(&arc.0 as *const _ as *mut _,
parent, pres_context,
&self, pseudo_ty, pseudo_tag);
// We're simulating a move by having C++ do a memcpy and then forgetting
// it on this end.
forget(self);
arc
};
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -2726,18 +2726,18 @@ impl ComputedValues {
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode,
flags: ComputedValueFlags,
rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>,
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
- ) -> Arc<Self> {
- Arc::new(Self {
+ ) -> UniqueArc<Self> {
+ UniqueArc::new(Self {
inner: ComputedValuesInner {
custom_properties,
writing_mode,
rules,
visited_style,
flags,
% for style_struct in data.active_style_structs():
${style_struct.ident},
@@ -3368,17 +3368,17 @@ impl<'a> StyleBuilder<'a> {
// to adjust or process visited style, so we can just build visited
// style here for simplicity.
let visited_style = parent.and_then(|parent| {
parent.visited_style().map(|style| {
Self::for_inheritance(
device,
Some(style),
pseudo,
- ).build()
+ ).build().shareable()
})
});
Self::new(
device,
parent,
parent,
pseudo,
CascadeFlags::empty(),
@@ -3478,17 +3478,17 @@ impl<'a> StyleBuilder<'a> {
/// Returns whether we have mutated any reset structs since the the last
/// time `clear_modified_reset` was called.
fn modified_reset(&self) -> bool {
self.modified_reset
}
/// Turns this `StyleBuilder` into a proper `ComputedValues` instance.
- pub fn build(self) -> Arc<ComputedValues> {
+ pub fn build(self) -> UniqueArc<ComputedValues> {
ComputedValues::new(
self.device,
self.parent_style,
self.pseudo,
self.custom_properties,
self.writing_mode,
self.flags,
self.rules,
@@ -3633,17 +3633,17 @@ pub fn cascade<E>(
layout_parent_style: Option<<&ComputedValues>,
visited_style: Option<Arc<ComputedValues>>,
font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags,
quirks_mode: QuirksMode,
rule_cache: Option<<&RuleCache>,
rule_cache_conditions: &mut RuleCacheConditions,
element: Option<E>,
-) -> Arc<ComputedValues>
+) -> UniqueArc<ComputedValues>
where
E: TElement,
{
debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some());
let empty = SmallBitVec::new();
let property_restriction = pseudo.and_then(|p| p.property_restriction());
@@ -3717,17 +3717,17 @@ pub fn apply_declarations<'a, E, F, I>(
layout_parent_style: Option<<&ComputedValues>,
visited_style: Option<Arc<ComputedValues>>,
font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags,
quirks_mode: QuirksMode,
rule_cache: Option<<&RuleCache>,
rule_cache_conditions: &mut RuleCacheConditions,
element: Option<E>,
-) -> Arc<ComputedValues>
+) -> UniqueArc<ComputedValues>
where
E: TElement,
F: Fn() -> I,
I: Iterator<Item = (&'a PropertyDeclaration, CascadeLevel)>,
{
debug_assert!(layout_parent_style.is_none() || parent_style.is_some());
debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some());
#[cfg(feature = "gecko")]
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -887,17 +887,17 @@ impl Stylist {
layout_parent_style_for_visited,
None,
font_metrics,
cascade_flags | CascadeFlags::VISITED_DEPENDENT_ONLY,
self.quirks_mode,
rule_cache,
rule_cache_conditions,
element,
- ));
+ ).shareable());
}
// Read the comment on `precomputed_values_for_pseudo` to see why it's
// difficult to assert that display: contents nodes never arrive here
// (tl;dr: It doesn't apply for replaced elements and such, but the
// computed value is still "contents").
//
// FIXME(emilio): We should assert that it holds if pseudo.is_none()!
@@ -911,17 +911,17 @@ impl Stylist {
layout_parent_style,
visited_values,
font_metrics,
cascade_flags,
self.quirks_mode,
rule_cache,
rule_cache_conditions,
element,
- )
+ ).shareable()
}
/// Computes the cascade inputs for a lazily-cascaded pseudo-element.
///
/// See the documentation on lazy pseudo-elements in
/// docs/components/style.md
fn lazy_pseudo_rules<E>(
&self,
@@ -1586,17 +1586,17 @@ impl Stylist {
Some(parent_style),
None,
&metrics,
CascadeFlags::empty(),
self.quirks_mode,
/* rule_cache = */ None,
&mut Default::default(),
/* element = */ None,
- )
+ ).shareable()
}
/// Accessor for a shared reference to the device.
#[inline]
pub fn device(&self) -> &Device {
&self.device
}
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -3078,17 +3078,17 @@ fn get_pseudo_style(
return style;
}
Some(style.unwrap_or_else(|| {
StyleBuilder::for_inheritance(
doc_data.stylist.device(),
Some(styles.primary()),
Some(pseudo),
- ).build()
+ ).build().shareable()
}))
}
#[no_mangle]
pub unsafe extern "C" fn Servo_ComputedValues_Inherit(
raw_data: RawServoStyleSetBorrowed,
pseudo_tag: *mut nsAtom,
parent_style_context: ComputedStyleBorrowedOrNull,
@@ -3106,17 +3106,17 @@ pub unsafe extern "C" fn Servo_ComputedV
parent_style_context,
Some(&pseudo)
);
if for_text {
StyleAdjuster::new(&mut style).adjust_for_text();
}
- style.build().into()
+ style.build().shareable().into()
}
#[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetStyleBits(values: ComputedStyleBorrowed) -> u8 {
use style::properties::computed_value_flags::ComputedValueFlags;
// FIXME(emilio): We could do this more efficiently I'm quite sure.
let flags = values.flags;
let mut result = 0;