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 | |
73 | convert_pixels_to_time(width, x, |
f66eba62 |
74 | &control_flow_data->Time_Window.start_time, |
75 | &window_end, |
76 | &start); |
77 | |
e9a9c513 |
78 | convert_pixels_to_time(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(); |
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); |
847b479d |
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) |
f0d936c0 |
133 | { |
847b479d |
134 | Drawing_t *Drawing = (Drawing_t*)user_data; |
f0d936c0 |
135 | |
f7afe191 |
136 | /* New Pixmap, size of the configure event */ |
847b479d |
137 | GdkPixmap *Pixmap = gdk_pixmap_new(widget->window, |
138 | widget->allocation.width, |
139 | widget->allocation.height, |
140 | -1); |
141 | |
f7afe191 |
142 | g_critical("drawing configure event"); |
143 | |
144 | /* If no old Pixmap present */ |
847b479d |
145 | if(Drawing->Pixmap == NULL) |
146 | { |
f7afe191 |
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); |
847b479d |
154 | Drawing->width = widget->allocation.width; |
155 | Drawing->height = widget->allocation.height; |
f7afe191 |
156 | g_critical("init data"); |
847b479d |
157 | /* Initial data request */ |
4c69e0cc |
158 | drawing_data_request(Drawing, &Drawing->Pixmap, 0, 0, |
847b479d |
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 */ |
f7afe191 |
180 | g_critical("missing data"); |
4c69e0cc |
181 | drawing_data_request(Drawing, &Pixmap, Drawing->width, 0, |
847b479d |
182 | widget->allocation.width - Drawing->width, |
183 | widget->allocation.height); |
4c69e0cc |
184 | drawing_data_request(Drawing, &Pixmap, 0, Drawing->height, |
847b479d |
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 | |
847b479d |
204 | |
847b479d |
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 | |
4c69e0cc |
234 | Drawing_t *drawing_construct(ControlFlowData *Control_Flow_Data) |
847b479d |
235 | { |
76a67e8a |
236 | Drawing_t *Drawing = g_new(Drawing_t, 1); |
f0d936c0 |
237 | |
238 | Drawing->Drawing_Area_V = gtk_drawing_area_new (); |
f7afe191 |
239 | Drawing->Control_Flow_Data = Control_Flow_Data; |
240 | |
847b479d |
241 | //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50); |
f0d936c0 |
242 | g_object_set_data_full( |
243 | G_OBJECT(Drawing->Drawing_Area_V), |
76a67e8a |
244 | "Link_Drawing_Data", |
f0d936c0 |
245 | Drawing, |
3cff8cc1 |
246 | (GDestroyNotify)drawing_destroy); |
f0d936c0 |
247 | |
847b479d |
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 | |
847b479d |
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 | |
f0d936c0 |
281 | return Drawing; |
282 | } |
283 | |
4c69e0cc |
284 | void drawing_destroy(Drawing_t *Drawing) |
f0d936c0 |
285 | { |
286 | |
76a67e8a |
287 | // Do not unref here, Drawing_t destroyed by it's widget. |
288 | //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V)); |
f0d936c0 |
289 | |
290 | g_free(Drawing); |
291 | } |
292 | |
4c69e0cc |
293 | GtkWidget *drawing_get_widget(Drawing_t *Drawing) |
76a67e8a |
294 | { |
295 | return Drawing->Drawing_Area_V; |
296 | } |
297 | |
f66eba62 |
298 | /* convert_pixels_to_time |
f0d936c0 |
299 | * |
f66eba62 |
300 | * Convert from window pixel and time interval to an absolute time. |
f0d936c0 |
301 | */ |
fa2c4dbe |
302 | void convert_pixels_to_time( |
e9a9c513 |
303 | gint width, |
fa2c4dbe |
304 | guint x, |
305 | LttTime *window_time_begin, |
306 | LttTime *window_time_end, |
76a67e8a |
307 | LttTime *time) |
f0d936c0 |
308 | { |
fa2c4dbe |
309 | LttTime window_time_interval; |
f0d936c0 |
310 | |
308711e5 |
311 | window_time_interval = ltt_time_sub(*window_time_end, |
312 | *window_time_begin); |
e9a9c513 |
313 | *time = ltt_time_mul(window_time_interval, (x/(float)width)); |
308711e5 |
314 | *time = ltt_time_add(*window_time_begin, *time); |
fa2c4dbe |
315 | } |
316 | |
317 | |
318 | |
319 | void convert_time_to_pixels( |
320 | LttTime window_time_begin, |
321 | LttTime window_time_end, |
322 | LttTime time, |
e9a9c513 |
323 | int width, |
76a67e8a |
324 | guint *x) |
fa2c4dbe |
325 | { |
326 | LttTime window_time_interval; |
76a67e8a |
327 | float interval_float, time_float; |
fa2c4dbe |
328 | |
308711e5 |
329 | window_time_interval = ltt_time_sub(window_time_end,window_time_begin); |
fa2c4dbe |
330 | |
308711e5 |
331 | time = ltt_time_sub(time, window_time_begin); |
fa2c4dbe |
332 | |
308711e5 |
333 | interval_float = ltt_time_to_double(window_time_interval); |
334 | time_float = ltt_time_to_double(time); |
76a67e8a |
335 | |
e9a9c513 |
336 | *x = (guint)(time_float/interval_float * width); |
f0d936c0 |
337 | |
338 | } |
339 | |
4c69e0cc |
340 | void drawing_refresh ( Drawing_t *Drawing, |
847b479d |
341 | guint x, guint y, |
342 | guint width, guint height) |
343 | { |
6d5ed1c3 |
344 | g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height); |
f7afe191 |
345 | GdkRectangle update_rect; |
346 | |
847b479d |
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); |
f7afe191 |
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 | |
847b479d |
362 | } |
363 | |
364 | |
4c69e0cc |
365 | void drawing_draw_line( Drawing_t *Drawing, |
847b479d |
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 | |
fa2c4dbe |
377 | |
378 | |
4c69e0cc |
379 | void drawing_resize(Drawing_t *Drawing, guint h, guint w) |
f0d936c0 |
380 | { |
f0d936c0 |
381 | Drawing->height = h ; |
76a67e8a |
382 | Drawing->width = w ; |
f0d936c0 |
383 | |
76a67e8a |
384 | gtk_widget_set_size_request ( Drawing->Drawing_Area_V, |
385 | Drawing->width, |
f0d936c0 |
386 | Drawing->height); |
387 | |
388 | |
389 | } |
847b479d |
390 | |
391 | |
5f16133f |
392 | /* Insert a square corresponding to a new process in the list */ |
393 | /* Applies to whole Drawing->width */ |
4c69e0cc |
394 | void drawing_insert_square(Drawing_t *Drawing, |
5f16133f |
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, |
1ab3d149 |
419 | Drawing->Drawing_Area_V->style->black_gc, |
5f16133f |
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 */ |
4c69e0cc |
455 | void drawing_remove_square(Drawing_t *Drawing, |
5f16133f |
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 | } |
189a5d08 |
501 | |
502 | |