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.


Other DWM-related Sources of Information


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

Comments (74)

  1. Anonymous says:

    I’d like to know why DWM can’t just use the alpha channel of the buffer that Avalon draws to, to be able to do completely hardware accelerated irregular shaped and alpha blended windows, but instead has to drop Avalon HW acceleration and go to software rendering…

  2. Konstantin Gonikman says:

    Great to see you again Greg. That’s very-very-very cool stuff, I’m just waiting to see more low-level details (particularly regarding the use of DWM in custom apps).

    Welcome back!

  3. Stephane Rodriguez says:

    "Tear free experience"

    How is this possible? Doesn’t this depend on how much is getting drawn?

    Two decades ago, on machines like Atari ST and Amiga, it was all about the vertical blank. People used to write applications (demo) that would draw based on the vertical blank frequency, avoid the drawing spot, resulting in smooth scrollers and so on. Whatever happened to this?

    In other words, I don’t think the tear experience scales well if you drawing too much on the screen at the same time, say you are running a couple videos concurrently.

    And I still fail to see how tear-free experience will make mom and dad feel excited about Windows Vista. Sorry, it had to be said.

  4. JoeW says:

    Thanks Greg

    I would like to know more about the public APIs.  Specifically I would like to know how Vista’s native dialog boxes are rendered (message box, explorer windows etc).  Do they still use GDI or do they use an unmanaged composition engine?

  5. jfo's coding says:

    Greg shows of what he’s been working on for the last 21 months. 

    It’s worth a read, as he points…

  6. Found this via Jessica Fosler’s blog. I’m subscribed. Hope to see more great posts like this. DWM is very exciting and I’m glad to see Windows painting working the way it always should have.

  7. Rob Relyea says:

    Greg Schechter rejoins us after a lengthy blogging pause to fill us in on profound changes in how Windows…

  8. David Larsson says:

    I have been playing around with the High DPI-mode in the latest Vista CTP, mainly to see what compatibility problems (if any) we will have with a medical record viewing application that I help building. And boy, do we have problems.

    Can we expect this feature to improve significantly during the beta cycle? I’m not sure this bitmap scaling for non-DPI-aware applications work – all text becomes very blurry and really isn’t much easier on the eyes. Then there are problems with popup windows, like menus and semi transparent "tooltips" that we use, appearing in the wrong location or not at all. (It’s an ATL/WTL application.)

    Well, it is otherwise an impressive improvement to Windows and I look forward to reading more about the DWM!

  9. Keith Hill says:

    Thanks for shedding light on this topic.  Regarding your future topics, please bring ’em on and the quicker, the better.  🙂

  10. Mat says:

    Can’t wait you to blog about all listed topics!

  11. David says:

    I think I’m understanding that each window’s content is stored in memory so that they do not receive WM_PAINT messages when a window moves over them and then reveals part of the background window.

    My question is how do you handle the memory requirements for that as it could potential eat a lot of memory?

  12. Shawn Oster says:

    As I’m reading a few dozen questions come to mind.  You hit on some of them in your "upcoming topics" hit list but here are the things that sparked:

    1. How signifigant will hardware acceleration be to Glass?  It used to be there was the 2D benchmarks for work apps then the 3D benchmark for the fun things.  An amazing game card would often be horrible at having a lot of small Excel/Word/Visual Studio windows open.

    2. One of the first things new developers learn is to do their own screen buffering, to a bitmap, metafile, etc.  Does the DWM change that since it’s already buffering?

    3. What kind of impact will this have on apps like Photoshop?  Are there things raster image editing programs can do to improve speed if they are running on Vista?

    4. If you are running old hardward does everything still go through the DWM?  Like inside a Virtual PC?

    5. How much control will we have over DWM?  For example could someone create Flip/Flip3D as a stand-alone app?  The nerdling fun side of my brain imagines interfaces a la Minority Report (minus the gloves and Tom Cruise).

    6. Hmm, speaking of the Minority Report UI, how well will video drag?

    7. How heavy a load does DWM put on the system?  I remember when shell replacements were big (LiteStep, geoShell, Cloud9, etc) and the goal was always reducing load while giving UI goodness.  Sounds like DWM could be that as long as it isn’t seen as a boat anchor.

    Looking forward to more blog posts on this subject.  Try to come up for air just a wee bit more often 🙂

  13. DCMonkey says:

    Will and how will the DWM affect windows redrawing while resizing? I’ve noticed some apps in the Feb CTP (Event Viewer comes to mind) that redraw rather chaotically when resizing. I guess I was expecting a more Mac OS X like experience, where the window contents are redrawn cleanly and completely even if this causes the size of the window to lag somewhat behind the mouse movements. Both methods have their downsides but the later gives a more solid feel to the applications IMHO.

    Any insights?

  14. Kirill Osenkov says:

    Great news, sounds very promising.

    What impact does it have on existing applications? My existing Win32 application uses a custom double-buffer to create a flicker-free experience.

    Does it mean I should get rid of my (now unnecessary) custom back buffer when I port my app to Vista? Does it also mean that all flickering applications will automatically become flicker-free?

  15. HTK says:

    Hi Greg, the first screenshot, with the bigger caption buttons, is this a real screenshot or something done with photoshop? If this is a real screenshot it shows how great vista will scale to higher dpi monitors!

  16. HTK says:

    Another thing related to what I stated first, but on the polar opposite:

    The same way one can have the system render itself proportionally bigger, the opposite seems technically feasable, to make everything smaller resulting in virtually more desktop space, at least to some extent, before text becomes unreadable.

    What do you think Greg?

  17. Kam VedBrat says:

    Greg Schechter is one of the Architects on the Avalon team who’s focus for the last year or so has been…

  18. Дельное объяснение без понтов и лишней зауми.

  19. Chris Nahr says:

    That sounds fantastic! Does the automatic window buffering mean we could get rid of the traditional WM_PAINT event processing altogether, and just draw new elements immediately as required?

    Also, what happens when a window is scaled to a higher resolution? Will OpenType text be recognized as such, and appropriately re-rendered at a greater point size?

  20. ion says:

    Is it possible to enable anti-aliasing on DWM to prevent the jagged edges on skin and in Flip3D?

  21. Eli says:

    Look forward to hearing about it. =)

    I have a couple of questions. How do the glass blurring effects work? Pixel shaders? And, does the DWM use the 3D hardware to accelerate non-WPF, old GDI drawing commands?

  22. Anonymous says:

    I would love to hear more details about how you are doing your text rendering now that you are going through the DWM all the time.

  23. Ian Ringrose says:

    Witch versions of Windows Vista will include this?  E.g. is it in the OEM version that will ship with ALL new PCs?

    As an application writer what should I do differently, e.g. given that the OS is doing "double buffering", should I detect that I am on Vista and do my redrawing in a different way?

  24. ping pong says:

    Is DWM written in managed language?

  25. Mike Dimmick says:

    Can you do anything about the fact that launching any Java app or applet with Sun’s JRE 1.5.0_06 causes the DWM to switch off?

    I’m guessing that Sun are using DirectDraw with a locked primary surface to do their rendering. A communication from David Blythe indicated that this would disable the DWM.

  26. DGC says:

    I’m interested in the memory usage of the DWM. If every window is rendered offscreen, isn’t it the case that in some extreme situations some of these offscreen surfaces may be either paged down to disk or re-rendered continuously affecting the whole system performance?

    Also, does the desktop composition process try to fix potential aliasing issues? I have noticed a quite annoying border aliasing on some of the Flick3D screenshots.

  27. Good work.  You definetely get people excited about the new interfaces.  I really am hoping it opens the door to UI development that might otherwise be outside of the box 😉

    Rawk on… and keep posting eye candy for us.

  28. KJK::Hyperion says:

    Ok, cool, but is it programmable from a third party application? in other words: how can I totally abuse this wonderful technology?

  29. Malheureusement en anglais, mais très intéressant, cet article vous expliquera le fonctionnement du Windows…

  30. Look like a familiar problem?  Want to know what we’re doing about in Windows Vista? 

    Greg…

  31. kiwi says:

    I do not like the transparency effect. The first thing I do is turn it off (thanks for providing the option BTW!).

    I think it’s very cool (the transparency effect) the first 10 minutes, but then it becomes annoying… It’s just confusing to see the graphics behind a window, especially from colored webpages. So, can’t MS graphical designers come with a different, less "poor", wow-effect for Vista? One that would be usable for ever, not just 10 minutes? Come on, I know you guys can do it 🙂

  32. bob says:

    second the request for info on anti-aliasing. The 3d flip is cool, but I can’t take jaggies any more…

    Also second the request for info on memory usage- should I buy a 512meg (1gig?) graphics card in the future, etc?

  33. First forgive me since I haven’t installed a beta copy of Vista yet (I have 5308 but haven’t decided to install or wait for consumer beta release) and some of this post may be answered if I had.

    This is really interesting to me and the off-screen approach makes total sense.  That said, what types of effects from DX10 will also make their way into the DWM?  A simple example from MAC is the way windows minimize and maximize.  Will the DWM take any advantage of particle affects or other fun UI?  Will this be left up to the community to build and not really be done by Gold Master time frame by MS?  Kinda the way things went with windowblinds etc…

    I worked for AOL over the last few years and we had a presentation 2 years ago on a concept of what a Vista AOL client may look and act like done by MS.  This showed seamless movements between browsing a picture on the web and dragging it into another app across the screen.  It also showed how the desktop can be utilized as a personal clip board with images from the web dragged seamlessly as well as text and special affects to make everything "alive" (move, pulse, etc…).  Do these things exist or will they in the coming consumer beta?

  34. GRiNSER says:

    why is there just flip3d and nothing equally functional like expose in mac os x where you can drag and drop from one to another window while seeing all windows at once? flip3d is, in my opinion, more like a toy than a useful thing, because tabbing or scrolling through the whole open windows is much more time consuming than having all windows in a small preview at once on the whole screen.

  35. Andy says:

    Shawn wrote:

    "4. If you are running old hardward does everything still go through the DWM?  Like inside a Virtual PC?"

    I got the impression from the post that DWM will only be used with the new Aero Glass interface. Therefore, if you’re running on older hardware, you can switch back to the XP look, and use the traditional window manager.

  36. Keith Patrick says:

    I’m curious to hear the relationship between DWM and WPF.  I’ve read on the Avalon newsgroup that Explorer (and thus DWM) is not using WPF, and that WPF isn’t even installed by default with Vista.  That leads me to think that there’s a great deal of duplicate code in both technologies, and I worry about a divergence of functionality along the lines of Office’s UI widgets and commctrl32.dll.  If this really is the case, do the two technologies eventually converge, with everything built to WPF?

  37. MueMeister says:

    Hey Greg,

    thanks for the post but what about the important topic: "How underlying WPF concepts and technology are being used"? I always read that DWM uses wpf tech? Please post about that issue it is important to know!!!

    chris

  38. I read and participate in newsgroups (and blogs) regularly.  This entry is derived from a recent long post of mine in response to some very passionate newsgroup posts by some folks using the latest Windows Vista CTP

    The are a number of very positive

  39. Greg Schechter says:

    Lots of great comments coming in.  Rather than responding to them with more comments, I added a new post to do that.

  40. deebs says:

    That is one very, very neatly constructed aero objects.  It is awesome!

  41. mahalax says:

    Very interesting and informative conversation. Thanks Greg…

  42. For the last few years, both desktop and laptop PCs have been outfitted with increasingly powerful graphics…

  43. Olivier Le Pichon says:

    Composition Engine remebere me of Microsoft Talisman project. May be a connexion?

  44. Kam VedBrat says:

    Charlie Owen on the Windows Media Center team has been posting quite a bit lately on Windows Vista. He’s…

  45. Here’s a list of topics that I have posted on (with active links) or expect to post on (without links)…

  46. Kam VedBrat says:

    I came across Sean’s blog while figuring out how to register with Technocrati… He recently got around…

  47. When talking about WPF during the Windows Vista ISV Touchdown training a lot of people were interested…

  48. A good amount of ink has been spilled on this blog talking about all the

    cost, nuance, impact, and…

  49. Today I’d like to share the fearful tale about a Vista upgrade gone horribly wrong.  Base on a true…

  50. When talking about WPF during the Windows Vista ISV Touchdown training a lot of people were interested