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