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
);
112 //guicontrolflow_get_process_list(drawing->control_flow_data),
115 //guicontrolflow_get_process_list(drawing->control_flow_data),
116 //drawing, *pixmap, x, y, width, height);
118 // Let's call processTrace() !!
119 EventRequest event_request
; // Variable freed at the end of the function.
120 event_request
.control_flow_data
= control_flow_data
;
121 event_request
.time_begin
= start
;
122 event_request
.time_end
= end
;
123 event_request
.x_begin
= x
;
124 event_request
.x_end
= x
+width
;
126 g_critical("req : start : %u, %u", event_request
.time_begin
.tv_sec
,
127 event_request
.time_begin
.tv_nsec
);
129 g_critical("req : end : %u, %u", event_request
.time_end
.tv_sec
,
130 event_request
.time_end
.tv_nsec
);
132 LttvHooks
*event
= lttv_hooks_new();
133 LttvHooks
*after_event
= lttv_hooks_new();
134 LttvHooks
*after_traceset
= lttv_hooks_new();
135 lttv_hooks_add(after_traceset
, after_data_request
, &event_request
);
136 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
137 //Modified by xiangxiu: state update hooks are added by the main window
138 //state_add_event_hooks_api(control_flow_data->mw);
139 lttv_hooks_add(after_event
, draw_after_hook
, &event_request
);
141 lttv_process_traceset_seek_time(tsc
, start
);
142 // FIXME : would like to place the after_traceset hook after the traceset,
143 // but the traceset context state is not valid anymore.
144 lttv_traceset_context_add_hooks(tsc
,
145 // NULL, after_traceset, NULL, NULL, NULL, NULL,
146 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
147 NULL
, after_traceset
, NULL
, event
, after_event
);
148 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
149 //after_data_request((void*)&event_request,(void*)tsc);
150 lttv_traceset_context_remove_hooks(tsc
,
151 //NULL, after_traceset, NULL, NULL, NULL, NULL,
152 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
153 NULL
, after_traceset
, NULL
, event
, after_event
);
154 //Modified by xiangxiu: state update hooks are removed by the main window
155 //state_remove_event_hooks_api(control_flow_data->mw);
157 lttv_hooks_destroy(after_traceset
);
158 lttv_hooks_destroy(event
);
159 lttv_hooks_destroy(after_event
);
167 /* Create a new backing pixmap of the appropriate size */
168 /* As the scaling will always change, it's of no use to copy old
172 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
175 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
178 /* First, get the new time interval of the main window */
179 /* we assume (see documentation) that the main window
180 * has updated the time interval before this configure gets
183 get_time_window(drawing
->control_flow_data
->mw
,
184 &drawing
->control_flow_data
->time_window
);
186 /* New pixmap, size of the configure event */
187 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
188 // widget->allocation.width + SAFETY,
189 // widget->allocation.height + SAFETY,
192 g_critical("drawing configure event");
193 g_critical("New draw size : %i by %i",widget
->allocation
.width
, widget
->allocation
.height
);
197 gdk_pixmap_unref(drawing
->pixmap
);
199 /* If no old pixmap present */
200 //if(drawing->pixmap == NULL)
202 drawing
->pixmap
= gdk_pixmap_new(
204 widget
->allocation
.width
+ SAFETY
,
205 widget
->allocation
.height
+ SAFETY
,
206 //ProcessList_get_height
207 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
209 drawing
->width
= widget
->allocation
.width
;
210 drawing
->height
= widget
->allocation
.height
;
214 gdk_draw_rectangle (drawing
->pixmap
,
215 widget
->style
->black_gc
,
218 widget
->allocation
.width
+SAFETY
,
219 widget
->allocation
.height
+SAFETY
);
221 //g_info("init data request");
224 /* Initial data request */
225 // Do not need to ask for data of 1 pixel : not synchronized with
226 // main window time at this moment.
227 drawing_data_request(drawing
, &drawing
->pixmap
, 0, 0,
228 widget
->allocation
.width
,
229 widget
->allocation
.height
);
231 drawing
->width
= widget
->allocation
.width
;
232 drawing
->height
= widget
->allocation
.height
;
240 // /* Draw empty background */
241 // gdk_draw_rectangle (pixmap,
242 // widget->style->black_gc,
245 // widget->allocation.width,
246 // widget->allocation.height);
248 /* Copy old data to new pixmap */
249 gdk_draw_drawable (pixmap
,
250 widget
->style
->black_gc
,
257 gdk_pixmap_unref(drawing
->pixmap
);
259 drawing
->pixmap
= pixmap
;
261 // Clear the bottom part of the image (SAFETY)
262 gdk_draw_rectangle (pixmap
,
263 widget
->style
->black_gc
,
265 0, drawing
->height
+SAFETY
,
266 drawing
->width
+SAFETY
, // do not overlap
267 (widget
->allocation
.height
) - drawing
->height
);
269 // Clear the right part of the image (SAFETY)
270 gdk_draw_rectangle (pixmap
,
271 widget
->style
->black_gc
,
273 drawing
->width
+SAFETY
, 0,
274 (widget
->allocation
.width
) - drawing
->width
, // do not overlap
275 drawing
->height
+SAFETY
);
277 /* Clear the backgound for data request, but not SAFETY */
278 gdk_draw_rectangle (pixmap
,
279 drawing
->drawing_area
->style
->black_gc
,
281 drawing
->width
+ SAFETY
, 0,
282 widget
->allocation
.width
- drawing
->width
, // do not overlap
283 widget
->allocation
.height
+SAFETY
);
285 /* Request data for missing space */
286 g_info("missing data request");
287 drawing_data_request(drawing
, &pixmap
, drawing
->width
, 0,
288 widget
->allocation
.width
- drawing
->width
,
289 widget
->allocation
.height
);
291 drawing
->width
= widget
->allocation
.width
;
292 drawing
->height
= widget
->allocation
.height
;
299 /* Redraw the screen from the backing pixmap */
301 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
303 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
304 ControlFlowData
*control_flow_data
=
305 (ControlFlowData
*)g_object_get_data(
307 "control_flow_data");
309 g_critical("drawing expose event");
312 LttTime
* current_time
=
313 guicontrolflow_get_current_time(control_flow_data
);
315 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
316 control_flow_data
->time_window
.start_time
);
318 convert_time_to_pixels(
319 control_flow_data
->time_window
.start_time
,
322 widget
->allocation
.width
,
325 gdk_draw_pixmap(widget
->window
,
326 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
328 event
->area
.x
, event
->area
.y
,
329 event
->area
.x
, event
->area
.y
,
330 event
->area
.width
, event
->area
.height
);
332 if(x
>= event
->area
.x
&& x
<= event
->area
.x
+event
->area
.width
)
334 gint8 dash_list
[] = { 1, 2 };
335 GdkGC
*gc
= gdk_gc_new(control_flow_data
->drawing
->pixmap
);
336 gdk_gc_copy(gc
, widget
->style
->white_gc
);
337 gdk_gc_set_line_attributes(gc
,
339 GDK_LINE_ON_OFF_DASH
,
342 gdk_gc_set_dashes(gc
,
346 drawing_draw_line(NULL
, widget
->window
,
348 x
, event
->area
.y
+event
->area
.height
,
357 button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
359 ControlFlowData
*control_flow_data
=
360 (ControlFlowData
*)g_object_get_data(
362 "control_flow_data");
363 Drawing_t
*drawing
= control_flow_data
->drawing
;
367 if(event
->button
== 1)
371 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
372 control_flow_data
->time_window
.start_time
);
375 /* left mouse button click */
376 g_critical("x click is : %f", event
->x
);
378 convert_pixels_to_time(widget
->allocation
.width
, (guint
)event
->x
,
379 &control_flow_data
->time_window
.start_time
,
383 set_current_time(control_flow_data
->mw
, &time
);
393 Drawing_t
*drawing_construct(ControlFlowData
*control_flow_data
)
395 Drawing_t
*drawing
= g_new(Drawing_t
, 1);
397 drawing
->control_flow_data
= control_flow_data
;
399 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
400 drawing
->ruler
= gtk_drawing_area_new ();
401 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 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->drawing_area
,
410 drawing
->pango_layout
=
411 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
413 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
414 g_object_set_data_full(
415 G_OBJECT(drawing
->drawing_area
),
418 (GDestroyNotify
)drawing_destroy
);
421 G_OBJECT(drawing
->ruler
),
426 //gtk_widget_modify_bg( drawing->drawing_area,
428 // &CF_Colors[BLACK]);
430 //gdk_window_get_geometry(drawing->drawing_area->window,
432 // &(drawing->width),
433 // &(drawing->height),
436 //drawing->pixmap = gdk_pixmap_new(
437 // drawing->drawing_area->window,
442 drawing
->pixmap
= NULL
;
444 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
445 // drawing->drawing_area->allocation.width,
446 // drawing->drawing_area->allocation.height,
449 gtk_widget_add_events(drawing
->drawing_area
, GDK_BUTTON_PRESS_MASK
);
451 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
453 G_CALLBACK (configure_event
),
456 g_signal_connect (G_OBJECT(drawing
->ruler
),
458 G_CALLBACK(expose_ruler
),
461 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
463 g_signal_connect (G_OBJECT(drawing
->ruler
),
464 "motion-notify-event",
465 G_CALLBACK(motion_notify_ruler
),
469 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
471 G_CALLBACK (expose_event
),
474 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
475 "button-press-event",
476 G_CALLBACK (button_press_event
),
479 gtk_widget_show(drawing
->ruler
);
480 gtk_widget_show(drawing
->drawing_area
);
486 void drawing_destroy(Drawing_t
*drawing
)
489 // Do not unref here, Drawing_t destroyed by it's widget.
490 //g_object_unref( G_OBJECT(drawing->drawing_area));
492 g_free(drawing
->pango_layout
);
496 GtkWidget
*drawing_get_drawing_area(Drawing_t
*drawing
)
498 return drawing
->drawing_area
;
501 GtkWidget
*drawing_get_widget(Drawing_t
*drawing
)
503 return drawing
->vbox
;
506 /* convert_pixels_to_time
508 * Convert from window pixel and time interval to an absolute time.
510 void convert_pixels_to_time(
513 LttTime
*window_time_begin
,
514 LttTime
*window_time_end
,
517 LttTime window_time_interval
;
519 window_time_interval
= ltt_time_sub(*window_time_end
,
521 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
522 *time
= ltt_time_add(*window_time_begin
, *time
);
527 void convert_time_to_pixels(
528 LttTime window_time_begin
,
529 LttTime window_time_end
,
534 LttTime window_time_interval
;
535 float interval_float
, time_float
;
537 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
539 time
= ltt_time_sub(time
, window_time_begin
);
541 interval_float
= ltt_time_to_double(window_time_interval
);
542 time_float
= ltt_time_to_double(time
);
544 *x
= (guint
)(time_float
/interval_float
* width
);
548 void drawing_refresh ( Drawing_t
*drawing
,
550 guint width
, guint height
)
552 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
553 GdkRectangle update_rect
;
556 drawing
->drawing_area
->window
,
557 drawing
->drawing_area
->
558 style
->fg_gc
[GTK_WIDGET_STATE (drawing
->drawing_area
)],
559 GDK_DRAWABLE(drawing
->pixmap
),
566 update_rect
.width
= drawing
->width
;
567 update_rect
.height
= drawing
->height
;
568 gtk_widget_draw( drawing
->drawing_area
, &update_rect
);
573 void drawing_draw_line( Drawing_t
*drawing
,
579 gdk_draw_line (pixmap
,
587 void drawing_resize(Drawing_t
*drawing
, guint h
, guint w
)
589 drawing
->height
= h
;
592 gtk_widget_set_size_request ( drawing
->drawing_area
,
600 /* Insert a square corresponding to a new process in the list */
601 /* Applies to whole drawing->width */
602 void drawing_insert_square(Drawing_t
*drawing
,
606 //GdkRectangle update_rect;
608 /* Allocate a new pixmap with new height */
609 GdkPixmap
*pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
610 drawing
->width
+ SAFETY
,
611 drawing
->height
+ height
+ SAFETY
,
614 /* Copy the high region */
615 gdk_draw_drawable (pixmap
,
616 drawing
->drawing_area
->style
->black_gc
,
620 drawing
->width
+ SAFETY
, y
);
625 /* add an empty square */
626 gdk_draw_rectangle (pixmap
,
627 drawing
->drawing_area
->style
->black_gc
,
630 drawing
->width
+ SAFETY
, // do not overlap
635 /* copy the bottom of the region */
636 gdk_draw_drawable (pixmap
,
637 drawing
->drawing_area
->style
->black_gc
,
641 drawing
->width
+SAFETY
, drawing
->height
- y
+ SAFETY
);
647 gdk_pixmap_unref(drawing
->pixmap
);
649 drawing
->pixmap
= pixmap
;
651 drawing
->height
+=height
;
653 /* Rectangle to update, from new drawing dimensions */
654 //update_rect.x = 0 ;
655 //update_rect.y = y ;
656 //update_rect.width = drawing->width;
657 //update_rect.height = drawing->height - y ;
658 //gtk_widget_draw( drawing->drawing_area, &update_rect);
662 /* Remove a square corresponding to a removed process in the list */
663 void drawing_remove_square(Drawing_t
*drawing
,
667 //GdkRectangle update_rect;
669 /* Allocate a new pixmap with new height */
670 GdkPixmap
*pixmap
= gdk_pixmap_new(
671 drawing
->drawing_area
->window
,
672 drawing
->width
+ SAFETY
,
673 drawing
->height
- height
+ SAFETY
,
676 /* Copy the high region */
677 gdk_draw_drawable (pixmap
,
678 drawing
->drawing_area
->style
->black_gc
,
682 drawing
->width
+ SAFETY
, y
);
686 /* Copy up the bottom of the region */
687 gdk_draw_drawable (pixmap
,
688 drawing
->drawing_area
->style
->black_gc
,
692 drawing
->width
, drawing
->height
- y
- height
+ SAFETY
);
696 gdk_pixmap_unref(drawing
->pixmap
);
698 drawing
->pixmap
= pixmap
;
700 drawing
->height
-=height
;
702 /* Rectangle to update, from new drawing dimensions */
703 //update_rect.x = 0 ;
704 //update_rect.y = y ;
705 //update_rect.width = drawing->width;
706 //update_rect.height = drawing->height - y ;
707 //gtk_widget_draw( drawing->drawing_area, &update_rect);
710 void drawing_update_ruler(Drawing_t
*drawing
, TimeWindow
*time_window
)
715 req
.width
= drawing
->ruler
->allocation
.width
;
716 req
.height
= drawing
->ruler
->allocation
.height
;
721 rect
.width
= req
.width
;
722 rect
.height
= req
.height
;
724 gtk_widget_queue_draw(drawing
->ruler
);
725 //gtk_widget_draw( drawing->ruler, &rect);
728 /* Redraw the ruler */
730 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
732 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
736 PangoContext
*context
;
738 PangoAttribute
*attribute
;
739 PangoFontDescription
*FontDesc
;
741 PangoRectangle ink_rect
;
742 guint global_width
=0;
743 GdkColor foreground
= { 0, 0, 0, 0 };
744 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
747 ltt_time_add(drawing
->control_flow_data
->time_window
.time_width
,
748 drawing
->control_flow_data
->time_window
.start_time
);
750 ltt_time_div(drawing
->control_flow_data
->time_window
.time_width
,2.0);
751 LttTime window_middle
=
752 ltt_time_add(half_width
,
753 drawing
->control_flow_data
->time_window
.start_time
);
754 g_critical("ruler expose event");
756 gdk_draw_rectangle (drawing
->ruler
->window
,
757 drawing
->ruler
->style
->white_gc
,
759 event
->area
.x
, event
->area
.y
,
763 GdkGC
*gc
= gdk_gc_new(drawing
->ruler
->window
);
764 gdk_gc_copy(gc
, drawing
->ruler
->style
->black_gc
);
765 gdk_gc_set_line_attributes(gc
,
770 gdk_draw_line (drawing
->ruler
->window
,
773 event
->area
.x
+ event
->area
.width
, 1);
776 snprintf(text
, 255, "%lus\n%luns",
777 drawing
->control_flow_data
->time_window
.start_time
.tv_sec
,
778 drawing
->control_flow_data
->time_window
.start_time
.tv_nsec
);
780 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
782 context
= pango_layout_get_context(layout
);
783 FontDesc
= pango_context_get_font_description(context
);
785 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
786 pango_layout_context_changed(layout
);
788 pango_layout_set_text(layout
, text
, -1);
789 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
790 global_width
+= ink_rect
.width
;
792 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
796 layout
, &foreground
, &background
);
798 gdk_gc_set_line_attributes(gc
,
804 gdk_draw_line (drawing
->ruler
->window
,
810 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
813 pango_layout_set_text(layout
, text
, -1);
814 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
815 global_width
+= ink_rect
.width
;
817 if(global_width
<= drawing
->ruler
->allocation
.width
)
819 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
821 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
823 layout
, &foreground
, &background
);
825 gdk_gc_set_line_attributes(gc
,
831 gdk_draw_line (drawing
->ruler
->window
,
833 drawing
->ruler
->allocation
.width
-1, 1,
834 drawing
->ruler
->allocation
.width
-1, 7);
838 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
839 window_middle
.tv_nsec
);
841 pango_layout_set_text(layout
, text
, -1);
842 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
843 global_width
+= ink_rect
.width
;
845 if(global_width
<= drawing
->ruler
->allocation
.width
)
847 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
849 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
851 layout
, &foreground
, &background
);
853 gdk_gc_set_line_attributes(gc
,
859 gdk_draw_line (drawing
->ruler
->window
,
861 drawing
->ruler
->allocation
.width
/2, 1,
862 drawing
->ruler
->allocation
.width
/2, 7);
870 g_object_unref(layout
);
876 /* notify mouse on ruler */
878 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
880 //g_critical("motion");
881 //eventually follow mouse and show time here