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

eframe: Repaint immediately on RepaintAsap, fixes #903 #2280

Merged
merged 6 commits into from
Nov 13, 2022
Merged

eframe: Repaint immediately on RepaintAsap, fixes #903 #2280

merged 6 commits into from
Nov 13, 2022

Conversation

LoganDark
Copy link
Contributor

@LoganDark LoganDark commented Nov 11, 2022

Fixed #903

This completely eliminates the white flickering seen on Windows when rapidly resizing a window on the glow backend. The reason that happens is because DWM only waits for the resize event to be delivered before displaying the window at its new size. You must repaint synchronously inside that iteration of the event loop or else you get flickering.

Draft because there may be another reason why it was done this way; there was no comment explaining it so I am unsure.

This completely eliminates the white flickering seen on Windows when
rapidly resizing a window on the glow backend. The reason that happens
is because DWM only waits for the resize event to be delivered before
displaying the window at its new size. You must repaint synchronously
inside that iteration of the event loop or else you get flickering.
RepaintNext looks like it is indeed needed in at least one case instead
of RepaintAsap.
Starting to understand why this was the behavior. It looks like only a
few special cases should be given RepaintAsap, such as the window being
resized. All other cases should be RepaintNext, as it can wait.

Using RepaintAsap in all situations will cause things like lag when
changing a slider by keyboard with a high key repeat rate.
I am a total hypocrite for forgetting to add these.
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Interesting!

On my Mac I notice no difference. In particular, #903 is not solved.

But if this solves the white flickering on Windows, that's a big win!

crates/eframe/src/native/run.rs Outdated Show resolved Hide resolved
There is no notion of "possibility" here like there is when waiting for
RedrawEventsCleared. RepaintNow causes an immediate repaint no matter
what.
@LoganDark
Copy link
Contributor Author

On my Mac I notice no difference. In particular, #903 is not solved.

Interesting. I also happen to have a Mac - would you like me to look into the stretching effect there?

Just beware that that is likely a glutin / glow issue. For example, even with this PR, if you boot up the wgpu backend on Windows, it will still stretch and wobble horribly. This isn't due to eframe not handling events correctly, this is due to the graphics context itself.

But if this solves the white flickering on Windows, that's a big win!

It does, completely! To the point where resizing is perfectly smooth, take a look at this:

firefox_zePsCkA2X7.mp4

That is perfection. I did not know it was even possible to do that. But, somehow, eframe does it now, and it's amazing.

@LoganDark
Copy link
Contributor Author

LoganDark commented Nov 11, 2022

It looks like this patch works as intended (glow is now perfect on Windows, even though wgpu still looks like crap; at least it didn't get worse); marking as ready for review.

@LoganDark LoganDark marked this pull request as ready for review November 11, 2022 20:33
@LoganDark LoganDark requested review from emilk and Mingun and removed request for emilk and Mingun November 11, 2022 20:33
@LoganDark
Copy link
Contributor Author

LoganDark commented Nov 11, 2022

oh wait, I didn't realize that's what was going on. derp.

GitHub is so unintuitive sometimes.

Really sorry for the review request spam

"Delays" is ambiguous.
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Awesome - thanks!

@emilk emilk merged commit 5bac853 into emilk:master Nov 13, 2022
@LoganDark LoganDark deleted the resize-flickering branch November 13, 2022 19:36
emilk pushed a commit that referenced this pull request Dec 2, 2022
* eframe: Repaint immediately on RepaintAsap, fixes #903

This completely eliminates the white flickering seen on Windows when
rapidly resizing a window on the glow backend. The reason that happens
is because DWM only waits for the resize event to be delivered before
displaying the window at its new size. You must repaint synchronously
inside that iteration of the event loop or else you get flickering.

* Differentiate between RepaintAsap and RepaintNext

RepaintNext looks like it is indeed needed in at least one case instead
of RepaintAsap.

* Use RepaintNext in more situations

Starting to understand why this was the behavior. It looks like only a
few special cases should be given RepaintAsap, such as the window being
resized. All other cases should be RepaintNext, as it can wait.

Using RepaintAsap in all situations will cause things like lag when
changing a slider by keyboard with a high key repeat rate.

* Add explanatory comments

I am a total hypocrite for forgetting to add these.

* Rename RepaintAsap to RepaintNow

There is no notion of "possibility" here like there is when waiting for
RedrawEventsCleared. RepaintNow causes an immediate repaint no matter
what.

* Fix RepaintNow comment

"Delays" is ambiguous.
This was referenced Dec 12, 2022
JohannesProgrammiert pushed a commit to JohannesProgrammiert/egui that referenced this pull request Jan 21, 2023
* eframe: Repaint immediately on RepaintAsap, fixes emilk#903

This completely eliminates the white flickering seen on Windows when
rapidly resizing a window on the glow backend. The reason that happens
is because DWM only waits for the resize event to be delivered before
displaying the window at its new size. You must repaint synchronously
inside that iteration of the event loop or else you get flickering.

* Differentiate between RepaintAsap and RepaintNext

RepaintNext looks like it is indeed needed in at least one case instead
of RepaintAsap.

* Use RepaintNext in more situations

Starting to understand why this was the behavior. It looks like only a
few special cases should be given RepaintAsap, such as the window being
resized. All other cases should be RepaintNext, as it can wait.

Using RepaintAsap in all situations will cause things like lag when
changing a slider by keyboard with a high key repeat rate.

* Add explanatory comments

I am a total hypocrite for forgetting to add these.

* Rename RepaintAsap to RepaintNow

There is no notion of "possibility" here like there is when waiting for
RedrawEventsCleared. RepaintNow causes an immediate repaint no matter
what.

* Fix RepaintNow comment

"Delays" is ambiguous.
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.

UI jittering/flickering on fast window resize with glow
3 participants