mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Don't use image metadata for layout when rendering to a file
PR #9208 added the ability to perform layout before an `<img>` resource is fully loaded. However, when we are rendering to an image file for testing purposes, we need to block until the image content is fully loaded (until issue #9441 is fixed). Fixes #9550.
This commit is contained in:
parent
57a96ece0c
commit
37dd2a654d
1 changed files with 16 additions and 36 deletions
|
@ -178,47 +178,27 @@ impl<'a> LayoutContext<'a> {
|
||||||
|
|
||||||
pub fn get_or_request_image_or_meta(&self, url: Url, use_placeholder: UsePlaceholder)
|
pub fn get_or_request_image_or_meta(&self, url: Url, use_placeholder: UsePlaceholder)
|
||||||
-> Option<ImageOrMetadataAvailable> {
|
-> Option<ImageOrMetadataAvailable> {
|
||||||
|
// If we are emitting an output file, load the image synchronously.
|
||||||
|
if opts::get().output_file.is_some() || opts::get().exit_after_load {
|
||||||
|
return self.get_or_request_image(url, use_placeholder)
|
||||||
|
.map(|img| ImageOrMetadataAvailable::ImageAvailable(img));
|
||||||
|
}
|
||||||
// See if the image is already available
|
// See if the image is already available
|
||||||
let result = self.shared.image_cache_thread.find_image_or_metadata(url.clone(),
|
let result = self.shared.image_cache_thread.find_image_or_metadata(url.clone(),
|
||||||
use_placeholder);
|
use_placeholder);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(image_or_metadata) => Some(image_or_metadata),
|
Ok(image_or_metadata) => Some(image_or_metadata),
|
||||||
Err(state) => {
|
|
||||||
// If we are emitting an output file, then we need to block on
|
|
||||||
// image load or we risk emitting an output file missing the image.
|
|
||||||
let is_sync = opts::get().output_file.is_some() ||
|
|
||||||
opts::get().exit_after_load;
|
|
||||||
|
|
||||||
match (state, is_sync) {
|
|
||||||
// Image failed to load, so just return nothing
|
// Image failed to load, so just return nothing
|
||||||
(ImageState::LoadError, _) => None,
|
Err(ImageState::LoadError) => None,
|
||||||
// Not loaded, test mode - load the image synchronously
|
|
||||||
(_, true) => {
|
|
||||||
let (sync_tx, sync_rx) = ipc::channel().unwrap();
|
|
||||||
self.shared.image_cache_thread.request_image(url,
|
|
||||||
ImageCacheChan(sync_tx),
|
|
||||||
None);
|
|
||||||
match sync_rx.recv().unwrap().image_response {
|
|
||||||
ImageResponse::Loaded(image) |
|
|
||||||
ImageResponse::PlaceholderLoaded(image) =>
|
|
||||||
Some(ImageOrMetadataAvailable::ImageAvailable(image)),
|
|
||||||
ImageResponse::None | ImageResponse::MetadataLoaded(_) =>
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Not yet requested, async mode - request image or metadata from the cache
|
// Not yet requested, async mode - request image or metadata from the cache
|
||||||
(ImageState::NotRequested, false) => {
|
Err(ImageState::NotRequested) => {
|
||||||
let sender = self.shared.image_cache_sender.lock().unwrap().clone();
|
let sender = self.shared.image_cache_sender.lock().unwrap().clone();
|
||||||
self.shared.image_cache_thread.request_image_and_metadata(url, sender, None);
|
self.shared.image_cache_thread.request_image_and_metadata(url, sender, None);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
// Image has been requested, is still pending. Return no image
|
// Image has been requested, is still pending. Return no image for this paint loop.
|
||||||
// for this paint loop. When the image loads it will trigger
|
// When the image loads it will trigger a reflow and/or repaint.
|
||||||
// a reflow and/or repaint.
|
Err(ImageState::Pending) => None,
|
||||||
(ImageState::Pending, false) => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue