From 52a6f63608a25e0574fd43b69f404f79a9a6c28f Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 16 Sep 2017 01:55:26 +0200 Subject: [PATCH] Introduce MainThreadScriptMsg::MainThreadRunnable This will allow us to separate the types for tasks that must run on the main script thread and regular tasks. --- components/script/dom/workletglobalscope.rs | 10 ++++++---- components/script/script_thread.rs | 15 ++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/components/script/dom/workletglobalscope.rs b/components/script/dom/workletglobalscope.rs index 64a2b3199fb..25540139135 100644 --- a/components/script/dom/workletglobalscope.rs +++ b/components/script/dom/workletglobalscope.rs @@ -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(&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. diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index c15531ff595..e1183368137 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -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), } impl OpaqueSender for Box { @@ -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) + }, } }