|
-
Aug 12th, 2010, 04:08 AM
#29
Re: Layer rendering (image program)
 Originally Posted by NickThissen
As far as I understand it (I'm not absolutely sure about this), when you call Invalidate the region is indeed placed in some kind of queue, and the actual painting happens only when the Update method is called. This allows you to invalidate multiple regions or rectangles in a row, and only call Update when you invalidated all the regions that need to be painted.
At first I thought that therefore one must call Update in order to get a repaint at all, but that doesn't seem to be the case. With all the painting I have ever done, calling Update or not does not seem to make a difference. This suggests to me that the control calls its own Update method when at least one region of it is invalidated. This can't happen instantly (otherwise calling Invalidate multiple times and only then calling Update would be nonsense) so I think that the 'control' simply waits a short time, in which you can potentially call Invalidate a few more times with different regions, until calling Update.
If you are for example moving some shape across the PictureBox, as I am doing in my example project, then you can now Invalidate both the old and the new locations of the shape before calling Update. If Invalidate would immediately repaint the control then the paint code would be run twice (or many many more times in more complicated drawing scenarios), while it is much more efficient to just run it once and then redraw the invalidated regions in one go.
I think the best option is to always call Update after you have invalidated all regions, but I have never seen anything behave wrong or even strange when not calling Update.
Thanks for your explanation Nick. I assumed the "queue" concerned was being handled by the OS (along with non-Framework painting tasks) but on further reading it is clear that I was wrong: apparently the application has its own Invalidate queue, although there isn't an implicit Update involved.
According to the graphics guru Bob Powell, the Invalidate queue is cleared when the application is about to enter an idle state. If there are any invalid rectangles to be handled, the application issues a WM_Paint Message. (Refresh and Update, on the other hand, issue an immediate WM_Paint Message.) In either case, the sequel to the WM_Paint message is:
1. Calculate the union Region of all the Invalid rectangles (Regions are basically collections of rectangles).
2. Clear the Invalidate queue
3. Call the OnPaint Sub
4. MyBase.OnPaint raises the Paint Event
5. Call any event handler subs for the Paint Event.
I assume that whatever happens next is handled by the OS and the graphics hardware. I hope I'm getting towards the truth now, because understanding this seems essential for measuring and optimizing GDI+ graphics performance.
BB
Tags for this Thread
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
|