now, main window resize will change the scale, not time interval
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Event_Hooks.c
index 785c73e42f36b84f2c48c4b67445574433a089a6..de41f0c64cc01948438bab4a23eb0724aa98f445 100644 (file)
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 #include <glib.h>
+#include <assert.h>
 
 //#include <pango/pango.h>
 
+#include <ltt/event.h>
+#include <ltt/time.h>
+
 #include <lttv/hook.h>
 #include <lttv/common.h>
+#include <lttv/state.h>
+
 
 #include "Event_Hooks.h"
 #include "CFV.h"
 #include "CFV-private.h"
 
 
+#define MAX_PATH_LEN 256
+
+//FIXME : remove this include when tests finished.
+#include <string.h>
+
+void test_draw_item(Drawing_t *Drawing,
+                       GdkPixmap *Pixmap) 
+{
+       PropertiesIcon properties_icon;
+       DrawContext draw_context;
+       
+       DrawInfo current, previous;
+       ItemInfo over, middle, under, modify_over, modify_middle, modify_under;
+
+       int i=0,j=0;
+       
+       //for(i=0; i<1024;i=i+15)
+       {
+       //      for(j=0;j<768;j=j+15)
+               {
+                       over.x = i;
+                       over.y = j;
+
+                       current.modify_over = &over;
+       
+                       draw_context.drawable = Pixmap;
+                       draw_context.gc = Drawing->Drawing_Area_V->style->black_gc;
+
+                       draw_context.Current = &current;
+                       draw_context.Previous = NULL;
+       
+                       properties_icon.icon_name = g_new(char, MAX_PATH_LEN);
+                       strncpy(properties_icon.icon_name, 
+                               "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
+                               MAX_PATH_LEN);
+                       properties_icon.width = -1;
+                       properties_icon.height = -1;
+                       properties_icon.position = OVER;
+                       draw_icon(&properties_icon, &draw_context);
+                       g_free(properties_icon.icon_name);
+               }
+       }
+
+}
+
+#ifdef NOTUSE
 /* NOTE : no drawing data should be sent there, since the drawing widget
  * has not been initialized */
 void send_test_drawing(ProcessList *Process_List,
                        Drawing_t *Drawing,
                        GdkPixmap *Pixmap,
                        gint x, gint y, // y not used here?
-                       gint width,
+                 gint width,
                        gint height) // height won't be used here ?
 {
-       int i;
+       int i,j;
        ProcessInfo Process_Info = {10000, 12000, 55600};
        //ProcessInfo Process_Info = {156, 14000, 55500};
        GtkTreeRowReference *got_RowRef;
@@ -42,13 +94,13 @@ void send_test_drawing(ProcessList *Process_List,
        gint Font_Size;
 
        //icon
-       GdkBitmap *mask = g_new(GdkBitmap, 1);
-       GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
-       GdkGC * gc = gdk_gc_new(Pixmap);
-       
+       //GdkBitmap *mask = g_new(GdkBitmap, 1);
+       //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
+       GdkGC * gc;
        // rectangle
        GdkColor color = { 0, 0xffff, 0x0000, 0x0000 };
        
+       gc = gdk_gc_new(Pixmap);
        /* Sent text data */
        layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V,
                        NULL);
@@ -95,21 +147,6 @@ void send_test_drawing(ProcessList *Process_List,
                y+(height/2), x + width, y+(height/2),
                Drawing->Drawing_Area_V->style->black_gc);
 
-
-       /* Draw icon */
-       icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
-//                             "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
-                               "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
-       gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
-       gdk_gc_set_clip_mask(gc, mask);
-       gdk_draw_drawable(Pixmap, 
-                       gc,
-                       icon_pixmap,
-                       0, 0, 0, 0, -1, -1);
-       
-       g_free(icon_pixmap);
-       g_free(mask);
-
        g_info("y : %u, height : %u", y, height);
 
        
@@ -138,7 +175,7 @@ void send_test_drawing(ProcessList *Process_List,
        
        /* Draw arc */
        gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc,
-                                                       TRUE, 100, y, 5, 5, 0, 360*64);
+                                                       TRUE, 100, y, height/2, height/2, 0, 360*64);
 
        g_info("y : %u, height : %u", y, height);
 
@@ -179,12 +216,47 @@ void send_test_drawing(ProcessList *Process_List,
                Drawing->Drawing_Area_V->style->black_gc);
 
        g_info("y : %u, height : %u", y, height);
+       
+
+       /* IMPORTANT : This action uses the cpu heavily! */
+       //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
+//                             "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
+       //                              "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
+
+       //              gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
+
+//     for(i=x;i<x+width;i=i+15)
+//     {
+//             for(j=0;j<height*20;j=j+15)
+//             {
+                       
+                       /* Draw icon */
+                       //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
+//                     gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
+//                     gdk_draw_drawable(Pixmap, 
+//                                     Drawing->Drawing_Area_V->style->black_gc,
+//                                     icon_pixmap,
+//                                     0, 0, i, j, -1, -1);
+
+//             }
+//     }
+
+       test_draw_item(Drawing,Pixmap);
+       
+       //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
+       //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
+
+       //g_free(icon_pixmap);
+       //g_free(mask);
+
+
+
+
 
 
        pango_font_description_set_size(FontDesc, Font_Size);
+       g_object_unref(layout);
        g_free(gc);
-       g_free(layout);
-       //g_free(context);
 }
 
 void send_test_process(ProcessList *Process_List, Drawing_t *Drawing)
@@ -330,7 +402,7 @@ void send_test_process(ProcessList *Process_List, Drawing_t *Drawing)
        Process_List->Test_Process_Sent = TRUE;
 
 }
-
+#endif//NOTUSE
 
 
 /**
@@ -348,12 +420,24 @@ h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * ke
        ControlFlowData *Control_Flow_Data = guicontrolflow() ;
        
        Control_Flow_Data->Parent_Window = pmParentWindow;
+       TimeWindow *time_window = guicontrolflow_get_time_window(Control_Flow_Data);
+       time_window->start_time.tv_sec = 0;
+       time_window->start_time.tv_nsec = 0;
+       time_window->time_width.tv_sec = 0;
+       time_window->time_width.tv_nsec = 0;
 
+       LttTime *current_time = guicontrolflow_get_current_time(Control_Flow_Data);
+       current_time->tv_sec = 0;
+       current_time->tv_nsec = 0;
+       
+       //g_critical("time width1 : %u",time_window->time_width);
+       
        get_time_window(pmParentWindow,
-                       guicontrolflow_get_time_window(Control_Flow_Data));
+                       time_window);
        get_current_time(pmParentWindow,
-                       guicontrolflow_get_current_time(Control_Flow_Data));
+                       current_time);
 
+       //g_critical("time width2 : %u",time_window->time_width);
        // Unreg done in the GuiControlFlow_Destructor
        reg_update_time_window(update_time_window_hook, Control_Flow_Data,
                                pmParentWindow);
@@ -377,16 +461,15 @@ int event_selected_hook(void *hook_data, void *call_data)
 
 }
 
-#ifdef DEBUG
 /* Hook called before drawing. Gets the initial context at the beginning of the
  * drawing interval and copy it to the context in Event_Request.
  */
 int draw_before_hook(void *hook_data, void *call_data)
 {
        EventRequest *Event_Request = (EventRequest*)hook_data;
-       EventsContext Events_Context = (EventsContext*)call_data;
+       //EventsContext Events_Context = (EventsContext*)call_data;
        
-       Event_Request->Events_Context = Events_Context;
+       //Event_Request->Events_Context = Events_Context;
 
        return 0;
 }
@@ -414,7 +497,104 @@ int draw_before_hook(void *hook_data, void *call_data)
 int draw_event_hook(void *hook_data, void *call_data)
 {
        EventRequest *Event_Request = (EventRequest*)hook_data;
+       ControlFlowData *control_flow_data = Event_Request->Control_Flow_Data;
+       //static int i=0;
+
+       //i++;
+       //g_critical("%i", i);
+       LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
+
+  LttvTracefileState *tfs = (LttvTracefileState *)call_data;
+
+  LttEvent *e;
+  e = tfc->e;
+
+       /* Temp dump */
+#ifdef DONTSHOW
+       GString *string = g_string_new("");;
+       gboolean field_names = TRUE, state = TRUE;
+
+  lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
+  g_string_append_printf(string,"\n");  
+
+  if(state) {
+    g_string_append_printf(string, " %s",
+        g_quark_to_string(tfs->process->state->s));
+  }
+
+  g_info("%s",string->str);
+
+       g_string_free(string, TRUE);
        
+       /* End of text dump */
+#endif //DONTSHOW
+       /* Add process to process list (if not present) and get drawing "y" from
+        * process position */
+       guint pid = tfs->process->pid;
+       LttTime birth = tfs->process->creation_time;
+       gchar *name = strdup("name");
+       guint y = 0, height = 0, pl_height = 0;
+       HashedProcessData *Hashed_Process_Data = NULL;
+
+       ProcessList *process_list =
+               guicontrolflow_get_process_list(Event_Request->Control_Flow_Data);
+       
+       if(processlist_get_process_pixels(process_list,
+                                       pid,
+                                       &birth,
+                                       &y,
+                                       &height,
+                                       &Hashed_Process_Data) == 1)
+       {
+               /* Process not present */
+               processlist_add(process_list,
+                               pid,
+                               &birth,
+                               name,
+                               &pl_height,
+                               &Hashed_Process_Data);
+               g_free(name);
+               drawing_insert_square( Event_Request->Control_Flow_Data->Drawing, y, height);
+       }
+       
+       /* Find pixels corresponding to time of the event. If the time does
+        * not fit in the window, show a warning, not supposed to happend. */
+       guint x = 0;
+       guint width = control_flow_data->Drawing->Drawing_Area_V->allocation.width;
+
+       LttTime time = ltt_event_time(e);
+
+       LttTime window_end = ltt_time_add(control_flow_data->Time_Window.time_width,
+                                                                                               control_flow_data->Time_Window.start_time);
+
+       
+       convert_time_to_pixels(
+                       control_flow_data->Time_Window.start_time,
+                       window_end,
+                       time,
+                       width,
+                       &x);
+       
+       assert(x <= width);
+       
+       /* Finally, draw what represents the event. */
+
+       GdkColor color = { 0, 0xffff, 0x0000, 0x0000 };
+       PropertiesArc prop_arc;
+       prop_arc.color = &color;
+       prop_arc.size = 10;
+       prop_arc.filled = TRUE;
+       prop_arc.position = OVER;
+       DrawContext *draw_context = Hashed_Process_Data->draw_context;
+       draw_context->Current->modify_over->x = x;
+       draw_context->Current->modify_over->y = y;
+       draw_context->drawable = control_flow_data->Drawing->Pixmap;
+       GtkWidget *widget = control_flow_data->Drawing->Drawing_Area_V;
+       //draw_context->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
+       draw_context->gc = widget->style->black_gc;
+       
+       draw_arc((void*)&prop_arc, (void*)draw_context);
+       //test_draw_item(control_flow_data->Drawing, control_flow_data->Drawing->Pixmap);
        return 0;
 }
 
@@ -426,41 +606,199 @@ int draw_after_hook(void *hook_data, void *call_data)
        g_free(Event_Request);
        return 0;
 }
-#endif
 
 
 
 
 void update_time_window_hook(void *hook_data, void *call_data)
 {
-       ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
-       TimeWindowTime_Window = 
-               guicontrolflow_get_time_window(Control_Flow_Data);
+       ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
+       TimeWindow *Old_Time_Window = 
+               guicontrolflow_get_time_window(control_flow_data);
        TimeWindow *New_Time_Window = ((TimeWindow*)call_data);
-
-       // As the time interval change will mostly be used for
-       // zoom in and out, it's not useful to keep old drawing
-       // sections, as scale will be changed.
        
+       /* Two cases : zoom in/out or scrolling */
+       
+       /* In order to make sure we can reuse the old drawing, the scale must
+        * be the same and the new time interval being partly located in the
+        * currently shown time interval. (reuse is only for scrolling)
+        */
+
+       g_info("Old time window HOOK : %u, %u to %u, %u",
+                       Old_Time_Window->start_time.tv_sec,
+                       Old_Time_Window->start_time.tv_nsec,
+                       Old_Time_Window->time_width.tv_sec,
+                       Old_Time_Window->time_width.tv_nsec);
 
-       *Time_Window = *New_Time_Window;
        g_info("New time window HOOK : %u, %u to %u, %u",
-                       Time_Window->start_time.tv_sec,
-                       Time_Window->start_time.tv_nsec,
-                       Time_Window->time_width.tv_sec,
-                       Time_Window->time_width.tv_nsec);
-
-  drawing_data_request(Control_Flow_Data->Drawing,
-                       &Control_Flow_Data->Drawing->Pixmap,
-                       0, 0,
-                       Control_Flow_Data->Drawing->width,
-                       Control_Flow_Data->Drawing->height);
-
-       drawing_refresh(Control_Flow_Data->Drawing,
-                       0, 0,
-                       Control_Flow_Data->Drawing->width,
-                       Control_Flow_Data->Drawing->height);
+                       New_Time_Window->start_time.tv_sec,
+                       New_Time_Window->start_time.tv_nsec,
+                       New_Time_Window->time_width.tv_sec,
+                       New_Time_Window->time_width.tv_nsec);
+
+       if( New_Time_Window->time_width.tv_sec == Old_Time_Window->time_width.tv_sec
+       && New_Time_Window->time_width.tv_nsec == Old_Time_Window->time_width.tv_nsec)
+       {
+               /* Same scale (scrolling) */
+               g_info("scrolling");
+               LttTime *ns = &New_Time_Window->start_time;
+               LttTime *os = &Old_Time_Window->start_time;
+               LttTime old_end = ltt_time_add(Old_Time_Window->start_time,
+                                                                                                                                               Old_Time_Window->time_width);
+               LttTime new_end = ltt_time_add(New_Time_Window->start_time,
+                                                                                                                                               New_Time_Window->time_width);
+               //if(ns<os+w<ns+w)
+               //if(ns<os+w && os+w<ns+w)
+               //if(ns<old_end && os<ns)
+               if(ltt_time_compare(*ns, old_end) == -1
+                               && ltt_time_compare(*os, *ns) == -1)
+               {
+                       g_info("scrolling near right");
+                       /* Scroll right, keep right part of the screen */
+                       guint x = 0;
+                       guint width = control_flow_data->Drawing->Drawing_Area_V->allocation.width;
+                       convert_time_to_pixels(
+                                       *os,
+                                       old_end,
+                                       *ns,
+                                       width,
+                                       &x);
+
+                 /* Copy old data to new location */
+                 gdk_draw_drawable (control_flow_data->Drawing->Pixmap,
+                                 control_flow_data->Drawing->Drawing_Area_V->style->white_gc,
+                                 control_flow_data->Drawing->Pixmap,
+                                 x, 0,
+                                 0, 0,
+                                 -1, -1);
+                       
+                       convert_time_to_pixels(
+                                       *ns,
+                                       new_end,
+                                       old_end,
+                                       width,
+                                       &x);
+
+                       *Old_Time_Window = *New_Time_Window;
+                       /* Clear the data request background, but not SAFETY */
+                       gdk_draw_rectangle (control_flow_data->Drawing->Pixmap,
+                                       control_flow_data->Drawing->Drawing_Area_V->style->white_gc,
+                     TRUE,
+                     x+SAFETY, 0,
+                     control_flow_data->Drawing->width - x,    // do not overlap
+                     control_flow_data->Drawing->height+SAFETY);
+                       /* Get new data for the rest. */
+                 drawing_data_request(control_flow_data->Drawing,
+                                       &control_flow_data->Drawing->Pixmap,
+                                       x, 0,
+                                       control_flow_data->Drawing->width - x,
+                                       control_flow_data->Drawing->height);
+       
+                       drawing_refresh(control_flow_data->Drawing,
+                                       0, 0,
+                                       control_flow_data->Drawing->width,
+                                       control_flow_data->Drawing->height);
+
+
+               } else { 
+                       //if(ns<os<ns+w)
+                       //if(ns<os && os<ns+w)
+                       //if(ns<os && os<new_end)
+                       if(ltt_time_compare(*ns,*os) == -1
+                                       && ltt_time_compare(*os,new_end) == -1)
+                       {
+                               g_info("scrolling near left");
+                               /* Scroll left, keep left part of the screen */
+                               guint x = 0;
+                               guint width = control_flow_data->Drawing->Drawing_Area_V->allocation.width;
+                               convert_time_to_pixels(
+                                               *ns,
+                                               new_end,
+                                               *os,
+                                               width,
+                                               &x);
+       
+                         /* Copy old data to new location */
+                         gdk_draw_drawable (control_flow_data->Drawing->Pixmap,
+                                       control_flow_data->Drawing->Drawing_Area_V->style->white_gc,
+                                         control_flow_data->Drawing->Pixmap,
+                                         0, 0,
+                                         x, 0,
+                                         -1, -1);
+       
+                               *Old_Time_Window = *New_Time_Window;
+
+                               /* Clean the data request background */
+                               gdk_draw_rectangle (control_flow_data->Drawing->Pixmap,
+                                       control_flow_data->Drawing->Drawing_Area_V->style->white_gc,
+                     TRUE,
+                     0, 0,
+                     x,        // do not overlap
+                     control_flow_data->Drawing->height+SAFETY);
+                               /* Get new data for the rest. */
+                         drawing_data_request(control_flow_data->Drawing,
+                                               &control_flow_data->Drawing->Pixmap,
+                                               0, 0,
+                                               x,
+                                               control_flow_data->Drawing->height);
+               
+                               drawing_refresh(control_flow_data->Drawing,
+                                               0, 0,
+                                               control_flow_data->Drawing->width,
+                                               control_flow_data->Drawing->height);
+                               
+                       } else {
+                               g_info("scrolling far");
+                               /* Cannot reuse any part of the screen : far jump */
+                               *Old_Time_Window = *New_Time_Window;
+                               
+                               
+                               gdk_draw_rectangle (control_flow_data->Drawing->Pixmap,
+                                       control_flow_data->Drawing->Drawing_Area_V->style->white_gc,
+                     TRUE,
+                     0, 0,
+                     control_flow_data->Drawing->width+SAFETY, // do not overlap
+                     control_flow_data->Drawing->height+SAFETY);
+
+                               drawing_data_request(control_flow_data->Drawing,
+                                               &control_flow_data->Drawing->Pixmap,
+                                               0, 0,
+                                               control_flow_data->Drawing->width,
+                                               control_flow_data->Drawing->height);
+               
+                               drawing_refresh(control_flow_data->Drawing,
+                                               0, 0,
+                                               control_flow_data->Drawing->width,
+                                               control_flow_data->Drawing->height);
+                       }
+               }
+       } else {
+               /* Different scale (zoom) */
+               g_info("zoom");
+
+               *Old_Time_Window = *New_Time_Window;
+       
+               gdk_draw_rectangle (control_flow_data->Drawing->Pixmap,
+                                       control_flow_data->Drawing->Drawing_Area_V->style->white_gc,
+                     TRUE,
+                     0, 0,
+                     control_flow_data->Drawing->width+SAFETY, // do not overlap
+                     control_flow_data->Drawing->height+SAFETY);
+
+       
+         drawing_data_request(control_flow_data->Drawing,
+                               &control_flow_data->Drawing->Pixmap,
+                               0, 0,
+                               control_flow_data->Drawing->width,
+                               control_flow_data->Drawing->height);
+       
+               drawing_refresh(control_flow_data->Drawing,
+                               0, 0,
+                               control_flow_data->Drawing->width,
+                               control_flow_data->Drawing->height);
+       }
 
+       
 }
 
 void update_current_time_hook(void *hook_data, void *call_data)
This page took 0.029586 seconds and 4 git commands to generate.