likely/unlikely branch prediction
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / drawing.c
index 2cd92c2eedafc3d4e36499b9b8310b8912171cc4..918d8c3bc5110c643cb7eb19075017a002eb95be 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
+#include <string.h>
 
 #include <lttv/lttv.h>
 #include <lttv/tracecontext.h>
 #include "drawing.h"
 #include "eventhooks.h"
 #include "cfv.h"
-#include "cfv-private.h"
 
 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
 
+//FIXME
+#define TRACE_NUMBER 0
+
+#if 0 /* colors for two lines representation */
+GdkColor drawing_colors[NUM_COLORS] =
+{ /* Pixel, R, G, B */
+  { 0, 0, 0, 0 }, /* COL_BLACK */
+  { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
+  { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
+  { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
+  { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
+  { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
+  { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
+  { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
+  { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
+  { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
+  { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
+  { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
+  { 0, 0xFFFF, 0xFFFF, 0xFFFF }  /* COL_MODE_UNKNOWN : white */
+
+};
+#endif //0
+
+
+GdkColor drawing_colors[NUM_COLORS] =
+{ /* Pixel, R, G, B */
+  { 0, 0, 0, 0 }, /* COL_BLACK */
+  { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
+  { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
+  { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
+  { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
+  { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_RUN_IRQ : red */
+  { 0, 0xA3FF, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
+  { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
+  { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
+  { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
+  { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
+  { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
+  { 0, 0xFFFF, 0xFFFF, 0xFFFF }  /* COL_UNNAMED : white */
+
+};
+
+/*
+RUN+USER MODE green
+RUN+SYSCALL
+RUN+TRAP
+RUN+IRQ
+WAIT+foncé
+WAIT CPU + WAIT FORK vert foncé ou jaune
+IRQ rouge
+TRAP: orange
+SYSCALL: bleu pâle
+
+ZOMBIE + WAIT EXIT
+*/
+
+
 /*****************************************************************************
  *                              drawing functions                            *
  *****************************************************************************/
@@ -44,28 +101,6 @@ static gboolean
 motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
 
 
-//FIXME Colors will need to be dynamic. Graphic context part not done so far.
-typedef enum 
-{
-  RED,
-  GREEN,
-  BLUE,
-  WHITE,
-  BLACK
-
-} ControlFlowColors;
-
-/* Vector of unallocated colors */
-static GdkColor CF_Colors [] = 
-{
-  { 0, 0xffff, 0x0000, 0x0000 },  // RED
-  { 0, 0x0000, 0xffff, 0x0000 },  // GREEN
-  { 0, 0x0000, 0x0000, 0xffff },  // BLUE
-  { 0, 0xffff, 0xffff, 0xffff },  // WHITE
-  { 0, 0x0000, 0x0000, 0x0000 } // BLACK
-};
-
-
 /* Function responsible for updating the exposed area.
  * It must do an events request to the lttvwindow API to ask for this update.
  * Note : this function cannot clear the background, because it may
@@ -80,24 +115,16 @@ void drawing_data_request(Drawing_t *drawing,
   if(width < 0) return ;
   if(height < 0) return ;
 
-  if(drawing->gc == NULL) {
-    drawing->gc = gdk_gc_new(drawing->drawing_area->window);
-    gdk_gc_copy(drawing->gc, drawing->drawing_area->style->black_gc);
-  }
-
-
-  
+  Tab *tab = drawing->control_flow_data->tab;
   TimeWindow time_window =
-              lttvwindow_get_time_window(drawing->control_flow_data->tab);
+              lttvwindow_get_time_window(tab);
 
   ControlFlowData *control_flow_data = drawing->control_flow_data;
-  Tab *tab = control_flow_data->tab;
   //    (ControlFlowData*)g_object_get_data(
   //               G_OBJECT(drawing->drawing_area), "control_flow_data");
 
   LttTime start, time_end;
-  LttTime window_end = ltt_time_add(time_window.time_width,
-                                    time_window.start_time);
+  LttTime window_end = time_window.end_time;
 
   g_debug("req : window start_time : %u, %u", time_window.start_time.tv_sec, 
                                        time_window.start_time.tv_nsec);
@@ -111,83 +138,242 @@ void drawing_data_request(Drawing_t *drawing,
   g_debug("x is : %i, x+width is : %i", x, x+width);
 
   convert_pixels_to_time(drawing->width, x,
-        time_window.start_time,
-        window_end,
+        time_window,
         &start);
 
   convert_pixels_to_time(drawing->width, x+width,
-        time_window.start_time,
-        window_end,
+        time_window,
         &time_end);
-  
-  EventsRequest *events_request = g_new(EventsRequest, 1);
-  // Create the hooks
-  LttvHooks *event = lttv_hooks_new();
-  LttvHooks *before_chunk_traceset = lttv_hooks_new();
-  LttvHooks *after_chunk_traceset = lttv_hooks_new();
-  LttvHooks *before_request_hook = lttv_hooks_new();
-  LttvHooks *after_request_hook = lttv_hooks_new();
-
-  lttv_hooks_add(before_chunk_traceset,
-                 before_chunk,
-                 events_request,
-                 LTTV_PRIO_DEFAULT);
+  time_end = ltt_time_add(time_end, ltt_time_one); // because main window
+                                                   // doesn't deliver end time.
 
-  lttv_hooks_add(after_chunk_traceset,
-                 after_chunk,
-                 events_request,
-                 LTTV_PRIO_DEFAULT);
+  lttvwindow_events_request_remove_all(tab,
+                                       control_flow_data);
 
-  lttv_hooks_add(before_request_hook,
-                 before_request,
-                 events_request,
-                 LTTV_PRIO_DEFAULT);
+  {
+    /* find the tracehooks */
+    LttvTracesetContext *tsc = lttvwindow_get_traceset_context(tab);
 
-  lttv_hooks_add(after_request_hook,
-                 after_request,
-                 events_request,
-                 LTTV_PRIO_DEFAULT);
+    LttvTraceset *traceset = tsc->ts;
+
+    guint i, k, nb_trace;
+
+    LttvTraceState *ts;
+
+    LttvTracefileState *tfs;
+
+    GArray *hooks;
+
+    LttvTraceHook hook;
+
+    LttvAttributeValue val;
+
+    nb_trace = lttv_traceset_number(traceset);
+    // FIXME : eventually request for more traces
+    // for(i = 0 ; i < nb_trace ; i++) {
+    for(i = 0; i<MIN(TRACE_NUMBER+1, nb_trace);i++)
+    {
+      EventsRequest *events_request = g_new(EventsRequest, 1);
+      // Create the hooks
+      //LttvHooks *event = lttv_hooks_new();
+      LttvHooksById *event_by_id = lttv_hooks_by_id_new();
+      LttvHooks *before_chunk_traceset = lttv_hooks_new();
+      LttvHooks *after_chunk_traceset = lttv_hooks_new();
+      LttvHooks *before_request_hook = lttv_hooks_new();
+      LttvHooks *after_request_hook = lttv_hooks_new();
+
+      lttv_hooks_add(before_chunk_traceset,
+                     before_chunk,
+                     events_request,
+                     LTTV_PRIO_DEFAULT);
+
+      lttv_hooks_add(after_chunk_traceset,
+                     after_chunk,
+                     events_request,
+                     LTTV_PRIO_DEFAULT);
+
+      lttv_hooks_add(before_request_hook,
+                     before_request,
+                     events_request,
+                     LTTV_PRIO_DEFAULT);
+
+      lttv_hooks_add(after_request_hook,
+                     after_request,
+                     events_request,
+                     LTTV_PRIO_DEFAULT);
+
+
+      ts = (LttvTraceState *)tsc->traces[i];
+
+      /* Find the eventtype id for the following events and register the
+         associated by id hooks. */
+
+      hooks = g_array_new(FALSE, FALSE, sizeof(LttvTraceHook));
+      g_array_set_size(hooks, 10);
+
+      /* before hooks */
+      
+      lttv_trace_find_hook(ts->parent.t, "core","syscall_entry","syscall_id", 
+    NULL, NULL, before_execmode_hook, &g_array_index(hooks, LttvTraceHook, 0));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "syscall_exit", NULL, NULL, 
+          NULL, before_execmode_hook, &g_array_index(hooks, LttvTraceHook, 1));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "trap_entry", "trap_id",
+    NULL, NULL, before_execmode_hook, &g_array_index(hooks, LttvTraceHook, 2));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL, NULL, 
+          before_execmode_hook, &g_array_index(hooks, LttvTraceHook, 3));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "irq_entry", "irq_id", NULL, 
+          NULL, before_execmode_hook, &g_array_index(hooks, LttvTraceHook, 4));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL, NULL, 
+          before_execmode_hook, &g_array_index(hooks, LttvTraceHook, 5));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "schedchange", "in", "out", 
+        "out_state", before_schedchange_hook, 
+        &g_array_index(hooks, LttvTraceHook, 6));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "process", "event_sub_id", 
+          "event_data1", "event_data2", before_process_hook,
+          &g_array_index(hooks, LttvTraceHook, 7));
+
+#if 0
+      lttv_trace_find_hook(ts->parent.t, "core", "process_fork", "child_pid", 
+          NULL, NULL, process_fork, &g_array_index(hooks, LttvTraceHook, 7));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "process_exit", NULL, NULL, 
+          NULL, process_exit, &g_array_index(hooks, LttvTraceHook, 8));
+#endif //0
+
+      /* after hooks */
+      
+#if 0
+      /**** DESACTIVATED ****/
+      lttv_trace_find_hook(ts->parent.t, "core","syscall_entry","syscall_id", 
+    NULL, NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, 8));
+      /**** DESACTIVATED ****/
+      lttv_trace_find_hook(ts->parent.t, "core", "syscall_exit", NULL, NULL, 
+          NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, 9));
+
+      /**** DESACTIVATED ****/
+      lttv_trace_find_hook(ts->parent.t, "core", "trap_entry", "trap_id",
+    NULL, NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, 10));
+
+      /**** DESACTIVATED ****/
+      lttv_trace_find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL, NULL, 
+          after_execmode_hook, &g_array_index(hooks, LttvTraceHook, 11));
+
+      /**** DESACTIVATED ****/
+      lttv_trace_find_hook(ts->parent.t, "core", "irq_entry", "irq_id", NULL, 
+          NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, 12));
+
+      /**** DESACTIVATED ****/
+      lttv_trace_find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL, NULL, 
+          after_execmode_hook, &g_array_index(hooks, LttvTraceHook, 13));
+#endif //0
+
+      lttv_trace_find_hook(ts->parent.t, "core", "schedchange", "in", "out", 
+        "out_state", after_schedchange_hook, 
+        &g_array_index(hooks, LttvTraceHook, 8));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "process", "event_sub_id", 
+          "event_data1", "event_data2", after_process_hook,
+          &g_array_index(hooks, LttvTraceHook, 9));
+
+#if 0
+      lttv_trace_find_hook(ts->parent.t, "core", "process_fork", "child_pid", 
+          NULL, NULL, process_fork, &g_array_index(hooks, LttvTraceHook, 7));
+
+      lttv_trace_find_hook(ts->parent.t, "core", "process_exit", NULL, NULL, 
+          NULL, process_exit, &g_array_index(hooks, LttvTraceHook, 8));
+#endif //0
+
+
+      
+      /* Add these hooks to each event_by_id hooks list */
+      /* add before */
+      for(k = 0 ; k < 8 ; k++) {
+        hook = g_array_index(hooks, LttvTraceHook, k);
+        lttv_hooks_add(lttv_hooks_by_id_find(event_by_id, 
+                        hook.id), hook.h,
+                        events_request,
+                        LTTV_PRIO_STATE-5);
+      }
+
+      /* add after */
+      for(k = 8 ; k < 10 ; k++) {
+        hook = g_array_index(hooks, LttvTraceHook, k);
+        lttv_hooks_add(lttv_hooks_by_id_find(event_by_id, 
+                       hook.id), hook.h,
+                       events_request,
+                       LTTV_PRIO_STATE+5);
+      }
+
+      events_request->hooks = hooks;
+
+      // Fill the events request
+      events_request->owner = control_flow_data;
+      events_request->viewer_data = control_flow_data;
+      events_request->servicing = FALSE;
+      events_request->start_time = start;
+      events_request->start_position = NULL;
+      events_request->stop_flag = FALSE;
+      events_request->end_time = time_end;
+      events_request->num_events = G_MAXUINT;
+      events_request->end_position = NULL;
+      events_request->trace = i;    /* FIXME */
+      events_request->before_chunk_traceset = before_chunk_traceset;
+      events_request->before_chunk_trace = NULL;
+      events_request->before_chunk_tracefile = NULL;
+      events_request->event = NULL;
+      events_request->event_by_id = event_by_id;
+      events_request->after_chunk_tracefile = NULL;
+      events_request->after_chunk_trace = NULL;
+      events_request->after_chunk_traceset = after_chunk_traceset;
+      events_request->before_request = before_request_hook;
+      events_request->after_request = after_request_hook;
+
+      g_debug("req : start : %u, %u", start.tv_sec, 
+                                          start.tv_nsec);
+
+      g_debug("req : end : %u, %u", time_end.tv_sec, 
+                                         time_end.tv_nsec);
+
+      lttvwindow_events_request(tab, events_request);
+
+    }
 
+  }
 
+#if 0
   lttv_hooks_add(event,
-                 draw_before_hook,
+                 before_schedchange_hook,
                  events_request,
                  LTTV_PRIO_STATE-5);
   lttv_hooks_add(event,
-                 draw_after_hook,
+                 after_schedchange_hook,
                  events_request,
                  LTTV_PRIO_STATE+5);
+  lttv_hooks_add(event,
+                 before_execmode_hook,
+                 events_request,
+                 LTTV_PRIO_STATE-5);
+  lttv_hooks_add(event,
+                 after_execmode_hook,
+                 events_request,
+                 LTTV_PRIO_STATE+5);
+  lttv_hooks_add(event,
+                 before_process_hook,
+                 events_request,
+                 LTTV_PRIO_STATE-5);
+  lttv_hooks_add(event,
+                 after_process_hook,
+                 events_request,
+                 LTTV_PRIO_STATE+5);
+#endif //0
 
-  // Fill the events request
-  events_request->owner = control_flow_data;
-  events_request->viewer_data = control_flow_data;
-  events_request->servicing = FALSE;
-  events_request->start_time = start;
-  events_request->start_position = NULL;
-  events_request->stop_flag = FALSE;
-  events_request->end_time = time_end;
-  events_request->num_events = G_MAXUINT;
-  events_request->end_position = NULL;
-  events_request->before_chunk_traceset = before_chunk_traceset;
-  events_request->before_chunk_trace = NULL;
-  events_request->before_chunk_tracefile = NULL;
-  events_request->event = event;
-  events_request->event_by_id = NULL;
-  events_request->after_chunk_tracefile = NULL;
-  events_request->after_chunk_trace = NULL;
-  events_request->after_chunk_traceset = after_chunk_traceset;
-  events_request->before_request = before_request_hook;
-  events_request->after_request = after_request_hook;
-
-  g_debug("req : start : %u, %u", start.tv_sec, 
-                                      start.tv_nsec);
-
-  g_debug("req : end : %u, %u", time_end.tv_sec, 
-                                     time_end.tv_nsec);
-
-  lttvwindow_events_request_remove_all(tab,
-                                       control_flow_data);
-  lttvwindow_events_request(tab, events_request);
 }
  
 
@@ -197,7 +383,16 @@ static void set_last_start(gpointer key, gpointer value, gpointer user_data)
   HashedProcessData *hashed_process_data = (HashedProcessData*)value;
   guint x = (guint)user_data;
 
-  hashed_process_data->x = x;
+  hashed_process_data->x.over = x;
+  hashed_process_data->x.over_used = FALSE;
+  hashed_process_data->x.over_marked = FALSE;
+  hashed_process_data->x.middle = x;
+  hashed_process_data->x.middle_used = FALSE;
+  hashed_process_data->x.middle_marked = FALSE;
+  hashed_process_data->x.under = x;
+  hashed_process_data->x.under_used = FALSE;
+  hashed_process_data->x.under_marked = FALSE;
+  hashed_process_data->next_good_time = ltt_time_zero;
 
   return;
 }
@@ -209,22 +404,22 @@ void drawing_data_request_begin(EventsRequest *events_request, LttvTracesetState
   LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tss);
   TimeWindow time_window = 
     lttvwindow_get_time_window(cfd->tab);
-  LttTime end_time = ltt_time_add(time_window.start_time,
-                                    time_window.time_width);
+  LttTime end_time = time_window.end_time;
+
   guint width = cfd->drawing->width;
   guint x=0;
 
   cfd->drawing->last_start = events_request->start_time;
 
   convert_time_to_pixels(
-          time_window.start_time,
-          end_time,
+          time_window,
           events_request->start_time,
           width,
           &x);
 
   g_hash_table_foreach(cfd->process_list->process_hash, set_last_start,
                             (gpointer)x);
+
 }
 
 void drawing_chunk_begin(EventsRequest *events_request, LttvTracesetState *tss)
@@ -233,8 +428,14 @@ void drawing_chunk_begin(EventsRequest *events_request, LttvTracesetState *tss)
   ControlFlowData *cfd = events_request->viewer_data;
   LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tss);
   LttTime current_time = lttv_traceset_context_get_current_tfc(tsc)->timestamp;
-
-  cfd->drawing->last_start = current_time;
+  guint num_cpu = 
+    ltt_trace_per_cpu_tracefile_number(tss->parent.traces[TRACE_NUMBER]->t);
+
+  cfd->process_list->current_hash_data = g_new(HashedProcessData*,num_cpu);
+  memset(cfd->process_list->current_hash_data, 0,
+         sizeof(HashedProcessData*)*num_cpu);
+  //cfd->drawing->last_start = LTT_TIME_MIN(current_time,
+  //                                        events_request->end_time);
 }
 
 
@@ -253,23 +454,23 @@ void drawing_request_expose(EventsRequest *events_request,
 
   g_debug("request expose");
   
-  LttTime window_end = ltt_time_add(time_window.time_width,
-                                    time_window.start_time);
+  LttTime window_end = time_window.end_time;
 
+#if 0
   convert_time_to_pixels(
-        time_window.start_time,
-        window_end,
+        time_window,
         cfd->drawing->last_start,
         drawing->width,
         &x);
 
+#endif //0
   convert_time_to_pixels(
-        time_window.start_time,
-        window_end,
+        time_window,
         end_time,
         drawing->width,
         &x_end);
-
+  x = drawing->damage_begin;
+ // x_end = drawing->damage_end;
   width = x_end - x;
 
   drawing->damage_begin = x+width;
@@ -391,6 +592,10 @@ expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
       (ControlFlowData*)g_object_get_data(
                 G_OBJECT(widget),
                 "control_flow_data");
+  if(unlikely(drawing->gc == NULL)) {
+    drawing->gc = gdk_gc_new(drawing->drawing_area->window);
+    gdk_gc_copy(drawing->gc, drawing->drawing_area->style->black_gc);
+  }
 
   TimeWindow time_window = 
       lttvwindow_get_time_window(control_flow_data->tab);
@@ -399,9 +604,7 @@ expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
 
   guint cursor_x=0;
 
-  LttTime window_end = ltt_time_add(time_window.time_width,
-                                    time_window.start_time);
-
+  LttTime window_end = time_window.end_time;
 
   /* update the screen from the pixmap buffer */
   gdk_draw_pixmap(widget->window,
@@ -417,8 +620,7 @@ expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
   {
     /* Draw the dotted lines */
     convert_time_to_pixels(
-          time_window.start_time,
-          window_end,
+          time_window,
           current_time,
           drawing->width,
           &cursor_x);
@@ -460,6 +662,27 @@ after_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data
 
 }
 
+#if 0
+void
+tree_row_activated(GtkTreeModel *treemodel,
+                   GtkTreePath *arg1,
+                   GtkTreeViewColumn *arg2,
+                   gpointer user_data)
+{
+  ControlFlowData *cfd = (ControlFlowData*)user_data;
+  Drawing_t *drawing = cfd->drawing;
+  GtkTreeView *treeview = cfd->process_list->process_list_widget;
+  gint *path_indices;
+  gint height;
+  
+  path_indices =  gtk_tree_path_get_indices (arg1);
+
+  height = get_cell_height(cfd->process_list,
+        GTK_TREE_VIEW(treeview));
+  drawing->horizontal_sel = height * path_indices[0];
+  g_critical("new hor sel : %i", drawing->horizontal_sel);
+}
+#endif //0
 
 /* mouse click */
 static gboolean
@@ -478,25 +701,20 @@ button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data
   {
     LttTime time;
 
-    LttTime window_end = ltt_time_add(time_window.time_width,
-                                      time_window.start_time);
+    LttTime window_end = time_window.end_time;
 
 
     /* left mouse button click */
     g_debug("x click is : %f", event->x);
 
     convert_pixels_to_time(drawing->width, (guint)event->x,
-        time_window.start_time,
-        window_end,
+        time_window,
         &time);
 
-    lttvwindow_report_current_time(control_flow_data->tab, &time);
+    lttvwindow_report_current_time(control_flow_data->tab, time);
 
   }
 
-  lttvwindow_report_focus(control_flow_data->tab,
-           gtk_widget_get_parent(guicontrolflow_get_widget(control_flow_data)));
-
   return FALSE;
 }
 
@@ -527,11 +745,9 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data)
   
   drawing->ruler_hbox = gtk_hbox_new(FALSE, 1);
   drawing->ruler = gtk_drawing_area_new ();
-  gtk_widget_add_events(drawing->ruler, GDK_BUTTON_PRESS_MASK);
   //gtk_widget_set_size_request(drawing->ruler, -1, 27);
   
   drawing->padding = gtk_drawing_area_new ();
-  gtk_widget_add_events(drawing->padding, GDK_BUTTON_PRESS_MASK);
   //gtk_widget_set_size_request(drawing->padding, -1, 27);
   gtk_box_pack_start(GTK_BOX(drawing->ruler_hbox), drawing->ruler, 
                      TRUE, TRUE, 0);
@@ -583,6 +799,7 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data)
   
   drawing->damage_begin = 0;
   drawing->damage_end = 0;
+  drawing->horizontal_sel = -1;
   
   //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
   g_object_set_data_full(
@@ -620,8 +837,6 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data)
 //        drawing->drawing_area->allocation.height,
 //        -1);
 
-  gtk_widget_add_events(drawing->drawing_area, GDK_BUTTON_PRESS_MASK);
-  
   g_signal_connect (G_OBJECT(drawing->drawing_area),
         "configure_event",
         G_CALLBACK (configure_event),
@@ -672,6 +887,11 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data)
   gtk_widget_show(drawing->scrollbar);
   gtk_widget_show(drawing->hbox);
 
+  /* Allocate the colors */
+  GdkColormap* colormap = gdk_colormap_get_system();
+  gboolean success[NUM_COLORS];
+  gdk_colormap_alloc_colors(colormap, drawing_colors, NUM_COLORS, FALSE,
+                            TRUE, success);
   
   return drawing;
 }
@@ -679,6 +899,14 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data)
 void drawing_destroy(Drawing_t *drawing)
 {
   g_info("drawing_destroy %p", drawing);
+
+  /* Free the colors */
+  GdkColormap* colormap = gdk_colormap_get_system();
+
+  gdk_colormap_free_colors(colormap, drawing_colors, NUM_COLORS);
+  
+
+
   // Do not unref here, Drawing_t destroyed by it's widget.
   //g_object_unref( G_OBJECT(drawing->drawing_area));
   if(drawing->gc != NULL)
@@ -700,53 +928,6 @@ GtkWidget *drawing_get_widget(Drawing_t *drawing)
   return drawing->vbox;
 }
 
-/* convert_pixels_to_time
- *
- * Convert from window pixel and time interval to an absolute time.
- */
-//FIXME : could need ceil and floor versions of this function
-void convert_pixels_to_time(
-    gint width,
-    guint x,
-    LttTime window_time_begin,
-    LttTime window_time_end,
-    LttTime *time)
-{
-  LttTime window_time_interval;
-  
-  window_time_interval = ltt_time_sub(window_time_end, 
-            window_time_begin);
-  *time = ltt_time_mul(window_time_interval, (x/(float)width));
-  *time = ltt_time_add(window_time_begin, *time);
-}
-
-//FIXME : could need ceil and floor versions of this function
-
-void convert_time_to_pixels(
-    LttTime window_time_begin,
-    LttTime window_time_end,
-    LttTime time,
-    int width,
-    guint *x)
-{
-  LttTime window_time_interval;
-  double interval_double, time_double;
-  
-  g_assert(ltt_time_compare(window_time_begin, time) <= 0 &&
-           ltt_time_compare(window_time_end, time) >= 0);
-  
-  window_time_interval = ltt_time_sub(window_time_end,window_time_begin);
-  
-  time = ltt_time_sub(time, window_time_begin);
-  
-  /* LttTime to double conversions here should really be under 4000 hours.. */
-  interval_double = ltt_time_to_double(window_time_interval);
-  time_double = ltt_time_to_double(time);
-
-  *x = (guint)(time_double/interval_double * width);
-  
-}
-
 void drawing_draw_line( Drawing_t *drawing,
       GdkPixmap *pixmap,
       guint x1, guint y1,
@@ -826,12 +1007,12 @@ void drawing_insert_square(Drawing_t *drawing,
     drawing->width+SAFETY, drawing->height - y);
 
 
-  if (drawing->pixmap)
+  if(likely(drawing->pixmap))
     gdk_pixmap_unref(drawing->pixmap);
 
   drawing->pixmap = pixmap;
   
-  if(drawing->height==1) drawing->height = height;
+  if(unlikely(drawing->height==1)) drawing->height = height;
   else drawing->height += height;
   
   gtk_widget_set_size_request(drawing->drawing_area,
@@ -853,7 +1034,7 @@ void drawing_remove_square(Drawing_t *drawing,
 {
   GdkPixmap *pixmap;
 
-  if(drawing->height == height) {
+  if(unlikely(drawing->height == height)) {
     pixmap = gdk_pixmap_new(
         drawing->drawing_area->window,
         drawing->width + SAFETY,
@@ -887,7 +1068,7 @@ void drawing_remove_square(Drawing_t *drawing,
     drawing->height-=height;
   }
 
-  if (drawing->pixmap)
+  if(likely(drawing->pixmap))
     gdk_pixmap_unref(drawing->pixmap);
 
   drawing->pixmap = pixmap;
@@ -938,9 +1119,7 @@ expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
   GdkColor foreground = { 0, 0, 0, 0 };
   GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
 
-  LttTime window_end = 
-    ltt_time_add(time_window.time_width,
-                 time_window.start_time);
+  LttTime window_end = time_window.end_time;
   LttTime half_width =
     ltt_time_div(time_window.time_width,2.0);
   LttTime window_middle =
This page took 0.031401 seconds and 4 git commands to generate.