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