diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 7fcbe5600ec..7d44df744a9 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -147,6 +147,8 @@ use keyboard_types::{Key, KeyState, Modifiers, NamedKey}; use layout_api::{LayoutFactory, ScriptThreadFactory}; use log::{debug, error, info, trace, warn}; use media::WindowGLContext; +use net::image_cache::ImageCacheImpl; +use net_traits::image_cache::ImageCache; use net_traits::pub_domains::reg_host; use net_traits::request::Referrer; use net_traits::storage_thread::{StorageThreadMsg, StorageType}; @@ -486,6 +488,9 @@ pub struct Constellation { /// A list of URLs that can access privileged internal APIs. privileged_urls: Vec, + + /// The image cache for the single-process mode + image_cache: Box, } /// State needed to construct a constellation. @@ -684,7 +689,7 @@ where compositor_receiver, layout_factory, embedder_proxy: state.embedder_proxy, - compositor_proxy: state.compositor_proxy, + compositor_proxy: state.compositor_proxy.clone(), webviews: WebViewManager::default(), devtools_sender: state.devtools_sender, #[cfg(feature = "bluetooth")] @@ -731,12 +736,16 @@ where active_keyboard_modifiers: Modifiers::empty(), hard_fail, active_media_session: None, - rippy_data, + rippy_data: rippy_data.clone(), user_content_manager: state.user_content_manager, process_manager: ProcessManager::new(state.mem_profiler_chan), async_runtime: state.async_runtime, script_join_handles: Default::default(), privileged_urls: state.privileged_urls, + image_cache: Box::new(ImageCacheImpl::new( + state.compositor_proxy.cross_process_compositor_api, + rippy_data, + )), }; constellation.run(); @@ -1014,6 +1023,10 @@ where rippy_data: self.rippy_data.clone(), user_content_manager: self.user_content_manager.clone(), privileged_urls: self.privileged_urls.clone(), + image_cache: self.image_cache.create_new_image_cache( + Some(pipeline_id), + self.compositor_proxy.cross_process_compositor_api.clone(), + ), }); let pipeline = match result { diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index ad78dcef5a0..4b8b0cacbe4 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -212,6 +212,9 @@ pub struct InitialPipelineState { /// A list of URLs that can access privileged internal APIs. pub privileged_urls: Vec, + + /// The image cache for the single-process mode + pub image_cache: Arc, } pub struct NewPipeline { @@ -338,6 +341,7 @@ impl Pipeline { false, state.layout_factory, register, + Some(state.image_cache), ); (None, None, Some(join_handle)) }; @@ -517,15 +521,20 @@ impl UnprivilegedPipelineContent { wait_for_completion: bool, layout_factory: Arc, background_hang_monitor_register: Box, + image_cache: Option>, ) -> JoinHandle<()> { // Setup pipeline-namespace-installing for all threads in this process. // Idempotent in single-process mode. PipelineNamespace::set_installer_sender(self.namespace_request_sender); - let image_cache = Arc::new(ImageCacheImpl::new( - self.cross_process_compositor_api.clone(), - self.rippy_data, - )); + let image_cache = image_cache.unwrap_or_else(|| { + // Create a new image cache (in the multiprocess case) + Arc::new(ImageCacheImpl::new( + self.cross_process_compositor_api.clone(), + self.rippy_data, + )) + }); + let (content_process_shutdown_chan, content_process_shutdown_port) = unbounded(); let join_handle = STF::create( InitialScriptState { @@ -542,7 +551,7 @@ impl UnprivilegedPipelineContent { #[cfg(feature = "bluetooth")] bluetooth_sender: self.bluetooth_thread, resource_threads: self.resource_threads, - image_cache: image_cache.clone(), + image_cache, time_profiler_sender: self.time_profiler_chan.clone(), memory_profiler_sender: self.mem_profiler_chan.clone(), devtools_server_sender: self.devtools_ipc_sender, diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 693aec0780d..dc5b59c9af1 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -1289,6 +1289,7 @@ pub fn run_content_process(token: String) { true, layout_factory, background_hang_monitor_register, + None, ); // Since wait_for_completion is true,