Auto merge of #21931 - jdm:reload-images, r=emilio

Make layout use available image data before querying the image cache.

These changes make layout more efficient for any page which contains images that have already loaded, since it does not require synchronously querying the image cache thread for each image present. It also makes reloading a page actually display the images that are already in the image cache.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21919
- [x] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21931)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-10-13 07:56:11 -04:00 committed by GitHub
commit e4657c1496
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 102 additions and 5 deletions

View file

@ -62,6 +62,7 @@ use js::jsapi::{JSContext, JSObject, JSRuntime};
use libc::{self, c_void, uintptr_t};
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use net_traits::image::base::{Image, ImageMetadata};
use ref_slice::ref_slice;
use script_layout_interface::{HTMLCanvasData, HTMLMediaData, LayoutElementType, LayoutNodeType};
use script_layout_interface::{OpaqueStyleAndLayoutData, SVGSVGData, TrustedNodeAddress};
@ -81,6 +82,7 @@ use std::default::Default;
use std::iter;
use std::mem;
use std::ops::Range;
use std::sync::Arc as StdArc;
use style::context::QuirksMode;
use style::dom::OpaqueNode;
use style::selector_parser::{SelectorImpl, SelectorParser};
@ -1086,6 +1088,7 @@ pub trait LayoutNodeHelpers {
fn selection(&self) -> Option<Range<usize>>;
fn image_url(&self) -> Option<ServoUrl>;
fn image_density(&self) -> Option<f64>;
fn image_data(&self) -> Option<(Option<StdArc<Image>>, Option<ImageMetadata>)>;
fn canvas_data(&self) -> Option<HTMLCanvasData>;
fn media_data(&self) -> Option<HTMLMediaData>;
fn svg_data(&self) -> Option<SVGSVGData>;
@ -1233,6 +1236,13 @@ impl LayoutNodeHelpers for LayoutDom<Node> {
}
}
#[allow(unsafe_code)]
fn image_data(&self) -> Option<(Option<StdArc<Image>>, Option<ImageMetadata>)> {
unsafe {
self.downcast::<HTMLImageElement>().map(|e| e.image_data())
}
}
#[allow(unsafe_code)]
fn image_density(&self) -> Option<f64> {
unsafe {