GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Oct 21, 2014 5:20 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: gtk_plot_canvas_paint
PostPosted: Tue Dec 20, 2011 12:47 pm 
Offline
Familiar Face

Joined: Thu May 26, 2011 11:11 am
Posts: 11
Hi,
Does someone know what exactly the function from gtkextra gtk_plot_canvas_paint does in order to repaint the canvas?

Since I must work with huge canvasses it costs a lot (in terms of time) to paint it entirely. So I'm searching for a surrogate group of functions that can paint only a restricted area of it.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: gtk_plot_canvas_paint
PostPosted: Tue Dec 20, 2011 7:16 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
I assume this is for your picdsp project.
What versions and revisions of Gtk and GtkExtra are you using ?
Can you give the hardware specs of the computer your testing this on.
From what I've read, GtkExtra2 uses Gdk for drawing and GtkExtra3 uses Cairo.
For GtkExtra+3.0.1, gtk_plot_canvas_paint() is in gtkplotcanvas.c
Code:
/**
* gtk_plot_canvas_paint:
* @canvas: a #GtkPlotCanvas.
*
*
*/
void
gtk_plot_canvas_paint (GtkPlotCanvas *canvas)
{
  GtkWidget *widget;
  GList *childs;

  widget = GTK_WIDGET(canvas);

  if(gtk_widget_get_realized(widget) && !canvas->pixmap) return;
  if(canvas->freeze_count > 0) return;

  if(!gtk_plot_pc_init(canvas->pc)) return;

  gtk_plot_pc_gsave(canvas->pc);

  if(!GTK_IS_PLOT_PS(canvas->pc) || !canvas->transparent){
    if(canvas->transparent){
      GdkColor white;
      gdk_color_white(gtk_widget_get_colormap(GTK_WIDGET(canvas)), &white);
      gtk_plot_pc_set_color(canvas->pc, &white);
    } else
      gtk_plot_pc_set_color(canvas->pc, &canvas->background);
    gtk_plot_pc_draw_rectangle(canvas->pc,
                              TRUE,
                              0,0,canvas->pixmap_width, canvas->pixmap_height);
  }

  gtk_plot_canvas_draw_grid(canvas);

  childs = canvas->childs;
  while(childs)
   {
     GtkPlotCanvasChild *child;

     child = GTK_PLOT_CANVAS_CHILD(childs->data);
     gtk_plot_canvas_child_draw(canvas, child);
     childs = childs->next;
   }

  gtk_plot_pc_grestore(canvas->pc);
  gtk_plot_pc_leave(canvas->pc);
}

gtk_plot_pc_draw_rectangle is in gtkplotpc.c
Code:
void gtk_plot_pc_draw_rectangle                          (GtkPlotPC *pc,
                                                         gint filled,
                                                         gdouble x, gdouble y,
                                                         gdouble width,
                                                         gdouble height)
{
  GTK_PLOT_PC_CLASS(GTK_OBJECT_GET_CLASS(GTK_OBJECT(pc)))->draw_rectangle(pc, filled, x, y, width, height);
}

And draw_rectangle is on line 216 of: gtkplotcairo.c
Code:
pc_class->draw_rectangle = gtk_plot_cairo_draw_rectangle;

And finally gtk_plot_cairo_draw_rectangle is in gtkplotcairo.c:
Code:
static void
gtk_plot_cairo_draw_rectangle                          (GtkPlotPC *pc,
                                                        gint filled,
                                                        gdouble x, gdouble y,
                                                        gdouble width, gdouble height)
{
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
  if(!cairo)
    return;

  cairo_move_to(cairo, x, y);
  cairo_line_to(cairo, x+width, y);
  cairo_line_to(cairo, x+width, y+height);
  cairo_line_to(cairo, x, y+height);
  cairo_close_path(cairo);
  if (filled)
    cairo_fill(cairo);
  else
    cairo_stroke(cairo);
}


So it seams gtk_plot_canvas_paint uses Cairo and it's basic drawing routines like: cairo_move_to and cairo_line_to. So if your not already using it, switching to GtkExtra3 might speed things up a bit. Or cut out the middle man entirely and use Cairo directly like Tadeboro gave here:
http://www.gtkforums.com/viewtopic.php?f=16&t=3301&hilit=humidity


Top
 Profile  
 
 Post subject: Re: gtk_plot_canvas_paint
PostPosted: Wed Dec 21, 2011 12:02 am 
Offline
Familiar Face

Joined: Thu May 26, 2011 11:11 am
Posts: 11
Hi,
thanks for your reply.

Yes, of course, it's for my dspic project. I'm using GtkExtra+3.0.1 on Ubuntu 10.10.
My hardware configuration is.. mmh.. a 2 GB RAM - intel atom N450 netbook.

I have traced the origins of gtk_plot_canvas as you did but I think that the actual drawing function lies in gtk_plot_canvas_child_draw(canvas, child);
Maybe gtk_plot_pc_draw_rectangle is the which one that paints the canvas background while childs are painted with the aforementioned one.
However, I really can't get where gtk_plot_canvas_child_draw(canvas, child) leads to.
It uses a not well specified draw(canvas,child) function whose pointer is setted to NULL inside the gtk_plot_canvas class.

Besides, there is a similar function called draw_selection(canvas, child, area) which (I think) is supposed to draw only a restricted area of a child.
It uses gdk_draw_rectangle and other stuff like this. I tried to adapt its code to my needs but that did't leads me to any way (maybe because I'm missing something).
(all these functions belong to gtkplotcanvas.c and gtkplotcanvas.h)



I can't understand the difference between painting a canvas towards invalidating his area (also called refresh)!

Lets take an example: suppose I'm going to draw a plot using two separate arrays, one for x and the other for y.
To do this I will simply link these arrays to my dataset and than I will call an invalidate function for the interested area.
But if I want the data (already painted) to change, why I can't simply modify its arrays values and invalidate that area again so that to be updated with the new ones?
I hope I have been clear enough.



However, I'm definitely going to have a look to Tadeboro's code and to cairo's libraries in order to better focus where the problem could lie.


Top
 Profile  
 
 Post subject: Re: gtk_plot_canvas_paint
PostPosted: Wed Dec 21, 2011 3:42 am 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Those Atom's have particularly poor graphics performance. I have a second computer, an Asus nettop with an Atom N450 and built in Nvidia ion graphics. I bought it for streaming NetFlix. It works pretty well for that but web browsing is terrible and I have fast cable Internet access. Perhaps at least a portion of your speed issue is the hardware. Can you test it on something like a Intel Corei3 or Corei5 ?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group