mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
parent
4848e37e2e
commit
1dc0d61c3c
12 changed files with 64 additions and 97 deletions
|
@ -148,7 +148,7 @@ pub struct Constellation<LTF, STF> {
|
||||||
/// A list of in-process senders to `WebGLPaintTask`s.
|
/// A list of in-process senders to `WebGLPaintTask`s.
|
||||||
webgl_paint_tasks: Vec<Sender<CanvasMsg>>,
|
webgl_paint_tasks: Vec<Sender<CanvasMsg>>,
|
||||||
|
|
||||||
scheduler_chan: Sender<TimerEventRequest>,
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// State needed to construct a constellation.
|
/// State needed to construct a constellation.
|
||||||
|
|
|
@ -68,6 +68,9 @@ pub struct CompositionPipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initial setup data needed to construct a pipeline.
|
/// Initial setup data needed to construct a pipeline.
|
||||||
|
///
|
||||||
|
/// *DO NOT* add any Senders to this unless you absolutely know what you're doing, or pcwalton will
|
||||||
|
/// have to rewrite your code. Use IPC senders instead.
|
||||||
pub struct InitialPipelineState {
|
pub struct InitialPipelineState {
|
||||||
/// The ID of the pipeline to create.
|
/// The ID of the pipeline to create.
|
||||||
pub id: PipelineId,
|
pub id: PipelineId,
|
||||||
|
@ -77,7 +80,7 @@ pub struct InitialPipelineState {
|
||||||
/// A channel to the associated constellation.
|
/// A channel to the associated constellation.
|
||||||
pub constellation_chan: ConstellationChan,
|
pub constellation_chan: ConstellationChan,
|
||||||
/// A channel to schedule timer events.
|
/// A channel to schedule timer events.
|
||||||
pub scheduler_chan: Sender<TimerEventRequest>,
|
pub scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
/// A channel to the compositor.
|
/// A channel to the compositor.
|
||||||
pub compositor_proxy: Box<CompositorProxy + 'static + Send>,
|
pub compositor_proxy: Box<CompositorProxy + 'static + Send>,
|
||||||
/// A channel to the developer tools, if applicable.
|
/// A channel to the developer tools, if applicable.
|
||||||
|
@ -315,7 +318,7 @@ pub struct PipelineContent {
|
||||||
id: PipelineId,
|
id: PipelineId,
|
||||||
parent_info: Option<(PipelineId, SubpageId)>,
|
parent_info: Option<(PipelineId, SubpageId)>,
|
||||||
constellation_chan: ConstellationChan,
|
constellation_chan: ConstellationChan,
|
||||||
scheduler_chan: Sender<TimerEventRequest>,
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
compositor_proxy: Box<CompositorProxy + Send + 'static>,
|
compositor_proxy: Box<CompositorProxy + Send + 'static>,
|
||||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||||
image_cache_task: ImageCacheTask,
|
image_cache_task: ImageCacheTask,
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use euclid::length::Length;
|
use euclid::length::Length;
|
||||||
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
|
use ipc_channel::router::ROUTER;
|
||||||
use num::traits::Saturating;
|
use num::traits::Saturating;
|
||||||
use script_traits::{MsDuration, NsDuration, precise_time_ms, precise_time_ns};
|
use script_traits::{MsDuration, NsDuration, precise_time_ms, precise_time_ns};
|
||||||
use script_traits::{TimerEvent, TimerEventRequest};
|
use script_traits::{TimerEvent, TimerEventRequest};
|
||||||
|
@ -11,7 +13,7 @@ use std::cmp::{self, Ord};
|
||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{self, AtomicBool};
|
use std::sync::atomic::{self, AtomicBool};
|
||||||
use std::sync::mpsc::{channel, Receiver, Select, Sender};
|
use std::sync::mpsc::{channel, Receiver, Select};
|
||||||
use std::thread::{self, spawn, Thread};
|
use std::thread::{self, spawn, Thread};
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
|
|
||||||
|
@ -107,11 +109,11 @@ enum Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimerScheduler {
|
impl TimerScheduler {
|
||||||
pub fn start() -> Sender<TimerEventRequest> {
|
pub fn start() -> IpcSender<TimerEventRequest> {
|
||||||
let (chan, port) = channel();
|
let (chan, port) = ipc::channel().unwrap();
|
||||||
|
|
||||||
let timer_scheduler = TimerScheduler {
|
let timer_scheduler = TimerScheduler {
|
||||||
port: port,
|
port: ROUTER.route_ipc_receiver_to_new_mpsc_receiver(port),
|
||||||
|
|
||||||
scheduled_events: RefCell::new(BinaryHeap::new()),
|
scheduled_events: RefCell::new(BinaryHeap::new()),
|
||||||
|
|
||||||
|
|
|
@ -169,3 +169,4 @@ pub enum EventResult {
|
||||||
DefaultAllowed,
|
DefaultAllowed,
|
||||||
DefaultPrevented,
|
DefaultPrevented,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ use net_traits::ResourceTask;
|
||||||
use profile_traits::mem;
|
use profile_traits::mem;
|
||||||
use script_task::{CommonScriptMsg, ScriptChan, ScriptPort, ScriptTask};
|
use script_task::{CommonScriptMsg, ScriptChan, ScriptPort, ScriptTask};
|
||||||
use script_traits::{MsDuration, TimerEventRequest};
|
use script_traits::{MsDuration, TimerEventRequest};
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
use timers::{ScheduledCallback, TimerHandle};
|
use timers::{ScheduledCallback, TimerHandle};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::mem::HeapSizeOf;
|
use util::mem::HeapSizeOf;
|
||||||
|
@ -100,7 +99,7 @@ impl<'a> GlobalRef<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the scheduler channel to request timer events.
|
/// Get the scheduler channel to request timer events.
|
||||||
pub fn scheduler_chan(&self) -> Sender<TimerEventRequest> {
|
pub fn scheduler_chan(&self) -> IpcSender<TimerEventRequest> {
|
||||||
match *self {
|
match *self {
|
||||||
GlobalRef::Window(window) => window.scheduler_chan(),
|
GlobalRef::Window(window) => window.scheduler_chan(),
|
||||||
GlobalRef::Worker(worker) => worker.scheduler_chan(),
|
GlobalRef::Worker(worker) => worker.scheduler_chan(),
|
||||||
|
|
|
@ -62,7 +62,7 @@ use net_traits::storage_task::StorageType;
|
||||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||||
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
||||||
use script_task::ScriptChan;
|
use script_task::ScriptChan;
|
||||||
use script_traits::{TimerEventChan, TimerEventId, TimerSource, UntrustedNodeAddress};
|
use script_traits::{TimerEventId, TimerSource, UntrustedNodeAddress};
|
||||||
use selectors::parser::PseudoElement;
|
use selectors::parser::PseudoElement;
|
||||||
use selectors::states::*;
|
use selectors::states::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -302,13 +302,6 @@ impl JSTraceable for Box<ScriptChan + Send> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JSTraceable for Box<TimerEventChan + Send> {
|
|
||||||
#[inline]
|
|
||||||
fn trace(&self, _trc: *mut JSTracer) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JSTraceable for Box<FnBox(f64, )> {
|
impl JSTraceable for Box<FnBox(f64, )> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn trace(&self, _trc: *mut JSTracer) {
|
fn trace(&self, _trc: *mut JSTracer) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ use dom::messageevent::MessageEvent;
|
||||||
use dom::worker::{SimpleWorkerErrorHandler, TrustedWorkerAddress, WorkerMessageHandler};
|
use dom::worker::{SimpleWorkerErrorHandler, TrustedWorkerAddress, WorkerMessageHandler};
|
||||||
use dom::workerglobalscope::WorkerGlobalScope;
|
use dom::workerglobalscope::WorkerGlobalScope;
|
||||||
use dom::workerglobalscope::WorkerGlobalScopeInit;
|
use dom::workerglobalscope::WorkerGlobalScopeInit;
|
||||||
use ipc_channel::ipc::IpcReceiver;
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||||
use ipc_channel::router::ROUTER;
|
use ipc_channel::router::ROUTER;
|
||||||
use js::jsapi::{HandleValue, JSContext, RootedValue};
|
use js::jsapi::{HandleValue, JSContext, RootedValue};
|
||||||
use js::jsapi::{JSAutoCompartment, JSAutoRequest};
|
use js::jsapi::{JSAutoCompartment, JSAutoRequest};
|
||||||
|
@ -30,7 +30,7 @@ use net_traits::load_whole_resource;
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use script_task::ScriptTaskEventCategory::WorkerEvent;
|
use script_task::ScriptTaskEventCategory::WorkerEvent;
|
||||||
use script_task::{ScriptTask, ScriptChan, ScriptPort, StackRootTLS, CommonScriptMsg};
|
use script_task::{ScriptTask, ScriptChan, ScriptPort, StackRootTLS, CommonScriptMsg};
|
||||||
use script_traits::{TimerEvent, TimerEventChan, TimerSource};
|
use script_traits::{TimerEvent, TimerSource};
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
|
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
|
||||||
|
@ -103,29 +103,6 @@ impl ScriptPort for Receiver<(TrustedWorkerAddress, WorkerScriptMsg)> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A TimerEventChan that can be cloned freely and will silently send a TrustedWorkerAddress
|
|
||||||
/// with timer events. While this SendableWorkerScriptChan is alive, the associated Worker
|
|
||||||
/// object will remain alive.
|
|
||||||
struct WorkerThreadTimerEventChan {
|
|
||||||
sender: Sender<(TrustedWorkerAddress, TimerEvent)>,
|
|
||||||
worker: TrustedWorkerAddress,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TimerEventChan for WorkerThreadTimerEventChan {
|
|
||||||
fn send(&self, event: TimerEvent) -> Result<(), ()> {
|
|
||||||
self.sender
|
|
||||||
.send((self.worker.clone(), event))
|
|
||||||
.map_err(|_| ())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clone(&self) -> Box<TimerEventChan + Send> {
|
|
||||||
box WorkerThreadTimerEventChan {
|
|
||||||
sender: self.sender.clone(),
|
|
||||||
worker: self.worker.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular
|
/// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular
|
||||||
/// value for the duration of this object's lifetime. This ensures that the related Worker
|
/// value for the duration of this object's lifetime. This ensures that the related Worker
|
||||||
/// object only lives as long as necessary (ie. while events are being executed), while
|
/// object only lives as long as necessary (ie. while events are being executed), while
|
||||||
|
@ -183,7 +160,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
parent_sender: Box<ScriptChan + Send>,
|
parent_sender: Box<ScriptChan + Send>,
|
||||||
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
||||||
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
||||||
timer_event_chan: Box<TimerEventChan + Send>,
|
timer_event_chan: IpcSender<TimerEvent>,
|
||||||
timer_event_port: Receiver<(TrustedWorkerAddress, TimerEvent)>)
|
timer_event_port: Receiver<(TrustedWorkerAddress, TimerEvent)>)
|
||||||
-> DedicatedWorkerGlobalScope {
|
-> DedicatedWorkerGlobalScope {
|
||||||
|
|
||||||
|
@ -207,7 +184,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
parent_sender: Box<ScriptChan + Send>,
|
parent_sender: Box<ScriptChan + Send>,
|
||||||
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
||||||
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
||||||
timer_event_chan: Box<TimerEventChan + Send>,
|
timer_event_chan: IpcSender<TimerEvent>,
|
||||||
timer_event_port: Receiver<(TrustedWorkerAddress, TimerEvent)>)
|
timer_event_port: Receiver<(TrustedWorkerAddress, TimerEvent)>)
|
||||||
-> Root<DedicatedWorkerGlobalScope> {
|
-> Root<DedicatedWorkerGlobalScope> {
|
||||||
let scope = box DedicatedWorkerGlobalScope::new_inherited(
|
let scope = box DedicatedWorkerGlobalScope::new_inherited(
|
||||||
|
@ -249,15 +226,17 @@ impl DedicatedWorkerGlobalScope {
|
||||||
ROUTER.route_ipc_receiver_to_mpsc_sender(from_devtools_receiver, devtools_mpsc_chan);
|
ROUTER.route_ipc_receiver_to_mpsc_sender(from_devtools_receiver, devtools_mpsc_chan);
|
||||||
|
|
||||||
let (timer_tx, timer_rx) = channel();
|
let (timer_tx, timer_rx) = channel();
|
||||||
let timer_event_chan = box WorkerThreadTimerEventChan {
|
let (timer_ipc_chan, timer_ipc_port) = ipc::channel().unwrap();
|
||||||
sender: timer_tx,
|
let worker_for_route = worker.clone();
|
||||||
worker: worker.clone(),
|
ROUTER.add_route(timer_ipc_port.to_opaque(), box move |message| {
|
||||||
};
|
let event = message.to().unwrap();
|
||||||
|
timer_tx.send((worker_for_route.clone(), event)).unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
let global = DedicatedWorkerGlobalScope::new(
|
let global = DedicatedWorkerGlobalScope::new(
|
||||||
init, url, id, devtools_mpsc_port, runtime.clone(),
|
init, url, id, devtools_mpsc_port, runtime.clone(),
|
||||||
parent_sender.clone(), own_sender, receiver,
|
parent_sender.clone(), own_sender, receiver,
|
||||||
timer_event_chan, timer_rx);
|
timer_ipc_chan, timer_rx);
|
||||||
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
|
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
|
||||||
// registration (#6631), so we instead use a random number and cross our fingers.
|
// registration (#6631), so we instead use a random number and cross our fingers.
|
||||||
let scope = global.upcast::<WorkerGlobalScope>();
|
let scope = global.upcast::<WorkerGlobalScope>();
|
||||||
|
|
|
@ -53,8 +53,8 @@ use page::Page;
|
||||||
use profile_traits::mem;
|
use profile_traits::mem;
|
||||||
use rustc_serialize::base64::{FromBase64, STANDARD, ToBase64};
|
use rustc_serialize::base64::{FromBase64, STANDARD, ToBase64};
|
||||||
use script_task::{ScriptChan, ScriptPort, MainThreadScriptMsg, RunnableWrapper};
|
use script_task::{ScriptChan, ScriptPort, MainThreadScriptMsg, RunnableWrapper};
|
||||||
use script_task::{SendableMainThreadScriptChan, MainThreadScriptChan, MainThreadTimerEventChan};
|
use script_task::{SendableMainThreadScriptChan, MainThreadScriptChan};
|
||||||
use script_traits::{MsDuration, TimerEventChan, TimerEventId, TimerEventRequest, TimerSource};
|
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerEventRequest, TimerSource};
|
||||||
use selectors::parser::PseudoElement;
|
use selectors::parser::PseudoElement;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
@ -129,7 +129,7 @@ pub struct Window {
|
||||||
session_storage: MutNullableHeap<JS<Storage>>,
|
session_storage: MutNullableHeap<JS<Storage>>,
|
||||||
local_storage: MutNullableHeap<JS<Storage>>,
|
local_storage: MutNullableHeap<JS<Storage>>,
|
||||||
#[ignore_heap_size_of = "channels are hard"]
|
#[ignore_heap_size_of = "channels are hard"]
|
||||||
scheduler_chan: Sender<TimerEventRequest>,
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
timers: ActiveTimers,
|
timers: ActiveTimers,
|
||||||
|
|
||||||
next_worker_id: Cell<WorkerId>,
|
next_worker_id: Cell<WorkerId>,
|
||||||
|
@ -1077,7 +1077,7 @@ impl Window {
|
||||||
self.constellation_chan.clone()
|
self.constellation_chan.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scheduler_chan(&self) -> Sender<TimerEventRequest> {
|
pub fn scheduler_chan(&self) -> IpcSender<TimerEventRequest> {
|
||||||
self.scheduler_chan.clone()
|
self.scheduler_chan.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1227,8 +1227,8 @@ impl Window {
|
||||||
mem_profiler_chan: mem::ProfilerChan,
|
mem_profiler_chan: mem::ProfilerChan,
|
||||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||||
constellation_chan: ConstellationChan,
|
constellation_chan: ConstellationChan,
|
||||||
scheduler_chan: Sender<TimerEventRequest>,
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
timer_event_chan: MainThreadTimerEventChan,
|
timer_event_chan: IpcSender<TimerEvent>,
|
||||||
layout_chan: LayoutChan,
|
layout_chan: LayoutChan,
|
||||||
id: PipelineId,
|
id: PipelineId,
|
||||||
parent_info: Option<(PipelineId, SubpageId)>,
|
parent_info: Option<(PipelineId, SubpageId)>,
|
||||||
|
@ -1261,7 +1261,7 @@ impl Window {
|
||||||
session_storage: Default::default(),
|
session_storage: Default::default(),
|
||||||
local_storage: Default::default(),
|
local_storage: Default::default(),
|
||||||
scheduler_chan: scheduler_chan.clone(),
|
scheduler_chan: scheduler_chan.clone(),
|
||||||
timers: ActiveTimers::new(box timer_event_chan, scheduler_chan),
|
timers: ActiveTimers::new(timer_event_chan, scheduler_chan),
|
||||||
next_worker_id: Cell::new(WorkerId(0)),
|
next_worker_id: Cell::new(WorkerId(0)),
|
||||||
id: id,
|
id: id,
|
||||||
parent_info: parent_info,
|
parent_info: parent_info,
|
||||||
|
|
|
@ -24,11 +24,11 @@ use msg::constellation_msg::{ConstellationChan, PipelineId, WorkerId};
|
||||||
use net_traits::{ResourceTask, load_whole_resource};
|
use net_traits::{ResourceTask, load_whole_resource};
|
||||||
use profile_traits::mem;
|
use profile_traits::mem;
|
||||||
use script_task::{CommonScriptMsg, ScriptChan, ScriptPort};
|
use script_task::{CommonScriptMsg, ScriptChan, ScriptPort};
|
||||||
use script_traits::{MsDuration, TimerEventChan, TimerEventId, TimerEventRequest, TimerSource};
|
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerEventRequest, TimerSource};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc::{Receiver, Sender};
|
use std::sync::mpsc::Receiver;
|
||||||
use timers::{ActiveTimers, IsInterval, ScheduledCallback, TimerCallback, TimerHandle};
|
use timers::{ActiveTimers, IsInterval, ScheduledCallback, TimerCallback, TimerHandle};
|
||||||
use url::{Url, UrlParser};
|
use url::{Url, UrlParser};
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
@ -44,7 +44,7 @@ pub struct WorkerGlobalScopeInit {
|
||||||
pub to_devtools_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
pub to_devtools_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||||
pub from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
|
pub from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
|
||||||
pub constellation_chan: ConstellationChan,
|
pub constellation_chan: ConstellationChan,
|
||||||
pub scheduler_chan: Sender<TimerEventRequest>,
|
pub scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
pub worker_id: WorkerId,
|
pub worker_id: WorkerId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ pub struct WorkerGlobalScope {
|
||||||
constellation_chan: ConstellationChan,
|
constellation_chan: ConstellationChan,
|
||||||
|
|
||||||
#[ignore_heap_size_of = "Defined in std"]
|
#[ignore_heap_size_of = "Defined in std"]
|
||||||
scheduler_chan: Sender<TimerEventRequest>,
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkerGlobalScope {
|
impl WorkerGlobalScope {
|
||||||
|
@ -95,7 +95,7 @@ impl WorkerGlobalScope {
|
||||||
worker_url: Url,
|
worker_url: Url,
|
||||||
runtime: Rc<Runtime>,
|
runtime: Rc<Runtime>,
|
||||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||||
timer_event_chan: Box<TimerEventChan + Send>)
|
timer_event_chan: IpcSender<TimerEvent>)
|
||||||
-> WorkerGlobalScope {
|
-> WorkerGlobalScope {
|
||||||
WorkerGlobalScope {
|
WorkerGlobalScope {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
|
@ -139,7 +139,7 @@ impl WorkerGlobalScope {
|
||||||
self.constellation_chan.clone()
|
self.constellation_chan.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scheduler_chan(&self) -> Sender<TimerEventRequest> {
|
pub fn scheduler_chan(&self) -> IpcSender<TimerEventRequest> {
|
||||||
self.scheduler_chan.clone()
|
self.scheduler_chan.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ use script_traits::CompositorEvent::{MouseDownEvent, MouseUpEvent, TouchEvent};
|
||||||
use script_traits::{CompositorEvent, ConstellationControlMsg};
|
use script_traits::{CompositorEvent, ConstellationControlMsg};
|
||||||
use script_traits::{InitialScriptState, MouseButton, NewLayoutInfo};
|
use script_traits::{InitialScriptState, MouseButton, NewLayoutInfo};
|
||||||
use script_traits::{OpaqueScriptLayoutChannel, ScriptState, ScriptTaskFactory};
|
use script_traits::{OpaqueScriptLayoutChannel, ScriptState, ScriptTaskFactory};
|
||||||
use script_traits::{TimerEvent, TimerEventChan, TimerEventRequest, TimerSource};
|
use script_traits::{TimerEvent, TimerEventRequest, TimerSource};
|
||||||
use script_traits::{TouchEventType, TouchId};
|
use script_traits::{TouchEventType, TouchId};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
@ -353,20 +353,6 @@ impl MainThreadScriptChan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MainThreadTimerEventChan(Sender<TimerEvent>);
|
|
||||||
|
|
||||||
impl TimerEventChan for MainThreadTimerEventChan {
|
|
||||||
fn send(&self, event: TimerEvent) -> Result<(), ()> {
|
|
||||||
let MainThreadTimerEventChan(ref chan) = *self;
|
|
||||||
chan.send(event).map_err(|_| ())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clone(&self) -> Box<TimerEventChan + Send> {
|
|
||||||
let MainThreadTimerEventChan(ref chan) = *self;
|
|
||||||
box MainThreadTimerEventChan((*chan).clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct StackRootTLS<'a>(PhantomData<&'a u32>);
|
pub struct StackRootTLS<'a>(PhantomData<&'a u32>);
|
||||||
|
|
||||||
impl<'a> StackRootTLS<'a> {
|
impl<'a> StackRootTLS<'a> {
|
||||||
|
@ -449,7 +435,7 @@ pub struct ScriptTask {
|
||||||
/// List of pipelines that have been owned and closed by this script task.
|
/// List of pipelines that have been owned and closed by this script task.
|
||||||
closed_pipelines: DOMRefCell<HashSet<PipelineId>>,
|
closed_pipelines: DOMRefCell<HashSet<PipelineId>>,
|
||||||
|
|
||||||
scheduler_chan: Sender<TimerEventRequest>,
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
timer_event_chan: Sender<TimerEvent>,
|
timer_event_chan: Sender<TimerEvent>,
|
||||||
timer_event_port: Receiver<TimerEvent>,
|
timer_event_port: Receiver<TimerEvent>,
|
||||||
}
|
}
|
||||||
|
@ -1607,6 +1593,10 @@ impl ScriptTask {
|
||||||
let mut page_remover = AutoPageRemover::new(self, page_to_remove);
|
let mut page_remover = AutoPageRemover::new(self, page_to_remove);
|
||||||
let MainThreadScriptChan(ref sender) = self.chan;
|
let MainThreadScriptChan(ref sender) = self.chan;
|
||||||
|
|
||||||
|
let (ipc_timer_event_chan, ipc_timer_event_port) = ipc::channel().unwrap();
|
||||||
|
ROUTER.route_ipc_receiver_to_mpsc_sender(ipc_timer_event_port,
|
||||||
|
self.timer_event_chan.clone());
|
||||||
|
|
||||||
// Create the window and document objects.
|
// Create the window and document objects.
|
||||||
let window = Window::new(self.js_runtime.clone(),
|
let window = Window::new(self.js_runtime.clone(),
|
||||||
page.clone(),
|
page.clone(),
|
||||||
|
@ -1620,7 +1610,7 @@ impl ScriptTask {
|
||||||
self.devtools_chan.clone(),
|
self.devtools_chan.clone(),
|
||||||
self.constellation_chan.clone(),
|
self.constellation_chan.clone(),
|
||||||
self.scheduler_chan.clone(),
|
self.scheduler_chan.clone(),
|
||||||
MainThreadTimerEventChan(self.timer_event_chan.clone()),
|
ipc_timer_event_chan,
|
||||||
incomplete.layout_chan,
|
incomplete.layout_chan,
|
||||||
incomplete.pipeline_id,
|
incomplete.pipeline_id,
|
||||||
incomplete.parent_info,
|
incomplete.parent_info,
|
||||||
|
|
|
@ -10,16 +10,16 @@ use dom::bindings::reflector::Reflectable;
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
use dom::window::ScriptHelpers;
|
use dom::window::ScriptHelpers;
|
||||||
use euclid::length::Length;
|
use euclid::length::Length;
|
||||||
|
use ipc_channel::ipc::IpcSender;
|
||||||
use js::jsapi::{HandleValue, Heap, RootedValue};
|
use js::jsapi::{HandleValue, Heap, RootedValue};
|
||||||
use js::jsval::{JSVal, UndefinedValue};
|
use js::jsval::{JSVal, UndefinedValue};
|
||||||
use num::traits::Saturating;
|
use num::traits::Saturating;
|
||||||
use script_traits::{MsDuration, precise_time_ms};
|
use script_traits::{MsDuration, precise_time_ms};
|
||||||
use script_traits::{TimerEventChan, TimerEventId, TimerEventRequest, TimerSource};
|
use script_traits::{TimerEvent, TimerEventId, TimerEventRequest, TimerSource};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::cmp::{self, Ord, Ordering};
|
use std::cmp::{self, Ord, Ordering};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
use util::mem::HeapSizeOf;
|
use util::mem::HeapSizeOf;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
@ -30,9 +30,9 @@ pub struct TimerHandle(i32);
|
||||||
#[privatize]
|
#[privatize]
|
||||||
pub struct ActiveTimers {
|
pub struct ActiveTimers {
|
||||||
#[ignore_heap_size_of = "Defined in std"]
|
#[ignore_heap_size_of = "Defined in std"]
|
||||||
timer_event_chan: Box<TimerEventChan + Send>,
|
timer_event_chan: IpcSender<TimerEvent>,
|
||||||
#[ignore_heap_size_of = "Defined in std"]
|
#[ignore_heap_size_of = "Defined in std"]
|
||||||
scheduler_chan: Sender<TimerEventRequest>,
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
next_timer_handle: Cell<TimerHandle>,
|
next_timer_handle: Cell<TimerHandle>,
|
||||||
timers: DOMRefCell<Vec<Timer>>,
|
timers: DOMRefCell<Vec<Timer>>,
|
||||||
suspended_since: Cell<Option<MsDuration>>,
|
suspended_since: Cell<Option<MsDuration>>,
|
||||||
|
@ -130,8 +130,8 @@ impl Clone for Box<ScheduledCallback> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveTimers {
|
impl ActiveTimers {
|
||||||
pub fn new(timer_event_chan: Box<TimerEventChan + Send>,
|
pub fn new(timer_event_chan: IpcSender<TimerEvent>,
|
||||||
scheduler_chan: Sender<TimerEventRequest>)
|
scheduler_chan: IpcSender<TimerEventRequest>)
|
||||||
-> ActiveTimers {
|
-> ActiveTimers {
|
||||||
ActiveTimers {
|
ActiveTimers {
|
||||||
timer_event_chan: timer_event_chan,
|
timer_event_chan: timer_event_chan,
|
||||||
|
|
|
@ -190,23 +190,20 @@ pub enum CompositorEvent {
|
||||||
pub struct OpaqueScriptLayoutChannel(pub (Box<Any + Send>, Box<Any + Send>));
|
pub struct OpaqueScriptLayoutChannel(pub (Box<Any + Send>, Box<Any + Send>));
|
||||||
|
|
||||||
/// Requests a TimerEvent-Message be sent after the given duration.
|
/// Requests a TimerEvent-Message be sent after the given duration.
|
||||||
pub struct TimerEventRequest(pub Box<TimerEventChan + Send>, pub TimerSource, pub TimerEventId, pub MsDuration);
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct TimerEventRequest(pub IpcSender<TimerEvent>,
|
||||||
|
pub TimerSource,
|
||||||
|
pub TimerEventId,
|
||||||
|
pub MsDuration);
|
||||||
|
|
||||||
/// Notifies the script task to fire due timers.
|
/// Notifies the script task to fire due timers.
|
||||||
/// TimerSource must be FromWindow when dispatched to ScriptTask and
|
/// TimerSource must be FromWindow when dispatched to ScriptTask and
|
||||||
/// must be FromWorker when dispatched to a DedicatedGlobalWorkerScope
|
/// must be FromWorker when dispatched to a DedicatedGlobalWorkerScope
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct TimerEvent(pub TimerSource, pub TimerEventId);
|
pub struct TimerEvent(pub TimerSource, pub TimerEventId);
|
||||||
|
|
||||||
/// A cloneable interface for sending timer events.
|
|
||||||
pub trait TimerEventChan {
|
|
||||||
/// Send a timer event to the associated event loop.
|
|
||||||
fn send(&self, msg: TimerEvent) -> Result<(), ()>;
|
|
||||||
/// Clone this handle.
|
|
||||||
fn clone(&self) -> Box<TimerEventChan + Send>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Describes the task that requested the TimerEvent.
|
/// Describes the task that requested the TimerEvent.
|
||||||
#[derive(Copy, Clone, HeapSizeOf)]
|
#[derive(Copy, Clone, HeapSizeOf, Deserialize, Serialize)]
|
||||||
pub enum TimerSource {
|
pub enum TimerSource {
|
||||||
/// The event was requested from a window (ScriptTask).
|
/// The event was requested from a window (ScriptTask).
|
||||||
FromWindow(PipelineId),
|
FromWindow(PipelineId),
|
||||||
|
@ -215,7 +212,7 @@ pub enum TimerSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The id to be used for a TimerEvent is defined by the corresponding TimerEventRequest.
|
/// The id to be used for a TimerEvent is defined by the corresponding TimerEventRequest.
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Debug, HeapSizeOf)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug, HeapSizeOf, Deserialize, Serialize)]
|
||||||
pub struct TimerEventId(pub u32);
|
pub struct TimerEventId(pub u32);
|
||||||
|
|
||||||
/// Unit of measurement.
|
/// Unit of measurement.
|
||||||
|
@ -240,6 +237,9 @@ pub fn precise_time_ns() -> NsDuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data needed to construct a script thread.
|
/// Data needed to construct a script thread.
|
||||||
|
///
|
||||||
|
/// NB: *DO NOT* add any Senders or Receivers here! pcwalton will have to rewrite your code if you
|
||||||
|
/// do! Use IPC senders and receivers instead.
|
||||||
pub struct InitialScriptState {
|
pub struct InitialScriptState {
|
||||||
/// The ID of the pipeline with which this script thread is associated.
|
/// The ID of the pipeline with which this script thread is associated.
|
||||||
pub id: PipelineId,
|
pub id: PipelineId,
|
||||||
|
@ -255,7 +255,7 @@ pub struct InitialScriptState {
|
||||||
/// A channel on which messages can be sent to the constellation from script.
|
/// A channel on which messages can be sent to the constellation from script.
|
||||||
pub constellation_chan: ConstellationChan,
|
pub constellation_chan: ConstellationChan,
|
||||||
/// A channel to schedule timer events.
|
/// A channel to schedule timer events.
|
||||||
pub scheduler_chan: Sender<TimerEventRequest>,
|
pub scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
/// Information that script sends out when it panics.
|
/// Information that script sends out when it panics.
|
||||||
pub failure_info: Failure,
|
pub failure_info: Failure,
|
||||||
/// A channel to the resource manager task.
|
/// A channel to the resource manager task.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue