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

Revisit the druid <-> druid-shell animation and invalidation interface. #1057

Merged
merged 7 commits into from
Aug 21, 2020
Merged

Revisit the druid <-> druid-shell animation and invalidation interface. #1057

merged 7 commits into from
Aug 21, 2020

Conversation

jneem
Copy link
Collaborator

@jneem jneem commented Jun 24, 2020

This implements (only for GTK so far) the invalidation scheme discussed on zulip, with a few small differences. I'm posting it in the hope of getting a little feedback before I dig into the other backends. (I went with GTK first because I think it'll be the hardest one, because there's a mismatch between what we want to do and what GTK wants us to do.)

The main issue with the current setup is that animation frames are propagated in the paint callback. This means that they can't invalidate any regions, which in turn means that when druid requests an animation frame, it has to invalidate the whole window just to be sure. So this patch introduces a two-phase paint protocol: first, druid-shell calls prepare_paint, which is allowed to invalidate whatever regions that it wants. Immediately after that, druid-shell calls paint and provides an invalidation region that must be filled. In the discussion on zulip, I proposed having prepare_paint return the region that it wants to be invalidated, but in fact it was simpler to just ask prepare_paint to use the existing invalidation methods.

Note that this is a breaking change, in that widgets that previously relied on request_anim_frame doing the invalidation will now need to do their own.

Here's a little gif showing (with debug_invalidation enabled) a scroll bar that doesn't repaint the whole window when it fades out.
scroll

Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

Generally this looks good to me, thanks. I skimmed it, and didn't go into details of, for example, the Region impl. The use of "viewWillDraw" on mac looks right to me, a detail I hadn't personally explored. I'd be happy merging a more polished version of this (CI looks like it's failing a bit).

@@ -127,6 +129,15 @@ pub(crate) fn recti_to_rect(rect: RECT) -> Rect {
)
}

/// Converts a `Region` into a vec of winapi `RECT`, with a scaling applied.
pub(crate) fn region_to_rectis(region: &Region, scale: Scale) -> Vec<RECT> {
Copy link
Contributor

Choose a reason for hiding this comment

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

"rectis" seems an odd name.

Copy link
Collaborator Author

@jneem jneem Jul 19, 2020

Choose a reason for hiding this comment

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

I'm not in love with it either, but I copied it from rect_to_recti...

@jneem jneem marked this pull request as ready for review July 21, 2020 03:04
@jneem
Copy link
Collaborator Author

jneem commented Jul 25, 2020

I think this is ready for another look. I've tested it on all platforms but mac, and I've been dogfooding it for a couple of weeks in my own druid project.

@luleyleo luleyleo added the S-needs-review waits for review label Jul 25, 2020
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

I tried this on macOS and it seems to work. I also took another quick pass through the code and didn't find any issue. I think it should be merged. Thanks for the work!

It looks like there are some merge conflicts on Linux, but hopefully not too bad. Do you mind fixing?

This will probably have merge conflicts with other work in flight; I'm particularly concerned about #1037, and I also strongly expect it to conflict with my simpler_d2d branch. In the latter case, I'm happy for this to go in first.

@jneem
Copy link
Collaborator Author

jneem commented Aug 21, 2020

I checked the conflict with #1037: merging this PR into #1037 results in just two conflicts. There's a trivial one in druid/src/lib.rs and one 8ish-line conflict in druid-shell/src/platform/window.rs. Anyway, much less than I expected, and so if I don't hear otherwise then I'll try to get this one in first.

@jneem jneem merged commit 495f9a9 into linebender:master Aug 21, 2020
luleyleo pushed a commit that referenced this pull request Aug 22, 2020
On GTK we need to create an initial Cairo surface, even if there's no resize.
ForLoveOfCats added a commit to ForLoveOfCats/druid that referenced this pull request Aug 27, 2020
ForLoveOfCats added a commit to ForLoveOfCats/druid that referenced this pull request Aug 27, 2020
ForLoveOfCats added a commit that referenced this pull request Sep 6, 2020
* Naive first step to refactor out scroll logic into separate component

* Move a bunch of event logic to `scroll_component` from `Scroll`

* Add method to coordinate painting with `scroll_component`

* Move a bunch of lifecycle logic to `scroll_component` from `Scroll`

* Documentation pass on `scroll_component`

* Rename `Scroll` to `AbsoluteScroll` & add scroll functionality to `List`

* Add ability to change layout axis for `List` with builder fn

* Scroll behavior component changelog

* Pass `BarHoveredState` by value and add impl Default for ScrollComponent

* `ScrollComponent` review changes

* Add some missing information to `ScrollComponent` documentation

* `ScrollContainer` review take 2

* Changes from #1057

* ScrollComponent clippy

* Remove List changes (updated to master) & fix Scroll regression

* Add missing doc comments

* Be a bit more careful about event consuming

* Fix dup changelog entry & doc comment misspelling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-review waits for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants