Skip to content

Commit

Permalink
Bug 1331213: Bootstrap a Gecko-side Device, and track it's dirtiness …
Browse files Browse the repository at this point in the history
…manually in the per-doc data. r=heycam

The setup is quite different to Servo-land, so add a comment about the different
setup.

Also, check viewport rules when flushing stylesheets. I believe that the
previous behavior is plain wrong, though I haven't taken the time to come up
with a test case.

In any case, it doesn't hurt any of both back-ends.

MozReview-Commit-ID: 46gtTkesOsr
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
  • Loading branch information
emilio committed Jan 17, 2017
1 parent 5d6ac65 commit 5b5243b
Show file tree
Hide file tree
Showing 11 changed files with 685 additions and 83 deletions.
1 change: 1 addition & 0 deletions components/style/build_gecko.rs
Expand Up @@ -497,6 +497,7 @@ mod bindings {
"RawGeckoAnimationValueList",
"RawServoAnimationValue",
"RawGeckoPresContext",
"RawGeckoPresContextOwned",
"ThreadSafeURIHolder",
"ThreadSafePrincipalHolder",
"CSSPseudoClassType",
Expand Down
50 changes: 28 additions & 22 deletions components/style/gecko/data.rs
Expand Up @@ -7,11 +7,10 @@
use animation::Animation;
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use dom::OpaqueNode;
use euclid::size::TypedSize2D;
use gecko_bindings::bindings::RawGeckoPresContextBorrowed;
use gecko_bindings::bindings::RawServoStyleSet;
use gecko_bindings::structs::RawGeckoPresContextOwned;
use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use media_queries::{Device, MediaType};
use media_queries::Device;
use num_cpus;
use parking_lot::RwLock;
use properties::ComputedValues;
Expand All @@ -21,7 +20,6 @@ use std::collections::HashMap;
use std::env;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};
use style_traits::ViewportPx;
use stylesheets::Stylesheet;
use stylist::Stylist;

Expand All @@ -37,6 +35,9 @@ pub struct PerDocumentStyleDataImpl {
/// Whether the stylesheets list above has changed since the last restyle.
pub stylesheets_changed: bool,

/// Whether the device has changed since the last restyle.
pub device_changed: bool,

// FIXME(bholley): Hook these up to something.
/// Unused. Will go away when we actually implement transitions and
/// animations properly.
Expand All @@ -57,9 +58,6 @@ pub struct PerDocumentStyleDataImpl {

/// The number of threads of the work queue.
pub num_threads: usize,

/// Default computed values for this document.
pub default_computed_values: Arc<ComputedValues>
}

/// The data itself is an `AtomicRefCell`, which guarantees the proper semantics
Expand All @@ -78,22 +76,16 @@ lazy_static! {

impl PerDocumentStyleData {
/// Create a dummy `PerDocumentStyleData`.
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
// FIXME(bholley): Real window size.
let window_size: TypedSize2D<f32, ViewportPx> = TypedSize2D::new(800.0, 600.0);
let default_computed_values = ComputedValues::default_values(pres_context);

// FIXME(bz): We're going to need to either update the computed values
// in the Stylist's Device or give the Stylist a new Device when our
// default_computed_values changes.
let device = Device::new(MediaType::Screen, window_size, &default_computed_values);
pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
let device = Device::new(pres_context);

let (new_anims_sender, new_anims_receiver) = channel();

PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
stylist: Arc::new(Stylist::new(device)),
stylesheets: vec![],
stylesheets_changed: true,
device_changed: true,
new_animations_sender: new_anims_sender,
new_animations_receiver: new_anims_receiver,
running_animations: Arc::new(RwLock::new(HashMap::new())),
Expand All @@ -106,7 +98,6 @@ impl PerDocumentStyleData {
rayon::ThreadPool::new(configuration).ok()
},
num_threads: *NUM_THREADS,
default_computed_values: default_computed_values,
}))
}

Expand All @@ -124,15 +115,30 @@ impl PerDocumentStyleData {
impl PerDocumentStyleDataImpl {
/// Recreate the style data if the stylesheets have changed.
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
// need to detect the latter case and trigger a flush as well.
let mut stylist = if self.device_changed || self.stylesheets_changed {
Some(Arc::get_mut(&mut self.stylist).unwrap())
} else {
None
};

if self.device_changed {
Arc::get_mut(&mut stylist.as_mut().unwrap().device).unwrap().reset();
self.device_changed = false;
// Force a stylesheet flush if the device has changed.
self.stylesheets_changed = true;
}

if self.stylesheets_changed {
let _ = Arc::get_mut(&mut self.stylist).unwrap()
.update(&self.stylesheets, None, true);
let _ = stylist.unwrap().update(&self.stylesheets, None, true);
self.stylesheets_changed = false;
}
}

/// Get the default computed values for this document.
pub fn default_computed_values(&self) -> &Arc<ComputedValues> {
debug_assert!(!self.device_changed, "A device flush was pending");
self.stylist.device.default_values_arc()
}
}

unsafe impl HasFFI for PerDocumentStyleData {
Expand Down

0 comments on commit 5b5243b

Please sign in to comment.