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