|
-
February 9th, 2011, 05:12 AM
#1
No repaint in Windows 7?
I'm using Windows 7.
I suddenly detected that I didn't have to repaint the content of a win32 window when it got obscured, neither by some other window nor when the window got outside the screen. I only had to repainted it when it got resized.
So in principle I only had to repaint on WM_SIZE, not on WM_PAINT. I seemed like Windows 7 kept the window updated anyway.
Then I had to reinstall Windows 7 (due to problems with Explorer probably caused by Parallel Nsight from nVidia). Afterwards this effect was gone. Now when the win32 window is obscured the content becomes messed up and I have to repaint from WM_PAINT.
Is there some setting which makes Windows 7 keep win32 windows automatically updated when obscured so applications don't have to repain them, or was it just a dream?
-
February 10th, 2011, 08:15 AM
#2
Re: No repaint in Windows 7?
No, the buzzword is "Desktop Composition". It is sort of a cache of window contents maintained by the OS to keep a better idea of what windows are doing and to improve performance. You should still do what you've always done, but just know that the OS is trying to lessen the number of repaints the actual application has to do. It will still send paint messages when it needs the window to repaint; it just does less of them if possible.
See: http://msdn.microsoft.com/en-us/libr...40(VS.85).aspx
-
February 10th, 2011, 08:51 AM
#3
Re: No repaint in Windows 7?
Even with Desktop Composition, you should still do all your painting in response to WM_PAINT messages and you should not do any painting anywhere else, for example in WM_SIZE.
-
February 10th, 2011, 01:26 PM
#4
Re: No repaint in Windows 7?
Thank you.
It looks like desktop composition is enabled by default on my computer but I notice one difference. Previously when I hovered the mouse pointer over the small application icons on the left side of the ribbon at the bottom of the screen, small thumbnail images of the applications were shown. I kind of liked that. Now much simpler information is displayed, just the application icon and the name.
Could this be an indication that deskop composition is disabled after all? I guess for the desktop manager to be able to display those thumbnail images also of obscured application windows it must keep the graphics content somewhere. And this would mean it shouldn't have to ask the application to repaint itself when it comes into view again. The desktop manager could do that.
Last edited by nuzzle; February 10th, 2011 at 01:34 PM.
-
February 10th, 2011, 02:19 PM
#5
Re: No repaint in Windows 7?
Dang!, I just found out.
After I reinstalled Windows 7 I thought the pitch black background I got by default looked more professional than the silly picture I had before. But this had the effect I described in my previous post. When I instead select an Aero background theme the small thumbnail application images are back again and the desktop definately has turned Aero.
The issue now is that if I respond to WM_PAINT and repaint my win32 window I get a visible performance degradation (it's a Direct3D window and this happens when there's a lot to render). This is completely unnecessary because if I don't repaint the Desktop Window Manager keeps the content updated anyway.
So in principle I need to repaint on WM_SIZE only (or rather on the first WM_PAINT immediately after a WM_SIZE). Otherwise, if desktop composition is on, I don't have to repaint on WM_PAINT. Will this approach work safely? I will need a way to check whether desktop compositions is enabled but that seems to be described here,
http://msdn.microsoft.com/en-us/libr...40(VS.85).aspx
Could you please advice me on how to handle this situation to utilize the DWM and desktop composition properly. I'm very new to win32 programming and don't want to do something stupid.
Last edited by nuzzle; February 10th, 2011 at 02:44 PM.
-
February 10th, 2011, 04:13 PM
#6
Re: No repaint in Windows 7?
 Originally Posted by nuzzle
The issue now is that if I respond to WM_PAINT and repaint my win32 window I get a visible performance degradation (it's a Direct3D window and this happens when there's a lot to render).
You may be able to use PAINTSTRUCT.rcPaint (which gets filled in by BeginPaint) to find out the specific area that needs to be painted. Then you may be able to save some processing by only re-drawing that section.
-
February 11th, 2011, 01:24 AM
#7
Re: No repaint in Windows 7?
 Originally Posted by Martin O
You may be able to use PAINTSTRUCT.rcPaint (which gets filled in by BeginPaint) to find out the specific area that needs to be painted. Then you may be able to save some processing by only re-drawing that section.
I've checked out PAINTSTRUCT and it tells me which part of the window has become dirty indeed. The problem is I'm rendering a 3D scene and it's quite impossible to know exactly which part of the 3D model ends up in the 2D surface indicated by PAINTSTRUCT.rcPaint. So the performance bottleneck is the 3D rendering itself. Whether I repaint the whole window or just the dirty part wouldn't improve anything much.
And the issue here is that the Desktop Window Manager will update the dirty window area anyway. It repaints the dirty rectangle using a clean copy of the window it keeps somewhere. That's the whole idea of desktop composition (I've learned in this thread).
My current solution is to set a flag on WM_SIZE. The only time I need to repaint in WM_PAINT is when this flag is set. Under all other circumstances the DWM keeps the window properly painted for me.
So to reformulate my question. How do I best avoid unnecessarily repeating the work of the DWM.
-
February 14th, 2011, 02:23 AM
#8
Re: No repaint in Windows 7?
I still haven't managed to solve this.
According to the documentation WM_PAINT shouldn't be sent to the application when desktop composition is enabled and the repainting is handled by the Desktop Window Manager.
But I get unnecessary WM_PAINTs and so does the Hilo Annotator Windows 7 application written by Microsoft.
I've explicitly enabled desktop composition like this,
hr = DwmEnableComposition(DWM_EC_ENABLECOMPOSITION);
and I've explicitly enabled support for Windows 7 by adding this in a manifest,
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
This doesn't change anything and I've simply run out of ideas for things to try so if someone has a suggestion I'll be very happy.
Maybe this is all in vain and the correct behaviour is what I'm experiencing. My "fix" is working fine so this is no big deal really but I would like to know. Should or shouldn't an application be getting these unnecessary WM_PAINT messages when desktop composition is enabled?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|