mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Take origin from window instead of creating a new one in case of reflow
Everytime a new LayoutContext was created, it created a new origin which caused endless stream of image loads to occur in case of reflow. The reason for this was that the existing image, although cached successfully, was not used because the entry in hashmap did not match because of different(new) origin. This is solved by storing the origin of a window in enum ScriptReflow and used in creating new LayoutContext in case of reflow.
This commit is contained in:
parent
3475790fc2
commit
a5b43b7df1
5 changed files with 20 additions and 6 deletions
|
@ -140,6 +140,7 @@ impl<'a> LayoutContext<'a> {
|
||||||
state: PendingImageState::Unrequested(url),
|
state: PendingImageState::Unrequested(url),
|
||||||
node: node.to_untrusted_node_address(),
|
node: node.to_untrusted_node_address(),
|
||||||
id: id,
|
id: id,
|
||||||
|
origin: self.origin.clone(),
|
||||||
};
|
};
|
||||||
self.pending_images
|
self.pending_images
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -160,6 +161,7 @@ impl<'a> LayoutContext<'a> {
|
||||||
state: PendingImageState::PendingResponse,
|
state: PendingImageState::PendingResponse,
|
||||||
node: node.to_untrusted_node_address(),
|
node: node.to_untrusted_node_address(),
|
||||||
id: id,
|
id: id,
|
||||||
|
origin: self.origin.clone(),
|
||||||
};
|
};
|
||||||
pending_images.lock().unwrap().push(image);
|
pending_images.lock().unwrap().push(image);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ use servo_atoms::Atom;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_config::pref;
|
use servo_config::pref;
|
||||||
use servo_geometry::MaxRect;
|
use servo_geometry::MaxRect;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -644,13 +644,18 @@ impl LayoutThread {
|
||||||
guards: StylesheetGuards<'a>,
|
guards: StylesheetGuards<'a>,
|
||||||
script_initiated_layout: bool,
|
script_initiated_layout: bool,
|
||||||
snapshot_map: &'a SnapshotMap,
|
snapshot_map: &'a SnapshotMap,
|
||||||
|
origin: Option<ImmutableOrigin>,
|
||||||
) -> LayoutContext<'a> {
|
) -> LayoutContext<'a> {
|
||||||
let thread_local_style_context_creation_data =
|
let thread_local_style_context_creation_data =
|
||||||
ThreadLocalStyleContextCreationInfo::new(self.new_animations_sender.clone());
|
ThreadLocalStyleContextCreationInfo::new(self.new_animations_sender.clone());
|
||||||
|
|
||||||
LayoutContext {
|
LayoutContext {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
origin: self.url.origin(),
|
origin: if let Some(origin) = origin {
|
||||||
|
origin
|
||||||
|
} else {
|
||||||
|
self.url.origin()
|
||||||
|
},
|
||||||
style_context: SharedStyleContext {
|
style_context: SharedStyleContext {
|
||||||
stylist: &self.stylist,
|
stylist: &self.stylist,
|
||||||
options: GLOBAL_STYLE_DATA.options.clone(),
|
options: GLOBAL_STYLE_DATA.options.clone(),
|
||||||
|
@ -1341,6 +1346,8 @@ impl LayoutThread {
|
||||||
Au::from_f32_px(initial_viewport.height),
|
Au::from_f32_px(initial_viewport.height),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let origin = data.origin.clone();
|
||||||
|
|
||||||
// Calculate the actual viewport as per DEVICE-ADAPT § 6
|
// Calculate the actual viewport as per DEVICE-ADAPT § 6
|
||||||
// If the entire flow tree is invalid, then it will be reflowed anyhow.
|
// If the entire flow tree is invalid, then it will be reflowed anyhow.
|
||||||
let document_shared_lock = document.style_shared_lock();
|
let document_shared_lock = document.style_shared_lock();
|
||||||
|
@ -1482,7 +1489,8 @@ impl LayoutThread {
|
||||||
self.stylist.flush(&guards, Some(element), Some(&map));
|
self.stylist.flush(&guards, Some(element), Some(&map));
|
||||||
|
|
||||||
// Create a layout context for use throughout the following passes.
|
// Create a layout context for use throughout the following passes.
|
||||||
let mut layout_context = self.build_layout_context(guards.clone(), true, &map);
|
let mut layout_context =
|
||||||
|
self.build_layout_context(guards.clone(), true, &map, Some(origin));
|
||||||
|
|
||||||
let pool;
|
let pool;
|
||||||
let (thread_pool, num_threads) = if self.parallel_flag {
|
let (thread_pool, num_threads) = if self.parallel_flag {
|
||||||
|
@ -1738,7 +1746,7 @@ impl LayoutThread {
|
||||||
ua_or_user: &ua_or_user_guard,
|
ua_or_user: &ua_or_user_guard,
|
||||||
};
|
};
|
||||||
let snapshots = SnapshotMap::new();
|
let snapshots = SnapshotMap::new();
|
||||||
let mut layout_context = self.build_layout_context(guards, false, &snapshots);
|
let mut layout_context = self.build_layout_context(guards, false, &snapshots, None);
|
||||||
|
|
||||||
let invalid_nodes = {
|
let invalid_nodes = {
|
||||||
// Perform an abbreviated style recalc that operates without access to the DOM.
|
// Perform an abbreviated style recalc that operates without access to the DOM.
|
||||||
|
|
|
@ -1622,6 +1622,7 @@ impl Window {
|
||||||
document: self.Document().upcast::<Node>().to_trusted_node_address(),
|
document: self.Document().upcast::<Node>().to_trusted_node_address(),
|
||||||
stylesheets_changed,
|
stylesheets_changed,
|
||||||
window_size: self.window_size.get(),
|
window_size: self.window_size.get(),
|
||||||
|
origin: self.origin().immutable().clone(),
|
||||||
reflow_goal,
|
reflow_goal,
|
||||||
script_join_chan: join_chan,
|
script_join_chan: join_chan,
|
||||||
dom_count: self.Document().dom_count(),
|
dom_count: self.Document().dom_count(),
|
||||||
|
|
|
@ -23,7 +23,7 @@ use ipc_channel::ipc::IpcSender;
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
use net_traits::image_cache::PendingImageId;
|
use net_traits::image_cache::PendingImageId;
|
||||||
use script_traits::UntrustedNodeAddress;
|
use script_traits::UntrustedNodeAddress;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::sync::atomic::AtomicIsize;
|
use std::sync::atomic::AtomicIsize;
|
||||||
use style::data::ElementData;
|
use style::data::ElementData;
|
||||||
|
@ -138,6 +138,7 @@ pub struct PendingImage {
|
||||||
pub state: PendingImageState,
|
pub state: PendingImageState,
|
||||||
pub node: UntrustedNodeAddress,
|
pub node: UntrustedNodeAddress,
|
||||||
pub id: PendingImageId,
|
pub id: PendingImageId,
|
||||||
|
pub origin: ImmutableOrigin,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HTMLMediaData {
|
pub struct HTMLMediaData {
|
||||||
|
|
|
@ -18,7 +18,7 @@ use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as Cons
|
||||||
use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
|
use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
|
||||||
use servo_arc::Arc as ServoArc;
|
use servo_arc::Arc as ServoArc;
|
||||||
use servo_atoms::Atom;
|
use servo_atoms::Atom;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::context::QuirksMode;
|
use style::context::QuirksMode;
|
||||||
|
@ -216,6 +216,8 @@ pub struct ScriptReflow {
|
||||||
pub reflow_goal: ReflowGoal,
|
pub reflow_goal: ReflowGoal,
|
||||||
/// The number of objects in the dom #10110
|
/// The number of objects in the dom #10110
|
||||||
pub dom_count: u32,
|
pub dom_count: u32,
|
||||||
|
/// The current window origin
|
||||||
|
pub origin: ImmutableOrigin,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LayoutThreadInit {
|
pub struct LayoutThreadInit {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue