Under the Hood of the Desktop Window Manager

I've made a grand total of one post in about the last 21 months.  What have I been doing during this time?  Why, working on the new Desktop Window Manager for Windows Vista, of course!  The Desktop Window Manager (DWM) is one of the more visible features and changes to Windows coming out with the upcoming Windows Vista release.

Does this mean that I've abandoned Windows Presentation Foundation (Avalon) to work on the DWM?  By no means.  The DWM is built upon the core graphics layer of Avalon, and is being developed by the same team responsible for Avalon. 

We've been heads down on design, development, and testing for quite some time, but now that there's an end in sight, I figured I'd come up for air and describe a bit about what we've done and the technical underpinnings of this visible feature.  There's lots and lots that can potentially be discussed, so I'm going to keep this first post fairly broad and high level, and will be interested in feedback if there are other specific areas of interest that readers would like to delve further into.  So please do comment with your thoughts!

The public face of the Desktop Window Manager

The DWM is of course just part of Windows Vista and not considered distinct from it.  Its features are exclusively available in the Windows Vista Aero experience.  I'm pulling out some of the more recognizable features here.

This is "Aero Glass", the semi-transparent look that Aero provides, with the blurry content behind the window frames, designed to allow the user to focus on the window itself, and not on what lies behind.


Here are the live thumbnail views provided on the Windows Vista taskbar.


And here are Windows Flip and Windows Flip3D -- the updated Windows Vista experiences invoked by Alt-Tab and Windows-Tab, respectively, for navigating between and selecting windows.


Desktop Composition

By far the largest change to Windows Vista in the way that windows are presented is the introduction of "desktop composition".  This underlies everything that is done by the DWM.  The primary takeaway for desktop composition:  the way an application gets pixels on the screen has fundamentally changed

In all versions of Windows, up until Windows XP, applications were asked by Windows to paint their visible region, and they would paint directly to the buffer that was to be displayed by the video card.  With Windows Vista, applications are asked by Windows to paint their entire surface to an offscreen surface (alternatively known as a bitmap, buffer, or texture), and it's up to the DWM to take all of these offscreen surfaces, and "compose" them together to the onscreen buffer.

Read the previous paragraph again.  From a windowing system display perspective, this has profound implications in terms of the features that can be implemented, and the quality that can be achieved.  Some examples:

  • Access to windows - now that applications are rendered offscreen, those offscreen representations can be used in other places.  This is precisely how the Flip, Flip3D, and thumbnail features work, and other features can be built that take advantage of this as well.

  • Don't involve background applications in window operations - when a window moves across the screen in XP and before, the portions of background windows that are newly visible only get painted when the background application wakes up and starts painting (in response to WM_PAINT messages it receives when the top window is moving).  For non-responsive background applications, or even responsive ones that happen to be paged out, this can yield a very poor user experience. 

    Consider moving an 'Paint' program window over an IE window.  On XP and before, the following symptoms are unfortunately all too common:


    In both of these cases, the underlying Internet Explorer application was unable to repaint itself quick enough to avoid the "trails" that the moving Paint window left behind. 

    Under Windows Vista, this simply isn't the case -- underlying windows do not receive WM_PAINTs and are not asked to re-render, since their content is already available to the DWM and is used to composite the screen.

  • Tear free experience - given that the DWM orchestrates all rendering to the screen, the latest technologies provided by DirectX that are typically used for games can be used for the overall desktop experience.  In particular, graphics cards' ability to "flip" the front buffer results in an absolutely tear free experience as windows are moved around the screen, increasing the smoothness and quality of the user experience.

  • High resolution support - the majority of applications out there are agnostic of the monitor resolution (DPI) that they're running at.  On the increasingly popular higher resolution monitors (120 DPI, 144 DPI, and beyond), this can produce a bad experience where applications appear very small in physical space.  Because the DWM has access to offscreen representation of the application window, the DWM is in a unique position to scale such DPI-unaware applications for their final presentation to the user, making for a much improved experience on the higher resolution monitor.

Possible Future Topics

Desktop composition is the most fundamental aspect of what the DWM provides, but we've really only scratched the surface of that topic, and there are still a lot of related topics to explore for a full understanding of what we're doing in Windows Vista.  Here's a rough cut of likely topics, roughly in the order I'd expect to tackle them.

  • DWMs use of DirectX, GPUs, and hardware acceleration
  • The importance and impact of the Windows Vista Display Driver Model to the DWM
  • Redirecting GDI and DirectX applications
  • How underlying WPF concepts and technology are being used
  • How the DWM paints the window frame and other non-client area
  • Remoting, Magnification, and Accessibility under the DWM
  • High DPI support
  • Publicly exposed DWM APIs
  • Rendering and visibility optimizations
  • Memory usage in the DWM

Again, please do comment with your interests and where you'd like this conversation to go.  No promises of course that we'll even get to any of them... but I do expect to.

While this is probably the most technically comprehensive discussion thus far of the DWM out on the web (though I'm certainly happy to be proven wrong), there are definitely other places with great sources of information and news: 

  • My ever-esteemed colleague Kam VedBrat maintains a blog that often gives a great inside perspective about the DWM, specific DWM features, and Windows Vista Aero. 
  • The microsoft.public.windows.developer.winfx.aero newsgroup carries discussion of all things Aero