Skip to content

Allow updating DPI, viewport, and theme of a pre-existing Device#260

Merged
mrobinson merged 1 commit intoservo:mainfrom
mrobinson:allow-updating-device
Nov 5, 2025
Merged

Allow updating DPI, viewport, and theme of a pre-existing Device#260
mrobinson merged 1 commit intoservo:mainfrom
mrobinson:allow-updating-device

Conversation

@mrobinson
Copy link
Copy Markdown
Member

@mrobinson mrobinson commented Nov 5, 2025

This will allow Servo to update the Device and do media queries
without having to create a new one.

Copy link
Copy Markdown
Collaborator

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

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

I'm definitely in favour of the concept.

I have some questions around invalidation:

I know the set_device function automatically marks some things as dirty:

  • Is the intention of device_mut and these new functions to bypass that (because it's not needed for these use cases). Or is it required that the caller apply those invalidation manually when calling these functions.
  • If invalidation is required, should we make device_mut apply it automatically? and/or document correct usage of the function?

Finally: I wonder, would we be better off with a single device_mut function with setters on the Device?
(EDIT: I see these function are on Device and device_mut already exist)

@mrobinson
Copy link
Copy Markdown
Member Author

mrobinson commented Nov 5, 2025

  • Is the intention of these new functions to bypass that (because it's not needed for these use cases). Or is it required that the caller apply those invalidation manually when calling these functions

The intention isn't to bypass it, but delay it until the next layout. In the meantime, the device can be used for media queries which do not require the stylesheets to be dirtied.

  • If invalidation is required, should we make these function apply it automatically? and/or document correct usage of the function?

I'm not sure these function can apply it automatically, because the invalidation actually happens in the Stylist and not the the Device. In general the relationship between changing the Device (or replacing it) hasn't changed in the Stylo API. We are just doing it in a different place in Servo, so the semantics of this API don't really change. This is the invalidation in question: https://github.com/servo/servo/pull/40432/files#diff-49c9dea0cc9af0161b4681a4c4b1ed81f38f8190bd6854fd2ba6b3d74502b047R998

@nicoburns
Copy link
Copy Markdown
Collaborator

The intention isn't to bypass it, but delay it until the next layout. In the meantime, the device can be used for media queries which do not require the stylesheets to be dirtied.

I see. This makes sense.

I'm not sure these function can apply it automatically, because the invalidation actually happens in the Stylist and not the the Device.

I think we could do this in device_mut if we want to (we might need to return a "guard" that deref_mut's to the Device) and calls the invalidation functions on Drop. That wouldn't work with the delaying the invalidation though (and I agree it makes sense to delay it).

My suggestion would be to store the device_has_changed bit inside the Device itself. Then I think recalc_style could automatically apply the invalidations. That could be done as a follow-up though (if you agree it makes sense).

Copy link
Copy Markdown
Collaborator

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

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

Looks good.

I think it would be nice to document the need for:

let sheet_origins_affected_by_device_change = stylist
      .media_features_change_changed_style(&guards, self.device());
stylist
    .force_stylesheet_origins_dirty(sheet_origins_affected_by_device_change);

on the device_mut method.

This will allow Servo to update the `Device` and do media queries
without having to create a new one.

Signed-off-by: Martin Robinson <[email protected]>
@mrobinson mrobinson force-pushed the allow-updating-device branch from be63d50 to ef89ad1 Compare November 5, 2025 18:38
@mrobinson
Copy link
Copy Markdown
Member Author

let sheet_origins_affected_by_device_change = stylist
      .media_features_change_changed_style(&guards, self.device());
stylist
    .force_stylesheet_origins_dirty(sheet_origins_affected_by_device_change);

on the device_mut method.

Since device_mut is shared code, I've just put this documentation on the new setters. Hopefully that's okay.

@mrobinson mrobinson enabled auto-merge November 5, 2025 18:39
@mrobinson mrobinson added this pull request to the merge queue Nov 5, 2025
Merged via the queue into servo:main with commit a9f1997 Nov 5, 2025
5 checks passed
@mrobinson mrobinson deleted the allow-updating-device branch November 5, 2025 18:42
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Nov 5, 2025
Instead of waiting for a reflow to update the `Device` in layout, update
it eagerly. This ensures that media queries can be answered correctly in
script before the next reflow. Also, it ensure that a new reflow is
triggered and reflects the change to the theme or viewport.

In addition, an unused viewport-related message from the Constellation
is removed. This would have needed to be updated by change, but since
it's unused I've just removed it.

This depends on servo/stylo#260.

Testing: This fixes a WebView API test.
Fixes: #40395.
Fixes: #40129.

Signed-off-by: Martin Robinson <[email protected]>
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Nov 5, 2025
Instead of waiting for a reflow to update the `Device` in layout, update
it eagerly. This ensures that media queries can be answered correctly in
script before the next reflow. Also, it ensure that a new reflow is
triggered and reflects the change to the theme or viewport.

In addition, an unused viewport-related message from the Constellation
is removed. This would have needed to be updated by change, but since
it's unused I've just removed it.

This depends on servo/stylo#260.

Testing: This fixes a WebView API test and improves

`/html/semantics/embedded-content/the-img-element/environment-changes/viewport-change.html`.

Fixes: #40395.
Fixes: #40129.

Signed-off-by: Martin Robinson <[email protected]>
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.

2 participants