[cairo] Performance of the image surface back-end

Nicholas Allen allen at ableton.com
Mon Aug 18 03:42:16 PDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Hi,

I have changed my line drawing code so that if the line is horizontal
or vertical it will use cairo_rectangle and cairo_fill to fill it.
This avoids the problem of line caps altogether and is guaranteed to
be pixel aligned. It seems the line capping code has absolutely
nothing to do with the performance problems of cairo. Using this new
approach I achieve almost identical performance as previously. It
takes 15476 ms to draw the horizontal lines compared with 15839 ms
when drawing the end caps on a non pixel aligned line. This is
basically no change. To put it in perspective using our simple
graphics API it takes 192 ms to to the same thing which means we are
81 X faster than Cairo!

The image surface back-end is so slow as to be completely unusable.
How can it possibly be this slow?

Nick


My line drawing code looks like this:

void ACairoGraphPort::DrawLine(TPoint P0, TPoint P1, TColor Color,
TInt Thickness)
{
  SetColor(Color);

  if (P0 == P1)
  {
    cairo_rectangle(mpCairo, P0.X(), P0.Y(), Thickness, Thickness);
    cairo_fill(mpCairo);
  }
  else if (P0.X() == P1.X())  // Vertical line
  {
    if (P0.Y() < P1.Y())
    {
      cairo_rectangle(mpCairo, P0.X(), P0.Y(), Thickness, P1.Y() -
P0.Y());     
    }
    else
    {
      cairo_rectangle(mpCairo, P1.X(), P1.Y(), Thickness, P0.Y() -
P1.Y());
    }

    cairo_fill(mpCairo);
  }
  else if (P0.Y() == P1.Y())  // Horizontal line
  {
    if (P0.X() < P1.X())
    {
      cairo_rectangle(mpCairo, P0.X(), P0.Y(), P1.X() - P0.X(),
Thickness);     
    }
    else
    {
      cairo_rectangle(mpCairo, P1.X(), P1.Y(), P0.X() - P1.X(),
Thickness);     
    }

    cairo_fill(mpCairo);
  }
  else  // Diagonal line
  {
    cairo_set_line_width(mpCairo, Thickness);
    cairo_move_to(mpCairo, P0.X(), P0.Y());
    cairo_line_to(mpCairo, P1.X(), P1.Y());
    cairo_stroke(mpCairo);
  }
}

Vladimir Vukicevic wrote:
>
> On Aug 15, 2008, at 6:20 AM, Nicholas Allen wrote:
>> Cairo (image surface back-end version 1.6.4 on Windows):
>>
>> ~     DrawHorizLine                 44352 ms             1000000 solid
>> horiz lines from 0.5, 50.5 to 500.5, 50.5
>
> This is not actually a pixel-aligned horizontal line, unless you are
> using the non-default SQUARE endcaps.  The horizontal line would be
> from 0.0, 50.5 to 501.0, 50.5.  With this line, you are getting
> essentially the slowest possible path for path rasterization;
> however, even with that, it seems quite slow.  As others mentioned,
> seeing the source for your benchmark would be useful!  (If, however,
> you are explicitly setting SQUARE endcaps, then something is likely
> going quite wrong.)
>
>     - Vlad
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFIqVIIbpmWsXfOU58RAnYkAKCSIv6/OuHTmpr7AyNyDYydITUo/QCfXGse
aIOQ3mtYxRqIjJjh77tFKuw=
=uUqd
-----END PGP SIGNATURE-----



More information about the cairo mailing list