I am currently working on a win form application user interface. The main window is a borderless form whose surface area is almost completely displayed in the Form.Paint event. A reverse buffer is created and executed conditionally:
private void form_Paint(object sender, PaintEventArgs e) {
e.Graphics.DrawImage(BackBuffer, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
}
Some areas of the back buffer are redrawn under various conditions; Mouse effects are fairly common. The class that performs the redrawing invalidates only the applicable areas. Despite this, simply scrolling the mouse in all its shape is enough to crank the high-performance processor to> 50% use in a few seconds.
I have profiled the application, and more than 80% of the processor time is burned when calling DrawImage above. I knew that GDI + is slow and not using (little?) GPU usage ... and the target platform for the application does not guarantee that the GPU will not be integrated in the first place. But I had no idea that it was bad.
Should I be faced with the fact that GDI + is simply not fast enough for what we want to do, or is there an opportunity to improve the code?
-edit -
BackBuffer is a bitmap that is created during system startup. Its size corresponds to the screen resolution. Different areas are drawn on it during various events, such as mouse add-ons and clicks. It is created quite simply:
this.BufferBmp = new Bitmap(screenWidth, screenHeight);
this.Gfx = Graphics.FromImage(BufferBmp);
Gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
Kivin