MapWindow Developer Team : MapWindow Discussion Forum
Hi, I'm reworking ocx drawing procedure now, and there is some problem with speed. I'm drawing polygon layer with ~40000 objects form RAM through GDI+ and the major slowdown is drawing of lines. Here is timing: ------Starting timer------- After reading data: 0.1
How to make GDI+ draw faster?
Posted by: Sergei ()
Date: May 14, 2010 01:26PM

Hi,

I'm reworking ocx drawing procedure now, and there is some problem with speed. I'm drawing polygon layer with ~40000 objects form RAM through GDI+ and the major slowdown is drawing of lines. Here is timing:

------Starting timer-------
After reading data: 0.187 sec
After drawing fill: 0.266 sec
After drawing lines: 1.156 sec

So without lines it works fast. But lines spoil everything.

I use GraphicsPath for both polygon and line drawing. For drawing of lines only these 2 lines are used:
Pen pen(Gdiplus::Color::Black);
graphics->DrawPath(&pen, path);

Before drawing I set everything to provide speed:
graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);
graphics.SetSmoothingMode(SmoothingModeNone);
graphics.SetPixelOffsetMode(PixelOffsetModeNone);
graphics.SetCompositingQuality(CompositingQualityHighSpeed);
graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel);

Most likely I'm doing something wrong but can't spot it. Perhaps some drawing options I don't know about? Any other ideas?

See screenshot in the attachment.

Thanks,
Sergei

Attachments: screenshot.png (63.7 KB)  
Re: How to make GDI+ draw faster?
Posted by: Sergei ()
Date: May 14, 2010 03:54PM

Well, I've passed line drawing to GDI and it became 'a bit' faster ;)

------Starting timer-------
After reading data: 0.172 sec
After drawing fill: 0.281 sec
After drawing lines: 0.328 sec

It appears that it's to early to sweep aside GDI. And for me there is a nice perspective of inventing a bicycle when drawing comlpex line patterns with GDI ;)

Any clues on speeding line drawing in GDI+ are still much appreciated!

Re: How to make GDI+ draw faster?
Posted by: pmeems ()
Date: May 17, 2010 02:32AM

I'm not an expert with GDI but I read stuff about OpenGL.
Don't know if it is related, but might that be a good approach?

I also found these links that might be helpful:
#1515: Add support for Direct2D to replace GDI if possible.
Drawing Dashed Lines and Curves
Comparing Direct2D and GDI
OpenGL - From Wikipedia, the free encyclopedia
Simple DirectMedia Layer - SDL

Quote

In comparison to GDI+ and DirectDraw; DirectDraw is faster, way faster.

OpenGL in general is faster then DirectX, but only when using a language that has direct access to it (ie; C/C++). DirectX is more used for games though because it has more support and is pretty much guaranteed to run on any system with Windows installed on it. OpenGL is typically used for games that need to be multi-platform.

Hope it helps,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Re: How to make GDI+ draw faster?
Posted by: Sergei ()
Date: May 17, 2010 03:46AM

Thanks for links!

I read about other technologies as well.

Direct2D isn't supported on Windows XP if I understand it right: [social.msdn.microsoft.com] [connect.microsoft.com]
So it's impossible to use as a single API for ocx when XP is still widely used.

Perhaps I'll give a try to OpenGL, if Igor provide some guidance.

But still implementing GDI+ is the fastest way, as I can borrow a lot of code from MW6. For now I continue implementation with drawing of fill through GDI+ and lines through GDI. But there will be problems, as I don't know how to set alpha blending for lines in GDI. Using GDI+ means it'll be slow.

Thanks,
Sergei

Re: How to make GDI+ draw faster?
Posted by: bmarch ()
Date: May 17, 2010 10:20AM

Hey Sergei,

Ted spent a lot of time optimizing drawing from GDI+ in MW6, it took a lot of work.

One big improvement that we came across was to merge all line paths into a single path before passing them into GDI+ instead of using a loop and calling draw on each individual line path.

Maybe you will see a similar improvement.

Brian

Re: How to make GDI+ draw faster?
Posted by: Sergei ()
Date: May 17, 2010 10:57AM

Brian,

thanks for reply. I examined MW6 code for drawing and actually already use Graphics path for all shapes. But somehow it takes about 0.1 sec to draw polygon fill and about 1.0 sec to draw lines for the same path. I examined old implementaion of GDI+ drawing in ocx (Graphics.DrawPolygon) and found the same story there: drawing of lines is very slow in comparison to fill. I'm really curious why is it so and is it possible to speed it up ;)

Re: How to make GDI+ draw faster?
Posted by: Sergei ()
Date: May 24, 2010 07:22AM

Just characteristic results for point layer with USA cities. Points were drawn as pentagons.

drawing outlines and fill with GDI: 0.016 sec 
drawing fill only with GDI+: 0.032 sec
drawing lines only with GDI+: 0.141 sec
drawing lines and fill with GDI+: 0.187 sec

GDI+ is very slow after all :(



Edited 1 time(s). Last edit at 05/24/2010 07:31AM by Sergei.

Attachments: cities.png (14.6 KB)  
Re: How to make GDI+ draw faster?
Posted by: pmeems ()
Date: May 25, 2010 03:06AM

Sergei,

Any progress on looking into OpenGL?
Is it useful or not?
Just found a new article about OpenGL: [www.codeproject.com]

--
Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Re: How to make GDI+ draw faster?
Posted by: Sergei ()
Date: May 25, 2010 11:02AM

Paul,

Igor kindly provided me some good examples and I'll to try to implement it. But I doubt that it'll be easy (if possible at all) to implement the whole list of featutes we have in GDI/GDI+. This library isn't designed specifically for 2D and GIS software typically not use it for 2D drawing (provide me some links if I'm wrong here). So I'd prefer to make a basic implemntation of GDI/GDI+ (as it's easy and obvious) and try to implement some features in OpenGL a bit later.

To deal with speed issues I plan several modes of drawing:
- pure GDI (fast, but scarce i functionality);
- pure GDI+ (fuctional but slow);
- mixed mode (fill with GDI+ and lines with GDI; the best combination I guess).

In options I plan to add 'autodetect' constant, when the mode will chosen automatically. For example,
GDI - when we want to see just solid lines and fill;
Mixed - when we wan't to see gradient for polygons, for example;
GDI+ - when we want to set transparency for lines (I can't do it through GDI).

Such approach needs more work, but then we can have real fast drawing. Perhaps OpenGL will be available as one more option later, if it'll prove useful in any specific aspects (it would have much better chances to be chosen in case I wrote 3D drawing for grid or TIN data ;)

Sergei

Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: