process list pid problem : everything is zero
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Drawing.c
1
2 #include <gtk/gtk.h>
3 #include <gdk/gdk.h>
4
5 #include <lttv/processTrace.h>
6 #include <lttv/gtkTraceSet.h>
7 #include <lttv/hook.h>
8
9 #include "Drawing.h"
10 #include "CFV.h"
11 #include "CFV-private.h"
12 #include "Event_Hooks.h"
13
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)
16
17
18 /*****************************************************************************
19 * Drawing functions *
20 *****************************************************************************/
21
22 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
23 typedef enum
24 {
25 RED,
26 GREEN,
27 BLUE,
28 WHITE,
29 BLACK
30
31 } ControlFlowColors;
32
33 /* Vector of unallocated colors */
34 static GdkColor CF_Colors [] =
35 {
36 { 0, 0xffff, 0x0000, 0x0000 }, // RED
37 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
38 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
39 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
40 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
41 };
42
43
44 /* Function responsible for updating the exposed area.
45 * It must call processTrace() to ask for this update.
46 */
47 void drawing_data_request(Drawing_t *Drawing,
48 GdkPixmap **Pixmap,
49 gint x, gint y,
50 gint width,
51 gint height)
52 {
53 if(width < 0) return ;
54 if(height < 0) return ;
55 ControlFlowData *control_flow_data =
56 (ControlFlowData*)g_object_get_data(
57 G_OBJECT(
58 Drawing->Drawing_Area_V),
59 "Control_Flow_Data");
60
61 LttTime start, end;
62 LttTime window_end = ltt_time_add(control_flow_data->Time_Window.time_width,
63 control_flow_data->Time_Window.start_time);
64
65 g_critical("req : window_end : %u, %u", window_end.tv_sec,
66 window_end.tv_nsec);
67
68 g_critical("req : time width : %u, %u", control_flow_data->Time_Window.time_width.tv_sec,
69 control_flow_data->Time_Window.time_width.tv_nsec);
70
71 g_critical("x is : %i, x+width is : %i", x, x+width);
72
73 convert_pixels_to_time(width, x,
74 &control_flow_data->Time_Window.start_time,
75 &window_end,
76 &start);
77
78 convert_pixels_to_time(width, x + width,
79 &control_flow_data->Time_Window.start_time,
80 &window_end,
81 &end);
82
83 LttvTracesetContext * tsc =
84 get_traceset_context(control_flow_data->Parent_Window);
85
86 gdk_draw_rectangle (*Pixmap,
87 Drawing->Drawing_Area_V->style->white_gc,
88 TRUE,
89 x, y,
90 width, // do not overlap
91 height);
92
93 //send_test_process(
94 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
95 //Drawing);
96 //send_test_drawing(
97 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
98 //Drawing, *Pixmap, x, y, width, height);
99
100 // Let's call processTrace() !!
101 EventRequest event_request; // Variable freed at the end of the function.
102 event_request.Control_Flow_Data = control_flow_data;
103 event_request.time_begin = start;
104 event_request.time_end = end;
105
106 g_critical("req : start : %u, %u", event_request.time_begin.tv_sec,
107 event_request.time_begin.tv_nsec);
108
109 g_critical("req : end : %u, %u", event_request.time_end.tv_sec,
110 event_request.time_end.tv_nsec);
111
112 LttvHooks *event = lttv_hooks_new();
113 lttv_hooks_add(event, draw_event_hook, &event_request);
114
115 lttv_process_traceset_seek_time(tsc, start);
116 lttv_traceset_context_add_hooks(tsc,
117 NULL, NULL, NULL, NULL, NULL, NULL,
118 NULL, NULL, NULL, event, NULL);
119 lttv_process_traceset(tsc, end, G_MAXULONG);
120 lttv_traceset_context_remove_hooks(tsc, NULL, NULL, NULL, NULL, NULL, NULL,
121 NULL, NULL, NULL, event, NULL);
122
123 lttv_hooks_destroy(event);
124 }
125
126 /* Callbacks */
127
128
129 /* Create a new backing pixmap of the appropriate size */
130 static gboolean
131 configure_event( GtkWidget *widget, GdkEventConfigure *event,
132 gpointer user_data)
133 {
134 Drawing_t *Drawing = (Drawing_t*)user_data;
135
136 /* New Pixmap, size of the configure event */
137 GdkPixmap *Pixmap = gdk_pixmap_new(widget->window,
138 widget->allocation.width,
139 widget->allocation.height,
140 -1);
141
142 g_critical("drawing configure event");
143
144 /* If no old Pixmap present */
145 if(Drawing->Pixmap == NULL)
146 {
147 Drawing->Pixmap = gdk_pixmap_new(
148 widget->window,
149 widget->allocation.width,
150 widget->allocation.height,
151 //ProcessList_get_height
152 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
153 -1);
154 Drawing->width = widget->allocation.width;
155 Drawing->height = widget->allocation.height;
156 g_critical("init data");
157 /* Initial data request */
158 drawing_data_request(Drawing, &Drawing->Pixmap, 0, 0,
159 widget->allocation.width,
160 widget->allocation.height);
161
162 }
163 // /* Draw empty background */
164 // gdk_draw_rectangle (Pixmap,
165 // widget->style->black_gc,
166 // TRUE,
167 // 0, 0,
168 // widget->allocation.width,
169 // widget->allocation.height);
170
171 /* Copy old data to new pixmap */
172 gdk_draw_drawable (Pixmap,
173 widget->style->white_gc,
174 Drawing->Pixmap,
175 0, 0,
176 0, 0,
177 -1, -1);
178
179 /* Request data for missing space */
180 g_critical("missing data");
181 drawing_data_request(Drawing, &Pixmap, Drawing->width, 0,
182 widget->allocation.width - Drawing->width,
183 widget->allocation.height);
184 drawing_data_request(Drawing, &Pixmap, 0, Drawing->height,
185 Drawing->width,
186 widget->allocation.height - Drawing->height);
187
188 // gdk_draw_rectangle (Pixmap,
189 // widget->style->white_gc,
190 // TRUE,
191 // Drawing->width, 0,
192 // widget->allocation.width -
193 // Drawing->width,
194 // widget->allocation.height);
195
196 // gdk_draw_rectangle (Pixmap,
197 // widget->style->white_gc,
198 // TRUE,
199 // 0, Drawing->height,
200 // Drawing->width, // do not overlap
201 // widget->allocation.height -
202 // Drawing->height);
203
204
205
206 if (Drawing->Pixmap)
207 gdk_pixmap_unref(Drawing->Pixmap);
208
209 Drawing->Pixmap = Pixmap;
210 Drawing->width = widget->allocation.width;
211 Drawing->height = widget->allocation.height;
212
213 return TRUE;
214 }
215
216
217 /* Redraw the screen from the backing pixmap */
218 static gboolean
219 expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
220 {
221 Drawing_t *Drawing = (Drawing_t*)user_data;
222 g_critical("drawing expose event");
223
224 gdk_draw_pixmap(widget->window,
225 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
226 Drawing->Pixmap,
227 event->area.x, event->area.y,
228 event->area.x, event->area.y,
229 event->area.width, event->area.height);
230
231 return FALSE;
232 }
233
234 Drawing_t *drawing_construct(ControlFlowData *Control_Flow_Data)
235 {
236 Drawing_t *Drawing = g_new(Drawing_t, 1);
237
238 Drawing->Drawing_Area_V = gtk_drawing_area_new ();
239 Drawing->Control_Flow_Data = Control_Flow_Data;
240
241 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
242 g_object_set_data_full(
243 G_OBJECT(Drawing->Drawing_Area_V),
244 "Link_Drawing_Data",
245 Drawing,
246 (GDestroyNotify)drawing_destroy);
247
248 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
249 // GTK_STATE_NORMAL,
250 // &CF_Colors[BLACK]);
251
252 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
253 // NULL, NULL,
254 // &(Drawing->width),
255 // &(Drawing->height),
256 // -1);
257
258 //Drawing->Pixmap = gdk_pixmap_new(
259 // Drawing->Drawing_Area_V->window,
260 // Drawing->width,
261 // Drawing->height,
262 // Drawing->depth);
263
264 Drawing->Pixmap = NULL;
265
266 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
267 // Drawing->Drawing_Area_V->allocation.width,
268 // Drawing->Drawing_Area_V->allocation.height,
269 // -1);
270
271 g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V),
272 "configure_event",
273 G_CALLBACK (configure_event),
274 (gpointer)Drawing);
275
276 g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V),
277 "expose_event",
278 G_CALLBACK (expose_event),
279 (gpointer)Drawing);
280
281 return Drawing;
282 }
283
284 void drawing_destroy(Drawing_t *Drawing)
285 {
286
287 // Do not unref here, Drawing_t destroyed by it's widget.
288 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
289
290 g_free(Drawing);
291 }
292
293 GtkWidget *drawing_get_widget(Drawing_t *Drawing)
294 {
295 return Drawing->Drawing_Area_V;
296 }
297
298 /* convert_pixels_to_time
299 *
300 * Convert from window pixel and time interval to an absolute time.
301 */
302 void convert_pixels_to_time(
303 gint width,
304 guint x,
305 LttTime *window_time_begin,
306 LttTime *window_time_end,
307 LttTime *time)
308 {
309 LttTime window_time_interval;
310
311 window_time_interval = ltt_time_sub(*window_time_end,
312 *window_time_begin);
313 *time = ltt_time_mul(window_time_interval, (x/(float)width));
314 *time = ltt_time_add(*window_time_begin, *time);
315 }
316
317
318
319 void convert_time_to_pixels(
320 LttTime window_time_begin,
321 LttTime window_time_end,
322 LttTime time,
323 int width,
324 guint *x)
325 {
326 LttTime window_time_interval;
327 float interval_float, time_float;
328
329 window_time_interval = ltt_time_sub(window_time_end,window_time_begin);
330
331 time = ltt_time_sub(time, window_time_begin);
332
333 interval_float = ltt_time_to_double(window_time_interval);
334 time_float = ltt_time_to_double(time);
335
336 *x = (guint)(time_float/interval_float * width);
337
338 }
339
340 void drawing_refresh ( Drawing_t *Drawing,
341 guint x, guint y,
342 guint width, guint height)
343 {
344 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height);
345 GdkRectangle update_rect;
346
347 gdk_draw_drawable(
348 Drawing->Drawing_Area_V->window,
349 Drawing->Drawing_Area_V->
350 style->fg_gc[GTK_WIDGET_STATE (Drawing->Drawing_Area_V)],
351 GDK_DRAWABLE(Drawing->Pixmap),
352 x, y,
353 x, y,
354 width, height);
355
356 update_rect.x = 0 ;
357 update_rect.y = 0 ;
358 update_rect.width = Drawing->width;
359 update_rect.height = Drawing->height ;
360 gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect);
361
362 }
363
364
365 void drawing_draw_line( Drawing_t *Drawing,
366 GdkPixmap *Pixmap,
367 guint x1, guint y1,
368 guint x2, guint y2,
369 GdkGC *GC)
370 {
371 gdk_draw_line (Pixmap,
372 GC,
373 x1, y1, x2, y2);
374 }
375
376
377
378
379 void drawing_resize(Drawing_t *Drawing, guint h, guint w)
380 {
381 Drawing->height = h ;
382 Drawing->width = w ;
383
384 gtk_widget_set_size_request ( Drawing->Drawing_Area_V,
385 Drawing->width,
386 Drawing->height);
387
388
389 }
390
391
392 /* Insert a square corresponding to a new process in the list */
393 /* Applies to whole Drawing->width */
394 void drawing_insert_square(Drawing_t *Drawing,
395 guint y,
396 guint height)
397 {
398 GdkRectangle update_rect;
399
400 /* Allocate a new pixmap with new height */
401 GdkPixmap *Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
402 Drawing->width,
403 Drawing->height + height,
404 -1);
405
406 /* Copy the high region */
407 gdk_draw_drawable (Pixmap,
408 Drawing->Drawing_Area_V->style->black_gc,
409 Drawing->Pixmap,
410 0, 0,
411 0, 0,
412 Drawing->width, y);
413
414
415
416
417 /* add an empty square */
418 gdk_draw_rectangle (Pixmap,
419 Drawing->Drawing_Area_V->style->black_gc,
420 TRUE,
421 0, y,
422 Drawing->width, // do not overlap
423 height);
424
425
426
427 /* copy the bottom of the region */
428 gdk_draw_drawable (Pixmap,
429 Drawing->Drawing_Area_V->style->black_gc,
430 Drawing->Pixmap,
431 0, y,
432 0, y + height,
433 Drawing->width, Drawing->height - y);
434
435
436
437
438 if (Drawing->Pixmap)
439 gdk_pixmap_unref(Drawing->Pixmap);
440
441 Drawing->Pixmap = Pixmap;
442
443 Drawing->height+=height;
444
445 /* Rectangle to update, from new Drawing dimensions */
446 update_rect.x = 0 ;
447 update_rect.y = y ;
448 update_rect.width = Drawing->width;
449 update_rect.height = Drawing->height - y ;
450 gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect);
451 }
452
453
454 /* Remove a square corresponding to a removed process in the list */
455 void drawing_remove_square(Drawing_t *Drawing,
456 guint y,
457 guint height)
458 {
459 GdkRectangle update_rect;
460
461 /* Allocate a new pixmap with new height */
462 GdkPixmap *Pixmap = gdk_pixmap_new(
463 Drawing->Drawing_Area_V->window,
464 Drawing->width,
465 Drawing->height - height,
466 -1);
467
468 /* Copy the high region */
469 gdk_draw_drawable (Pixmap,
470 Drawing->Drawing_Area_V->style->black_gc,
471 Drawing->Pixmap,
472 0, 0,
473 0, 0,
474 Drawing->width, y);
475
476
477
478 /* Copy up the bottom of the region */
479 gdk_draw_drawable (Pixmap,
480 Drawing->Drawing_Area_V->style->black_gc,
481 Drawing->Pixmap,
482 0, y + height,
483 0, y,
484 Drawing->width, Drawing->height - y - height);
485
486
487 if (Drawing->Pixmap)
488 gdk_pixmap_unref(Drawing->Pixmap);
489
490 Drawing->Pixmap = Pixmap;
491
492 Drawing->height-=height;
493
494 /* Rectangle to update, from new Drawing dimensions */
495 update_rect.x = 0 ;
496 update_rect.y = y ;
497 update_rect.width = Drawing->width;
498 update_rect.height = Drawing->height - y ;
499 gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect);
500 }
501
502
This page took 0.040348 seconds and 4 git commands to generate.