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 *****************************************************************************/
38 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
49 /* Vector of unallocated colors */
50 static GdkColor CF_Colors
[] =
52 { 0, 0xffff, 0x0000, 0x0000 }, // RED
53 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
54 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
55 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
56 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
60 /* Function responsible for updating the exposed area.
61 * It must call processTrace() to ask for this update.
62 * Note : this function cannot clear the background, because it may
63 * erase drawing already present (SAFETY).
65 void drawing_data_request(Drawing_t
*drawing
,
71 if(width
< 0) return ;
72 if(height
< 0) return ;
73 ControlFlowData
*control_flow_data
=
74 (ControlFlowData
*)g_object_get_data(
76 drawing
->drawing_area
),
80 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
81 control_flow_data
->time_window
.start_time
);
83 g_critical("req : window_end : %u, %u", window_end
.tv_sec
,
86 g_critical("req : time width : %u, %u", control_flow_data
->time_window
.time_width
.tv_sec
,
87 control_flow_data
->time_window
.time_width
.tv_nsec
);
89 g_critical("x is : %i, x+width is : %i", x
, x
+width
);
91 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
,
92 &control_flow_data
->time_window
.start_time
,
96 convert_pixels_to_time(drawing
->drawing_area
->allocation
.width
, x
+ width
,
97 &control_flow_data
->time_window
.start_time
,
101 LttvTracesetContext
* tsc
=
102 get_traceset_context(control_flow_data
->mw
);
105 //guicontrolflow_get_process_list(drawing->control_flow_data),
108 //guicontrolflow_get_process_list(drawing->control_flow_data),
109 //drawing, *pixmap, x, y, width, height);
111 // Let's call processTrace() !!
112 EventRequest event_request
; // Variable freed at the end of the function.
113 event_request
.control_flow_data
= control_flow_data
;
114 event_request
.time_begin
= start
;
115 event_request
.time_end
= end
;
116 event_request
.x_begin
= x
;
117 event_request
.x_end
= x
+width
;
119 g_critical("req : start : %u, %u", event_request
.time_begin
.tv_sec
,
120 event_request
.time_begin
.tv_nsec
);
122 g_critical("req : end : %u, %u", event_request
.time_end
.tv_sec
,
123 event_request
.time_end
.tv_nsec
);
125 LttvHooks
*event
= lttv_hooks_new();
126 LttvHooks
*after_event
= lttv_hooks_new();
127 LttvHooks
*after_traceset
= lttv_hooks_new();
128 lttv_hooks_add(after_traceset
, after_data_request
, &event_request
);
129 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
130 //Modified by xiangxiu: state update hooks are added by the main window
131 //state_add_event_hooks_api(control_flow_data->mw);
132 lttv_hooks_add(after_event
, draw_after_hook
, &event_request
);
134 lttv_process_traceset_seek_time(tsc
, start
);
135 // FIXME : would like to place the after_traceset hook after the traceset,
136 // but the traceset context state is not valid anymore.
137 lttv_traceset_context_add_hooks(tsc
,
138 // NULL, after_traceset, NULL, NULL, NULL, NULL,
139 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
140 NULL
, after_traceset
, NULL
, event
, after_event
);
141 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
142 //after_data_request((void*)&event_request,(void*)tsc);
143 lttv_traceset_context_remove_hooks(tsc
,
144 //NULL, after_traceset, NULL, NULL, NULL, NULL,
145 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
146 NULL
, after_traceset
, NULL
, event
, after_event
);
147 //Modified by xiangxiu: state update hooks are removed by the main window
148 //state_remove_event_hooks_api(control_flow_data->mw);
150 lttv_hooks_destroy(after_traceset
);
151 lttv_hooks_destroy(event
);
152 lttv_hooks_destroy(after_event
);
160 /* Create a new backing pixmap of the appropriate size */
161 /* As the scaling will always change, it's of no use to copy old
165 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
168 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
171 /* First, get the new time interval of the main window */
172 /* we assume (see documentation) that the main window
173 * has updated the time interval before this configure gets
176 get_time_window(drawing
->control_flow_data
->mw
,
177 &drawing
->control_flow_data
->time_window
);
179 /* New pixmap, size of the configure event */
180 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
181 // widget->allocation.width + SAFETY,
182 // widget->allocation.height + SAFETY,
185 g_critical("drawing configure event");
186 g_critical("New draw size : %i by %i",widget
->allocation
.width
, widget
->allocation
.height
);
190 gdk_pixmap_unref(drawing
->pixmap
);
192 /* If no old pixmap present */
193 //if(drawing->pixmap == NULL)
195 drawing
->pixmap
= gdk_pixmap_new(
197 widget
->allocation
.width
+ SAFETY
,
198 widget
->allocation
.height
+ SAFETY
,
199 //ProcessList_get_height
200 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
202 drawing
->width
= widget
->allocation
.width
;
203 drawing
->height
= widget
->allocation
.height
;
207 gdk_draw_rectangle (drawing
->pixmap
,
208 widget
->style
->black_gc
,
211 widget
->allocation
.width
+SAFETY
,
212 widget
->allocation
.height
+SAFETY
);
214 //g_info("init data request");
217 /* Initial data request */
218 // Do not need to ask for data of 1 pixel : not synchronized with
219 // main window time at this moment.
220 drawing_data_request(drawing
, &drawing
->pixmap
, 0, 0,
221 widget
->allocation
.width
,
222 widget
->allocation
.height
);
224 drawing
->width
= widget
->allocation
.width
;
225 drawing
->height
= widget
->allocation
.height
;
233 // /* Draw empty background */
234 // gdk_draw_rectangle (pixmap,
235 // widget->style->black_gc,
238 // widget->allocation.width,
239 // widget->allocation.height);
241 /* Copy old data to new pixmap */
242 gdk_draw_drawable (pixmap
,
243 widget
->style
->black_gc
,
250 gdk_pixmap_unref(drawing
->pixmap
);
252 drawing
->pixmap
= pixmap
;
254 // Clear the bottom part of the image (SAFETY)
255 gdk_draw_rectangle (pixmap
,
256 widget
->style
->black_gc
,
258 0, drawing
->height
+SAFETY
,
259 drawing
->width
+SAFETY
, // do not overlap
260 (widget
->allocation
.height
) - drawing
->height
);
262 // Clear the right part of the image (SAFETY)
263 gdk_draw_rectangle (pixmap
,
264 widget
->style
->black_gc
,
266 drawing
->width
+SAFETY
, 0,
267 (widget
->allocation
.width
) - drawing
->width
, // do not overlap
268 drawing
->height
+SAFETY
);
270 /* Clear the backgound for data request, but not SAFETY */
271 gdk_draw_rectangle (pixmap
,
272 drawing
->drawing_area
->style
->black_gc
,
274 drawing
->width
+ SAFETY
, 0,
275 widget
->allocation
.width
- drawing
->width
, // do not overlap
276 widget
->allocation
.height
+SAFETY
);
278 /* Request data for missing space */
279 g_info("missing data request");
280 drawing_data_request(drawing
, &pixmap
, drawing
->width
, 0,
281 widget
->allocation
.width
- drawing
->width
,
282 widget
->allocation
.height
);
284 drawing
->width
= widget
->allocation
.width
;
285 drawing
->height
= widget
->allocation
.height
;
292 /* Redraw the screen from the backing pixmap */
294 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
296 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
297 ControlFlowData
*control_flow_data
=
298 (ControlFlowData
*)g_object_get_data(
300 "control_flow_data");
302 g_critical("drawing expose event");
305 LttTime
* current_time
=
306 guicontrolflow_get_current_time(control_flow_data
);
308 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
309 control_flow_data
->time_window
.start_time
);
311 convert_time_to_pixels(
312 control_flow_data
->time_window
.start_time
,
315 widget
->allocation
.width
,
318 gdk_draw_pixmap(widget
->window
,
319 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
321 event
->area
.x
, event
->area
.y
,
322 event
->area
.x
, event
->area
.y
,
323 event
->area
.width
, event
->area
.height
);
325 if(x
>= event
->area
.x
&& x
<= event
->area
.x
+event
->area
.width
)
327 gint8 dash_list
[] = { 1, 2 };
328 GdkGC
*gc
= gdk_gc_new(control_flow_data
->drawing
->pixmap
);
329 gdk_gc_copy(gc
, widget
->style
->white_gc
);
330 gdk_gc_set_line_attributes(gc
,
332 GDK_LINE_ON_OFF_DASH
,
335 gdk_gc_set_dashes(gc
,
339 drawing_draw_line(NULL
, widget
->window
,
341 x
, event
->area
.y
+event
->area
.height
,
350 button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
352 ControlFlowData
*control_flow_data
=
353 (ControlFlowData
*)g_object_get_data(
355 "control_flow_data");
356 Drawing_t
*drawing
= control_flow_data
->drawing
;
360 if(event
->button
== 1)
364 LttTime window_end
= ltt_time_add(control_flow_data
->time_window
.time_width
,
365 control_flow_data
->time_window
.start_time
);
368 /* left mouse button click */
369 g_critical("x click is : %f", event
->x
);
371 convert_pixels_to_time(widget
->allocation
.width
, (guint
)event
->x
,
372 &control_flow_data
->time_window
.start_time
,
376 set_current_time(control_flow_data
->mw
, &time
);
386 Drawing_t
*drawing_construct(ControlFlowData
*control_flow_data
)
388 Drawing_t
*drawing
= g_new(Drawing_t
, 1);
390 drawing
->drawing_area
= gtk_drawing_area_new ();
391 drawing
->control_flow_data
= control_flow_data
;
393 drawing
->pango_layout
=
394 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
396 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
397 g_object_set_data_full(
398 G_OBJECT(drawing
->drawing_area
),
401 (GDestroyNotify
)drawing_destroy
);
403 //gtk_widget_modify_bg( drawing->drawing_area,
405 // &CF_Colors[BLACK]);
407 //gdk_window_get_geometry(drawing->drawing_area->window,
409 // &(drawing->width),
410 // &(drawing->height),
413 //drawing->pixmap = gdk_pixmap_new(
414 // drawing->drawing_area->window,
419 drawing
->pixmap
= NULL
;
421 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
422 // drawing->drawing_area->allocation.width,
423 // drawing->drawing_area->allocation.height,
426 gtk_widget_add_events(drawing
->drawing_area
, GDK_BUTTON_PRESS_MASK
);
428 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
430 G_CALLBACK (configure_event
),
433 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
435 G_CALLBACK (expose_event
),
438 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
439 "button-press-event",
440 G_CALLBACK (button_press_event
),
447 void drawing_destroy(Drawing_t
*drawing
)
450 // Do not unref here, Drawing_t destroyed by it's widget.
451 //g_object_unref( G_OBJECT(drawing->drawing_area));
453 g_free(drawing
->pango_layout
);
457 GtkWidget
*drawing_get_widget(Drawing_t
*drawing
)
459 return drawing
->drawing_area
;
462 /* convert_pixels_to_time
464 * Convert from window pixel and time interval to an absolute time.
466 void convert_pixels_to_time(
469 LttTime
*window_time_begin
,
470 LttTime
*window_time_end
,
473 LttTime window_time_interval
;
475 window_time_interval
= ltt_time_sub(*window_time_end
,
477 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
478 *time
= ltt_time_add(*window_time_begin
, *time
);
483 void convert_time_to_pixels(
484 LttTime window_time_begin
,
485 LttTime window_time_end
,
490 LttTime window_time_interval
;
491 float interval_float
, time_float
;
493 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
495 time
= ltt_time_sub(time
, window_time_begin
);
497 interval_float
= ltt_time_to_double(window_time_interval
);
498 time_float
= ltt_time_to_double(time
);
500 *x
= (guint
)(time_float
/interval_float
* width
);
504 void drawing_refresh ( Drawing_t
*drawing
,
506 guint width
, guint height
)
508 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
509 GdkRectangle update_rect
;
512 drawing
->drawing_area
->window
,
513 drawing
->drawing_area
->
514 style
->fg_gc
[GTK_WIDGET_STATE (drawing
->drawing_area
)],
515 GDK_DRAWABLE(drawing
->pixmap
),
522 update_rect
.width
= drawing
->width
;
523 update_rect
.height
= drawing
->height
;
524 gtk_widget_draw( drawing
->drawing_area
, &update_rect
);
529 void drawing_draw_line( Drawing_t
*drawing
,
535 gdk_draw_line (pixmap
,
543 void drawing_resize(Drawing_t
*drawing
, guint h
, guint w
)
545 drawing
->height
= h
;
548 gtk_widget_set_size_request ( drawing
->drawing_area
,
556 /* Insert a square corresponding to a new process in the list */
557 /* Applies to whole drawing->width */
558 void drawing_insert_square(Drawing_t
*drawing
,
562 //GdkRectangle update_rect;
564 /* Allocate a new pixmap with new height */
565 GdkPixmap
*pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
566 drawing
->width
+ SAFETY
,
567 drawing
->height
+ height
+ SAFETY
,
570 /* Copy the high region */
571 gdk_draw_drawable (pixmap
,
572 drawing
->drawing_area
->style
->black_gc
,
576 drawing
->width
+ SAFETY
, y
);
581 /* add an empty square */
582 gdk_draw_rectangle (pixmap
,
583 drawing
->drawing_area
->style
->black_gc
,
586 drawing
->width
+ SAFETY
, // do not overlap
591 /* copy the bottom of the region */
592 gdk_draw_drawable (pixmap
,
593 drawing
->drawing_area
->style
->black_gc
,
597 drawing
->width
+SAFETY
, drawing
->height
- y
+ SAFETY
);
603 gdk_pixmap_unref(drawing
->pixmap
);
605 drawing
->pixmap
= pixmap
;
607 drawing
->height
+=height
;
609 /* Rectangle to update, from new drawing dimensions */
610 //update_rect.x = 0 ;
611 //update_rect.y = y ;
612 //update_rect.width = drawing->width;
613 //update_rect.height = drawing->height - y ;
614 //gtk_widget_draw( drawing->drawing_area, &update_rect);
618 /* Remove a square corresponding to a removed process in the list */
619 void drawing_remove_square(Drawing_t
*drawing
,
623 //GdkRectangle update_rect;
625 /* Allocate a new pixmap with new height */
626 GdkPixmap
*pixmap
= gdk_pixmap_new(
627 drawing
->drawing_area
->window
,
628 drawing
->width
+ SAFETY
,
629 drawing
->height
- height
+ SAFETY
,
632 /* Copy the high region */
633 gdk_draw_drawable (pixmap
,
634 drawing
->drawing_area
->style
->black_gc
,
638 drawing
->width
+ SAFETY
, y
);
642 /* Copy up the bottom of the region */
643 gdk_draw_drawable (pixmap
,
644 drawing
->drawing_area
->style
->black_gc
,
648 drawing
->width
, drawing
->height
- y
- height
+ 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);