Navigation Menu

Skip to content

Commit

Permalink
Fix broken viewport percentage length units after a viewport resize.
Browse files Browse the repository at this point in the history
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 fafc357
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions components/layout/context.rs
Expand Up @@ -41,6 +41,10 @@ fn create_or_get_local_context(shared_layout_context: &SharedLayoutContext) -> *
style_sharing_candidate_cache: StyleSharingCandidateCache::new(), style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
}; };
r.set(unsafe { boxed::into_raw(context) }); 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() r.get()
Expand All @@ -54,6 +58,9 @@ pub struct SharedLayoutContext {
/// The current screen size. /// The current screen size.
pub screen_size: Size2D<Au>, pub screen_size: Size2D<Au>,


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

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


Expand Down
4 changes: 4 additions & 0 deletions components/layout/css/matching.rs
Expand Up @@ -153,6 +153,10 @@ impl ApplicableDeclarationsCache {
fn insert(&mut self, declarations: Vec<DeclarationBlock>, style: Arc<ComputedValues>) { fn insert(&mut self, declarations: Vec<DeclarationBlock>, style: Arc<ComputedValues>) {
self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style) 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. /// An LRU cache of the last few nodes seen, so that we can aggressively try to reuse their styles.
Expand Down
13 changes: 8 additions & 5 deletions components/layout/layout_task.rs
Expand Up @@ -311,12 +311,14 @@ impl LayoutTask {
// Create a layout context for use in building display lists, hit testing, &c. // Create a layout context for use in building display lists, hit testing, &c.
fn build_shared_layout_context(&self, fn build_shared_layout_context(&self,
rw_data: &LayoutTaskData, rw_data: &LayoutTaskData,
screen_size_changed: bool,
reflow_root: &LayoutNode, reflow_root: &LayoutNode,
url: &Url) url: &Url)
-> SharedLayoutContext { -> SharedLayoutContext {
SharedLayoutContext { SharedLayoutContext {
image_cache: rw_data.local_image_cache.clone(), image_cache: rw_data.local_image_cache.clone(),
screen_size: rw_data.screen_size.clone(), screen_size: rw_data.screen_size.clone(),
screen_size_changed: screen_size_changed,
constellation_chan: rw_data.constellation_chan.clone(), constellation_chan: rw_data.constellation_chan.clone(),
layout_chan: self.chan.clone(), layout_chan: self.chan.clone(),
font_cache_task: self.font_cache_task.clone(), font_cache_task: self.font_cache_task.clone(),
Expand Down Expand Up @@ -774,11 +776,6 @@ impl LayoutTask {
Au::from_frac32_px(viewport_size.height.get())); Au::from_frac32_px(viewport_size.height.get()));
rw_data.screen_size = current_screen_size; 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. // Handle conditions where the entire flow tree is invalid.
let screen_size_changed = current_screen_size != old_screen_size; let screen_size_changed = current_screen_size != old_screen_size;


Expand All @@ -803,6 +800,12 @@ impl LayoutTask {
|mut flow| LayoutTask::reflow_all_nodes(&mut *flow)); |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, let mut layout_root = profile(TimeProfilerCategory::LayoutStyleRecalc,
self.profiler_metadata(data), self.profiler_metadata(data),
self.time_profiler_chan.clone(), self.time_profiler_chan.clone(),
Expand Down

5 comments on commit fafc357

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at luniv@fafc357

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = a508070

Please sign in to comment.