Using Canvas->Handle is 1000 times slower

Using Canvas->Handle is 1000 times slower

Post by Chri » Thu, 26 Jun 2003 09:30:45



Hi

Just wished to pass on this tidbit of information I just discovered which
shocked me somewhat

I created a function to test some custom drawing routines I was creating

I wanted to find out if there was any performance penalty in using
StretchDiBits over SetDIBitstoDevice (win API)

so I set up a form and then redrew a picture 1000 times using each
routine and recorded the timings

in each loop I called Form1->Canvas->Handle to get the HDC to draw to
eg:
for (int i = 0; i < 1000;i++)
 Draw(Form1->Canvas->Handle,pic);

because the results were on the slow side (12ms per draw Av) I decided to
optimize, and instead of getting the HDC each time I called it once at
the beginning of the function, stored the results and used that in the
loop

eg:
HDC hdc = Form1->Canvas->Handle;
for (int i = 0; i < 1000;i++)
 Draw(hdc,pic);

SHOCK and Amazement!!!

my drawing routines increased in speed by 1000

in other words it went from 12ms per draw to 0.012ms per draw

I tried to follow the Handle routine using CPU view and after tracing
thru quite a bit of code it threw an exception ?, but it was obviously
setting up critical sections and seemed to be locking drawing surfaces

I also found that if I hid the form ( using Hide() ) prior to running the
routine my speed returned ?? I am not sure why this would be as there are
a few possible reasons.

So the m*of this story is if you are drawing to a canvas get your
handle (HDC) only once and re-use it, it could greatly speed up your
graphics

I am using BCB 4 on a WinXP AMD 1800+ CPU with 512M

Oh and by the way StretchDIBits takes the same time as SetDIBitsToDevice
just as Microsoft claims

Chris

 
 
 

Using Canvas->Handle is 1000 times slower

Post by zhang l » Fri, 27 Jun 2003 22:51:00


I also thought the speed question of VCL component.

The "property" not a real data, even use it like a data.
it has via a function call, after return data type, so be slow.

C++Builder keyword extensions

<property declaration> ::=

      __property <type> <id> [ <prop dim list> ] = "{" <prop attrib list>
"}"

regards

Li

Quote:> for (int i = 0; i < 1000;i++)
>  Draw(Form1->Canvas->Handle,pic);

> because the results were on the slow side (12ms per draw Av) I decided to
> optimize, and instead of getting the HDC each time I called it once at
> the beginning of the function, stored the results and used that in the
> loop

> eg:
> HDC hdc = Form1->Canvas->Handle;
> for (int i = 0; i < 1000;i++)
>  Draw(hdc,pic);

> SHOCK and Amazement!!!

> my drawing routines increased in speed by 1000


 
 
 

1. canvas->pixel is slow slow slow...

 hi...there...

   i want to draw a pic thru pixels...
   and i used to adapting canvas->pixel to have it done dot by dot..
  and it's incredibily slow...

   if there any method like 1. to initial a Graphic base viables first and
then put pixels in,
                                            after all, print the graphic out
via the viables...
                                       2. call DIB to handle ...and how?
                                       3. DirectDraw ...???
   thanx for helping~~~

2. Unexplainable bug in my OpenGL animation

3. Slow Canvas->Draw and Canvas->CopyRect

4. Importing DWG files - Can it be done?

5. TImage->Canvas->Pixels is very slow...

6. Collision detection

7. Problem /w TMetafile Canvas DPI using Printer.Handle

8. Need 3D app for web pages

9. canvas->handle is NULL

10. Replace HDC (devicecontext handle) with Bitmap.Canvas.Handle ??

11. Where to drawlines on Printer.Handle or Printer.Canvas.Handle

12. picture->canvas to printer->canvas

13. Image->Canvas vs. Bitmap->Canvas Transparency