microsoft / Windows.UI.Composition-Win32-Samples

Windows.UI.Composition Win32 Samples
MIT License
457 stars 186 forks source link

WGC CaptureFrame returns wrong SystemRelativeTime in window capture mode #127

Open artths opened 7 months ago

artths commented 7 months ago

Using the Desktop Duplication API, I can compare dirty rects with the coordinates of the window I'm interested in, and having the present time of the frame update, I know exactly when the frame in this window was updated.

When using WGC to capture the window I'm interested in, for some reason I get frame updates every time the DWM updates, why if I capture a single window? Well OK, let it be so, if only the frame time contained in the captured frame corresponded specifically to the update time of this window, and not DWM in general.

The documentation says:

SystemRelativeTime The QPC (Query Performance Counter) time at which the compositor rendered the frame.

If we capture only a specific window, then the refresh time of the frame should also refer to that window, not the other windows on desktop, right? I don't know if it's by design or if it's a bug, but there's no way to tell when exactly a new frame arrived so you might end up with a duplicate.

robmikh commented 7 months ago

Unfortunately, this was a limitation of WGC, especially on older versions of Windows. Recent Windows 11 builds should not have this behavior and should do a better job only updating when there are changes to the window. What version of Windows do you see this on?

artths commented 7 months ago

I had observed this in all versions of Windows, starting with the first version that supported it for classic applications Windows 10 1903 and ending with the current installed Windows 11 22H2. I haven't noticed any change in API behavior between all the intermediate releases. Now, when capturing a game locked at 30 FPS, API sends about 140 frames a second (floating) when on 144 Hz monitor. If it should improve, what could I be doing wrong?