Skip to content
Permalink
Browse files

Fix broken viewport percentage length units after a viewport resize.

When a viewport is resized, the computed values for a style containing viewport percentage length units become stale. However, there's no way for those styles to be invalidated after a resize. As a solution, this commit invalidates the computed values cache after a resize has occurred, which is probably over-kill.

A better solution would probably be to track under what conditions computed values remain valid, and invalidate them as indicated.
  • Loading branch information...
luniv committed Mar 8, 2015
1 parent 09c36de commit fafc357308bfb11a31cb66c5346f54239e22c0f5
Showing with 19 additions and 5 deletions.
  1. +7 −0 components/layout/context.rs
  2. +4 −0 components/layout/css/matching.rs
  3. +8 −5 components/layout/layout_task.rs
@@ -41,6 +41,10 @@ fn create_or_get_local_context(shared_layout_context: &SharedLayoutContext) -> *
style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
};
r.set(unsafe { boxed::into_raw(context) });
} else if shared_layout_context.screen_size_changed {
unsafe {
(*r.get()).applicable_declarations_cache.evict_all();
}
}

r.get()
@@ -54,6 +58,9 @@ pub struct SharedLayoutContext {
/// The current screen size.
pub screen_size: Size2D<Au>,

/// Screen sized changed?
pub screen_size_changed: bool,

/// A channel up to the constellation.
pub constellation_chan: ConstellationChan,

@@ -153,6 +153,10 @@ impl ApplicableDeclarationsCache {
fn insert(&mut self, declarations: Vec<DeclarationBlock>, style: Arc<ComputedValues>) {
self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style)
}

pub fn evict_all(&mut self) {
self.cache.evict_all();
}
}

/// An LRU cache of the last few nodes seen, so that we can aggressively try to reuse their styles.
@@ -311,12 +311,14 @@ impl LayoutTask {
// Create a layout context for use in building display lists, hit testing, &c.
fn build_shared_layout_context(&self,
rw_data: &LayoutTaskData,
screen_size_changed: bool,
reflow_root: &LayoutNode,
url: &Url)
-> SharedLayoutContext {
SharedLayoutContext {
image_cache: rw_data.local_image_cache.clone(),
screen_size: rw_data.screen_size.clone(),
screen_size_changed: screen_size_changed,
constellation_chan: rw_data.constellation_chan.clone(),
layout_chan: self.chan.clone(),
font_cache_task: self.font_cache_task.clone(),
@@ -774,11 +776,6 @@ impl LayoutTask {
Au::from_frac32_px(viewport_size.height.get()));
rw_data.screen_size = current_screen_size;

// Create a layout context for use throughout the following passes.
let mut shared_layout_context = self.build_shared_layout_context(&*rw_data,
node,
&data.url);

// Handle conditions where the entire flow tree is invalid.
let screen_size_changed = current_screen_size != old_screen_size;

@@ -803,6 +800,12 @@ impl LayoutTask {
|mut flow| LayoutTask::reflow_all_nodes(&mut *flow));
}

// Create a layout context for use throughout the following passes.
let mut shared_layout_context = self.build_shared_layout_context(&*rw_data,
screen_size_changed,
node,
&data.url);

let mut layout_root = profile(TimeProfilerCategory::LayoutStyleRecalc,
self.profiler_metadata(data),
self.time_profiler_chan.clone(),

5 comments on commit fafc357

@bors-servo

This comment has been minimized.

Copy link
Contributor

replied Mar 13, 2015

saw approval from SimonSapin
at luniv@fafc357

@bors-servo

This comment has been minimized.

Copy link
Contributor

replied Mar 13, 2015

merging luniv/servo/viewport-length-cached-values-invalidation = fafc357 into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

replied Mar 13, 2015

luniv/servo/viewport-length-cached-values-invalidation = fafc357 merged ok, testing candidate = a508070

@bors-servo

This comment has been minimized.

Copy link
Contributor

replied Mar 13, 2015

fast-forwarding master to auto = a508070

Please sign in to comment.
You can’t perform that action at this time.