Is Double-buffering required with Desktop Composition enabled?
Is double-buffering still required when Desktop Composition is enabled?
In Microsoft's Application Compatibility Guide:
Graphical Device Interface (GDI)
Prior to Windows Vista and Windows Server 2008, a window handle (HWND) was painted directly to the screen,开发者_开发问答 which had certain benefits, but limited how Windows could display and manage top-level windows. In Windows Vista and Windows Server 2008, all top-level windows are rendered to an off-screen bitmap (similar to WS_EX_LAYERED), and the Desktop Window Manager combines the images together to draw the desktop.
It sounds like all rendering is now done to an off-screen bitmap:
windows are rendered to an off-screen bitmap
Is this correct?
The reason i ask is because i still see flickering during the standard paint cycle:
- WM_ERASEBKGND
- WM_PAINT
while desktop composition is enabled:
i would have assumed that between the calls to
BeginPaint(hWnd, paintStructure);
...
EndPaint(hWnd, paintStructure);
that all painting would happen to a back buffer:
windows are rendered to an off-screen bitmap
Meanwhile the a front buffer would stay unaffected.
Is this correct?
Yup (which is how the thumbnails can show you parts of the window that are currently obscured).
DWM's rendering of the screen is double-buffered. However, if it grabs your buffer betewen erasing and painting... it's going to show up as a visible artefact. So you still need to double buffer. The double buffering occurs on the desktop (i.e. it draws the next desktop view completely and then flips), not on the off-screen buffers that each window is drawn to.
Well, painting to an off-screen bitmap just enables the DWM to composite the windows as it likes to without having to wait for the application to redraw (as is the case in XP when you move windows over another, for example).
This does not mean that drawing to that off-screen surface automagically reduces flickering. If you erase the window and then redraw it and between both actions the DWM redraws the screen (which it does around 60 times per second), then of course you will see flickering.
It does solve the "white windows" problem when an application doesn't redraw fast enough and it also reduces redraw due to overlapping windows. But it doesn't help against flickering. The DWM has no way of knowing that your paint operation wasn't complete yet and that you wish to have the old image of the window displayed until after you have drawn the contents again.
This has changed in Windows 10 (1903, at least).
When DWM is enabled, everything is properly double-buffered now by default. There is no flicker on repaint/resize, even when moving and resizing controls in the most basic way.
The DWM now appears to only present a new bitmap once painting has finished, and not before.
精彩评论