Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make image cache per-document rather than global #16048

Merged
merged 4 commits into from Mar 27, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -24,6 +24,7 @@ ipc-channel = "0.7"
layout_traits = {path = "../layout_traits"}
log = "0.3.5"
msg = {path = "../msg"}
net = {path = "../net"}
net_traits = {path = "../net_traits"}
offscreen_gl_context = "0.8"
profile_traits = {path = "../profile_traits"}
@@ -87,7 +87,6 @@ use msg::constellation_msg::{FrameId, FrameType, PipelineId};
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId, TraversalDirection};
use net_traits::{self, IpcSend, ResourceThreads};
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::pub_domains::reg_host;
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
use offscreen_gl_context::{GLContextAttributes, GLLimits};
@@ -175,10 +174,6 @@ pub struct Constellation<Message, LTF, STF> {
/// browsing.
private_resource_threads: ResourceThreads,

/// A channel for the constellation to send messages to the image
/// cache thread.
image_cache_thread: ImageCacheThread,

/// A channel for the constellation to send messages to the font
/// cache thread.
font_cache_thread: FontCacheThread,
@@ -302,9 +297,6 @@ pub struct InitialConstellationState {
/// A channel to the bluetooth thread.
pub bluetooth_thread: IpcSender<BluetoothRequest>,

/// A channel to the image cache thread.
pub image_cache_thread: ImageCacheThread,

/// A channel to the font cache thread.
pub font_cache_thread: FontCacheThread,

@@ -518,7 +510,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
bluetooth_thread: state.bluetooth_thread,
public_resource_threads: state.public_resource_threads,
private_resource_threads: state.private_resource_threads,
image_cache_thread: state.image_cache_thread,
font_cache_thread: state.font_cache_thread,
swmanager_chan: None,
swmanager_receiver: swmanager_receiver,
@@ -657,7 +648,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
devtools_chan: self.devtools_chan.clone(),
bluetooth_thread: self.bluetooth_thread.clone(),
swmanager_thread: self.swmanager_sender.clone(),
image_cache_thread: self.image_cache_thread.clone(),
font_cache_thread: self.font_cache_thread.clone(),
resource_threads: resource_threads,
time_profiler_chan: self.time_profiler_chan.clone(),
@@ -1210,9 +1200,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
let (core_sender, core_receiver) = ipc::channel().expect("Failed to create IPC channel!");
let (storage_sender, storage_receiver) = ipc::channel().expect("Failed to create IPC channel!");

debug!("Exiting image cache.");
self.image_cache_thread.exit();

debug!("Exiting core resource threads.");
if let Err(e) = self.public_resource_threads.send(net_traits::CoreResourceMsg::Exit(core_sender)) {
warn!("Exit resource thread failed ({})", e);
@@ -24,6 +24,7 @@ extern crate layout_traits;
#[macro_use]
extern crate log;
extern crate msg;
extern crate net;
extern crate net_traits;
extern crate offscreen_gl_context;
extern crate profile_traits;
@@ -16,8 +16,9 @@ use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use layout_traits::LayoutThreadFactory;
use msg::constellation_msg::{FrameId, FrameType, PipelineId, PipelineNamespaceId};
use net::image_cache::ImageCacheImpl;
use net_traits::{IpcSend, ResourceThreads};
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::image_cache::ImageCache;
use profile_traits::mem as profile_mem;
use profile_traits::time;
use script_traits::{ConstellationControlMsg, DevicePixel, DiscardBrowsingContext};
@@ -34,6 +35,7 @@ use std::env;
use std::ffi::OsStr;
use std::process;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::mpsc::Sender;
use style_traits::CSSPixel;
use webrender_traits;
@@ -133,9 +135,6 @@ pub struct InitialPipelineState {
/// A channel to the service worker manager thread
pub swmanager_thread: IpcSender<SWManagerMsg>,

/// A channel to the image cache thread.
pub image_cache_thread: ImageCacheThread,

/// A channel to the font cache thread.
pub font_cache_thread: FontCacheThread,

@@ -250,7 +249,6 @@ impl Pipeline {
devtools_chan: script_to_devtools_chan,
bluetooth_thread: state.bluetooth_thread,
swmanager_thread: state.swmanager_thread,
image_cache_thread: state.image_cache_thread,
font_cache_thread: state.font_cache_thread,
resource_threads: state.resource_threads,
time_profiler_chan: state.time_profiler_chan,
@@ -451,7 +449,6 @@ pub struct UnprivilegedPipelineContent {
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
bluetooth_thread: IpcSender<BluetoothRequest>,
swmanager_thread: IpcSender<SWManagerMsg>,
image_cache_thread: ImageCacheThread,
font_cache_thread: FontCacheThread,
resource_threads: ResourceThreads,
time_profiler_chan: time::ProfilerChan,
@@ -477,6 +474,7 @@ impl UnprivilegedPipelineContent {
where LTF: LayoutThreadFactory<Message=Message>,
STF: ScriptThreadFactory<Message=Message>
{
let image_cache = Arc::new(ImageCacheImpl::new(self.webrender_api_sender.create_api()));
let layout_pair = STF::create(InitialScriptState {
id: self.id,
frame_id: self.frame_id,
@@ -489,7 +487,7 @@ impl UnprivilegedPipelineContent {
scheduler_chan: self.scheduler_chan,
bluetooth_thread: self.bluetooth_thread,
resource_threads: self.resource_threads,
image_cache_thread: self.image_cache_thread.clone(),
image_cache: image_cache.clone(),
time_profiler_chan: self.time_profiler_chan.clone(),
mem_profiler_chan: self.mem_profiler_chan.clone(),
devtools_chan: self.devtools_chan,
@@ -507,7 +505,7 @@ impl UnprivilegedPipelineContent {
self.pipeline_port,
self.layout_to_constellation_chan,
self.script_chan,
self.image_cache_thread,
image_cache.clone(),
self.font_cache_thread,
self.time_profiler_chan,
self.mem_profiler_chan,
@@ -9,8 +9,8 @@ use gfx::display_list::{WebRenderImageInfo, OpaqueNode};
use gfx::font_cache_thread::FontCacheThread;
use gfx::font_context::FontContext;
use heapsize::HeapSizeOf;
use net_traits::image_cache_thread::{ImageCacheThread, ImageState, CanRequestImages};
use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder};
use net_traits::image_cache::{CanRequestImages, ImageCache, ImageState};
use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder};
use opaque_node::OpaqueNodeMethods;
use parking_lot::RwLock;
use script_layout_interface::{PendingImage, PendingImageState};
@@ -79,8 +79,8 @@ pub struct LayoutContext<'a> {
/// Bits shared by the layout and style system.
pub style_context: SharedStyleContext<'a>,

/// The shared image cache thread.
pub image_cache_thread: Mutex<ImageCacheThread>,
/// Reference to the script thread image cache.
pub image_cache: Arc<ImageCache>,

/// Interface to the font cache thread.
pub font_cache_thread: Mutex<FontCacheThread>,
@@ -126,10 +126,9 @@ impl<'a> LayoutContext<'a> {
};

// See if the image is already available
let result = self.image_cache_thread.lock().unwrap()
.find_image_or_metadata(url.clone(),
use_placeholder,
can_request);
let result = self.image_cache.find_image_or_metadata(url.clone(),
use_placeholder,
can_request);
match result {
Ok(image_or_metadata) => Some(image_or_metadata),
// Image failed to load, so just return nothing
@@ -36,7 +36,7 @@ use list_item::ListItemFlow;
use model::{self, MaybeAuto};
use msg::constellation_msg::PipelineId;
use net_traits::image::base::PixelFormat;
use net_traits::image_cache_thread::UsePlaceholder;
use net_traits::image_cache::UsePlaceholder;
use range::Range;
use servo_config::opts;
use servo_url::ServoUrl;
@@ -27,7 +27,7 @@ use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, SizeC
use model::{style_length, ToGfxMatrix};
use msg::constellation_msg::PipelineId;
use net_traits::image::base::{Image, ImageMetadata};
use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder};
use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder};
use range::*;
use script_layout_interface::HTMLCanvasData;
use script_layout_interface::SVGSVGData;
@@ -76,8 +76,7 @@ use layout::wrapper::LayoutNodeLayoutData;
use layout::wrapper::drop_style_and_layout_data;
use layout_traits::LayoutThreadFactory;
use msg::constellation_msg::{FrameId, PipelineId};
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::image_cache_thread::UsePlaceholder;
use net_traits::image_cache::{ImageCache, UsePlaceholder};
use parking_lot::RwLock;
use profile_traits::mem::{self, Report, ReportKind, ReportsChan};
use profile_traits::time::{self, TimerMetadata, profile};
@@ -157,8 +156,8 @@ pub struct LayoutThread {
/// The channel on which messages can be sent to the memory profiler.
mem_profiler_chan: mem::ProfilerChan,

/// The channel on which messages can be sent to the image cache.
image_cache_thread: ImageCacheThread,
/// Reference to the script thread image cache.
image_cache: Arc<ImageCache>,

/// Public interface to the font cache thread.
font_cache_thread: FontCacheThread,
@@ -245,7 +244,7 @@ impl LayoutThreadFactory for LayoutThread {
pipeline_port: IpcReceiver<LayoutControlMsg>,
constellation_chan: IpcSender<ConstellationMsg>,
script_chan: IpcSender<ConstellationControlMsg>,
image_cache_thread: ImageCacheThread,
image_cache: Arc<ImageCache>,
font_cache_thread: FontCacheThread,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan,
@@ -268,7 +267,7 @@ impl LayoutThreadFactory for LayoutThread {
pipeline_port,
constellation_chan,
script_chan,
image_cache_thread,
image_cache.clone(),
font_cache_thread,
time_profiler_chan,
mem_profiler_chan.clone(),
@@ -382,7 +381,7 @@ impl LayoutThread {
pipeline_port: IpcReceiver<LayoutControlMsg>,
constellation_chan: IpcSender<ConstellationMsg>,
script_chan: IpcSender<ConstellationControlMsg>,
image_cache_thread: ImageCacheThread,
image_cache: Arc<ImageCache>,
font_cache_thread: FontCacheThread,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan,
@@ -432,7 +431,7 @@ impl LayoutThread {
constellation_chan: constellation_chan.clone(),
time_profiler_chan: time_profiler_chan,
mem_profiler_chan: mem_profiler_chan,
image_cache_thread: image_cache_thread,
image_cache: image_cache.clone(),
font_cache_thread: font_cache_thread,
first_reflow: true,
font_cache_receiver: font_cache_receiver,
@@ -522,7 +521,7 @@ impl LayoutThread {
quirks_mode: self.quirks_mode.unwrap(),
animation_only_restyle: false,
},
image_cache_thread: Mutex::new(self.image_cache_thread.clone()),
image_cache: self.image_cache.clone(),
font_cache_thread: Mutex::new(self.font_cache_thread.clone()),
webrender_image_cache: self.webrender_image_cache.clone(),
pending_images: if request_images { Some(Mutex::new(vec![])) } else { None },
@@ -693,7 +692,7 @@ impl LayoutThread {
info.pipeline_port,
info.constellation_chan,
info.script_chan.clone(),
self.image_cache_thread.clone(),
info.image_cache.clone(),
self.font_cache_thread.clone(),
self.time_profiler_chan.clone(),
self.mem_profiler_chan.clone(),
@@ -21,11 +21,12 @@ extern crate webrender_traits;
use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::constellation_msg::{FrameId, PipelineId};
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::image_cache::ImageCache;
use profile_traits::{mem, time};
use script_traits::{ConstellationControlMsg, LayoutControlMsg};
use script_traits::LayoutMsg as ConstellationMsg;
use servo_url::ServoUrl;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender};

// A static method creating a layout thread
@@ -40,7 +41,7 @@ pub trait LayoutThreadFactory {
pipeline_port: IpcReceiver<LayoutControlMsg>,
constellation_chan: IpcSender<ConstellationMsg>,
script_chan: IpcSender<ConstellationControlMsg>,
image_cache_thread: ImageCacheThread,
image_cache: Arc<ImageCache>,
font_cache_thread: FontCacheThread,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.