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
);
43 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
54 /* Vector of unallocated colors */
55 static GdkColor CF_Colors
[] =
57 { 0, 0xffff, 0x0000, 0x0000 }, // RED
58 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
59 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
60 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
61 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
65 /* Function responsible for updating the exposed area.
66 * It must call processTrace() to ask for this update.
67 * Note : this function cannot clear the background, because it may
68 * erase drawing already present (SAFETY).
70 void drawing_data_request(Drawing_t
*drawing
,
76 if(width
< 0) return ;
77 if(height
< 0) return ;
78 ControlFlowData
*control_flow_data
=
79 (ControlFlowData
*)g_object_get_data(
81 drawing
->drawing_area
),
85 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
86 control_flow_data
->time_window
.start_time
);
88 g_critical("req : window_end : %u, %u", window_end
.tv_sec
,
91 g_critical("req : time width : %u, %u", control_flow_data
->time_window
.time_width
.tv_sec
,
92 control_flow_data
->time_window
.time_width
.tv_nsec
);
94 g_critical("x is : %i, x+width is : %i", x
, x
+width
);
96 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
,
97 &control_flow_data
->time_window
.start_time
,
101 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
+ width
,
102 &control_flow_data
->time_window
.start_time
,
106 LttvTracesetContext
* tsc
=
107 get_traceset_context(control_flow_data
->mw
);
110 //guicontrolflow_get_process_list(drawing->control_flow_data),
113 //guicontrolflow_get_process_list(drawing->control_flow_data),
114 //drawing, *pixmap, x, y, width, height);
116 // Let's call processTrace() !!
117 EventRequest event_request
; // Variable freed at the end of the function.
118 event_request
.control_flow_data
= control_flow_data
;
119 event_request
.time_begin
= start
;
120 event_request
.time_end
= end
;
121 event_request
.x_begin
= x
;
122 event_request
.x_end
= x
+width
;
124 g_critical("req : start : %u, %u", event_request
.time_begin
.tv_sec
,
125 event_request
.time_begin
.tv_nsec
);
127 g_critical("req : end : %u, %u", event_request
.time_end
.tv_sec
,
128 event_request
.time_end
.tv_nsec
);
130 LttvHooks
*event
= lttv_hooks_new();
131 LttvHooks
*after_event
= lttv_hooks_new();
132 LttvHooks
*after_traceset
= lttv_hooks_new();
133 lttv_hooks_add(after_traceset
, after_data_request
, &event_request
);
134 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
135 //Modified by xiangxiu: state update hooks are added by the main window
136 //state_add_event_hooks_api(control_flow_data->mw);
137 lttv_hooks_add(after_event
, draw_after_hook
, &event_request
);
139 lttv_process_traceset_seek_time(tsc
, start
);
140 // FIXME : would like to place the after_traceset hook after the traceset,
141 // but the traceset context state is not valid anymore.
142 lttv_traceset_context_add_hooks(tsc
,
143 // NULL, after_traceset, NULL, NULL, NULL, NULL,
144 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
145 NULL
, after_traceset
, NULL
, event
, after_event
);
146 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
147 //after_data_request((void*)&event_request,(void*)tsc);
148 lttv_traceset_context_remove_hooks(tsc
,
149 //NULL, after_traceset, NULL, NULL, NULL, NULL,
150 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
151 NULL
, after_traceset
, NULL
, event
, after_event
);
152 //Modified by xiangxiu: state update hooks are removed by the main window
153 //state_remove_event_hooks_api(control_flow_data->mw);
155 lttv_hooks_destroy(after_traceset
);
156 lttv_hooks_destroy(event
);
157 lttv_hooks_destroy(after_event
);
165 /* Create a new backing pixmap of the appropriate size */
166 /* As the scaling will always change, it's of no use to copy old
170 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
173 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
176 /* First, get the new time interval of the main window */
177 /* we assume (see documentation) that the main window
178 * has updated the time interval before this configure gets
181 get_time_window(drawing
->control_flow_data
->mw
,
182 &drawing
->control_flow_data
->time_window
);
184 /* New pixmap, size of the configure event */
185 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
186 // widget->allocation.width + SAFETY,
187 // widget->allocation.height + SAFETY,
190 g_critical("drawing configure event");
191 g_critical("New draw size : %i by %i",widget
->allocation
.width
, widget
->allocation
.height
);
195 gdk_pixmap_unref(drawing
->pixmap
);
197 /* If no old pixmap present */
198 //if(drawing->pixmap == NULL)
200 drawing
->pixmap
= gdk_pixmap_new(
202 widget
->allocation
.width
+ SAFETY
,
203 widget
->allocation
.height
+ SAFETY
,
204 //ProcessList_get_height
205 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
207 drawing
->width
= widget
->allocation
.width
;
208 drawing
->height
= widget
->allocation
.height
;
212 gdk_draw_rectangle (drawing
->pixmap
,
213 widget
->style
->black_gc
,
216 widget
->allocation
.width
+SAFETY
,
217 widget
->allocation
.height
+SAFETY
);
219 //g_info("init data request");
222 /* Initial data request */
223 // Do not need to ask for data of 1 pixel : not synchronized with
224 // main window time at this moment.
225 drawing_data_request(drawing
, &drawing
->pixmap
, 0, 0,
226 widget
->allocation
.width
,
227 widget
->allocation
.height
);
229 drawing
->width
= widget
->allocation
.width
;
230 drawing
->height
= widget
->allocation
.height
;
238 // /* Draw empty background */
239 // gdk_draw_rectangle (pixmap,
240 // widget->style->black_gc,
243 // widget->allocation.width,
244 // widget->allocation.height);
246 /* Copy old data to new pixmap */
247 gdk_draw_drawable (pixmap
,
248 widget
->style
->black_gc
,
255 gdk_pixmap_unref(drawing
->pixmap
);
257 drawing
->pixmap
= pixmap
;
259 // Clear the bottom part of the image (SAFETY)
260 gdk_draw_rectangle (pixmap
,
261 widget
->style
->black_gc
,
263 0, drawing
->height
+SAFETY
,
264 drawing
->width
+SAFETY
, // do not overlap
265 (widget
->allocation
.height
) - drawing
->height
);
267 // Clear the right part of the image (SAFETY)
268 gdk_draw_rectangle (pixmap
,
269 widget
->style
->black_gc
,
271 drawing
->width
+SAFETY
, 0,
272 (widget
->allocation
.width
) - drawing
->width
, // do not overlap
273 drawing
->height
+SAFETY
);
275 /* Clear the backgound for data request, but not SAFETY */
276 gdk_draw_rectangle (pixmap
,
277 drawing
->drawing_area
->style
->black_gc
,
279 drawing
->width
+ SAFETY
, 0,
280 widget
->allocation
.width
- drawing
->width
, // do not overlap
281 widget
->allocation
.height
+SAFETY
);
283 /* Request data for missing space */
284 g_info("missing data request");
285 drawing_data_request(drawing
, &pixmap
, drawing
->width
, 0,
286 widget
->allocation
.width
- drawing
->width
,
287 widget
->allocation
.height
);
289 drawing
->width
= widget
->allocation
.width
;
290 drawing
->height
= widget
->allocation
.height
;
297 /* Redraw the screen from the backing pixmap */
299 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
301 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
302 ControlFlowData
*control_flow_data
=
303 (ControlFlowData
*)g_object_get_data(
305 "control_flow_data");
307 g_critical("drawing expose event");
310 LttTime
* current_time
=
311 guicontrolflow_get_current_time(control_flow_data
);
313 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
314 control_flow_data
->time_window
.start_time
);
316 convert_time_to_pixels(
317 control_flow_data
->time_window
.start_time
,
320 widget
->allocation
.width
,
323 gdk_draw_pixmap(widget
->window
,
324 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
326 event
->area
.x
, event
->area
.y
,
327 event
->area
.x
, event
->area
.y
,
328 event
->area
.width
, event
->area
.height
);
330 if(x
>= event
->area
.x
&& x
<= event
->area
.x
+event
->area
.width
)
332 gint8 dash_list
[] = { 1, 2 };
333 GdkGC
*gc
= gdk_gc_new(control_flow_data
->drawing
->pixmap
);
334 gdk_gc_copy(gc
, widget
->style
->white_gc
);
335 gdk_gc_set_line_attributes(gc
,
337 GDK_LINE_ON_OFF_DASH
,
340 gdk_gc_set_dashes(gc
,
344 drawing_draw_line(NULL
, widget
->window
,
346 x
, event
->area
.y
+event
->area
.height
,
355 button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
357 ControlFlowData
*control_flow_data
=
358 (ControlFlowData
*)g_object_get_data(
360 "control_flow_data");
361 Drawing_t
*drawing
= control_flow_data
->drawing
;
365 if(event
->button
== 1)
369 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
370 control_flow_data
->time_window
.start_time
);
373 /* left mouse button click */
374 g_critical("x click is : %f", event
->x
);
376 convert_pixels_to_time(widget
->allocation
.width
, (guint
)event
->x
,
377 &control_flow_data
->time_window
.start_time
,
381 set_current_time(control_flow_data
->mw
, &time
);
391 Drawing_t
*drawing_construct(ControlFlowData
*control_flow_data
)
393 Drawing_t
*drawing
= g_new(Drawing_t
, 1);
395 drawing
->control_flow_data
= control_flow_data
;
397 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
399 drawing
->ruler
= gtk_drawing_area_new ();
400 gtk_widget_set_size_request(drawing
->ruler
, -1, 27);
403 drawing
->drawing_area
= gtk_drawing_area_new ();
405 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler
,
407 //g_object_unref(G_OBJECT(drawing->ruler));
408 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->drawing_area
,
410 //g_object_unref(G_OBJECT(drawing->drawing_area));
412 drawing
->pango_layout
=
413 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
415 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
416 g_object_set_data_full(
417 G_OBJECT(drawing
->drawing_area
),
420 (GDestroyNotify
)drawing_destroy
);
423 G_OBJECT(drawing
->ruler
),
428 //gtk_widget_modify_bg( drawing->drawing_area,
430 // &CF_Colors[BLACK]);
432 //gdk_window_get_geometry(drawing->drawing_area->window,
434 // &(drawing->width),
435 // &(drawing->height),
438 //drawing->pixmap = gdk_pixmap_new(
439 // drawing->drawing_area->window,
444 drawing
->pixmap
= NULL
;
446 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
447 // drawing->drawing_area->allocation.width,
448 // drawing->drawing_area->allocation.height,
451 gtk_widget_add_events(drawing
->drawing_area
, GDK_BUTTON_PRESS_MASK
);
453 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
455 G_CALLBACK (configure_event
),
458 g_signal_connect (G_OBJECT(drawing
->ruler
),
460 G_CALLBACK(expose_ruler
),
463 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
465 G_CALLBACK (expose_event
),
468 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
469 "button-press-event",
470 G_CALLBACK (button_press_event
),
473 gtk_widget_show(drawing
->ruler
);
474 gtk_widget_show(drawing
->drawing_area
);
480 void drawing_destroy(Drawing_t
*drawing
)
483 // Do not unref here, Drawing_t destroyed by it's widget.
484 //g_object_unref( G_OBJECT(drawing->drawing_area));
486 g_free(drawing
->pango_layout
);
490 GtkWidget
*drawing_get_drawing_area(Drawing_t
*drawing
)
492 return drawing
->drawing_area
;
495 GtkWidget
*drawing_get_widget(Drawing_t
*drawing
)
497 return drawing
->vbox
;
500 /* convert_pixels_to_time
502 * Convert from window pixel and time interval to an absolute time.
504 void convert_pixels_to_time(
507 LttTime
*window_time_begin
,
508 LttTime
*window_time_end
,
511 LttTime window_time_interval
;
513 window_time_interval
= ltt_time_sub(*window_time_end
,
515 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
516 *time
= ltt_time_add(*window_time_begin
, *time
);
521 void convert_time_to_pixels(
522 LttTime window_time_begin
,
523 LttTime window_time_end
,
528 LttTime window_time_interval
;
529 float interval_float
, time_float
;
531 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
533 time
= ltt_time_sub(time
, window_time_begin
);
535 interval_float
= ltt_time_to_double(window_time_interval
);
536 time_float
= ltt_time_to_double(time
);
538 *x
= (guint
)(time_float
/interval_float
* width
);
542 void drawing_refresh ( Drawing_t
*drawing
,
544 guint width
, guint height
)
546 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
547 GdkRectangle update_rect
;
550 drawing
->drawing_area
->window
,
551 drawing
->drawing_area
->
552 style
->fg_gc
[GTK_WIDGET_STATE (drawing
->drawing_area
)],
553 GDK_DRAWABLE(drawing
->pixmap
),
560 update_rect
.width
= drawing
->width
;
561 update_rect
.height
= drawing
->height
;
562 gtk_widget_draw( drawing
->drawing_area
, &update_rect
);
567 void drawing_draw_line( Drawing_t
*drawing
,
573 gdk_draw_line (pixmap
,
581 void drawing_resize(Drawing_t
*drawing
, guint h
, guint w
)
583 drawing
->height
= h
;
586 gtk_widget_set_size_request ( drawing
->drawing_area
,
594 /* Insert a square corresponding to a new process in the list */
595 /* Applies to whole drawing->width */
596 void drawing_insert_square(Drawing_t
*drawing
,
600 //GdkRectangle update_rect;
602 /* Allocate a new pixmap with new height */
603 GdkPixmap
*pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
604 drawing
->width
+ SAFETY
,
605 drawing
->height
+ height
+ SAFETY
,
608 /* Copy the high region */
609 gdk_draw_drawable (pixmap
,
610 drawing
->drawing_area
->style
->black_gc
,
614 drawing
->width
+ SAFETY
, y
);
619 /* add an empty square */
620 gdk_draw_rectangle (pixmap
,
621 drawing
->drawing_area
->style
->black_gc
,
624 drawing
->width
+ SAFETY
, // do not overlap
629 /* copy the bottom of the region */
630 gdk_draw_drawable (pixmap
,
631 drawing
->drawing_area
->style
->black_gc
,
635 drawing
->width
+SAFETY
, drawing
->height
- y
+ SAFETY
);
641 gdk_pixmap_unref(drawing
->pixmap
);
643 drawing
->pixmap
= pixmap
;
645 drawing
->height
+=height
;
647 /* Rectangle to update, from new drawing dimensions */
648 //update_rect.x = 0 ;
649 //update_rect.y = y ;
650 //update_rect.width = drawing->width;
651 //update_rect.height = drawing->height - y ;
652 //gtk_widget_draw( drawing->drawing_area, &update_rect);
656 /* Remove a square corresponding to a removed process in the list */
657 void drawing_remove_square(Drawing_t
*drawing
,
661 //GdkRectangle update_rect;
663 /* Allocate a new pixmap with new height */
664 GdkPixmap
*pixmap
= gdk_pixmap_new(
665 drawing
->drawing_area
->window
,
666 drawing
->width
+ SAFETY
,
667 drawing
->height
- height
+ SAFETY
,
670 /* Copy the high region */
671 gdk_draw_drawable (pixmap
,
672 drawing
->drawing_area
->style
->black_gc
,
676 drawing
->width
+ SAFETY
, y
);
680 /* Copy up the bottom of the region */
681 gdk_draw_drawable (pixmap
,
682 drawing
->drawing_area
->style
->black_gc
,
686 drawing
->width
, drawing
->height
- y
- height
+ SAFETY
);
690 gdk_pixmap_unref(drawing
->pixmap
);
692 drawing
->pixmap
= pixmap
;
694 drawing
->height
-=height
;
696 /* Rectangle to update, from new drawing dimensions */
697 //update_rect.x = 0 ;
698 //update_rect.y = y ;
699 //update_rect.width = drawing->width;
700 //update_rect.height = drawing->height - y ;
701 //gtk_widget_draw( drawing->drawing_area, &update_rect);
704 void drawing_update_ruler(Drawing_t
*drawing
, TimeWindow
*time_window
)
709 req
.width
= drawing
->ruler
->allocation
.width
;
710 req
.height
= drawing
->ruler
->allocation
.height
;
715 rect
.width
= req
.width
;
716 rect
.height
= req
.height
;
718 gtk_widget_queue_draw(drawing
->ruler
);
719 //gtk_widget_draw( drawing->ruler, &rect);
722 /* Redraw the ruler */
724 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
726 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
730 PangoContext
*context
;
732 PangoAttribute
*attribute
;
733 PangoFontDescription
*FontDesc
;
735 PangoRectangle ink_rect
;
736 guint global_width
=0;
737 GdkColor foreground
= { 0, 0, 0, 0 };
738 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
741 ltt_time_add(drawing
->control_flow_data
->time_window
.time_width
,
742 drawing
->control_flow_data
->time_window
.start_time
);
744 ltt_time_div(drawing
->control_flow_data
->time_window
.time_width
,2.0);
745 LttTime window_middle
=
746 ltt_time_add(half_width
,
747 drawing
->control_flow_data
->time_window
.start_time
);
748 g_critical("ruler expose event");
750 gdk_draw_rectangle (drawing
->ruler
->window
,
751 drawing
->ruler
->style
->white_gc
,
753 event
->area
.x
, event
->area
.y
,
757 GdkGC
*gc
= gdk_gc_new(drawing
->ruler
->window
);
758 gdk_gc_copy(gc
, drawing
->ruler
->style
->black_gc
);
759 gdk_gc_set_line_attributes(gc
,
764 gdk_draw_line (drawing
->ruler
->window
,
767 event
->area
.x
+ event
->area
.width
, 1);
770 snprintf(text
, 255, "%lus\n%luns",
771 drawing
->control_flow_data
->time_window
.start_time
.tv_sec
,
772 drawing
->control_flow_data
->time_window
.start_time
.tv_nsec
);
774 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
776 context
= pango_layout_get_context(layout
);
777 FontDesc
= pango_context_get_font_description(context
);
779 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
780 pango_layout_context_changed(layout
);
782 pango_layout_set_text(layout
, text
, -1);
783 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
784 global_width
+= ink_rect
.width
;
786 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
790 layout
, &foreground
, &background
);
792 gdk_gc_set_line_attributes(gc
,
798 gdk_draw_line (drawing
->ruler
->window
,
804 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
807 pango_layout_set_text(layout
, text
, -1);
808 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
809 global_width
+= ink_rect
.width
;
811 if(global_width
<= drawing
->ruler
->allocation
.width
)
813 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
815 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
817 layout
, &foreground
, &background
);
819 gdk_gc_set_line_attributes(gc
,
825 gdk_draw_line (drawing
->ruler
->window
,
827 drawing
->ruler
->allocation
.width
-1, 1,
828 drawing
->ruler
->allocation
.width
-1, 7);
832 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
833 window_middle
.tv_nsec
);
835 pango_layout_set_text(layout
, text
, -1);
836 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
837 global_width
+= ink_rect
.width
;
839 if(global_width
<= drawing
->ruler
->allocation
.width
)
841 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
843 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
845 layout
, &foreground
, &background
);
847 gdk_gc_set_line_attributes(gc
,
853 gdk_draw_line (drawing
->ruler
->window
,
855 drawing
->ruler
->allocation
.width
/2, 1,
856 drawing
->ruler
->allocation
.width
/2, 7);
864 g_object_unref(layout
);