Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to send iframe resize messages directly from layout thread to constellation #15129

Merged
merged 1 commit into from Jan 23, 2017

Conversation

@cynicaldevil
Copy link
Contributor

cynicaldevil commented Jan 20, 2017


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14682.

r? @jdm
passing tests:
tests/wpt/mozilla/tests/css/matchMedia.html, tests/wpt/mozilla/tests/mozilla/window_resize_not_triggered_on_load.html, tests/wpt/mozilla/tests/mozilla/iframe/resize_after_load.html, tests/wpt/mozilla/tests/css/meta_viewport_resize.html


This change is Reviewable

@highfive
Copy link

highfive commented Jan 20, 2017

Heads up! This PR modifies the following files:

  • @asajeffrey: components/constellation/constellation.rs
  • @fitzgen: components/script_traits/lib.rs, components/script_traits/lib.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs
  • @KiChjang: components/script_traits/lib.rs, components/script_traits/lib.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs
DisplayItem::Iframe(ref iframe) => {
let size = Size2D::new((*item).bounds().size.width.to_f32_px(),
(*item).bounds().size.height.to_f32_px());
debug!("new iframe size: {:?}", size);

This comment has been minimized.

@cynicaldevil

cynicaldevil Jan 20, 2017

Author Contributor

Left this debug message because I thought it would be helpful, but can remove if its unneeded.

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

Rather than iterating over the complete display list every time we build one, we should send this message when we create an iframe display item instead: https://dxr.mozilla.org/servo/rev/1f76aa6ef7ec7db0a0c40223874a72e8f4059deb/components/layout/display_list_builder.rs#1441

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

In fact, we may want to consider batching up all of the iframe sizes that are discovered and sending them in a single message once the display list has been created, rather than one by one.

This comment has been minimized.

@cynicaldevil

cynicaldevil Jan 20, 2017

Author Contributor

heh, I had thought of this but forgot all about it when I couldn't get those tests to pass....

Copy link
Member

jdm left a comment

Great work! @jrmuizel will be pleased by this change.

@@ -1089,6 +1083,12 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
FromLayoutMsg::ChangeRunningAnimationsState(pipeline_id, animation_state) => {
self.handle_change_running_animations_state(pipeline_id, animation_state)
}
// The compositor discovered the size of a subframe. This needs to be reflected by all

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

s/The compositor/Layout/

DisplayItem::Iframe(ref iframe) => {
let size = Size2D::new((*item).bounds().size.width.to_f32_px(),
(*item).bounds().size.height.to_f32_px());
debug!("new iframe size: {:?}", size);

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

Rather than iterating over the complete display list every time we build one, we should send this message when we create an iframe display item instead: https://dxr.mozilla.org/servo/rev/1f76aa6ef7ec7db0a0c40223874a72e8f4059deb/components/layout/display_list_builder.rs#1441

warn!("Layout resize to constellation failed ({}).", e);
}
},
_ => debug!("other!"),

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

This looks unnecessary :)

