-
Notifications
You must be signed in to change notification settings - Fork 306
Add external event notifications in transactions. #3020
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
Conversation
|
☔ The latest upstream changes (presumably #2989) made this pull request unmergeable. Please resolve the merge conflicts. |
webrender/src/resource_cache.rs
Outdated
| match update { | ||
| drain_filter( | ||
| updates, | ||
| |update: &mut ResourceUpdate| match *update { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't the update type inferred from the closure argument type? we shouldn't need to specify : &mut ResourceUpdate, unless you want it explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too, then I was battling some build errors and ended up putting that and thought it was what helped. Turns out this wasn't what fixed my trouble since it indeed compiles when I remove the argument type now.
webrender/src/util.rs
Outdated
| device_rect.round_out() | ||
| } | ||
|
|
||
| /// Run a first callback over all elements in the array. If the callback returns true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "the first callback"
webrender/src/util.rs
Outdated
| } | ||
|
|
||
| /// Run a first callback over all elements in the array. If the callback returns true, | ||
| /// The element is removed from the array and moved to a second callback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "the element"
webrender/src/util.rs
Outdated
| /// When that happens, code like: | ||
| /// | ||
| /// ``` | ||
| /// let filter = |&mut op| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have that in unit tests instead of (or in addition to) the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you can even write |&mut op| so checking these by the compiler would help ;)
webrender/src/util.rs
Outdated
| /// ``` | ||
| /// | ||
| /// See https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain_filter | ||
| pub fn drain_filter<T, F1, F2>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we rename F1 -> Filter and F2 -> Action?
| let mut i = 0; | ||
| while i != vec.len() { | ||
| if filter(&mut vec[i]) { | ||
| action(vec.remove(i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quadratic asymptotic complexity, or rather O(N*M) where M is the number of filter matches. Can we do better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can but should we? We'll get the the optimized version for free when the std implementation stabilizes and I am certain this will not show up in profiles.
To be honest it also rubs me the wrong way and I'd probably have made more of an effort if we weren't getting the better implementation through std eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, that's fine by me, assuming there is a limited array size on the input
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now the size of resource updates vector is 0 the vast majority of times, 3 while playing a video. occasionally 1 when loading an image, etc.
webrender_api/src/api.rs
Outdated
| self.merge(resources); | ||
| } | ||
|
|
||
| pub fn notify(&mut self, event: ExternalEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have some documentation here on what does this mean? When will the notification be fired, and why we need it.
e626c5f to
11db1a8
Compare
webrender_api/src/api.rs
Outdated
| // potentially long blob rasterization or scene build is ready to be rendered. | ||
| // sp that the tab-switching integration can react adequately when tab | ||
| // switching takes too long. For this use case what matters is that the | ||
| // notification doesn't fire before scene building. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not clear from the description if it fires after blob rasterization or after the scene building
webrender_api/src/api.rs
Outdated
|
|
||
| // Note: Gecko uses this to get notified when a transaction that contains | ||
| // potentially long blob rasterization or scene build is ready to be rendered. | ||
| // sp that the tab-switching integration can react adequately when tab |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"sp"
2034b12 to
2fa053c
Compare
webrender/src/render_backend.rs
Outdated
| } | ||
| drain_filter( | ||
| &mut notifications, | ||
| |n| { n.when() == CheckPoint::AfterFrameBuilding }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: CheckPoint should be a single word
webrender_api/src/api.rs
Outdated
|
|
||
| #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub enum CheckPoint { | ||
| AfterSceneBuilding, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe SceneBuilt and FrameBuilt?
|
☔ The latest upstream changes (presumably #3036) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@kvark are we good to go? |
|
@nical yes, if you are confident that a try push isn't needed here :) |
|
@bors-servo r=kvark |
|
📌 Commit 503be4a has been approved by |
Add external event notifications in transactions. This allows gecko to attach a callback to the transaction and run it after the scene is built to notify the tab switcher that the work is done. The first commit adds a drain_filter utility modeled after currently unstable Vec::drain_filter. The idea is to be able to get a vector of operations, and each stage of the pipeline can decide to move operations out of the the array and handle them or let them for the next stages to consume. Hopefully we can use this to merge back the frame_ops, scene_ops and the other vectors in the `Transaction` struct. This was previously inconvenient because of how some operations need to move elements out of the vector but while we need to keep the array alive at the same time, and drain_filter makes that less painful. This PR is based on top of #2989 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/3020) <!-- Reviewable:end -->
|
☀️ Test successful - status-appveyor, status-taskcluster |
This allows gecko to attach a callback to the transaction and run it after the scene is built to notify the tab switcher that the work is done.
The first commit adds a drain_filter utility modeled after currently unstable Vec::drain_filter. The idea is to be able to get a vector of operations, and each stage of the pipeline can decide to move operations out of the the array and handle them or let them for the next stages to consume.
Hopefully we can use this to merge back the frame_ops, scene_ops and the other vectors in the
Transactionstruct.This was previously inconvenient because of how some operations need to move elements out of the vector but while we need to keep the array alive at the same time, and drain_filter makes that less painful.
This PR is based on top of #2989
This change is