views:

227

answers:

2

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:

alt text

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.

+1  A: 

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.

Joey
Given that painting on windows is nicely bracketed between calls to BeginPaint, and EndPaint you would think that the DWM *could* know when its safe to grab an update.
Chris Becke
It would have to keep track of this. I suspect, performance considerations are put above possibly half-painted content.
Joey
+1  A: 

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.

DrPizza
You both pointed out the same thing: which probably makes it the correct answer. i paint directly to a buffer which is used for painting. If DWM grabs that buffer while i'm half-painted, i'll see half-painted content.
Ian Boyd