mirror of
https://github.com/servo/servo.git
synced 2025-07-16 03:43:38 +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::time;
|
||||
use script_layout_interface::message::Msg;
|
||||
use script_runtime::CommonScriptMsg;
|
||||
use script_runtime::ScriptThreadEventCategory;
|
||||
use script_thread::MainThreadScriptMsg;
|
||||
use script_thread::Runnable;
|
||||
|
@ -100,9 +99,12 @@ impl WorkletGlobalScope {
|
|||
pub fn run_in_script_thread<R>(&self, runnable: R) where
|
||||
R: 'static + Send + Runnable,
|
||||
{
|
||||
let msg = CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::WorkletEvent, box runnable);
|
||||
let msg = MainThreadScriptMsg::Common(msg);
|
||||
self.to_script_thread_sender.send(msg).expect("Worklet thread outlived script thread.");
|
||||
self.to_script_thread_sender
|
||||
.send(MainThreadScriptMsg::MainThreadRunnable(
|
||||
ScriptThreadEventCategory::WorkletEvent,
|
||||
box runnable,
|
||||
))
|
||||
.expect("Worklet thread outlived script thread.");
|
||||
}
|
||||
|
||||
/// Send a message to layout.
|
||||
|
|
|
@ -274,7 +274,7 @@ enum MixedMessage {
|
|||
FromScheduler(TimerEvent),
|
||||
}
|
||||
|
||||
/// Messages used to control the script event loop
|
||||
/// Messages used to control the script event loop.
|
||||
#[derive(Debug)]
|
||||
pub enum MainThreadScriptMsg {
|
||||
/// 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
|
||||
/// reflowed.
|
||||
WorkletLoaded(PipelineId),
|
||||
/// Runs a Runnable in the main thread.
|
||||
MainThreadRunnable(ScriptThreadEventCategory, Box<Runnable + Send>),
|
||||
}
|
||||
|
||||
impl OpaqueSender<CommonScriptMsg> for Box<ScriptChan + Send> {
|
||||
|
@ -1167,9 +1169,9 @@ impl ScriptThread {
|
|||
MixedMessage::FromImageCache(_) => ScriptThreadEventCategory::ImageCacheMsg,
|
||||
MixedMessage::FromScript(ref inner_msg) => {
|
||||
match *inner_msg {
|
||||
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(ref category, _)) =>
|
||||
*category,
|
||||
_ => ScriptThreadEventCategory::ScriptEvent
|
||||
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(category, _)) |
|
||||
MainThreadScriptMsg::MainThreadRunnable(category, _) => category,
|
||||
_ => ScriptThreadEventCategory::ScriptEvent,
|
||||
}
|
||||
},
|
||||
MixedMessage::FromScheduler(_) => ScriptThreadEventCategory::TimerEvent
|
||||
|
@ -1299,7 +1301,7 @@ impl ScriptThread {
|
|||
self.handle_exit_window_msg(id)
|
||||
},
|
||||
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable)) => {
|
||||
runnable.main_thread_handler(self)
|
||||
runnable.handler()
|
||||
}
|
||||
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => {
|
||||
self.collect_reports(chan)
|
||||
|
@ -1307,6 +1309,9 @@ impl ScriptThread {
|
|||
MainThreadScriptMsg::WorkletLoaded(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