aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-10-13 07:56:11 -0400
committerGitHub <noreply@github.com>2018-10-13 07:56:11 -0400
commite4657c14961db58bedd0a13ba72667bcb470f34d (patch)
treefe22cf7e7b12d25e28aac7cc98e64302ba99b60d /components/script
parent42ca43e51fd705d6c0c915c699abf65b4b15de78 (diff)
parent49d2ea4f74d94cc5c72b5dcc724d9e5ddf6fc4d6 (diff)
downloadservo-e4657c14961db58bedd0a13ba72667bcb470f34d.tar.gz
servo-e4657c14961db58bedd0a13ba72667bcb470f34d.zip
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 -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/htmlimageelement.rs11
-rw-r--r--components/script/dom/node.rs10
2 files changed, 21 insertions, 0 deletions
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index ca9243beb1b..b31c5e886af 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -1328,6 +1328,9 @@ pub trait LayoutHTMLImageElementHelpers {
#[allow(unsafe_code)]
unsafe fn image_density(&self) -> Option<f64>;
+ #[allow(unsafe_code)]
+ unsafe fn image_data(&self) -> (Option<Arc<Image>>, Option<ImageMetadata>);
+
fn get_width(&self) -> LengthOrPercentageOrAuto;
fn get_height(&self) -> LengthOrPercentageOrAuto;
}
@@ -1352,6 +1355,14 @@ impl LayoutHTMLImageElementHelpers for LayoutDom<HTMLImageElement> {
}
#[allow(unsafe_code)]
+ unsafe fn image_data(&self) -> (Option<Arc<Image>>, Option<ImageMetadata>) {
+ let current_request = (*self.unsafe_get())
+ .current_request
+ .borrow_for_layout();
+ (current_request.image.clone(), current_request.metadata.clone())
+ }
+
+ #[allow(unsafe_code)]
unsafe fn image_density(&self) -> Option<f64> {
(*self.unsafe_get())
.current_request
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 1a5a23f4ef6..8024f2a04a7 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -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>;
@@ -1234,6 +1237,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 {
self.downcast::<HTMLImageElement>()