// early exit if that occurs.
match self.pipelines.get_mut(&pipeline_id) {
Some(pipeline) => {
let result = match self.pipelines.get_mut(&pipeline_id) {

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

let result = self.pipelines.get_mut(&pipeline_id).map(|pipeline| {

This comment has been minimized.

@cynicaldevil

cynicaldevil Jan 22, 2017

Author Contributor

The compiler complains about having mutably borrowed self outside the closure if I use this. Besides, I can't use map here because result can be None even if pipeline is resolved, in the case where sizes are equal.

@@ -32,6 +32,8 @@ use style_traits::viewport::ViewportConstraints;
pub enum LayoutMsg {
/// Indicates whether this pipeline is currently running animations.
ChangeRunningAnimationsState(PipelineId, AnimationState),
/// Inform the constellation of the size of the viewport.

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

"size of the pipeline's viewport"

DisplayItem::Iframe(ref iframe) => {
let size = Size2D::new((*item).bounds().size.width.to_f32_px(),
(*item).bounds().size.height.to_f32_px());
debug!("new iframe size: {:?}", size);

This comment has been minimized.

@jdm

jdm Jan 20, 2017

Member

In fact, we may want to consider batching up all of the iframe sizes that are discovered and sending them in a single message once the display list has been created, rather than one by one.

@jrmuizel
Copy link

jrmuizel commented Jan 20, 2017

Indeed this will allow a nice cleanup.

@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented Jan 22, 2017

@jdm Added new changes.

// frame trees in the navigation context containing the subframe.
FromLayoutMsg::FrameSize(pipeline_id, size) => {
FromLayoutMsg::FrameSize(iframe_sizes) => {

This comment has been minimized.

@emilio

emilio Jan 22, 2017

Member

nit: rename to FrameSizes?

} else {
None
iframe_sizes: Vec<(PipelineId, Size2D<f32>)>) {
for size_data in iframe_sizes {

This comment has been minimized.

@emilio

emilio Jan 22, 2017

Member

nit: for (pipeline_id, untyped_size) in frame sizes.

Also, could we send the TypedSize2D through IPC directly? if not, why not?

if let Err(e) = self.constellation_chan.send(msg) {
warn!("Layout resize to constellation failed ({}).", e);
}
iframe_sizes.push(((*iframe).iframe, size));

This comment has been minimized.

@emilio

emilio Jan 22, 2017

Member

This is still walking all the display list instead of doing it at display list building time. You should collect the sizes in build_fragment_type_specific_display_items in components/layout/display_list_builder.rs, under the Iframe branch.

For that, you probably want to add the vector of iframe sizes to DisplayListBuildState (in that same file), and send the sizes to the constellation once you're done building the display list.

}
}

if iframe_sizes.len() > 0 {

This comment has been minimized.

@emilio

emilio Jan 22, 2017

Member

nit: if !iframe_sizes.is_empty().

@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented Jan 22, 2017

@emilio Fixed.

@cynicaldevil cynicaldevil force-pushed the cynicaldevil:iframe-resize branch from b5d95ec to 5feba01 Jan 22, 2017
Copy link
Member

emilio left a comment

The rest looks great to me, thanks for doing this @cynicaldevil! \o/

@@ -105,6 +107,7 @@ pub struct DisplayListBuildState<'a> {
/// The current scroll root id, used to keep track of state when
/// recursively building and processing the display list.
pub current_scroll_root_id: ScrollRootId,
pub iframe_sizes: Vec<(PipelineId, TypedSize2D<f32, PagePx>)>,

This comment has been minimized.

@emilio

emilio Jan 22, 2017

Member

Can you add a comment here, in the lines of:

/// The collection of sizes of iframe display items, needed to inform the constellation about iframe resizes.
@@ -1463,6 +1467,10 @@ impl FragmentDisplayListBuilding for Fragment {
iframe: fragment_info.pipeline_id,
});

let size = Size2D::new((item).bounds().size.width.to_f32_px(),

This comment has been minimized.

@emilio

emilio Jan 22, 2017

Member

nit: I believe you don't need the parenthesis around item, do you?

@@ -934,6 +934,14 @@ impl LayoutThread {
let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size);
build_state.root_stacking_context.bounds = origin;
build_state.root_stacking_context.overflow = origin;

if !build_state.iframe_sizes.is_empty() {
let msg = ConstellationMsg::FrameSizes(build_state.iframe_sizes.clone());

This comment has been minimized.

@emilio

emilio Jan 22, 2017

Member

nit: Since the iframe sizes are not going to be useful, you can prevent the extra allocation doing the following:

let iframe_sizes = mem::replace(&mut build_state.iframe_sizes, vec![]);
let msg = ConstellationMsg::FrameSizes(iframe_sizes);

You can also make that first line a method in DisplayListBuildState if you want, something along the lines of:

fn take_iframe_sizes(&mut self) -> Vec<..> {
    mem::replace(..)
}

But given it's only used here, it's not a big deal.

@emilio
Copy link
Member

emilio commented Jan 22, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jan 22, 2017

Trying commit 5feba01 with merge 0e088be...

bors-servo added a commit that referenced this pull request Jan 22, 2017
Refactor to send iframe resize messages directly from layout thread to constellation

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14682.
<!-- Either: -->

r? @jdm
passing tests:
tests/wpt/mozilla/tests/css/matchMedia.html, tests/wpt/mozilla/tests/mozilla/window_resize_not_triggered_on_load.html, tests/wpt/mozilla/tests/mozilla/iframe/resize_after_load.html, tests/wpt/mozilla/tests/css/meta_viewport_resize.html

<!-- 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/15129)
<!-- Reviewable:end -->
@emilio
Copy link
Member

emilio commented Jan 22, 2017

Also, please do squash all the commits together :)

@bors-servo
Copy link
Contributor

bors-servo commented Jan 23, 2017

@cynicaldevil cynicaldevil force-pushed the cynicaldevil:iframe-resize branch from 5feba01 to bca565a Jan 23, 2017
@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented Jan 23, 2017

Fixed and squashed the commits!

None => return,
None => None
};
if let Some(Err(e)) = result {

This comment has been minimized.

@emilio

emilio Jan 23, 2017

Member

We could handle this below send, and early return in the None case so this looks a bit clearer, but not a big deal.

This comment has been minimized.

@cynicaldevil

cynicaldevil Jan 23, 2017

Author Contributor

That's actually not possible, the compiler complains about self being mutably borrowed in the match line; because self needs to be mutably borrowed again for handle_send_error. I had to resort to using this method then :)

This comment has been minimized.

@emilio

emilio Jan 23, 2017

Member

Yeah, but early-returning should make this more legible anyway :P

@emilio
Copy link
Member

emilio commented Jan 23, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jan 23, 2017

📌 Commit bca565a has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jan 23, 2017

Testing commit bca565a with merge 7e2329e...

bors-servo added a commit that referenced this pull request Jan 23, 2017
Refactor to send iframe resize messages directly from layout thread to constellation

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14682.
<!-- Either: -->

r? @jdm
passing tests:
tests/wpt/mozilla/tests/css/matchMedia.html, tests/wpt/mozilla/tests/mozilla/window_resize_not_triggered_on_load.html, tests/wpt/mozilla/tests/mozilla/iframe/resize_after_load.html, tests/wpt/mozilla/tests/css/meta_viewport_resize.html

<!-- 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/15129)
<!-- Reviewable:end -->
@bors-servo bors-servo merged commit bca565a into servo:master Jan 23, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@cynicaldevil cynicaldevil deleted the cynicaldevil:iframe-resize branch Jan 23, 2017
@jrmuizel
Copy link

jrmuizel commented Jan 23, 2017

@cynicaldevil Thanks for doing this work!

emilio added a commit to emilio/servo that referenced this pull request Jan 23, 2017
This is a followup to servo#15129, addressing my last review comment.
bors-servo added a commit that referenced this pull request Jan 23, 2017
constellation: Cleanup the frame size handler.

This is a followup to #15129, addressing my last review comment.

r? anyone

<!-- 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/15155)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jan 24, 2017
Revert several changes that broke tests

This is based on #15158 by @aneeshusa, with additional reverts.

This reverts #15064, which is causing many tests not to run, and #15129 and #15155 which landed while tests were not running and may have caused some new failures in iframe tests.

<!-- 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/15164)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jan 24, 2017
Revert several changes that broke tests

This is based on #15158 by @aneeshusa, with additional reverts.

This reverts #15064, which is causing many tests not to run, and #15129 and #15155 which landed while tests were not running and may have caused some new failures in iframe tests.

<!-- 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/15164)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jan 24, 2017
Revert several changes that broke tests

This is based on #15158 by @aneeshusa, with additional reverts.

This reverts #15064, which is causing many tests not to run, and #15129 and #15155 which landed while tests were not running and may have caused some new failures in iframe tests.

<!-- 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/15164)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

7 participants
You can’t perform that action at this time.