Fix: [Win32] now we are drawing on a tick, no longer use WM_PAINT #8702
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
With the 60fps patch, mouse movements should be silky smooth on Windows too. It was not. It turns out it is because I assumed
WM_PAINT
worked slightly different than it does.Description
In the old days, are drawing was driven by
WM_PAINT
, when ever Windows decided it was a good time to redraw the screen. This is based on when we sendInvalidateRect
to the window. This is a good system if you don't care about fps and just want to redraw when ever is best for the OS.With the 60fps patch, we do care when we redraw. So depending on
WM_PAINT
gives a "lagging" effect, especially noticeable with mouse movements. When ever you move your mouse, we register it, tell Windows to redraw the window, which happens .. some time later. So you get this feeling you mouse is never where it should be.So, instead, what is perfectly normal for games to do, is to drive the drawing yourself. As we already have a draw-tick, we can do this perfectly fine.
It does mean we can no longer depend on
InvalidateRect
, asGetUpdateRect
does not return the same value you just set withInvalidateRect
without yielding. Shocker, I know. So, instead, the Win32 video driver is now a lot more like all other drivers, and records its own dirty-rect, and redraws that screen.WM_PAINT
is still used if outside influences trigger anGetUpdateRect
, to indicate an overlapping window moved etc. We will redraw that surface once it has done.In a result, we will be redrawing more and too much in more cases (especially when the window is being overlapped by another). This is a consequence of wanting to hit 60fps :)
Result: silky smooth mouse movement on Windows too!
Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.