5 #include <lttv/processTrace.h>
6 #include <lttv/gtkTraceSet.h>
11 #include "CFV-private.h"
12 #include "Event_Hooks.h"
14 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
15 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
17 /*****************************************************************************
19 *****************************************************************************/
21 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
32 /* Vector of unallocated colors */
33 static GdkColor CF_Colors
[] =
35 { 0, 0xffff, 0x0000, 0x0000 }, // RED
36 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
37 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
38 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
39 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
43 /* Function responsible for updating the exposed area.
44 * It must call processTrace() to ask for this update.
45 * Note : this function cannot clear the background, because it may
46 * erase drawing already present (SAFETY).
48 void drawing_data_request(Drawing_t
*Drawing
,
54 if(width
< 0) return ;
55 if(height
< 0) return ;
56 ControlFlowData
*control_flow_data
=
57 (ControlFlowData
*)g_object_get_data(
59 Drawing
->Drawing_Area_V
),
63 LttTime window_end
= ltt_time_add(control_flow_data
->Time_Window
.time_width
,
64 control_flow_data
->Time_Window
.start_time
);
66 g_critical("req : window_end : %u, %u", window_end
.tv_sec
,
69 g_critical("req : time width : %u, %u", control_flow_data
->Time_Window
.time_width
.tv_sec
,
70 control_flow_data
->Time_Window
.time_width
.tv_nsec
);
72 g_critical("x is : %i, x+width is : %i", x
, x
+width
);
74 convert_pixels_to_time(Drawing
->Drawing_Area_V
->allocation
.width
, x
,
75 &control_flow_data
->Time_Window
.start_time
,
79 convert_pixels_to_time(Drawing
->Drawing_Area_V
->allocation
.width
, x
+ width
,
80 &control_flow_data
->Time_Window
.start_time
,
84 LttvTracesetContext
* tsc
=
85 get_traceset_context(control_flow_data
->Parent_Window
);
88 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
91 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
92 //Drawing, *Pixmap, x, y, width, height);
94 // Let's call processTrace() !!
95 EventRequest event_request
; // Variable freed at the end of the function.
96 event_request
.Control_Flow_Data
= control_flow_data
;
97 event_request
.time_begin
= start
;
98 event_request
.time_end
= end
;
100 g_critical("req : start : %u, %u", event_request
.time_begin
.tv_sec
,
101 event_request
.time_begin
.tv_nsec
);
103 g_critical("req : end : %u, %u", event_request
.time_end
.tv_sec
,
104 event_request
.time_end
.tv_nsec
);
106 LttvHooks
*event
= lttv_hooks_new();
107 state_add_event_hooks_api(control_flow_data
->Parent_Window
);
108 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
110 lttv_process_traceset_seek_time(tsc
, start
);
111 lttv_traceset_context_add_hooks(tsc
,
112 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
113 NULL
, NULL
, NULL
, event
, NULL
);
114 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
115 lttv_traceset_context_remove_hooks(tsc
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
116 NULL
, NULL
, NULL
, event
, NULL
);
118 state_remove_event_hooks_api(control_flow_data
->Parent_Window
);
119 lttv_hooks_destroy(event
);
125 /* Create a new backing pixmap of the appropriate size */
127 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
130 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
133 /* First, get the new time interval of the main window */
134 /* we assume (see documentation) that the main window
135 * has updated the time interval before this configure gets
138 get_time_window(Drawing
->Control_Flow_Data
->Parent_Window
,
139 &Drawing
->Control_Flow_Data
->Time_Window
);
141 /* New Pixmap, size of the configure event */
142 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
143 widget
->allocation
.width
+ SAFETY
,
144 widget
->allocation
.height
+ SAFETY
,
147 g_critical("drawing configure event");
149 /* If no old Pixmap present */
150 if(Drawing
->Pixmap
== NULL
)
152 Drawing
->Pixmap
= gdk_pixmap_new(
154 widget
->allocation
.width
+ SAFETY
,
155 widget
->allocation
.height
+ SAFETY
,
156 //ProcessList_get_height
157 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
159 Drawing
->width
= widget
->allocation
.width
;
160 Drawing
->height
= widget
->allocation
.height
;
163 gdk_draw_rectangle (Drawing
->Pixmap
,
164 widget
->style
->white_gc
,
167 widget
->allocation
.width
+SAFETY
,
168 widget
->allocation
.height
+SAFETY
);
170 g_info("init data request");
173 /* Initial data request */
174 drawing_data_request(Drawing
, &Drawing
->Pixmap
, 0, 0,
175 widget
->allocation
.width
,
176 widget
->allocation
.height
);
179 // /* Draw empty background */
180 // gdk_draw_rectangle (Pixmap,
181 // widget->style->black_gc,
184 // widget->allocation.width,
185 // widget->allocation.height);
187 /* Copy old data to new pixmap */
188 gdk_draw_drawable (Pixmap
,
189 widget
->style
->white_gc
,
196 gdk_pixmap_unref(Drawing
->Pixmap
);
198 Drawing
->Pixmap
= Pixmap
;
200 // Clear the bottom part of the image (SAFETY)
201 gdk_draw_rectangle (Pixmap
,
202 widget
->style
->white_gc
,
204 0, Drawing
->height
+SAFETY
,
205 Drawing
->width
+SAFETY
, // do not overlap
206 (widget
->allocation
.height
) - Drawing
->height
);
207 // Clear the right part of the image (SAFETY)
208 gdk_draw_rectangle (Pixmap
,
209 widget
->style
->white_gc
,
211 Drawing
->width
+SAFETY
, 0,
212 (widget
->allocation
.width
) - Drawing
->width
, // do not overlap
213 Drawing
->height
+SAFETY
);
215 /* Clear the backgound for data request, but not SAFETY */
216 gdk_draw_rectangle (Pixmap
,
217 Drawing
->Drawing_Area_V
->style
->white_gc
,
219 Drawing
->width
+ SAFETY
, 0,
220 widget
->allocation
.width
- Drawing
->width
, // do not overlap
221 widget
->allocation
.height
+SAFETY
);
222 /* Request data for missing space */
223 g_info("missing data request");
224 drawing_data_request(Drawing
, &Pixmap
, Drawing
->width
, 0,
225 widget
->allocation
.width
- Drawing
->width
,
226 widget
->allocation
.height
);
227 // we do not request data vertically!
228 // drawing_data_request(Drawing, &Pixmap, 0, Drawing->height,
230 // widget->allocation.height - Drawing->height);
232 // gdk_draw_rectangle (Pixmap,
233 // widget->style->white_gc,
235 // Drawing->width, 0,
236 // widget->allocation.width -
238 // widget->allocation.height);
239 Drawing
->width
= widget
->allocation
.width
;
240 Drawing
->height
= widget
->allocation
.height
;
246 /* Redraw the screen from the backing pixmap */
248 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
250 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
251 g_critical("drawing expose event");
253 gdk_draw_pixmap(widget
->window
,
254 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
256 event
->area
.x
, event
->area
.y
,
257 event
->area
.x
, event
->area
.y
,
258 event
->area
.width
, event
->area
.height
);
263 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
265 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
267 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
268 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
270 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
271 g_object_set_data_full(
272 G_OBJECT(Drawing
->Drawing_Area_V
),
275 (GDestroyNotify
)drawing_destroy
);
277 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
279 // &CF_Colors[BLACK]);
281 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
283 // &(Drawing->width),
284 // &(Drawing->height),
287 //Drawing->Pixmap = gdk_pixmap_new(
288 // Drawing->Drawing_Area_V->window,
293 Drawing
->Pixmap
= NULL
;
295 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
296 // Drawing->Drawing_Area_V->allocation.width,
297 // Drawing->Drawing_Area_V->allocation.height,
300 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
302 G_CALLBACK (configure_event
),
305 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
307 G_CALLBACK (expose_event
),
313 void drawing_destroy(Drawing_t
*Drawing
)
316 // Do not unref here, Drawing_t destroyed by it's widget.
317 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
322 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
324 return Drawing
->Drawing_Area_V
;
327 /* convert_pixels_to_time
329 * Convert from window pixel and time interval to an absolute time.
331 void convert_pixels_to_time(
334 LttTime
*window_time_begin
,
335 LttTime
*window_time_end
,
338 LttTime window_time_interval
;
340 window_time_interval
= ltt_time_sub(*window_time_end
,
342 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
343 *time
= ltt_time_add(*window_time_begin
, *time
);
348 void convert_time_to_pixels(
349 LttTime window_time_begin
,
350 LttTime window_time_end
,
355 LttTime window_time_interval
;
356 float interval_float
, time_float
;
358 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
360 time
= ltt_time_sub(time
, window_time_begin
);
362 interval_float
= ltt_time_to_double(window_time_interval
);
363 time_float
= ltt_time_to_double(time
);
365 *x
= (guint
)(time_float
/interval_float
* width
);
369 void drawing_refresh ( Drawing_t
*Drawing
,
371 guint width
, guint height
)
373 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
374 GdkRectangle update_rect
;
377 Drawing
->Drawing_Area_V
->window
,
378 Drawing
->Drawing_Area_V
->
379 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
380 GDK_DRAWABLE(Drawing
->Pixmap
),
387 update_rect
.width
= Drawing
->width
;
388 update_rect
.height
= Drawing
->height
;
389 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
394 void drawing_draw_line( Drawing_t
*Drawing
,
400 gdk_draw_line (Pixmap
,
408 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
410 Drawing
->height
= h
;
413 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
421 /* Insert a square corresponding to a new process in the list */
422 /* Applies to whole Drawing->width */
423 void drawing_insert_square(Drawing_t
*Drawing
,
427 GdkRectangle update_rect
;
429 /* Allocate a new pixmap with new height */
430 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
431 Drawing
->width
+ SAFETY
,
432 Drawing
->height
+ height
+ SAFETY
,
435 /* Copy the high region */
436 gdk_draw_drawable (Pixmap
,
437 Drawing
->Drawing_Area_V
->style
->black_gc
,
441 Drawing
->width
+ SAFETY
, y
);
446 /* add an empty square */
447 gdk_draw_rectangle (Pixmap
,
448 Drawing
->Drawing_Area_V
->style
->black_gc
,
451 Drawing
->width
+ SAFETY
, // do not overlap
456 /* copy the bottom of the region */
457 gdk_draw_drawable (Pixmap
,
458 Drawing
->Drawing_Area_V
->style
->black_gc
,
462 Drawing
->width
, Drawing
->height
- y
+ SAFETY
);
468 gdk_pixmap_unref(Drawing
->Pixmap
);
470 Drawing
->Pixmap
= Pixmap
;
472 Drawing
->height
+=height
;
474 /* Rectangle to update, from new Drawing dimensions */
477 update_rect
.width
= Drawing
->width
;
478 update_rect
.height
= Drawing
->height
- y
;
479 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
483 /* Remove a square corresponding to a removed process in the list */
484 void drawing_remove_square(Drawing_t
*Drawing
,
488 GdkRectangle update_rect
;
490 /* Allocate a new pixmap with new height */
491 GdkPixmap
*Pixmap
= gdk_pixmap_new(
492 Drawing
->Drawing_Area_V
->window
,
493 Drawing
->width
+ SAFETY
,
494 Drawing
->height
- height
+ SAFETY
,
497 /* Copy the high region */
498 gdk_draw_drawable (Pixmap
,
499 Drawing
->Drawing_Area_V
->style
->black_gc
,
503 Drawing
->width
+ SAFETY
, y
);
507 /* Copy up the bottom of the region */
508 gdk_draw_drawable (Pixmap
,
509 Drawing
->Drawing_Area_V
->style
->black_gc
,
513 Drawing
->width
, Drawing
->height
- y
- height
+ SAFETY
);
517 gdk_pixmap_unref(Drawing
->Pixmap
);
519 Drawing
->Pixmap
= Pixmap
;
521 Drawing
->height
-=height
;
523 /* Rectangle to update, from new Drawing dimensions */
526 update_rect
.width
= Drawing
->width
;
527 update_rect
.height
= Drawing
->height
- y
;
528 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);