I'm using python v 3.8.9 with windows 7 and grabbing portions of the screen using the mss module.
I'm attempting to capture output of a program that updates with the monitor vertical sync at ~60 FPS. Knowing the relative time (to around 1ms) of the capture with respect to the vsync is also import.
Using a high resolution timer to wait until a time of 1/FPS would have an unknown time, possibly constant, relative to the vsync.
I've made use of DwmFlush from dwmapi.dll, however it requires "desktop composition" to be enabled. When this is enabled, without waiting for the vsync, the frame rate of grabbing drops to 30 fps (from over 500 fps).
How might I determine if a new vsync has occurred?
Might it be possible to cause a screen update to block until vsync using a library such as pygame, opengl, open cv, etc.?
As the frame grab is fast, one solution would be to poll the screen by grabbing and look for a difference the grabbed images, however, I'd prefer a more elegant solution if available.
Ultimately, this wait for vsync could be a feature that is built into mss.
An example that uses glfw to wait for the vsync. This solution requires a glfw context window to be created, which can be hidden. As written it works only on the primary monitor.
Using another monitor has seems to require a system delay as the target monitor enters a full-screen mode. The full-screen mode can then be exited. In set_window_monitor when the monitor is none, the refresh rate isn't used.
glfw doc for create window
glfw doc for set window monitor