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

Bug 1332969: stylo: Synchronously do a style update when the device changes #15157

Merged
merged 1 commit into from Jan 28, 2017

Conversation

emilio
Copy link
Member

@emilio emilio commented Jan 23, 2017

Ideally this would be lazy, but eventually we're going to need to restyle in
RebuildAllStyleData anyway, which would require us to have the style up to date,
so no need to complicate our lives.

r? @heycam or @upsuper or @bholley


This change is Reviewable

…hanges.

Ideally this would be lazy, but eventually we're going to need to restyle in
RebuildAllStyleData anyway, which would require us to have the style up to date,
so no need to complicate our lives.

MozReview-Commit-ID: AlmUGRCNm2z
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
@highfive
Copy link

Heads up! This PR modifies the following files:

  • @bholley: components/style/gecko/data.rs

@highfive
Copy link

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 23, 2017
}
self.stylesheets_changed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to mark the stylesheets as having changed if the device changes? It seems like we need to recascade the DOM and reevaluate media queries, but stylesheets_changed does more work, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to reconstruct the style data because different rules may match.

We can definitely be more granular in the future, but that mechanism isn't there right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

s/may match/may apply/

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to reconstruct the style data because different rules may match.

Oh ok. So We should put a RESTYLE_SELF | RESTYLE_DESCENDANTS hint on the root then.

We can definitely be more granular in the future, but that mechanism isn't there right now.

My understanding is that the servo architecture already differentiates between "stylesheets changed" and "device changed". What machinery is missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to do the restyle stuff after I've finished all the medialist work, because gecko has its own control about which media queries have matched and not, and can provide us with an adequate restyle hint if we do the right thing.

Servo does indeed have the concept of "setting a new device", but there are fundamental differences between a servo device and a Gecko device that don't allow us to do that for gecko.

Concretely, in gecko right now the device is represented by the pres context and effectively unique. There's no easy way to compare against a previous state of the pres context (and I think its not bad, but we can't just reuse that piece of code so easily)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - Just add a comment indicating that Gecko doesn't use that machinery?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, and just so that I understand - if Gecko does provide us with such a restyle hint, will it avoid invoke RebuildAllStyleData? Because otherwise we're still going to dirty everything.

I guess I'm probably enough context here that it makes sense for heycam to review it, since he reviewed the media query stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, RebuildAllStyleData receives a hint and a change hint.

@heycam
Copy link
Contributor

heycam commented Jan 24, 2017

Here is how it works in Gecko.

To respond to window resizes, we call nsPresContext::MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0)). For certain other changes, like dppx changes (via the pref, or dragging the window to another screen) and theme changes, we pass in some non-zero hints.

In nsPresContext::MediaFeatureValuesChanged, we call nsStyleSet::MediumFeaturesChanged which returns true if the set of matching @media rules has changed. It does that by calling MediumFeaturesChanged on each nsCSSRuleProcessor (the object that represents the result of cascading all the sheets at a given cascade level). We can do this "has the set of rules changed" check quickly, because we cache the result of @media rule matching in an nsMediaQueryResultCacheKey object on each nsCSSRuleProcessor, and can just re-evaluate each of the features stored on that cache key. If we return false from nsStyleSet::MediumFeaturesChanged, and we didn't have any non-zero hints passed in, and it's not the case that { we ever used vw/vh/etc. units in the document, and the window was resized }, then we don't do any work. If any of the nsCSSRuleProcessor::MediumFeaturesChanged methods is about to return true, it also re-builds its cascade data (i.e., equivalent to the work done when stylesheets_changed = true).

It's quite important for performance that we can quickly evaluate whether the current set of matched @media rules has changed, and to avoid doing any restyling in those cases.

@heycam
Copy link
Contributor

heycam commented Jan 24, 2017

Oh, and when nsStyleSet::MediumFeaturesChanged does return true, we add eRestyle_Subtree to the restyle hint we pass to RebuildAllStyleData.

@emilio
Copy link
Member Author

emilio commented Jan 24, 2017

@heycam asked me to comment on this PR.

So the thing is that right now we try to reconstruct the style and device data lazily. This changes that so it's sychronous.

The background of this is that right now we might fail to flush the device on time. There are two ways to solve it.

  1. Flush the device and stylesheets before processing restyles. That works, but below is why I think it's not worth it.
  2. Do this sync flush when the device changes.

The reason why I want to go with (2), is because the RebuildAllStyleData call may/uses to require a restyle, so we need to have the style up-to-date anyway.

@emilio
Copy link
Member Author

emilio commented Jan 27, 2017

@bholley: I think we should still land this, I think @heycam is on PTO, so feel free to take the review.

@bholley
Copy link
Contributor

bholley commented Jan 28, 2017

I think we should redo this infrastructure per [1]. However, if you think this PR makes things more correct in the interim, I'm ok with landing it.

@bors-servo delegate+

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1334732

@bors-servo
Copy link
Contributor

✌️ @emilio can now approve this pull request

@emilio
Copy link
Member Author

emilio commented Jan 28, 2017

Yes, I believe this is the right thing to do in the meantime.

@bors-servo r=bholley

@bors-servo
Copy link
Contributor

📌 Commit d29fade has been approved by bholley

@highfive highfive assigned bholley and unassigned heycam Jan 28, 2017
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 28, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit d29fade with merge 227c576...

bors-servo pushed a commit that referenced this pull request Jan 28, 2017
Bug 1332969: stylo: Synchronously do a style update when the device changes

Ideally this would be lazy, but eventually we're going to need to restyle in
RebuildAllStyleData anyway, which would require us to have the style up to date,
so no need to complicate our lives.

r? @heycam or @upsuper or @bholley

<!-- 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/15157)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

💔 Test failed - windows-gnu-dev

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jan 28, 2017
@emilio
Copy link
Member Author

emilio commented Jan 28, 2017

@bors-servo retry

@bors-servo
Copy link
Contributor

⌛ Testing commit d29fade with merge 73bb759...

bors-servo pushed a commit that referenced this pull request Jan 28, 2017
Bug 1332969: stylo: Synchronously do a style update when the device changes

Ideally this would be lazy, but eventually we're going to need to restyle in
RebuildAllStyleData anyway, which would require us to have the style up to date,
so no need to complicate our lives.

r? @heycam or @upsuper or @bholley

<!-- 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/15157)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jan 28, 2017
@bors-servo
Copy link
Contributor

@bors-servo bors-servo merged commit d29fade into servo:master Jan 28, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants