diff options
author | Josh Matthews <josh@joshmatthews.net> | 2016-11-21 18:13:40 -0500 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2017-02-22 14:19:35 -0500 |
commit | c890c9143cc1ae82e1116b8fb0c4e9eb478b8a03 (patch) | |
tree | 131dcf8dd5a2880562101497d958c02a31903183 /components/script/script_thread.rs | |
parent | 78e8c31a4d1890260dda83f2db85672f693c1e97 (diff) | |
download | servo-c890c9143cc1ae82e1116b8fb0c4e9eb478b8a03.tar.gz servo-c890c9143cc1ae82e1116b8fb0c4e9eb478b8a03.zip |
Make script thread initiate requests for images needed by layout.
In support of this goal, the layout thread collects information about
CSS images that are missing image data and hands it off to the script
thread after layout completes. The script thread stores a list of
nodes that will need to be reflowed after the associated network
request is complete. The script thread ensures that the nodes are
not GCed while a request is ongoing, which the layout thread is
incapable of guaranteeing.
The image cache's API has also been redesigned in support of this
work. No network requests are made by the new image cache, since it
does not possess the document-specific information necessary to
initiate them. Instead, there is now a single, synchronous
query operation that optionally reserves a slot when a cache
entry for a URL cannot be found. This reserved slot is then
the responsibility of the queryer to populate with the contents
of the network response for the URL once it is complete. Any
subsequent queries for the same URL will be informed that the
response is pending until that occurs.
The changes to layout also remove the synchronous image loading
code path, which means that reftests now test the same code
that non-test binaries execute. The decision to take a screenshot
now considers whether there are any outstanding image
requests for layout in order to avoid intermittent failures in
reftests that use CSS images.
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 2ab421c707b..192923294a6 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -73,7 +73,7 @@ use microtask::{MicrotaskQueue, Microtask}; use msg::constellation_msg::{FrameId, FrameType, PipelineId, PipelineNamespace}; use net_traits::{CoreResourceMsg, FetchMetadata, FetchResponseListener}; use net_traits::{IpcSend, Metadata, ReferrerPolicy, ResourceThreads}; -use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread}; +use net_traits::image_cache_thread::{PendingImageResponse, ImageCacheThread}; use net_traits::request::{CredentialsMode, Destination, RequestInit}; use net_traits::storage_thread::StorageType; use network_listener::NetworkListener; @@ -120,6 +120,8 @@ use url::Position; use webdriver_handlers; use webvr_traits::WebVRMsg; +pub type ImageCacheMsg = (PipelineId, PendingImageResponse); + thread_local!(pub static STACK_ROOTS: Cell<Option<RootCollectionPtr>> = Cell::new(None)); thread_local!(static SCRIPT_THREAD_ROOT: Cell<Option<*const ScriptThread>> = Cell::new(None)); @@ -230,7 +232,7 @@ enum MixedMessage { FromConstellation(ConstellationControlMsg), FromScript(MainThreadScriptMsg), FromDevtools(DevtoolScriptControlMsg), - FromImageCache(ImageCacheResult), + FromImageCache((PipelineId, PendingImageResponse)), FromScheduler(TimerEvent) } @@ -444,10 +446,10 @@ pub struct ScriptThread { layout_to_constellation_chan: IpcSender<LayoutMsg>, /// The port on which we receive messages from the image cache - image_cache_port: Receiver<ImageCacheResult>, + image_cache_port: Receiver<ImageCacheMsg>, /// The channel on which the image cache can send messages to ourself. - image_cache_channel: ImageCacheChan, + image_cache_channel: Sender<ImageCacheMsg>, /// For providing contact with the time profiler. time_profiler_chan: time::ProfilerChan, @@ -646,11 +648,6 @@ impl ScriptThread { let (ipc_devtools_sender, ipc_devtools_receiver) = ipc::channel().unwrap(); let devtools_port = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_devtools_receiver); - // Ask the router to proxy IPC messages from the image cache thread to us. - let (ipc_image_cache_channel, ipc_image_cache_port) = ipc::channel().unwrap(); - let image_cache_port = - ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_image_cache_port); - let (timer_event_chan, timer_event_port) = channel(); // Ask the router to proxy IPC messages from the control port to us. @@ -658,6 +655,8 @@ impl ScriptThread { let boxed_script_sender = MainThreadScriptChan(chan.clone()).clone(); + let (image_cache_channel, image_cache_port) = channel(); + ScriptThread { documents: DOMRefCell::new(Documents::new()), browsing_contexts: DOMRefCell::new(HashMap::new()), @@ -666,7 +665,7 @@ impl ScriptThread { job_queue_map: Rc::new(JobQueue::new()), image_cache_thread: state.image_cache_thread, - image_cache_channel: ImageCacheChan(ipc_image_cache_channel), + image_cache_channel: image_cache_channel, image_cache_port: image_cache_port, resource_threads: state.resource_threads, @@ -1111,8 +1110,11 @@ impl ScriptThread { } } - fn handle_msg_from_image_cache(&self, msg: ImageCacheResult) { - msg.responder.unwrap().respond(msg.image_response); + fn handle_msg_from_image_cache(&self, (id, response): (PipelineId, PendingImageResponse)) { + let window = self.documents.borrow().find_window(id); + if let Some(ref window) = window { + window.pending_image_notification(response); + } } fn handle_webdriver_msg(&self, pipeline_id: PipelineId, msg: WebDriverScriptCommand) { |