Wrap SharedLayoutContext::new_animations_sender in a Mutex.

This commit is contained in:
Ms2ger 2015-11-06 23:01:38 +01:00
parent 552a03fde6
commit 8fc75704c9
4 changed files with 10 additions and 11 deletions

View file

@ -14,14 +14,14 @@ use script::layout_interface::Animation;
use script_traits::ConstellationControlMsg; use script_traits::ConstellationControlMsg;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::sync::Arc;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex};
use style::animation::{GetMod, PropertyAnimation}; use style::animation::{GetMod, PropertyAnimation};
use style::properties::ComputedValues; use style::properties::ComputedValues;
/// Inserts transitions into the queue of running animations as applicable for the given style /// Inserts transitions into the queue of running animations as applicable for the given style
/// difference. This is called from the layout worker threads. /// difference. This is called from the layout worker threads.
pub fn start_transitions_if_applicable(new_animations_sender: &Sender<Animation>, pub fn start_transitions_if_applicable(new_animations_sender: &Mutex<Sender<Animation>>,
node: OpaqueNode, node: OpaqueNode,
old_style: &ComputedValues, old_style: &ComputedValues,
new_style: &mut ComputedValues) { new_style: &mut ComputedValues) {
@ -37,7 +37,7 @@ pub fn start_transitions_if_applicable(new_animations_sender: &Sender<Animation>
let animation_style = new_style.get_animation(); let animation_style = new_style.get_animation();
let start_time = let start_time =
now + (animation_style.transition_delay.0.get_mod(i).seconds() as f64); now + (animation_style.transition_delay.0.get_mod(i).seconds() as f64);
new_animations_sender.send(Animation { new_animations_sender.lock().unwrap().send(Animation {
node: node.id(), node: node.id(),
property_animation: property_animation, property_animation: property_animation,
start_time: start_time, start_time: start_time,

View file

@ -105,7 +105,7 @@ pub struct SharedLayoutContext {
/// A channel on which new animations that have been triggered by style recalculation can be /// A channel on which new animations that have been triggered by style recalculation can be
/// sent. /// sent.
pub new_animations_sender: Sender<Animation>, pub new_animations_sender: Mutex<Sender<Animation>>,
/// A channel to send canvas renderers to paint task, in order to correctly paint the layers /// A channel to send canvas renderers to paint task, in order to correctly paint the layers
pub canvas_layers_sender: Sender<(LayerId, IpcSender<CanvasMsg>)>, pub canvas_layers_sender: Sender<(LayerId, IpcSender<CanvasMsg>)>,
@ -123,7 +123,6 @@ pub struct SharedLayoutContext {
// FIXME(#6569) This implementations is unsound: // FIXME(#6569) This implementations is unsound:
// XXX UNSOUND!!! for image_cache_task // XXX UNSOUND!!! for image_cache_task
// XXX UNSOUND!!! for stylist // XXX UNSOUND!!! for stylist
// XXX UNSOUND!!! for new_animations_sender
// XXX UNSOUND!!! for canvas_layers_sender // XXX UNSOUND!!! for canvas_layers_sender
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe impl Sync for SharedLayoutContext {} unsafe impl Sync for SharedLayoutContext {}

View file

@ -21,8 +21,8 @@ use smallvec::SmallVec;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::slice::Iter; use std::slice::Iter;
use std::sync::Arc;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex};
use string_cache::{Atom, Namespace}; use string_cache::{Atom, Namespace};
use style::node::TElementAttributes; use style::node::TElementAttributes;
use style::properties::{ComputedValues, PropertyDeclaration, cascade}; use style::properties::{ComputedValues, PropertyDeclaration, cascade};
@ -406,7 +406,7 @@ pub trait MatchMethods {
parent: Option<LayoutNode>, parent: Option<LayoutNode>,
applicable_declarations: &ApplicableDeclarations, applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache, applicable_declarations_cache: &mut ApplicableDeclarationsCache,
new_animations_sender: &Sender<Animation>); new_animations_sender: &Mutex<Sender<Animation>>);
} }
trait PrivateMatchMethods { trait PrivateMatchMethods {
@ -417,7 +417,7 @@ trait PrivateMatchMethods {
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
applicable_declarations_cache: applicable_declarations_cache:
&mut ApplicableDeclarationsCache, &mut ApplicableDeclarationsCache,
new_animations_sender: &Sender<Animation>, new_animations_sender: &Mutex<Sender<Animation>>,
shareable: bool, shareable: bool,
animate_properties: bool) animate_properties: bool)
-> RestyleDamage; -> RestyleDamage;
@ -438,7 +438,7 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
applicable_declarations_cache: applicable_declarations_cache:
&mut ApplicableDeclarationsCache, &mut ApplicableDeclarationsCache,
new_animations_sender: &Sender<Animation>, new_animations_sender: &Mutex<Sender<Animation>>,
shareable: bool, shareable: bool,
animate_properties: bool) animate_properties: bool)
-> RestyleDamage { -> RestyleDamage {
@ -655,7 +655,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
parent: Option<LayoutNode>, parent: Option<LayoutNode>,
applicable_declarations: &ApplicableDeclarations, applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache, applicable_declarations_cache: &mut ApplicableDeclarationsCache,
new_animations_sender: &Sender<Animation>) { new_animations_sender: &Mutex<Sender<Animation>>) {
// Get our parent's style. This must be unsafe so that we don't touch the parent's // Get our parent's style. This must be unsafe so that we don't touch the parent's
// borrow flags. // borrow flags.
// //

View file

@ -461,7 +461,7 @@ impl LayoutTask {
url: (*url).clone(), url: (*url).clone(),
visible_rects: rw_data.visible_rects.clone(), visible_rects: rw_data.visible_rects.clone(),
generation: rw_data.generation, generation: rw_data.generation,
new_animations_sender: rw_data.new_animations_sender.clone(), new_animations_sender: Mutex::new(rw_data.new_animations_sender.clone()),
goal: goal, goal: goal,
running_animations: rw_data.running_animations.clone(), running_animations: rw_data.running_animations.clone(),
} }