mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
Use AtomicRefCell for RawServoStyleSet.
MozReview-Commit-ID: 27JeRluDAo3
This commit is contained in:
parent
e597719b73
commit
63ac0d2540
3 changed files with 42 additions and 30 deletions
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use animation::Animation;
|
||||
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
||||
use context::SharedStyleContext;
|
||||
use dom::OpaqueNode;
|
||||
use euclid::size::TypedSize2D;
|
||||
|
@ -22,7 +23,7 @@ use stylesheets::Stylesheet;
|
|||
use thread_state;
|
||||
use workqueue::WorkQueue;
|
||||
|
||||
pub struct PerDocumentStyleData {
|
||||
pub struct PerDocumentStyleDataImpl {
|
||||
/// Rule processor.
|
||||
pub stylist: Arc<Stylist>,
|
||||
|
||||
|
@ -44,6 +45,8 @@ pub struct PerDocumentStyleData {
|
|||
pub num_threads: usize,
|
||||
}
|
||||
|
||||
pub struct PerDocumentStyleData(AtomicRefCell<PerDocumentStyleDataImpl>);
|
||||
|
||||
lazy_static! {
|
||||
pub static ref NUM_THREADS: usize = {
|
||||
match env::var("STYLO_THREADS").map(|s| s.parse::<usize>().expect("invalid STYLO_THREADS")) {
|
||||
|
@ -54,14 +57,14 @@ lazy_static! {
|
|||
}
|
||||
|
||||
impl PerDocumentStyleData {
|
||||
pub fn new() -> PerDocumentStyleData {
|
||||
pub fn new() -> Self {
|
||||
// FIXME(bholley): Real window size.
|
||||
let window_size: TypedSize2D<f32, ViewportPx> = TypedSize2D::new(800.0, 600.0);
|
||||
let device = Device::new(MediaType::Screen, window_size);
|
||||
|
||||
let (new_anims_sender, new_anims_receiver) = channel();
|
||||
|
||||
PerDocumentStyleData {
|
||||
PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
|
||||
stylist: Arc::new(Stylist::new(device)),
|
||||
stylesheets: vec![],
|
||||
stylesheets_changed: true,
|
||||
|
@ -75,9 +78,19 @@ impl PerDocumentStyleData {
|
|||
WorkQueue::new("StyleWorker", thread_state::LAYOUT, *NUM_THREADS).ok()
|
||||
},
|
||||
num_threads: *NUM_THREADS,
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn borrow(&self) -> AtomicRef<PerDocumentStyleDataImpl> {
|
||||
self.0.borrow()
|
||||
}
|
||||
|
||||
pub fn borrow_mut(&self) -> AtomicRefMut<PerDocumentStyleDataImpl> {
|
||||
self.0.borrow_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl PerDocumentStyleDataImpl {
|
||||
pub fn flush_stylesheets(&mut self) {
|
||||
// The stylist wants to be flushed if either the stylesheets change or the
|
||||
// device dimensions change. When we add support for media queries, we'll
|
||||
|
@ -96,7 +109,7 @@ unsafe impl HasFFI for PerDocumentStyleData {
|
|||
unsafe impl HasSimpleFFI for PerDocumentStyleData {}
|
||||
unsafe impl HasBoxFFI for PerDocumentStyleData {}
|
||||
|
||||
impl Drop for PerDocumentStyleData {
|
||||
impl Drop for PerDocumentStyleDataImpl {
|
||||
fn drop(&mut self) {
|
||||
if let Some(ref mut queue) = self.work_queue {
|
||||
queue.shutdown();
|
||||
|
|
|
@ -826,21 +826,21 @@ extern "C" {
|
|||
pub fn Servo_StyleSet_Drop(set: RawServoStyleSetOwned);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowedMut,
|
||||
pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowed,
|
||||
sheet: RawServoStyleSheetBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleSet_PrependStyleSheet(set: RawServoStyleSetBorrowedMut,
|
||||
pub fn Servo_StyleSet_PrependStyleSheet(set: RawServoStyleSetBorrowed,
|
||||
sheet:
|
||||
RawServoStyleSheetBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleSet_RemoveStyleSheet(set: RawServoStyleSetBorrowedMut,
|
||||
pub fn Servo_StyleSet_RemoveStyleSheet(set: RawServoStyleSetBorrowed,
|
||||
sheet: RawServoStyleSheetBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleSet_InsertStyleSheetBefore(set:
|
||||
RawServoStyleSetBorrowedMut,
|
||||
RawServoStyleSetBorrowed,
|
||||
sheet:
|
||||
RawServoStyleSheetBorrowed,
|
||||
reference:
|
||||
|
@ -912,7 +912,7 @@ extern "C" {
|
|||
ServoComputedValuesBorrowedOrNull,
|
||||
pseudoTag: *mut nsIAtom,
|
||||
set:
|
||||
RawServoStyleSetBorrowedMut)
|
||||
RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong;
|
||||
}
|
||||
extern "C" {
|
||||
|
@ -922,7 +922,7 @@ extern "C" {
|
|||
RawGeckoElementBorrowed,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
set:
|
||||
RawServoStyleSetBorrowedMut,
|
||||
RawServoStyleSetBorrowed,
|
||||
is_probe: bool)
|
||||
-> ServoComputedValuesStrong;
|
||||
}
|
||||
|
@ -953,7 +953,7 @@ extern "C" {
|
|||
}
|
||||
extern "C" {
|
||||
pub fn Servo_RestyleSubtree(node: RawGeckoNodeBorrowed,
|
||||
set: RawServoStyleSetBorrowedMut);
|
||||
set: RawServoStyleSetBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_GetStyleFont(computed_values:
|
||||
|
|
|
@ -15,7 +15,7 @@ use std::sync::{Arc, Mutex};
|
|||
use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering};
|
||||
use style::arc_ptr_eq;
|
||||
use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext};
|
||||
use style::dom::{NodeInfo, TDocument, TElement, TNode};
|
||||
use style::dom::{NodeInfo, TElement, TNode};
|
||||
use style::error_reporting::StdoutErrorReporter;
|
||||
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData};
|
||||
use style::gecko::selector_impl::{GeckoSelectorImpl, PseudoElement};
|
||||
|
@ -31,7 +31,6 @@ use style::gecko_bindings::bindings::{ServoDeclarationBlockBorrowed, ServoDeclar
|
|||
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
||||
use style::gecko_bindings::bindings::{nsHTMLCSSStyleSheet, ServoComputedValuesBorrowedOrNull};
|
||||
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
||||
use style::gecko_bindings::bindings::RawServoStyleSetBorrowedMut;
|
||||
use style::gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI};
|
||||
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
||||
use style::gecko_bindings::structs::ServoElementSnapshot;
|
||||
|
@ -77,7 +76,7 @@ pub extern "C" fn Servo_Shutdown() -> () {
|
|||
unsafe { ComputedValues::shutdown(); }
|
||||
}
|
||||
|
||||
fn restyle_subtree(node: GeckoNode, raw_data: RawServoStyleSetBorrowedMut) {
|
||||
fn restyle_subtree(node: GeckoNode, raw_data: RawServoStyleSetBorrowed) {
|
||||
debug_assert!(node.is_element() || node.is_text_node());
|
||||
|
||||
// Force the creation of our lazily-constructed initial computed values on
|
||||
|
@ -90,7 +89,7 @@ fn restyle_subtree(node: GeckoNode, raw_data: RawServoStyleSetBorrowedMut) {
|
|||
ComputedValues::initial_values();
|
||||
|
||||
// The stylist consumes stylesheets lazily.
|
||||
let per_doc_data = PerDocumentStyleData::from_ffi_mut(raw_data);
|
||||
let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
per_doc_data.flush_stylesheets();
|
||||
|
||||
let local_context_data =
|
||||
|
@ -122,7 +121,7 @@ fn restyle_subtree(node: GeckoNode, raw_data: RawServoStyleSetBorrowedMut) {
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_RestyleSubtree(node: RawGeckoNodeBorrowed,
|
||||
raw_data: RawServoStyleSetBorrowedMut) -> () {
|
||||
raw_data: RawServoStyleSetBorrowed) -> () {
|
||||
let node = GeckoNode(node);
|
||||
restyle_subtree(node, raw_data);
|
||||
}
|
||||
|
@ -200,9 +199,9 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(bytes: *const u8,
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_AppendStyleSheet(raw_data: RawServoStyleSetBorrowedMut,
|
||||
pub extern "C" fn Servo_StyleSet_AppendStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
||||
raw_sheet: RawServoStyleSheetBorrowed) {
|
||||
let data = PerDocumentStyleData::from_ffi_mut(raw_data);
|
||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
||||
data.stylesheets.push(sheet.clone());
|
||||
|
@ -210,9 +209,9 @@ pub extern "C" fn Servo_StyleSet_AppendStyleSheet(raw_data: RawServoStyleSetBorr
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_PrependStyleSheet(raw_data: RawServoStyleSetBorrowedMut,
|
||||
pub extern "C" fn Servo_StyleSet_PrependStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
||||
raw_sheet: RawServoStyleSheetBorrowed) {
|
||||
let data = PerDocumentStyleData::from_ffi_mut(raw_data);
|
||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
||||
data.stylesheets.insert(0, sheet.clone());
|
||||
|
@ -220,10 +219,10 @@ pub extern "C" fn Servo_StyleSet_PrependStyleSheet(raw_data: RawServoStyleSetBor
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(raw_data: RawServoStyleSetBorrowedMut,
|
||||
pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(raw_data: RawServoStyleSetBorrowed,
|
||||
raw_sheet: RawServoStyleSheetBorrowed,
|
||||
raw_reference: RawServoStyleSheetBorrowed) {
|
||||
let data = PerDocumentStyleData::from_ffi_mut(raw_data);
|
||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||
let reference = HasArcFFI::as_arc(&raw_reference);
|
||||
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
||||
|
@ -233,9 +232,9 @@ pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(raw_data: RawServoStyleS
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_RemoveStyleSheet(raw_data: RawServoStyleSetBorrowedMut,
|
||||
pub extern "C" fn Servo_StyleSet_RemoveStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
||||
raw_sheet: RawServoStyleSheetBorrowed) {
|
||||
let data = PerDocumentStyleData::from_ffi_mut(raw_data);
|
||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
||||
data.stylesheets_changed = true;
|
||||
|
@ -277,10 +276,10 @@ pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowedOrNull,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
raw_data: RawServoStyleSetBorrowedMut)
|
||||
raw_data: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong {
|
||||
// The stylist consumes stylesheets lazily.
|
||||
let data = PerDocumentStyleData::from_ffi_mut(raw_data);
|
||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
data.flush_stylesheets();
|
||||
|
||||
let atom = Atom::from(pseudo_tag);
|
||||
|
@ -296,7 +295,7 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
|
|||
pub extern "C" fn Servo_ComputedValues_GetForPseudoElement(parent_style: ServoComputedValuesBorrowed,
|
||||
match_element: RawGeckoElementBorrowed,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
raw_data: RawServoStyleSetBorrowedMut,
|
||||
raw_data: RawServoStyleSetBorrowed,
|
||||
is_probe: bool)
|
||||
-> ServoComputedValuesStrong {
|
||||
debug_assert!(!(match_element as *const _).is_null());
|
||||
|
@ -313,7 +312,7 @@ pub extern "C" fn Servo_ComputedValues_GetForPseudoElement(parent_style: ServoCo
|
|||
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false);
|
||||
|
||||
// The stylist consumes stylesheets lazily.
|
||||
let data = PerDocumentStyleData::from_ffi_mut(raw_data);
|
||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
data.flush_stylesheets();
|
||||
|
||||
let element = GeckoElement(match_element);
|
||||
|
@ -518,7 +517,7 @@ pub extern "C" fn Servo_CSSSupports(property: *const u8, property_length: u32,
|
|||
pub extern "C" fn Servo_ComputeRestyleHint(element: RawGeckoElementBorrowed,
|
||||
snapshot: *mut ServoElementSnapshot,
|
||||
raw_data: RawServoStyleSetBorrowed) -> nsRestyleHint {
|
||||
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data);
|
||||
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let snapshot = unsafe { GeckoElementSnapshot::from_raw(snapshot) };
|
||||
let element = GeckoElement(element);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue