GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Oct 26, 2014 7:46 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [cairo] drawing circle is slow
PostPosted: Mon Nov 28, 2011 4:52 pm 
Offline
Familiar Face

Joined: Mon Oct 31, 2011 11:10 am
Posts: 8
Hi,
i try to port my gtk-drawing functions to cairo, it seems to work, but cairo ist extremly slow (maybe my fault)...

example i draw ~2000 circles using this function:
Code:
void TCanvas::DrawEllipse(int x,int y,int w,int h,bool filled)
{
  gdk_draw_arc (drawable, gc, filled, x, y, w, h, 0,64*360);
}


this takes ~50 ms...same with cairo:
Code:
const double full_circle=2*M_PI;

void TCanvas::DrawEllipse(int x,int y,int w,int h,bool filled)
{
  //cairo_arc(cairo_t *cr,double xc,double yc,double radius,double angle1,double angle2);
  cairo_arc(cr, x+w/2, y+h/2, w/2, 0, full_circle);
  if (filled)
    cairo_fill(cr);
  else
    cairo_stroke(cr);

  cairo_close_path(cr);
}

takes nearly 1000ms.

how can i speedup this? i have antialiasing disabled...

regards Frank


Top
 Profile  
 
 Post subject: Re: [cairo] drawing circle is slow
PostPosted: Mon Dec 05, 2011 4:30 pm 
Offline
Familiar Face

Joined: Mon Oct 31, 2011 11:10 am
Posts: 8
has noone an idea, how to get this faster done? i also tried without close_path, but nothing changes.

my current try is to draw as tiled pixmap:

old code:
Code:
  for (int i=1;i<fWidth;i++)
  {
      for (int j=1;j<fHeight;j++)
      {
        p=Point(i,j);
        p=CalcAbsolute(p);
      //Canvas_Circle(pm,x-fHoleRadius,y-fHoleRadius,2*fHoleRadius,2*fHoleRadius,clr);

        canvas_grid.DrawEllipse(p.x-fHoleRadius,p.y-fHoleRadius,2*fHoleRadius,2*fHoleRadius);
         //DrawPoint(pixmap_grid,i,j,clSilver);
      }
  }


new code:
Code:
  GdkPixmap *pm_tmp = gdk_pixmap_new(DrawingArea->window,
                          fHoleSpacing,
                          fHoleSpacing,
                          24);

  TCanvas cv_tmp;
  cv_tmp.Init(pm_tmp);
  cv_tmp.SetFGColor(clSilver);
//draw a single circle as pattern
  cv_tmp.DrawEllipse(0,0,2*fHoleRadius,2*fHoleRadius);
//draw this pattern starting at position fHoleRadius
  canvas_grid.DrawTiledPixmap(pm_tmp,fHoleRadius,fHoleRadius,w-fHoleRadius,h-fHoleRadius);
  gdk_pixmap_unref(pm_tmp);


where DrawTiledBitmap is defined like this:
Code:
void TCanvas::DrawTiledPixmap(GdkPixmap *pixmap,int x,int y,int w,int h)
{
   gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
   cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
   cairo_rectangle (cr, x, y, w, h);
   cairo_fill (cr);
}


this draws faster, but i cannot get my circles aligned the right way.
cairo starts not with a full pattern in the upper left corner...how to get this solved?
i've solved the incorrect alignment:

Code:
gdk_cairo_set_source_pixmap (cr, pixmap, 0-x, 0-y);


but maybe it exists a possibility to draw circles faster with cairo...pls post some suggestions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group