Avoid dropping image requests on the ground from non-script-initiated reflow.

This commit is contained in:
Josh Matthews 2016-12-29 14:07:57 -05:00
parent 541ecbfe21
commit 980eb5ac33
6 changed files with 96 additions and 47 deletions

View file

@ -79,7 +79,10 @@ pub enum ImageOrMetadataAvailable {
pub enum ImageCacheCommand {
/// Synchronously check the state of an image in the cache. If the image is in a loading
/// state and but its metadata has been made available, it will be sent as a response.
GetImageOrMetadataIfAvailable(ServoUrl, UsePlaceholder, IpcSender<Result<ImageOrMetadataAvailable, ImageState>>),
GetImageOrMetadataIfAvailable(ServoUrl,
UsePlaceholder,
CanRequestImages,
IpcSender<Result<ImageOrMetadataAvailable, ImageState>>),
/// Add a new listener for the given pending image.
AddListener(PendingImageId, ImageResponder),
@ -98,6 +101,15 @@ pub enum UsePlaceholder {
Yes,
}
/// Whether a consumer is in a position to request images or not. This can occur when
/// animations are being processed by the layout thread while the script thread is executing
/// in parallel.
#[derive(Copy, Clone, PartialEq, Deserialize, Serialize)]
pub enum CanRequestImages {
No,
Yes,
}
/// The client side of the image cache thread. This can be safely cloned
/// and passed to different threads.
#[derive(Clone, Deserialize, Serialize)]
@ -120,10 +132,14 @@ impl ImageCacheThread {
/// FIXME: We shouldn't do IPC for data uris!
pub fn find_image_or_metadata(&self,
url: ServoUrl,
use_placeholder: UsePlaceholder)
use_placeholder: UsePlaceholder,
can_request: CanRequestImages)
-> Result<ImageOrMetadataAvailable, ImageState> {
let (sender, receiver) = ipc::channel().unwrap();
let msg = ImageCacheCommand::GetImageOrMetadataIfAvailable(url, use_placeholder, sender);
let msg = ImageCacheCommand::GetImageOrMetadataIfAvailable(url,
use_placeholder,
can_request,
sender);
let _ = self.chan.send(msg);
try!(receiver.recv().map_err(|_| ImageState::LoadError))
}