mirror of
https://github.com/servo/servo.git
synced 2025-07-17 04:13:42 +01:00
Introduce MainThreadScriptMsg::MainThreadRunnable
This will allow us to separate the types for tasks that must run on the main script thread and regular tasks.
This commit is contained in:
parent
7ca52152a6
commit
52a6f63608
2 changed files with 16 additions and 9 deletions
|
@ -23,7 +23,6 @@ use net_traits::image_cache::ImageCache;
|
||||||
use profile_traits::mem;
|
use profile_traits::mem;
|
||||||
use profile_traits::time;
|
use profile_traits::time;
|
||||||
use script_layout_interface::message::Msg;
|
use script_layout_interface::message::Msg;
|
||||||
use script_runtime::CommonScriptMsg;
|
|
||||||
use script_runtime::ScriptThreadEventCategory;
|
use script_runtime::ScriptThreadEventCategory;
|
||||||
use script_thread::MainThreadScriptMsg;
|
use script_thread::MainThreadScriptMsg;
|
||||||
use script_thread::Runnable;
|
use script_thread::Runnable;
|
||||||
|
@ -100,9 +99,12 @@ impl WorkletGlobalScope {
|
||||||
pub fn run_in_script_thread<R>(&self, runnable: R) where
|
pub fn run_in_script_thread<R>(&self, runnable: R) where
|
||||||
R: 'static + Send + Runnable,
|
R: 'static + Send + Runnable,
|
||||||
{
|
{
|
||||||
let msg = CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::WorkletEvent, box runnable);
|
self.to_script_thread_sender
|
||||||
let msg = MainThreadScriptMsg::Common(msg);
|
.send(MainThreadScriptMsg::MainThreadRunnable(
|
||||||
self.to_script_thread_sender.send(msg).expect("Worklet thread outlived script thread.");
|
ScriptThreadEventCategory::WorkletEvent,
|
||||||
|
box runnable,
|
||||||
|
))
|
||||||
|
.expect("Worklet thread outlived script thread.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message to layout.
|
/// Send a message to layout.
|
||||||
|
|
|
@ -274,7 +274,7 @@ enum MixedMessage {
|
||||||
FromScheduler(TimerEvent),
|
FromScheduler(TimerEvent),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Messages used to control the script event loop
|
/// Messages used to control the script event loop.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MainThreadScriptMsg {
|
pub enum MainThreadScriptMsg {
|
||||||
/// Common variants associated with the script messages
|
/// Common variants associated with the script messages
|
||||||
|
@ -289,6 +289,8 @@ pub enum MainThreadScriptMsg {
|
||||||
/// Notifies the script thread that a new worklet has been loaded, and thus the page should be
|
/// Notifies the script thread that a new worklet has been loaded, and thus the page should be
|
||||||
/// reflowed.
|
/// reflowed.
|
||||||
WorkletLoaded(PipelineId),
|
WorkletLoaded(PipelineId),
|
||||||
|
/// Runs a Runnable in the main thread.
|
||||||
|
MainThreadRunnable(ScriptThreadEventCategory, Box<Runnable + Send>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpaqueSender<CommonScriptMsg> for Box<ScriptChan + Send> {
|
impl OpaqueSender<CommonScriptMsg> for Box<ScriptChan + Send> {
|
||||||
|
@ -1167,9 +1169,9 @@ impl ScriptThread {
|
||||||
MixedMessage::FromImageCache(_) => ScriptThreadEventCategory::ImageCacheMsg,
|
MixedMessage::FromImageCache(_) => ScriptThreadEventCategory::ImageCacheMsg,
|
||||||
MixedMessage::FromScript(ref inner_msg) => {
|
MixedMessage::FromScript(ref inner_msg) => {
|
||||||
match *inner_msg {
|
match *inner_msg {
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(ref category, _)) =>
|
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(category, _)) |
|
||||||
*category,
|
MainThreadScriptMsg::MainThreadRunnable(category, _) => category,
|
||||||
_ => ScriptThreadEventCategory::ScriptEvent
|
_ => ScriptThreadEventCategory::ScriptEvent,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
MixedMessage::FromScheduler(_) => ScriptThreadEventCategory::TimerEvent
|
MixedMessage::FromScheduler(_) => ScriptThreadEventCategory::TimerEvent
|
||||||
|
@ -1299,7 +1301,7 @@ impl ScriptThread {
|
||||||
self.handle_exit_window_msg(id)
|
self.handle_exit_window_msg(id)
|
||||||
},
|
},
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable)) => {
|
||||||
runnable.main_thread_handler(self)
|
runnable.handler()
|
||||||
}
|
}
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => {
|
||||||
self.collect_reports(chan)
|
self.collect_reports(chan)
|
||||||
|
@ -1307,6 +1309,9 @@ impl ScriptThread {
|
||||||
MainThreadScriptMsg::WorkletLoaded(pipeline_id) => {
|
MainThreadScriptMsg::WorkletLoaded(pipeline_id) => {
|
||||||
self.handle_worklet_loaded(pipeline_id)
|
self.handle_worklet_loaded(pipeline_id)
|
||||||
},
|
},
|
||||||
|
MainThreadScriptMsg::MainThreadRunnable(_, runnable) => {
|
||||||
|
runnable.main_thread_handler(self)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue