1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 #include <lttv/lttv.h>
23 #include <lttv/tracecontext.h>
24 #include <lttv/gtktraceset.h>
25 #include <lttv/hook.h>
29 #include "cfv-private.h"
30 #include "eventhooks.h"
32 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
33 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
35 /*****************************************************************************
37 *****************************************************************************/
40 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
43 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
46 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
57 /* Vector of unallocated colors */
58 static GdkColor CF_Colors
[] =
60 { 0, 0xffff, 0x0000, 0x0000 }, // RED
61 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
62 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
63 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
64 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
68 /* Function responsible for updating the exposed area.
69 * It must call processTrace() to ask for this update.
70 * Note : this function cannot clear the background, because it may
71 * erase drawing already present (SAFETY).
73 void drawing_data_request(Drawing_t
*drawing
,
79 if(width
< 0) return ;
80 if(height
< 0) return ;
81 ControlFlowData
*control_flow_data
=
82 (ControlFlowData
*)g_object_get_data(
84 drawing
->drawing_area
),
88 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
89 control_flow_data
->time_window
.start_time
);
91 g_debug("req : window_end : %u, %u", window_end
.tv_sec
,
94 g_debug("req : time width : %u, %u", control_flow_data
->time_window
.time_width
.tv_sec
,
95 control_flow_data
->time_window
.time_width
.tv_nsec
);
97 g_debug("x is : %i, x+width is : %i", x
, x
+width
);
99 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
,
100 &control_flow_data
->time_window
.start_time
,
104 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
+ width
,
105 &control_flow_data
->time_window
.start_time
,
109 LttvTracesetContext
* tsc
=
110 get_traceset_context(control_flow_data
->mw
);
111 LttvTracesetState
* tss
=
112 (LttvTracesetState
*)tsc
;
115 //guicontrolflow_get_process_list(drawing->control_flow_data),
118 //guicontrolflow_get_process_list(drawing->control_flow_data),
119 //drawing, *pixmap, x, y, width, height);
121 // Let's call processTrace() !!
122 EventRequest event_request
; // Variable freed at the end of the function.
123 event_request
.control_flow_data
= control_flow_data
;
124 event_request
.time_begin
= start
;
125 event_request
.time_end
= end
;
126 event_request
.x_begin
= x
;
127 event_request
.x_end
= x
+width
;
129 g_debug("req : start : %u, %u", event_request
.time_begin
.tv_sec
,
130 event_request
.time_begin
.tv_nsec
);
132 g_debug("req : end : %u, %u", event_request
.time_end
.tv_sec
,
133 event_request
.time_end
.tv_nsec
);
135 LttvHooks
*event
= lttv_hooks_new();
136 LttvHooks
*after_event
= lttv_hooks_new();
137 LttvHooks
*after_traceset
= lttv_hooks_new();
138 lttv_hooks_add(after_traceset
, after_data_request
, &event_request
);
139 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
140 //Modified by xiangxiu: state update hooks are added by the main window
141 //state_add_event_hooks_api(control_flow_data->mw);
142 lttv_hooks_add(after_event
, draw_after_hook
, &event_request
);
144 //lttv_process_traceset_seek_time(tsc, start);
145 lttv_state_traceset_seek_time_closest(tss
, start
);
146 // FIXME : would like to place the after_traceset hook after the traceset,
147 // but the traceset context state is not valid anymore.
148 lttv_traceset_context_add_hooks(tsc
,
149 NULL
, after_traceset
, NULL
, NULL
, NULL
, NULL
,
150 //NULL, NULL, NULL, NULL, NULL, NULL,
151 NULL
, NULL
, NULL
, event
, after_event
);
152 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
153 //after_data_request((void*)&event_request,(void*)tsc);
154 lttv_traceset_context_remove_hooks(tsc
,
155 NULL
, after_traceset
, NULL
, NULL
, NULL
, NULL
,
156 // NULL, NULL, NULL, NULL, NULL, NULL,
157 NULL
, NULL
, NULL
, event
, after_event
);
158 //Modified by xiangxiu: state update hooks are removed by the main window
159 //state_remove_event_hooks_api(control_flow_data->mw);
161 lttv_hooks_destroy(after_traceset
);
162 lttv_hooks_destroy(event
);
163 lttv_hooks_destroy(after_event
);
171 /* Create a new backing pixmap of the appropriate size */
172 /* As the scaling will always change, it's of no use to copy old
176 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
179 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
182 /* First, get the new time interval of the main window */
183 /* we assume (see documentation) that the main window
184 * has updated the time interval before this configure gets
187 get_time_window(drawing
->control_flow_data
->mw
,
188 &drawing
->control_flow_data
->time_window
);
190 /* New pixmap, size of the configure event */
191 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
192 // widget->allocation.width + SAFETY,
193 // widget->allocation.height + SAFETY,
196 g_debug("drawing configure event");
197 g_debug("New draw size : %i by %i",widget
->allocation
.width
, widget
->allocation
.height
);
201 gdk_pixmap_unref(drawing
->pixmap
);
203 /* If no old pixmap present */
204 //if(drawing->pixmap == NULL)
206 drawing
->pixmap
= gdk_pixmap_new(
208 widget
->allocation
.width
+ SAFETY
,
209 widget
->allocation
.height
+ SAFETY
,
210 //ProcessList_get_height
211 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
213 drawing
->width
= widget
->allocation
.width
;
214 drawing
->height
= widget
->allocation
.height
;
218 gdk_draw_rectangle (drawing
->pixmap
,
219 widget
->style
->black_gc
,
222 widget
->allocation
.width
+SAFETY
,
223 widget
->allocation
.height
+SAFETY
);
225 //g_info("init data request");
228 /* Initial data request */
229 // Do not need to ask for data of 1 pixel : not synchronized with
230 // main window time at this moment.
231 drawing_data_request(drawing
, &drawing
->pixmap
, 0, 0,
232 widget
->allocation
.width
,
233 widget
->allocation
.height
);
235 drawing
->width
= widget
->allocation
.width
;
236 drawing
->height
= widget
->allocation
.height
;
244 // /* Draw empty background */
245 // gdk_draw_rectangle (pixmap,
246 // widget->style->black_gc,
249 // widget->allocation.width,
250 // widget->allocation.height);
252 /* Copy old data to new pixmap */
253 gdk_draw_drawable (pixmap
,
254 widget
->style
->black_gc
,
261 gdk_pixmap_unref(drawing
->pixmap
);
263 drawing
->pixmap
= pixmap
;
265 // Clear the bottom part of the image (SAFETY)
266 gdk_draw_rectangle (pixmap
,
267 widget
->style
->black_gc
,
269 0, drawing
->height
+SAFETY
,
270 drawing
->width
+SAFETY
, // do not overlap
271 (widget
->allocation
.height
) - drawing
->height
);
273 // Clear the right part of the image (SAFETY)
274 gdk_draw_rectangle (pixmap
,
275 widget
->style
->black_gc
,
277 drawing
->width
+SAFETY
, 0,
278 (widget
->allocation
.width
) - drawing
->width
, // do not overlap
279 drawing
->height
+SAFETY
);
281 /* Clear the backgound for data request, but not SAFETY */
282 gdk_draw_rectangle (pixmap
,
283 drawing
->drawing_area
->style
->black_gc
,
285 drawing
->width
+ SAFETY
, 0,
286 widget
->allocation
.width
- drawing
->width
, // do not overlap
287 widget
->allocation
.height
+SAFETY
);
289 /* Request data for missing space */
290 g_info("missing data request");
291 drawing_data_request(drawing
, &pixmap
, drawing
->width
, 0,
292 widget
->allocation
.width
- drawing
->width
,
293 widget
->allocation
.height
);
295 drawing
->width
= widget
->allocation
.width
;
296 drawing
->height
= widget
->allocation
.height
;
303 /* Redraw the screen from the backing pixmap */
305 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
307 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
308 ControlFlowData
*control_flow_data
=
309 (ControlFlowData
*)g_object_get_data(
311 "control_flow_data");
313 g_debug("drawing expose event");
316 LttTime
* current_time
=
317 guicontrolflow_get_current_time(control_flow_data
);
319 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
320 control_flow_data
->time_window
.start_time
);
322 convert_time_to_pixels(
323 control_flow_data
->time_window
.start_time
,
326 widget
->allocation
.width
,
329 gdk_draw_pixmap(widget
->window
,
330 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
332 event
->area
.x
, event
->area
.y
,
333 event
->area
.x
, event
->area
.y
,
334 event
->area
.width
, event
->area
.height
);
336 if(x
>= event
->area
.x
&& x
<= event
->area
.x
+event
->area
.width
)
338 gint8 dash_list
[] = { 1, 2 };
339 GdkGC
*gc
= gdk_gc_new(control_flow_data
->drawing
->pixmap
);
340 gdk_gc_copy(gc
, widget
->style
->white_gc
);
341 gdk_gc_set_line_attributes(gc
,
343 GDK_LINE_ON_OFF_DASH
,
346 gdk_gc_set_dashes(gc
,
350 drawing_draw_line(NULL
, widget
->window
,
352 x
, event
->area
.y
+event
->area
.height
,
361 button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
363 ControlFlowData
*control_flow_data
=
364 (ControlFlowData
*)g_object_get_data(
366 "control_flow_data");
367 Drawing_t
*drawing
= control_flow_data
->drawing
;
371 if(event
->button
== 1)
375 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
376 control_flow_data
->time_window
.start_time
);
379 /* left mouse button click */
380 g_debug("x click is : %f", event
->x
);
382 convert_pixels_to_time(widget
->allocation
.width
, (guint
)event
->x
,
383 &control_flow_data
->time_window
.start_time
,
387 set_current_time(control_flow_data
->mw
, &time
);
391 set_focused_pane(control_flow_data
->mw
, gtk_widget_get_parent(control_flow_data
->scrolled_window
));
399 Drawing_t
*drawing_construct(ControlFlowData
*control_flow_data
)
401 Drawing_t
*drawing
= g_new(Drawing_t
, 1);
403 drawing
->control_flow_data
= control_flow_data
;
405 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
406 drawing
->ruler
= gtk_drawing_area_new ();
407 gtk_widget_set_size_request(drawing
->ruler
, -1, 27);
409 drawing
->drawing_area
= gtk_drawing_area_new ();
411 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler
,
413 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->drawing_area
,
416 drawing
->pango_layout
=
417 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
419 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
420 g_object_set_data_full(
421 G_OBJECT(drawing
->drawing_area
),
424 (GDestroyNotify
)drawing_destroy
);
427 G_OBJECT(drawing
->ruler
),
432 //gtk_widget_modify_bg( drawing->drawing_area,
434 // &CF_Colors[BLACK]);
436 //gdk_window_get_geometry(drawing->drawing_area->window,
438 // &(drawing->width),
439 // &(drawing->height),
442 //drawing->pixmap = gdk_pixmap_new(
443 // drawing->drawing_area->window,
448 drawing
->pixmap
= NULL
;
450 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
451 // drawing->drawing_area->allocation.width,
452 // drawing->drawing_area->allocation.height,
455 gtk_widget_add_events(drawing
->drawing_area
, GDK_BUTTON_PRESS_MASK
);
457 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
459 G_CALLBACK (configure_event
),
462 g_signal_connect (G_OBJECT(drawing
->ruler
),
464 G_CALLBACK(expose_ruler
),
467 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
469 g_signal_connect (G_OBJECT(drawing
->ruler
),
470 "motion-notify-event",
471 G_CALLBACK(motion_notify_ruler
),
475 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
477 G_CALLBACK (expose_event
),
480 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
481 "button-press-event",
482 G_CALLBACK (button_press_event
),
485 gtk_widget_show(drawing
->ruler
);
486 gtk_widget_show(drawing
->drawing_area
);
492 void drawing_destroy(Drawing_t
*drawing
)
495 // Do not unref here, Drawing_t destroyed by it's widget.
496 //g_object_unref( G_OBJECT(drawing->drawing_area));
498 g_free(drawing
->pango_layout
);
502 GtkWidget
*drawing_get_drawing_area(Drawing_t
*drawing
)
504 return drawing
->drawing_area
;
507 GtkWidget
*drawing_get_widget(Drawing_t
*drawing
)
509 return drawing
->vbox
;
512 /* convert_pixels_to_time
514 * Convert from window pixel and time interval to an absolute time.
516 void convert_pixels_to_time(
519 LttTime
*window_time_begin
,
520 LttTime
*window_time_end
,
523 LttTime window_time_interval
;
525 window_time_interval
= ltt_time_sub(*window_time_end
,
527 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
528 *time
= ltt_time_add(*window_time_begin
, *time
);
533 void convert_time_to_pixels(
534 LttTime window_time_begin
,
535 LttTime window_time_end
,
540 LttTime window_time_interval
;
541 float interval_float
, time_float
;
543 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
545 time
= ltt_time_sub(time
, window_time_begin
);
547 interval_float
= ltt_time_to_double(window_time_interval
);
548 time_float
= ltt_time_to_double(time
);
550 *x
= (guint
)(time_float
/interval_float
* width
);
554 void drawing_refresh ( Drawing_t
*drawing
,
556 guint width
, guint height
)
558 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
559 GdkRectangle update_rect
;
562 drawing
->drawing_area
->window
,
563 drawing
->drawing_area
->
564 style
->fg_gc
[GTK_WIDGET_STATE (drawing
->drawing_area
)],
565 GDK_DRAWABLE(drawing
->pixmap
),
572 update_rect
.width
= drawing
->width
;
573 update_rect
.height
= drawing
->height
;
574 gtk_widget_draw( drawing
->drawing_area
, &update_rect
);
579 void drawing_draw_line( Drawing_t
*drawing
,
585 gdk_draw_line (pixmap
,
593 void drawing_resize(Drawing_t
*drawing
, guint h
, guint w
)
595 drawing
->height
= h
;
598 gtk_widget_set_size_request ( drawing
->drawing_area
,
606 /* Insert a square corresponding to a new process in the list */
607 /* Applies to whole drawing->width */
608 void drawing_insert_square(Drawing_t
*drawing
,
612 //GdkRectangle update_rect;
614 /* Allocate a new pixmap with new height */
615 GdkPixmap
*pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
616 drawing
->width
+ SAFETY
,
617 drawing
->height
+ height
+ SAFETY
,
620 /* Copy the high region */
621 gdk_draw_drawable (pixmap
,
622 drawing
->drawing_area
->style
->black_gc
,
626 drawing
->width
+ SAFETY
, y
);
631 /* add an empty square */
632 gdk_draw_rectangle (pixmap
,
633 drawing
->drawing_area
->style
->black_gc
,
636 drawing
->width
+ SAFETY
, // do not overlap
641 /* copy the bottom of the region */
642 gdk_draw_drawable (pixmap
,
643 drawing
->drawing_area
->style
->black_gc
,
647 drawing
->width
+SAFETY
, drawing
->height
- y
+ SAFETY
);
653 gdk_pixmap_unref(drawing
->pixmap
);
655 drawing
->pixmap
= pixmap
;
657 drawing
->height
+=height
;
659 /* Rectangle to update, from new drawing dimensions */
660 //update_rect.x = 0 ;
661 //update_rect.y = y ;
662 //update_rect.width = drawing->width;
663 //update_rect.height = drawing->height - y ;
664 //gtk_widget_draw( drawing->drawing_area, &update_rect);
668 /* Remove a square corresponding to a removed process in the list */
669 void drawing_remove_square(Drawing_t
*drawing
,
673 //GdkRectangle update_rect;
675 /* Allocate a new pixmap with new height */
676 GdkPixmap
*pixmap
= gdk_pixmap_new(
677 drawing
->drawing_area
->window
,
678 drawing
->width
+ SAFETY
,
679 drawing
->height
- height
+ SAFETY
,
682 /* Copy the high region */
683 gdk_draw_drawable (pixmap
,
684 drawing
->drawing_area
->style
->black_gc
,
688 drawing
->width
+ SAFETY
, y
);
692 /* Copy up the bottom of the region */
693 gdk_draw_drawable (pixmap
,
694 drawing
->drawing_area
->style
->black_gc
,
698 drawing
->width
, drawing
->height
- y
- height
+ SAFETY
);
702 gdk_pixmap_unref(drawing
->pixmap
);
704 drawing
->pixmap
= pixmap
;
706 drawing
->height
-=height
;
708 /* Rectangle to update, from new drawing dimensions */
709 //update_rect.x = 0 ;
710 //update_rect.y = y ;
711 //update_rect.width = drawing->width;
712 //update_rect.height = drawing->height - y ;
713 //gtk_widget_draw( drawing->drawing_area, &update_rect);
716 void drawing_update_ruler(Drawing_t
*drawing
, TimeWindow
*time_window
)
721 req
.width
= drawing
->ruler
->allocation
.width
;
722 req
.height
= drawing
->ruler
->allocation
.height
;
727 rect
.width
= req
.width
;
728 rect
.height
= req
.height
;
730 gtk_widget_queue_draw(drawing
->ruler
);
731 //gtk_widget_draw( drawing->ruler, &rect);
734 /* Redraw the ruler */
736 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
738 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
742 PangoContext
*context
;
744 PangoAttribute
*attribute
;
745 PangoFontDescription
*FontDesc
;
747 PangoRectangle ink_rect
;
748 guint global_width
=0;
749 GdkColor foreground
= { 0, 0, 0, 0 };
750 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
753 ltt_time_add(drawing
->control_flow_data
->time_window
.time_width
,
754 drawing
->control_flow_data
->time_window
.start_time
);
756 ltt_time_div(drawing
->control_flow_data
->time_window
.time_width
,2.0);
757 LttTime window_middle
=
758 ltt_time_add(half_width
,
759 drawing
->control_flow_data
->time_window
.start_time
);
760 g_debug("ruler expose event");
762 gdk_draw_rectangle (drawing
->ruler
->window
,
763 drawing
->ruler
->style
->white_gc
,
765 event
->area
.x
, event
->area
.y
,
769 GdkGC
*gc
= gdk_gc_new(drawing
->ruler
->window
);
770 gdk_gc_copy(gc
, drawing
->ruler
->style
->black_gc
);
771 gdk_gc_set_line_attributes(gc
,
776 gdk_draw_line (drawing
->ruler
->window
,
779 event
->area
.x
+ event
->area
.width
, 1);
782 snprintf(text
, 255, "%lus\n%luns",
783 drawing
->control_flow_data
->time_window
.start_time
.tv_sec
,
784 drawing
->control_flow_data
->time_window
.start_time
.tv_nsec
);
786 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
788 context
= pango_layout_get_context(layout
);
789 FontDesc
= pango_context_get_font_description(context
);
791 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
792 pango_layout_context_changed(layout
);
794 pango_layout_set_text(layout
, text
, -1);
795 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
796 global_width
+= ink_rect
.width
;
798 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
802 layout
, &foreground
, &background
);
804 gdk_gc_set_line_attributes(gc
,
810 gdk_draw_line (drawing
->ruler
->window
,
816 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
819 pango_layout_set_text(layout
, text
, -1);
820 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
821 global_width
+= ink_rect
.width
;
823 if(global_width
<= drawing
->ruler
->allocation
.width
)
825 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
827 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
829 layout
, &foreground
, &background
);
831 gdk_gc_set_line_attributes(gc
,
837 gdk_draw_line (drawing
->ruler
->window
,
839 drawing
->ruler
->allocation
.width
-1, 1,
840 drawing
->ruler
->allocation
.width
-1, 7);
844 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
845 window_middle
.tv_nsec
);
847 pango_layout_set_text(layout
, text
, -1);
848 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
849 global_width
+= ink_rect
.width
;
851 if(global_width
<= drawing
->ruler
->allocation
.width
)
853 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
855 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
857 layout
, &foreground
, &background
);
859 gdk_gc_set_line_attributes(gc
,
865 gdk_draw_line (drawing
->ruler
->window
,
867 drawing
->ruler
->allocation
.width
/2, 1,
868 drawing
->ruler
->allocation
.width
/2, 7);
876 g_object_unref(layout
);
882 /* notify mouse on ruler */
884 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
887 //eventually follow mouse and show time here