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/processTrace.h>
23 #include <lttv/gtktraceset.h>
24 #include <lttv/hook.h>
28 #include "cfv-private.h"
29 #include "eventhooks.h"
31 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
32 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
34 /*****************************************************************************
36 *****************************************************************************/
39 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
42 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
45 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
56 /* Vector of unallocated colors */
57 static GdkColor CF_Colors
[] =
59 { 0, 0xffff, 0x0000, 0x0000 }, // RED
60 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
61 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
62 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
63 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
67 /* Function responsible for updating the exposed area.
68 * It must call processTrace() to ask for this update.
69 * Note : this function cannot clear the background, because it may
70 * erase drawing already present (SAFETY).
72 void drawing_data_request(Drawing_t
*drawing
,
78 if(width
< 0) return ;
79 if(height
< 0) return ;
80 ControlFlowData
*control_flow_data
=
81 (ControlFlowData
*)g_object_get_data(
83 drawing
->drawing_area
),
87 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
88 control_flow_data
->time_window
.start_time
);
90 g_critical("req : window_end : %u, %u", window_end
.tv_sec
,
93 g_critical("req : time width : %u, %u", control_flow_data
->time_window
.time_width
.tv_sec
,
94 control_flow_data
->time_window
.time_width
.tv_nsec
);
96 g_critical("x is : %i, x+width is : %i", x
, x
+width
);
98 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
,
99 &control_flow_data
->time_window
.start_time
,
103 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
+ width
,
104 &control_flow_data
->time_window
.start_time
,
108 LttvTracesetContext
* tsc
=
109 get_traceset_context(control_flow_data
->mw
);
110 LttvTracesetState
* tss
=
111 (LttvTracesetState
*)tsc
;
114 //guicontrolflow_get_process_list(drawing->control_flow_data),
117 //guicontrolflow_get_process_list(drawing->control_flow_data),
118 //drawing, *pixmap, x, y, width, height);
120 // Let's call processTrace() !!
121 EventRequest event_request
; // Variable freed at the end of the function.
122 event_request
.control_flow_data
= control_flow_data
;
123 event_request
.time_begin
= start
;
124 event_request
.time_end
= end
;
125 event_request
.x_begin
= x
;
126 event_request
.x_end
= x
+width
;
128 g_critical("req : start : %u, %u", event_request
.time_begin
.tv_sec
,
129 event_request
.time_begin
.tv_nsec
);
131 g_critical("req : end : %u, %u", event_request
.time_end
.tv_sec
,
132 event_request
.time_end
.tv_nsec
);
134 LttvHooks
*event
= lttv_hooks_new();
135 LttvHooks
*after_event
= lttv_hooks_new();
136 LttvHooks
*after_traceset
= lttv_hooks_new();
137 lttv_hooks_add(after_traceset
, after_data_request
, &event_request
);
138 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
139 //Modified by xiangxiu: state update hooks are added by the main window
140 //state_add_event_hooks_api(control_flow_data->mw);
141 lttv_hooks_add(after_event
, draw_after_hook
, &event_request
);
143 //lttv_process_traceset_seek_time(tsc, start);
144 lttv_state_traceset_seek_time_closest(tss
, start
);
145 // FIXME : would like to place the after_traceset hook after the traceset,
146 // but the traceset context state is not valid anymore.
147 lttv_traceset_context_add_hooks(tsc
,
148 NULL
, after_traceset
, NULL
, NULL
, NULL
, NULL
,
149 //NULL, NULL, NULL, NULL, NULL, NULL,
150 NULL
, NULL
, NULL
, event
, after_event
);
151 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
152 //after_data_request((void*)&event_request,(void*)tsc);
153 lttv_traceset_context_remove_hooks(tsc
,
154 NULL
, after_traceset
, NULL
, NULL
, NULL
, NULL
,
155 // NULL, NULL, NULL, NULL, NULL, NULL,
156 NULL
, NULL
, NULL
, event
, after_event
);
157 //Modified by xiangxiu: state update hooks are removed by the main window
158 //state_remove_event_hooks_api(control_flow_data->mw);
160 lttv_hooks_destroy(after_traceset
);
161 lttv_hooks_destroy(event
);
162 lttv_hooks_destroy(after_event
);
170 /* Create a new backing pixmap of the appropriate size */
171 /* As the scaling will always change, it's of no use to copy old
175 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
178 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
181 /* First, get the new time interval of the main window */
182 /* we assume (see documentation) that the main window
183 * has updated the time interval before this configure gets
186 get_time_window(drawing
->control_flow_data
->mw
,
187 &drawing
->control_flow_data
->time_window
);
189 /* New pixmap, size of the configure event */
190 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
191 // widget->allocation.width + SAFETY,
192 // widget->allocation.height + SAFETY,
195 g_critical("drawing configure event");
196 g_critical("New draw size : %i by %i",widget
->allocation
.width
, widget
->allocation
.height
);
200 gdk_pixmap_unref(drawing
->pixmap
);
202 /* If no old pixmap present */
203 //if(drawing->pixmap == NULL)
205 drawing
->pixmap
= gdk_pixmap_new(
207 widget
->allocation
.width
+ SAFETY
,
208 widget
->allocation
.height
+ SAFETY
,
209 //ProcessList_get_height
210 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
212 drawing
->width
= widget
->allocation
.width
;
213 drawing
->height
= widget
->allocation
.height
;
217 gdk_draw_rectangle (drawing
->pixmap
,
218 widget
->style
->black_gc
,
221 widget
->allocation
.width
+SAFETY
,
222 widget
->allocation
.height
+SAFETY
);
224 //g_info("init data request");
227 /* Initial data request */
228 // Do not need to ask for data of 1 pixel : not synchronized with
229 // main window time at this moment.
230 drawing_data_request(drawing
, &drawing
->pixmap
, 0, 0,
231 widget
->allocation
.width
,
232 widget
->allocation
.height
);
234 drawing
->width
= widget
->allocation
.width
;
235 drawing
->height
= widget
->allocation
.height
;
243 // /* Draw empty background */
244 // gdk_draw_rectangle (pixmap,
245 // widget->style->black_gc,
248 // widget->allocation.width,
249 // widget->allocation.height);
251 /* Copy old data to new pixmap */
252 gdk_draw_drawable (pixmap
,
253 widget
->style
->black_gc
,
260 gdk_pixmap_unref(drawing
->pixmap
);
262 drawing
->pixmap
= pixmap
;
264 // Clear the bottom part of the image (SAFETY)
265 gdk_draw_rectangle (pixmap
,
266 widget
->style
->black_gc
,
268 0, drawing
->height
+SAFETY
,
269 drawing
->width
+SAFETY
, // do not overlap
270 (widget
->allocation
.height
) - drawing
->height
);
272 // Clear the right part of the image (SAFETY)
273 gdk_draw_rectangle (pixmap
,
274 widget
->style
->black_gc
,
276 drawing
->width
+SAFETY
, 0,
277 (widget
->allocation
.width
) - drawing
->width
, // do not overlap
278 drawing
->height
+SAFETY
);
280 /* Clear the backgound for data request, but not SAFETY */
281 gdk_draw_rectangle (pixmap
,
282 drawing
->drawing_area
->style
->black_gc
,
284 drawing
->width
+ SAFETY
, 0,
285 widget
->allocation
.width
- drawing
->width
, // do not overlap
286 widget
->allocation
.height
+SAFETY
);
288 /* Request data for missing space */
289 g_info("missing data request");
290 drawing_data_request(drawing
, &pixmap
, drawing
->width
, 0,
291 widget
->allocation
.width
- drawing
->width
,
292 widget
->allocation
.height
);
294 drawing
->width
= widget
->allocation
.width
;
295 drawing
->height
= widget
->allocation
.height
;
302 /* Redraw the screen from the backing pixmap */
304 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
306 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
307 ControlFlowData
*control_flow_data
=
308 (ControlFlowData
*)g_object_get_data(
310 "control_flow_data");
312 g_critical("drawing expose event");
315 LttTime
* current_time
=
316 guicontrolflow_get_current_time(control_flow_data
);
318 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
319 control_flow_data
->time_window
.start_time
);
321 convert_time_to_pixels(
322 control_flow_data
->time_window
.start_time
,
325 widget
->allocation
.width
,
328 gdk_draw_pixmap(widget
->window
,
329 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
331 event
->area
.x
, event
->area
.y
,
332 event
->area
.x
, event
->area
.y
,
333 event
->area
.width
, event
->area
.height
);
335 if(x
>= event
->area
.x
&& x
<= event
->area
.x
+event
->area
.width
)
337 gint8 dash_list
[] = { 1, 2 };
338 GdkGC
*gc
= gdk_gc_new(control_flow_data
->drawing
->pixmap
);
339 gdk_gc_copy(gc
, widget
->style
->white_gc
);
340 gdk_gc_set_line_attributes(gc
,
342 GDK_LINE_ON_OFF_DASH
,
345 gdk_gc_set_dashes(gc
,
349 drawing_draw_line(NULL
, widget
->window
,
351 x
, event
->area
.y
+event
->area
.height
,
360 button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
362 ControlFlowData
*control_flow_data
=
363 (ControlFlowData
*)g_object_get_data(
365 "control_flow_data");
366 Drawing_t
*drawing
= control_flow_data
->drawing
;
370 if(event
->button
== 1)
374 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
375 control_flow_data
->time_window
.start_time
);
378 /* left mouse button click */
379 g_critical("x click is : %f", event
->x
);
381 convert_pixels_to_time(widget
->allocation
.width
, (guint
)event
->x
,
382 &control_flow_data
->time_window
.start_time
,
386 set_current_time(control_flow_data
->mw
, &time
);
390 set_focused_pane(control_flow_data
->mw
, gtk_widget_get_parent(control_flow_data
->scrolled_window
));
398 Drawing_t
*drawing_construct(ControlFlowData
*control_flow_data
)
400 Drawing_t
*drawing
= g_new(Drawing_t
, 1);
402 drawing
->control_flow_data
= control_flow_data
;
404 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
405 drawing
->ruler
= gtk_drawing_area_new ();
406 gtk_widget_set_size_request(drawing
->ruler
, -1, 27);
408 drawing
->drawing_area
= gtk_drawing_area_new ();
410 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler
,
412 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->drawing_area
,
415 drawing
->pango_layout
=
416 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
418 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
419 g_object_set_data_full(
420 G_OBJECT(drawing
->drawing_area
),
423 (GDestroyNotify
)drawing_destroy
);
426 G_OBJECT(drawing
->ruler
),
431 //gtk_widget_modify_bg( drawing->drawing_area,
433 // &CF_Colors[BLACK]);
435 //gdk_window_get_geometry(drawing->drawing_area->window,
437 // &(drawing->width),
438 // &(drawing->height),
441 //drawing->pixmap = gdk_pixmap_new(
442 // drawing->drawing_area->window,
447 drawing
->pixmap
= NULL
;
449 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
450 // drawing->drawing_area->allocation.width,
451 // drawing->drawing_area->allocation.height,
454 gtk_widget_add_events(drawing
->drawing_area
, GDK_BUTTON_PRESS_MASK
);
456 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
458 G_CALLBACK (configure_event
),
461 g_signal_connect (G_OBJECT(drawing
->ruler
),
463 G_CALLBACK(expose_ruler
),
466 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
468 g_signal_connect (G_OBJECT(drawing
->ruler
),
469 "motion-notify-event",
470 G_CALLBACK(motion_notify_ruler
),
474 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
476 G_CALLBACK (expose_event
),
479 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
480 "button-press-event",
481 G_CALLBACK (button_press_event
),
484 gtk_widget_show(drawing
->ruler
);
485 gtk_widget_show(drawing
->drawing_area
);
491 void drawing_destroy(Drawing_t
*drawing
)
494 // Do not unref here, Drawing_t destroyed by it's widget.
495 //g_object_unref( G_OBJECT(drawing->drawing_area));
497 g_free(drawing
->pango_layout
);
501 GtkWidget
*drawing_get_drawing_area(Drawing_t
*drawing
)
503 return drawing
->drawing_area
;
506 GtkWidget
*drawing_get_widget(Drawing_t
*drawing
)
508 return drawing
->vbox
;
511 /* convert_pixels_to_time
513 * Convert from window pixel and time interval to an absolute time.
515 void convert_pixels_to_time(
518 LttTime
*window_time_begin
,
519 LttTime
*window_time_end
,
522 LttTime window_time_interval
;
524 window_time_interval
= ltt_time_sub(*window_time_end
,
526 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
527 *time
= ltt_time_add(*window_time_begin
, *time
);
532 void convert_time_to_pixels(
533 LttTime window_time_begin
,
534 LttTime window_time_end
,
539 LttTime window_time_interval
;
540 float interval_float
, time_float
;
542 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
544 time
= ltt_time_sub(time
, window_time_begin
);
546 interval_float
= ltt_time_to_double(window_time_interval
);
547 time_float
= ltt_time_to_double(time
);
549 *x
= (guint
)(time_float
/interval_float
* width
);
553 void drawing_refresh ( Drawing_t
*drawing
,
555 guint width
, guint height
)
557 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
558 GdkRectangle update_rect
;
561 drawing
->drawing_area
->window
,
562 drawing
->drawing_area
->
563 style
->fg_gc
[GTK_WIDGET_STATE (drawing
->drawing_area
)],
564 GDK_DRAWABLE(drawing
->pixmap
),
571 update_rect
.width
= drawing
->width
;
572 update_rect
.height
= drawing
->height
;
573 gtk_widget_draw( drawing
->drawing_area
, &update_rect
);
578 void drawing_draw_line( Drawing_t
*drawing
,
584 gdk_draw_line (pixmap
,
592 void drawing_resize(Drawing_t
*drawing
, guint h
, guint w
)
594 drawing
->height
= h
;
597 gtk_widget_set_size_request ( drawing
->drawing_area
,
605 /* Insert a square corresponding to a new process in the list */
606 /* Applies to whole drawing->width */
607 void drawing_insert_square(Drawing_t
*drawing
,
611 //GdkRectangle update_rect;
613 /* Allocate a new pixmap with new height */
614 GdkPixmap
*pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
615 drawing
->width
+ SAFETY
,
616 drawing
->height
+ height
+ SAFETY
,
619 /* Copy the high region */
620 gdk_draw_drawable (pixmap
,
621 drawing
->drawing_area
->style
->black_gc
,
625 drawing
->width
+ SAFETY
, y
);
630 /* add an empty square */
631 gdk_draw_rectangle (pixmap
,
632 drawing
->drawing_area
->style
->black_gc
,
635 drawing
->width
+ SAFETY
, // do not overlap
640 /* copy the bottom of the region */
641 gdk_draw_drawable (pixmap
,
642 drawing
->drawing_area
->style
->black_gc
,
646 drawing
->width
+SAFETY
, drawing
->height
- y
+ SAFETY
);
652 gdk_pixmap_unref(drawing
->pixmap
);
654 drawing
->pixmap
= pixmap
;
656 drawing
->height
+=height
;
658 /* Rectangle to update, from new drawing dimensions */
659 //update_rect.x = 0 ;
660 //update_rect.y = y ;
661 //update_rect.width = drawing->width;
662 //update_rect.height = drawing->height - y ;
663 //gtk_widget_draw( drawing->drawing_area, &update_rect);
667 /* Remove a square corresponding to a removed process in the list */
668 void drawing_remove_square(Drawing_t
*drawing
,
672 //GdkRectangle update_rect;
674 /* Allocate a new pixmap with new height */
675 GdkPixmap
*pixmap
= gdk_pixmap_new(
676 drawing
->drawing_area
->window
,
677 drawing
->width
+ SAFETY
,
678 drawing
->height
- height
+ SAFETY
,
681 /* Copy the high region */
682 gdk_draw_drawable (pixmap
,
683 drawing
->drawing_area
->style
->black_gc
,
687 drawing
->width
+ SAFETY
, y
);
691 /* Copy up the bottom of the region */
692 gdk_draw_drawable (pixmap
,
693 drawing
->drawing_area
->style
->black_gc
,
697 drawing
->width
, drawing
->height
- y
- height
+ SAFETY
);
701 gdk_pixmap_unref(drawing
->pixmap
);
703 drawing
->pixmap
= pixmap
;
705 drawing
->height
-=height
;
707 /* Rectangle to update, from new drawing dimensions */
708 //update_rect.x = 0 ;
709 //update_rect.y = y ;
710 //update_rect.width = drawing->width;
711 //update_rect.height = drawing->height - y ;
712 //gtk_widget_draw( drawing->drawing_area, &update_rect);
715 void drawing_update_ruler(Drawing_t
*drawing
, TimeWindow
*time_window
)
720 req
.width
= drawing
->ruler
->allocation
.width
;
721 req
.height
= drawing
->ruler
->allocation
.height
;
726 rect
.width
= req
.width
;
727 rect
.height
= req
.height
;
729 gtk_widget_queue_draw(drawing
->ruler
);
730 //gtk_widget_draw( drawing->ruler, &rect);
733 /* Redraw the ruler */
735 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
737 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
741 PangoContext
*context
;
743 PangoAttribute
*attribute
;
744 PangoFontDescription
*FontDesc
;
746 PangoRectangle ink_rect
;
747 guint global_width
=0;
748 GdkColor foreground
= { 0, 0, 0, 0 };
749 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
752 ltt_time_add(drawing
->control_flow_data
->time_window
.time_width
,
753 drawing
->control_flow_data
->time_window
.start_time
);
755 ltt_time_div(drawing
->control_flow_data
->time_window
.time_width
,2.0);
756 LttTime window_middle
=
757 ltt_time_add(half_width
,
758 drawing
->control_flow_data
->time_window
.start_time
);
759 g_critical("ruler expose event");
761 gdk_draw_rectangle (drawing
->ruler
->window
,
762 drawing
->ruler
->style
->white_gc
,
764 event
->area
.x
, event
->area
.y
,
768 GdkGC
*gc
= gdk_gc_new(drawing
->ruler
->window
);
769 gdk_gc_copy(gc
, drawing
->ruler
->style
->black_gc
);
770 gdk_gc_set_line_attributes(gc
,
775 gdk_draw_line (drawing
->ruler
->window
,
778 event
->area
.x
+ event
->area
.width
, 1);
781 snprintf(text
, 255, "%lus\n%luns",
782 drawing
->control_flow_data
->time_window
.start_time
.tv_sec
,
783 drawing
->control_flow_data
->time_window
.start_time
.tv_nsec
);
785 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
787 context
= pango_layout_get_context(layout
);
788 FontDesc
= pango_context_get_font_description(context
);
790 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
791 pango_layout_context_changed(layout
);
793 pango_layout_set_text(layout
, text
, -1);
794 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
795 global_width
+= ink_rect
.width
;
797 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
801 layout
, &foreground
, &background
);
803 gdk_gc_set_line_attributes(gc
,
809 gdk_draw_line (drawing
->ruler
->window
,
815 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
818 pango_layout_set_text(layout
, text
, -1);
819 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
820 global_width
+= ink_rect
.width
;
822 if(global_width
<= drawing
->ruler
->allocation
.width
)
824 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
826 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
828 layout
, &foreground
, &background
);
830 gdk_gc_set_line_attributes(gc
,
836 gdk_draw_line (drawing
->ruler
->window
,
838 drawing
->ruler
->allocation
.width
-1, 1,
839 drawing
->ruler
->allocation
.width
-1, 7);
843 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
844 window_middle
.tv_nsec
);
846 pango_layout_set_text(layout
, text
, -1);
847 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
848 global_width
+= ink_rect
.width
;
850 if(global_width
<= drawing
->ruler
->allocation
.width
)
852 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
854 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
856 layout
, &foreground
, &background
);
858 gdk_gc_set_line_attributes(gc
,
864 gdk_draw_line (drawing
->ruler
->window
,
866 drawing
->ruler
->allocation
.width
/2, 1,
867 drawing
->ruler
->allocation
.width
/2, 7);
875 g_object_unref(layout
);
881 /* notify mouse on ruler */
883 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
885 //g_critical("motion");
886 //eventually follow mouse and show time here