mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Refactor ImageCache::find_image_or_metadata API.
This commit is contained in:
parent
7d1f968d52
commit
2742fd2bea
9 changed files with 266 additions and 227 deletions
|
@ -11,7 +11,7 @@ use gfx::font_cache_thread::FontCacheThread;
|
|||
use gfx::font_context::FontContext;
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::image_cache::{CanRequestImages, ImageCache, ImageState};
|
||||
use net_traits::image_cache::{CanRequestImages, ImageCache, ImageCacheResult};
|
||||
use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder};
|
||||
use parking_lot::RwLock;
|
||||
use script_layout_interface::{PendingImage, PendingImageState};
|
||||
|
@ -122,24 +122,40 @@ impl<'a> LayoutContext<'a> {
|
|||
CanRequestImages::No
|
||||
};
|
||||
|
||||
// See if the image is already available
|
||||
let result = self.image_cache.find_image_or_metadata(
|
||||
// Check for available image or start tracking.
|
||||
let cache_result = self.image_cache.get_cached_image_status(
|
||||
url.clone(),
|
||||
self.origin.clone(),
|
||||
None,
|
||||
use_placeholder,
|
||||
can_request,
|
||||
);
|
||||
match result {
|
||||
Ok(image_or_metadata) => Some(image_or_metadata),
|
||||
// Image failed to load, so just return nothing
|
||||
Err(ImageState::LoadError) => None,
|
||||
|
||||
match cache_result {
|
||||
ImageCacheResult::Available(img_or_meta) => Some(img_or_meta),
|
||||
// Image has been requested, is still pending. Return no image for this paint loop.
|
||||
// When the image loads it will trigger a reflow and/or repaint.
|
||||
ImageCacheResult::Pending(id) => {
|
||||
//XXXjdm if self.pending_images is not available, we should make sure that
|
||||
// this node gets marked dirty again so it gets a script-initiated
|
||||
// reflow that deals with this properly.
|
||||
if let Some(ref pending_images) = self.pending_images {
|
||||
let image = PendingImage {
|
||||
state: PendingImageState::PendingResponse,
|
||||
node: node.to_untrusted_node_address(),
|
||||
id,
|
||||
origin: self.origin.clone(),
|
||||
};
|
||||
pending_images.lock().unwrap().push(image);
|
||||
}
|
||||
None
|
||||
},
|
||||
// Not yet requested - request image or metadata from the cache
|
||||
Err(ImageState::NotRequested(id)) => {
|
||||
ImageCacheResult::ReadyForRequest(id) => {
|
||||
let image = PendingImage {
|
||||
state: PendingImageState::Unrequested(url),
|
||||
node: node.to_untrusted_node_address(),
|
||||
id: id,
|
||||
id,
|
||||
origin: self.origin.clone(),
|
||||
};
|
||||
self.pending_images
|
||||
|
@ -150,23 +166,8 @@ impl<'a> LayoutContext<'a> {
|
|||
.push(image);
|
||||
None
|
||||
},
|
||||
// Image has been requested, is still pending. Return no image for this paint loop.
|
||||
// When the image loads it will trigger a reflow and/or repaint.
|
||||
Err(ImageState::Pending(id)) => {
|
||||
//XXXjdm if self.pending_images is not available, we should make sure that
|
||||
// this node gets marked dirty again so it gets a script-initiated
|
||||
// reflow that deals with this properly.
|
||||
if let Some(ref pending_images) = self.pending_images {
|
||||
let image = PendingImage {
|
||||
state: PendingImageState::PendingResponse,
|
||||
node: node.to_untrusted_node_address(),
|
||||
id: id,
|
||||
origin: self.origin.clone(),
|
||||
};
|
||||
pending_images.lock().unwrap().push(image);
|
||||
}
|
||||
None
|
||||
},
|
||||
// Image failed to load, so just return nothing
|
||||
ImageCacheResult::LoadError => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue