81edb1e363fa21481ca7c2cf3d63c6621ffc188e
[lttv.git] / ltt / branches / poly / lttv / modules / gui / resourceview / drawing.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <gtk/gtk.h>
24 #include <gdk/gdk.h>
25 #include <string.h>
26
27 #include <ltt/trace.h>
28
29 #include <lttv/lttv.h>
30 #include <lttv/tracecontext.h>
31 #include <lttvwindow/lttvwindow.h>
32 #include <lttv/state.h>
33 #include <lttv/hook.h>
34
35 #include "drawing.h"
36 #include "eventhooks.h"
37 #include "cfv.h"
38
39 //#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
40 //#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
41
42 //FIXME
43 // fixed #define TRACE_NUMBER 0
44 #define EXTRA_ALLOC 1024 // pixels
45
46
47 #if 0 /* colors for two lines representation */
48 GdkColor drawing_colors[NUM_COLORS] =
49 { /* Pixel, R, G, B */
50 { 0, 0, 0, 0 }, /* COL_BLACK */
51 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
52 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
53 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
54 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
55 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
56 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
57 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
58 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
59 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
60 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
61 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
62 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
63
64 };
65 #endif //0
66
67
68 GdkColor drawing_colors[NUM_COLORS] =
69 { /* Pixel, R, G, B */
70 { 0, 0, 0, 0 }, /* COL_BLACK */
71 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
72 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
73 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
74 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
75 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : orange */
76 { 0, 0xFFFF, 0x9400, 0x9600 }, /* COL_RUN_SOFT_IRQ : pink */
77 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
78 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
79 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
80 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
81 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
82 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
83 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
84
85 };
86
87 /*
88 RUN+USER MODE green
89 RUN+SYSCALL
90 RUN+TRAP
91 RUN+IRQ
92 WAIT+foncé
93 WAIT CPU + WAIT FORK vert foncé ou jaune
94 IRQ rouge
95 TRAP: orange
96 SYSCALL: bleu pâle
97
98 ZOMBIE + WAIT EXIT
99 */
100
101
102 /*****************************************************************************
103 * drawing functions *
104 *****************************************************************************/
105
106 static gboolean
107 expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data );
108
109 static gboolean
110 motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
111
112
113 /* Function responsible for updating the exposed area.
114 * It must do an events request to the lttvwindow API to ask for this update.
115 * Note : this function cannot clear the background, because it may
116 * erase drawing already present (SAFETY).
117 */
118 void drawing_data_request(Drawing_t *drawing,
119 gint x, gint y,
120 gint width,
121 gint height)
122 {
123 if(width < 0) return ;
124 if(height < 0) return ;
125
126
127 Tab *tab = drawing->control_flow_data->tab;
128 TimeWindow time_window =
129 lttvwindow_get_time_window(tab);
130
131 ControlFlowData *control_flow_data = drawing->control_flow_data;
132 // (ControlFlowData*)g_object_get_data(
133 // G_OBJECT(drawing->drawing_area), "control_flow_data");
134
135 LttTime start, time_end;
136 LttTime window_end = time_window.end_time;
137
138 g_debug("req : window start_time : %lu, %lu", time_window.start_time.tv_sec,
139 time_window.start_time.tv_nsec);
140
141 g_debug("req : window time width : %lu, %lu", time_window.time_width.tv_sec,
142 time_window.time_width.tv_nsec);
143
144 g_debug("req : window_end : %lu, %lu", window_end.tv_sec,
145 window_end.tv_nsec);
146
147 g_debug("x is : %i, x+width is : %i", x, x+width);
148
149 convert_pixels_to_time(drawing->width, x,
150 time_window,
151 &start);
152
153 convert_pixels_to_time(drawing->width, x+width,
154 time_window,
155 &time_end);
156 time_end = ltt_time_add(time_end, ltt_time_one); // because main window
157 // doesn't deliver end time.
158
159 lttvwindow_events_request_remove_all(tab,
160 control_flow_data);
161
162 {
163 /* find the tracehooks */
164 LttvTracesetContext *tsc = lttvwindow_get_traceset_context(tab);
165
166 LttvTraceset *traceset = tsc->ts;
167
168 guint i, k, l, nb_trace;
169
170 LttvTraceState *ts;
171
172 LttvTracefileState *tfs;
173
174 GArray *hooks;
175
176 LttvTraceHook *hook;
177
178 LttvTraceHookByFacility *thf;
179
180 guint ret;
181 gint before_hn, after_hn;
182
183 nb_trace = lttv_traceset_number(traceset);
184 // FIXME (fixed) : eventually request for more traces
185 for(i = 0 ; i < nb_trace ; i++) {
186 //for(i = 0; i<MIN(TRACE_NUMBER+1, nb_trace);i++) {
187 EventsRequest *events_request = g_new(EventsRequest, 1);
188 // Create the hooks
189 //LttvHooks *event = lttv_hooks_new();
190 LttvHooksById *event_by_id = lttv_hooks_by_id_new();
191 LttvHooks *before_chunk_traceset = lttv_hooks_new();
192 LttvHooks *after_chunk_traceset = lttv_hooks_new();
193 LttvHooks *before_request_hook = lttv_hooks_new();
194 LttvHooks *after_request_hook = lttv_hooks_new();
195
196 lttv_hooks_add(before_chunk_traceset,
197 before_chunk,
198 events_request,
199 LTTV_PRIO_DEFAULT);
200
201 lttv_hooks_add(after_chunk_traceset,
202 after_chunk,
203 events_request,
204 LTTV_PRIO_DEFAULT);
205
206 lttv_hooks_add(before_request_hook,
207 before_request,
208 events_request,
209 LTTV_PRIO_DEFAULT);
210
211 lttv_hooks_add(after_request_hook,
212 after_request,
213 events_request,
214 LTTV_PRIO_DEFAULT);
215
216
217 ts = (LttvTraceState *)tsc->traces[i];
218
219 /* Find the eventtype id for the following events and register the
220 associated by id hooks. */
221
222 hooks = g_array_new(FALSE, FALSE, sizeof(LttvTraceHook));
223 hooks = g_array_set_size(hooks, 18);
224 before_hn = after_hn = 0;
225
226 /* before hooks */
227
228 // ret = lttv_trace_find_hook(ts->parent.t,
229 // LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_ENTRY,
230 // LTT_FIELD_SYSCALL_ID, 0, 0,
231 // before_execmode_hook,
232 // events_request,
233 // &g_array_index(hooks, LttvTraceHook, before_hn++));
234 // if(ret) before_hn--;
235 //
236 // ret = lttv_trace_find_hook(ts->parent.t,
237 // LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_EXIT,
238 // 0, 0, 0,
239 // before_execmode_hook,
240 // events_request,
241 // &g_array_index(hooks, LttvTraceHook, before_hn++));
242 // if(ret) before_hn--;
243 //
244 // ret = lttv_trace_find_hook(ts->parent.t,
245 // LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_TRAP_ENTRY,
246 // LTT_FIELD_TRAP_ID, 0, 0,
247 // before_execmode_hook,
248 // events_request,
249 // &g_array_index(hooks, LttvTraceHook, before_hn++));
250 // if(ret) before_hn--;
251 //
252 // ret = lttv_trace_find_hook(ts->parent.t,
253 // LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_TRAP_EXIT,
254 // 0, 0, 0,
255 // before_execmode_hook,
256 // events_request,
257 // &g_array_index(hooks, LttvTraceHook, before_hn++));
258 // if(ret) before_hn--;
259 //
260 // ret = lttv_trace_find_hook(ts->parent.t,
261 // LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_ENTRY,
262 // LTT_FIELD_IRQ_ID, 0, 0,
263 // before_execmode_hook,
264 // events_request,
265 // &g_array_index(hooks, LttvTraceHook, before_hn++));
266 // if(ret) before_hn--;
267 //
268 // ret = lttv_trace_find_hook(ts->parent.t,
269 // LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_EXIT,
270 // 0, 0, 0,
271 // before_execmode_hook,
272 // events_request,
273 // &g_array_index(hooks, LttvTraceHook, before_hn++));
274 // if(ret) before_hn--;
275 //
276 // ret = lttv_trace_find_hook(ts->parent.t,
277 // LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_ENTRY,
278 // LTT_FIELD_SOFT_IRQ_ID, 0, 0,
279 // before_execmode_hook,
280 // events_request,
281 // &g_array_index(hooks, LttvTraceHook, before_hn++));
282 // if(ret) before_hn--;
283 //
284 // ret = lttv_trace_find_hook(ts->parent.t,
285 // LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_EXIT,
286 // 0, 0, 0,
287 // before_execmode_hook,
288 // events_request,
289 // &g_array_index(hooks, LttvTraceHook, before_hn++));
290 // if(ret) before_hn--;
291
292
293 ret = lttv_trace_find_hook(ts->parent.t,
294 LTT_FACILITY_KERNEL, LTT_EVENT_SCHED_SCHEDULE,
295 LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE,
296 before_schedchange_hook,
297 events_request,
298 &g_array_index(hooks, LttvTraceHook, before_hn++));
299 if(ret) before_hn--;
300
301 // ret = lttv_trace_find_hook(ts->parent.t,
302 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_EXIT,
303 // LTT_FIELD_PID, 0, 0,
304 // before_process_exit_hook,
305 // events_request,
306 // &g_array_index(hooks, LttvTraceHook, before_hn++));
307 // if(ret) before_hn--;
308 //
309 // ret = lttv_trace_find_hook(ts->parent.t,
310 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_FREE,
311 // LTT_FIELD_PID, 0, 0,
312 // before_process_release_hook,
313 // events_request,
314 // &g_array_index(hooks, LttvTraceHook, before_hn++));
315 // if(ret) before_hn--;
316 //
317 // ret = lttv_trace_find_hook(ts->parent.t,
318 // LTT_FACILITY_LIST, LTT_EVENT_STATEDUMP_END,
319 // 0, 0, 0,
320 // before_statedump_end,
321 // events_request,
322 // &g_array_index(hooks, LttvTraceHook, before_hn++));
323 // if(ret) before_hn--;
324
325 #if 0
326 lttv_trace_find_hook(ts->parent.t,
327 "core", "process", "event_sub_id",
328 "event_data1", "event_data2", before_process_hook,
329 &g_array_index(hooks, LttvTraceHook, hn++));
330 #endif //0
331 #if 0
332 lttv_trace_find_hook(ts->parent.t, "core", "process_fork", "child_pid",
333 NULL, NULL, process_fork, &g_array_index(hooks, LttvTraceHook, hn++));
334
335 lttv_trace_find_hook(ts->parent.t, "core", "process_exit", NULL, NULL,
336 NULL, process_exit, &g_array_index(hooks, LttvTraceHook, hn++));
337 #endif //0
338
339 /* after hooks */
340
341 #if 0
342 /**** DESACTIVATED ****/
343 lttv_trace_find_hook(ts->parent.t, "core","syscall_entry","syscall_id",
344 NULL, NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
345 /**** DESACTIVATED ****/
346 lttv_trace_find_hook(ts->parent.t, "core", "syscall_exit", NULL, NULL,
347 NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
348
349 /**** DESACTIVATED ****/
350 lttv_trace_find_hook(ts->parent.t, "core", "trap_entry", "trap_id",
351 NULL, NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
352
353 /**** DESACTIVATED ****/
354 lttv_trace_find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL, NULL,
355 after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
356
357 /**** DESACTIVATED ****/
358 lttv_trace_find_hook(ts->parent.t, "core", "irq_entry", "irq_id", NULL,
359 NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
360
361 /**** DESACTIVATED ****/
362 lttv_trace_find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL, NULL,
363 after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
364 #endif //0
365 #if 0
366 lttv_trace_find_hook(ts->parent.t, "core", "schedchange", "in", "out",
367 "out_state", after_schedchange_hook,
368 &g_array_index(hooks, LttvTraceHook, hn++));
369
370 lttv_trace_find_hook(ts->parent.t, "core", "process", "event_sub_id",
371 "event_data1", "event_data2", after_process_hook,
372 &g_array_index(hooks, LttvTraceHook, hn++));
373 #endif //0
374 after_hn = before_hn;
375
376 ret = lttv_trace_find_hook(ts->parent.t,
377 LTT_FACILITY_KERNEL, LTT_EVENT_SCHED_SCHEDULE,
378 LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE,
379 after_schedchange_hook,
380 events_request,
381 &g_array_index(hooks, LttvTraceHook, after_hn++));
382 if(ret) after_hn--;
383
384 // ret = lttv_trace_find_hook(ts->parent.t,
385 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_FORK,
386 // LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID, 0,
387 // after_process_fork_hook,
388 // events_request,
389 // &g_array_index(hooks, LttvTraceHook, after_hn++));
390 // if(ret) after_hn--;
391 //
392 // ret = lttv_trace_find_hook(ts->parent.t,
393 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_EXIT,
394 // LTT_FIELD_PID, 0, 0,
395 // after_process_exit_hook,
396 // events_request,
397 // &g_array_index(hooks, LttvTraceHook, after_hn++));
398 // if(ret) after_hn--;
399 //
400 // ret = lttv_trace_find_hook(ts->parent.t,
401 // LTT_FACILITY_FS, LTT_EVENT_EXEC,
402 // 0, 0, 0,
403 // after_fs_exec_hook,
404 // events_request,
405 // &g_array_index(hooks, LttvTraceHook, after_hn++));
406 // if(ret) after_hn--;
407 //
408 // ret = lttv_trace_find_hook(ts->parent.t,
409 // LTT_FACILITY_USER_GENERIC, LTT_EVENT_THREAD_BRAND,
410 // LTT_FIELD_NAME, 0, 0,
411 // after_user_generic_thread_brand_hook,
412 // events_request,
413 // &g_array_index(hooks, LttvTraceHook, after_hn++));
414 // if(ret) after_hn--;
415 //
416 // ret = lttv_trace_find_hook(ts->parent.t,
417 // LTT_FACILITY_LIST, LTT_EVENT_PROCESS_STATE,
418 // LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
419 // after_event_enum_process_hook,
420 // events_request,
421 // &g_array_index(hooks, LttvTraceHook, after_hn++));
422 // if(ret) after_hn--;
423
424 hooks = g_array_set_size(hooks, after_hn);
425
426 #if 0
427 lttv_trace_find_hook(ts->parent.t, "core", "process_fork", "child_pid",
428 NULL, NULL, process_fork, &g_array_index(hooks, LttvTraceHook, hn++));
429
430 lttv_trace_find_hook(ts->parent.t, "core", "process_exit", NULL, NULL,
431 NULL, process_exit, &g_array_index(hooks, LttvTraceHook, hn++));
432 #endif //0
433
434
435
436 /* Add these hooks to each event_by_id hooks list */
437 /* add before */
438 for(k = 0 ; k < before_hn ; k++) {
439 hook = &g_array_index(hooks, LttvTraceHook, k);
440 for(l=0;l<hook->fac_list->len;l++) {
441 thf = g_array_index(hook->fac_list, LttvTraceHookByFacility*, l);
442 lttv_hooks_add(lttv_hooks_by_id_find(event_by_id, thf->id),
443 thf->h,
444 thf,
445 LTTV_PRIO_STATE-5);
446 }
447 }
448
449 /* add after */
450 for(k = before_hn ; k < after_hn ; k++) {
451 hook = &g_array_index(hooks, LttvTraceHook, k);
452 for(l=0;l<hook->fac_list->len;l++) {
453 thf = g_array_index(hook->fac_list, LttvTraceHookByFacility*, l);
454 lttv_hooks_add(lttv_hooks_by_id_find(event_by_id, thf->id),
455 thf->h,
456 thf,
457 LTTV_PRIO_STATE+5);
458 }
459 }
460
461 events_request->hooks = hooks;
462
463 // Fill the events request
464 events_request->owner = control_flow_data;
465 events_request->viewer_data = control_flow_data;
466 events_request->servicing = FALSE;
467 events_request->start_time = start;
468 events_request->start_position = NULL;
469 events_request->stop_flag = FALSE;
470 events_request->end_time = time_end;
471 events_request->num_events = G_MAXUINT;
472 events_request->end_position = NULL;
473 events_request->trace = i; //fixed /* FIXME */
474 events_request->before_chunk_traceset = before_chunk_traceset;
475 events_request->before_chunk_trace = NULL;
476 events_request->before_chunk_tracefile = NULL;
477 events_request->event = NULL;
478 events_request->event_by_id = event_by_id;
479 events_request->after_chunk_tracefile = NULL;
480 events_request->after_chunk_trace = NULL;
481 events_request->after_chunk_traceset = after_chunk_traceset;
482 events_request->before_request = before_request_hook;
483 events_request->after_request = after_request_hook;
484
485 g_debug("req : start : %lu, %lu", start.tv_sec,
486 start.tv_nsec);
487
488 g_debug("req : end : %lu, %lu", time_end.tv_sec,
489 time_end.tv_nsec);
490
491 lttvwindow_events_request(tab, events_request);
492
493 }
494
495 }
496
497 #if 0
498 lttv_hooks_add(event,
499 before_schedchange_hook,
500 events_request,
501 LTTV_PRIO_STATE-5);
502 lttv_hooks_add(event,
503 after_schedchange_hook,
504 events_request,
505 LTTV_PRIO_STATE+5);
506 lttv_hooks_add(event,
507 before_execmode_hook,
508 events_request,
509 LTTV_PRIO_STATE-5);
510 lttv_hooks_add(event,
511 after_execmode_hook,
512 events_request,
513 LTTV_PRIO_STATE+5);
514 lttv_hooks_add(event,
515 before_process_hook,
516 events_request,
517 LTTV_PRIO_STATE-5);
518 lttv_hooks_add(event,
519 after_process_hook,
520 events_request,
521 LTTV_PRIO_STATE+5);
522 #endif //0
523
524 }
525
526
527 static void set_last_start(gpointer key, gpointer value, gpointer user_data)
528 {
529 ResourceInfo *process_info = (ResourceInfo*)key;
530 HashedResourceData *hashed_process_data = (HashedResourceData*)value;
531 guint x = (guint)user_data;
532
533 hashed_process_data->x.over = x;
534 hashed_process_data->x.over_used = FALSE;
535 hashed_process_data->x.over_marked = FALSE;
536 hashed_process_data->x.middle = x;
537 hashed_process_data->x.middle_used = FALSE;
538 hashed_process_data->x.middle_marked = FALSE;
539 hashed_process_data->x.under = x;
540 hashed_process_data->x.under_used = FALSE;
541 hashed_process_data->x.under_marked = FALSE;
542 hashed_process_data->next_good_time = ltt_time_zero;
543
544 return;
545 }
546
547 void drawing_data_request_begin(EventsRequest *events_request, LttvTracesetState *tss)
548 {
549 g_debug("Begin of data request");
550 ControlFlowData *cfd = events_request->viewer_data;
551 LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tss);
552 TimeWindow time_window =
553 lttvwindow_get_time_window(cfd->tab);
554
555 guint width = cfd->drawing->width;
556 guint x=0;
557
558 cfd->drawing->last_start = events_request->start_time;
559
560 convert_time_to_pixels(
561 time_window,
562 events_request->start_time,
563 width,
564 &x);
565
566 g_hash_table_foreach(cfd->process_list->process_hash, set_last_start,
567 (gpointer)x);
568
569 }
570
571 void drawing_chunk_begin(EventsRequest *events_request, LttvTracesetState *tss)
572 {
573 g_debug("Begin of chunk");
574 ControlFlowData *cfd = events_request->viewer_data;
575 LttvTracesetContext *tsc = &tss->parent.parent;
576 //LttTime current_time = lttv_traceset_context_get_current_tfc(tsc)->timestamp;
577 guint i;
578 LttvTraceset *traceset = tsc->ts;
579 guint nb_trace = lttv_traceset_number(traceset);
580
581 if(!cfd->process_list->current_hash_data) {
582 cfd->process_list->current_hash_data = g_new(HashedResourceData**,nb_trace);
583 for(i = 0 ; i < nb_trace ; i++) {
584 guint num_cpu = ltt_trace_get_num_cpu(tss->parent.traces[i]->t);
585 cfd->process_list->current_hash_data[i] = g_new(HashedResourceData*,num_cpu);
586 memset(cfd->process_list->current_hash_data[i], 0,
587 sizeof(HashedResourceData*)*num_cpu);
588 }
589 }
590 //cfd->drawing->last_start = LTT_TIME_MIN(current_time,
591 // events_request->end_time);
592 }
593
594
595 void drawing_request_expose(EventsRequest *events_request,
596 LttvTracesetState *tss,
597 LttTime end_time)
598 {
599 gint x, width;
600 guint x_end;
601
602 ControlFlowData *cfd = events_request->viewer_data;
603 LttvTracesetContext *tsc = (LttvTracesetContext*)tss;
604 Drawing_t *drawing = cfd->drawing;
605
606 TimeWindow time_window =
607 lttvwindow_get_time_window(cfd->tab);
608
609 g_debug("request expose");
610
611 convert_time_to_pixels(
612 time_window,
613 end_time,
614 drawing->width,
615 &x_end);
616 x = drawing->damage_begin;
617
618 width = x_end - x;
619
620 drawing->damage_begin = x+width;
621
622 // FIXME ?
623 gtk_widget_queue_draw_area ( drawing->drawing_area,
624 x, 0,
625 width, drawing->drawing_area->allocation.height);
626
627 /* Update directly when scrolling */
628 gdk_window_process_updates(drawing->drawing_area->window,
629 TRUE);
630 }
631
632
633 /* Callbacks */
634
635
636 /* Create a new backing pixmap of the appropriate size */
637 /* As the scaling will always change, it's of no use to copy old
638 * pixmap.
639 *
640 * Only change the size if width changes. The height is specified and changed
641 * when process ID are added or removed from the process list.
642 */
643 static gboolean
644 configure_event( GtkWidget *widget, GdkEventConfigure *event,
645 gpointer user_data)
646 {
647 Drawing_t *drawing = (Drawing_t*)user_data;
648
649
650 /* First, get the new time interval of the main window */
651 /* we assume (see documentation) that the main window
652 * has updated the time interval before this configure gets
653 * executed.
654 */
655 //lttvwindow_get_time_window(drawing->control_flow_data->mw,
656 // &drawing->control_flow_data->time_window);
657
658 /* New pixmap, size of the configure event */
659 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
660 // widget->allocation.width + SAFETY,
661 // widget->allocation.height + SAFETY,
662 // -1);
663
664 if(widget->allocation.width != drawing->width) {
665 g_debug("drawing configure event");
666 g_debug("New alloc draw size : %i by %i",widget->allocation.width,
667 widget->allocation.height);
668
669 drawing->width = widget->allocation.width;
670
671 if(drawing->alloc_width < widget->allocation.width) {
672 //if(drawing->pixmap)
673 // gdk_pixmap_unref(drawing->pixmap);
674
675 //drawing->pixmap = gdk_pixmap_new(widget->window,
676 // drawing->width + SAFETY + EXTRA_ALLOC,
677 // drawing->height + EXTRA_ALLOC,
678 // -1);
679 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
680 drawing->alloc_height = drawing->height + EXTRA_ALLOC;
681 update_pixmap_size(drawing->control_flow_data->process_list,
682 drawing->alloc_width);
683 update_index_to_pixmap(drawing->control_flow_data->process_list);
684 }
685 //drawing->height = widget->allocation.height;
686
687 //ProcessList_get_height
688 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
689
690
691 // Clear the image
692 //gdk_draw_rectangle (drawing->pixmap,
693 // widget->style->black_gc,
694 // TRUE,
695 // 0, 0,
696 // drawing->width+SAFETY,
697 // drawing->height);
698
699 //g_info("init data request");
700
701
702 /* Initial data request */
703 /* no, do initial data request in the expose event */
704 // Do not need to ask for data of 1 pixel : not synchronized with
705 // main window time at this moment.
706 //drawing_data_request(drawing, &drawing->pixmap, 0, 0,
707 // widget->allocation.width,
708 // widget->allocation.height);
709
710 //drawing->width = widget->allocation.width;
711 //drawing->height = widget->allocation.height;
712
713 drawing->damage_begin = 0;
714 drawing->damage_end = widget->allocation.width;
715
716 if((widget->allocation.width != 1 &&
717 widget->allocation.height != 1)
718 && drawing->damage_begin < drawing->damage_end)
719 {
720
721 rectangle_pixmap (drawing->control_flow_data->process_list,
722 drawing->drawing_area->style->black_gc,
723 TRUE,
724 0, 0,
725 drawing->alloc_width, // do not overlap
726 -1);
727
728
729 drawing_data_request(drawing,
730 drawing->damage_begin,
731 0,
732 drawing->damage_end - drawing->damage_begin,
733 drawing->height);
734 }
735 }
736 return TRUE;
737 }
738
739
740 /* Redraw the screen from the backing pixmap */
741 static gboolean
742 expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
743 {
744 Drawing_t *drawing = (Drawing_t*)user_data;
745
746 ControlFlowData *control_flow_data =
747 (ControlFlowData*)g_object_get_data(
748 G_OBJECT(widget),
749 "control_flow_data");
750 #if 0
751 if(unlikely(drawing->gc == NULL)) {
752 drawing->gc = gdk_gc_new(drawing->drawing_area->window);
753 gdk_gc_copy(drawing->gc, drawing->drawing_area->style->black_gc);
754 }
755 #endif //0
756 TimeWindow time_window =
757 lttvwindow_get_time_window(control_flow_data->tab);
758 LttTime current_time =
759 lttvwindow_get_current_time(control_flow_data->tab);
760
761 guint cursor_x=0;
762
763 LttTime window_end = time_window.end_time;
764
765 /* update the screen from the pixmap buffer */
766 #if 0
767 gdk_draw_pixmap(widget->window,
768 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
769 drawing->pixmap,
770 event->area.x, event->area.y,
771 event->area.x, event->area.y,
772 event->area.width, event->area.height);
773 #endif //0
774 drawing->height = processlist_get_height(control_flow_data->process_list);
775 #if 0
776 copy_pixmap_to_screen(control_flow_data->process_list,
777 widget->window,
778 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
779 event->area.x, event->area.y,
780 event->area.width, event->area.height);
781 #endif //0
782 copy_pixmap_to_screen(control_flow_data->process_list,
783 widget->window,
784 drawing->gc,
785 event->area.x, event->area.y,
786 event->area.width, event->area.height);
787
788
789 /* Erase the dotted lines left.. */
790 if(widget->allocation.height > drawing->height)
791 {
792 gdk_draw_rectangle (widget->window,
793 drawing->drawing_area->style->black_gc,
794 TRUE,
795 event->area.x, drawing->height,
796 event->area.width, // do not overlap
797 widget->allocation.height - drawing->height);
798 }
799 if(ltt_time_compare(time_window.start_time, current_time) <= 0 &&
800 ltt_time_compare(window_end, current_time) >= 0)
801 {
802 /* Draw the dotted lines */
803 convert_time_to_pixels(
804 time_window,
805 current_time,
806 drawing->width,
807 &cursor_x);
808
809 #if 0
810 if(drawing->dotted_gc == NULL) {
811
812 drawing->dotted_gc = gdk_gc_new(drawing->drawing_area->window);
813 gdk_gc_copy(drawing->dotted_gc, widget->style->white_gc);
814
815 gint8 dash_list[] = { 1, 2 };
816 gdk_gc_set_line_attributes(drawing->dotted_gc,
817 1,
818 GDK_LINE_ON_OFF_DASH,
819 GDK_CAP_BUTT,
820 GDK_JOIN_MITER);
821 gdk_gc_set_dashes(drawing->dotted_gc,
822 0,
823 dash_list,
824 2);
825 }
826 #endif //0
827 gint height_tot = MAX(widget->allocation.height, drawing->height);
828 gdk_draw_line(widget->window,
829 drawing->dotted_gc,
830 cursor_x, 0,
831 cursor_x, height_tot);
832 }
833 return FALSE;
834 }
835
836 static gboolean
837 after_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
838 {
839 //g_assert(0);
840 g_debug("AFTER EXPOSE");
841
842 return FALSE;
843
844
845 }
846
847 #if 0
848 void
849 tree_row_activated(GtkTreeModel *treemodel,
850 GtkTreePath *arg1,
851 GtkTreeViewColumn *arg2,
852 gpointer user_data)
853 {
854 ControlFlowData *cfd = (ControlFlowData*)user_data;
855 Drawing_t *drawing = cfd->drawing;
856 GtkTreeView *treeview = cfd->process_list->process_list_widget;
857 gint *path_indices;
858 gint height;
859
860 path_indices = gtk_tree_path_get_indices (arg1);
861
862 height = get_cell_height(cfd->process_list,
863 GTK_TREE_VIEW(treeview));
864 drawing->horizontal_sel = height * path_indices[0];
865 g_critical("new hor sel : %i", drawing->horizontal_sel);
866 }
867 #endif //0
868
869 /* mouse click */
870 static gboolean
871 button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data )
872 {
873 ControlFlowData *control_flow_data =
874 (ControlFlowData*)g_object_get_data(
875 G_OBJECT(widget),
876 "control_flow_data");
877 Drawing_t *drawing = control_flow_data->drawing;
878 TimeWindow time_window =
879 lttvwindow_get_time_window(control_flow_data->tab);
880
881 g_debug("click");
882 if(event->button == 1)
883 {
884 LttTime time;
885
886 /* left mouse button click */
887 g_debug("x click is : %f", event->x);
888
889 convert_pixels_to_time(drawing->width, (guint)event->x,
890 time_window,
891 &time);
892
893 lttvwindow_report_current_time(control_flow_data->tab, time);
894
895 }
896
897 return FALSE;
898 }
899
900 static gboolean
901 scrollbar_size_allocate(GtkWidget *widget,
902 GtkAllocation *allocation,
903 gpointer user_data)
904 {
905 Drawing_t *drawing = (Drawing_t*)user_data;
906
907 gtk_widget_set_size_request(drawing->padding, allocation->width, -1);
908 //gtk_widget_queue_resize(drawing->padding);
909 //gtk_widget_queue_resize(drawing->ruler);
910 gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox));
911 return 0;
912 }
913
914
915
916 Drawing_t *drawing_construct(ControlFlowData *control_flow_data)
917 {
918 Drawing_t *drawing = g_new(Drawing_t, 1);
919
920 drawing->control_flow_data = control_flow_data;
921
922 drawing->vbox = gtk_vbox_new(FALSE, 1);
923
924
925 drawing->ruler_hbox = gtk_hbox_new(FALSE, 1);
926 drawing->ruler = gtk_drawing_area_new ();
927 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
928
929 drawing->padding = gtk_drawing_area_new ();
930 //gtk_widget_set_size_request(drawing->padding, -1, 27);
931 gtk_box_pack_start(GTK_BOX(drawing->ruler_hbox), drawing->ruler,
932 TRUE, TRUE, 0);
933 gtk_box_pack_end(GTK_BOX(drawing->ruler_hbox), drawing->padding,
934 FALSE, FALSE, 0);
935
936
937
938 drawing->drawing_area = gtk_drawing_area_new ();
939
940 drawing->gc = NULL;
941
942 drawing->hbox = gtk_hbox_new(FALSE, 1);
943 drawing->viewport = gtk_viewport_new(NULL, control_flow_data->v_adjust);
944 drawing->scrollbar = gtk_vscrollbar_new(control_flow_data->v_adjust);
945 gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport,
946 TRUE, TRUE, 0);
947 gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar,
948 FALSE, FALSE, 0);
949
950 //drawing->scrolled_window =
951 // gtk_scrolled_window_new (NULL,
952 // control_flow_data->v_adjust);
953
954 //gtk_scrolled_window_set_policy(
955 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
956 // GTK_POLICY_NEVER,
957 // GTK_POLICY_AUTOMATIC);
958
959 gtk_container_add(GTK_CONTAINER(drawing->viewport),
960 drawing->drawing_area);
961 //gtk_scrolled_window_add_with_viewport(
962 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
963 // drawing->drawing_area);
964
965 gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler_hbox,
966 FALSE, FALSE, 0);
967 gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->hbox,
968 TRUE, TRUE, 0);
969
970 drawing->pango_layout =
971 gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
972
973 drawing->height = 1;
974 drawing->width = 1;
975 drawing->depth = 0;
976 drawing->alloc_height = 1;
977 drawing->alloc_width = 1;
978
979 drawing->damage_begin = 0;
980 drawing->damage_end = 0;
981 drawing->horizontal_sel = -1;
982
983 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
984 g_object_set_data_full(
985 G_OBJECT(drawing->drawing_area),
986 "Link_drawing_Data",
987 drawing,
988 (GDestroyNotify)drawing_destroy);
989
990 g_object_set_data(
991 G_OBJECT(drawing->ruler),
992 "drawing",
993 drawing);
994
995
996 //gtk_widget_modify_bg( drawing->drawing_area,
997 // GTK_STATE_NORMAL,
998 // &CF_Colors[BLACK]);
999
1000 //gdk_window_get_geometry(drawing->drawing_area->window,
1001 // NULL, NULL,
1002 // &(drawing->width),
1003 // &(drawing->height),
1004 // -1);
1005
1006 //drawing->pixmap = gdk_pixmap_new(
1007 // drawing->drawing_area->window,
1008 // drawing->width,
1009 // drawing->height,
1010 // drawing->depth);
1011
1012 //drawing->pixmap = NULL;
1013
1014 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1015 // drawing->drawing_area->allocation.width,
1016 // drawing->drawing_area->allocation.height,
1017 // -1);
1018
1019 g_signal_connect (G_OBJECT(drawing->drawing_area),
1020 "configure_event",
1021 G_CALLBACK (configure_event),
1022 (gpointer)drawing);
1023
1024 g_signal_connect (G_OBJECT(drawing->ruler),
1025 "expose_event",
1026 G_CALLBACK(expose_ruler),
1027 (gpointer)drawing);
1028
1029 gtk_widget_add_events(drawing->ruler, GDK_POINTER_MOTION_MASK);
1030
1031 g_signal_connect (G_OBJECT(drawing->ruler),
1032 "motion-notify-event",
1033 G_CALLBACK(motion_notify_ruler),
1034 (gpointer)drawing);
1035
1036
1037 g_signal_connect (G_OBJECT(drawing->scrollbar),
1038 "size-allocate",
1039 G_CALLBACK(scrollbar_size_allocate),
1040 (gpointer)drawing);
1041
1042
1043
1044 g_signal_connect (G_OBJECT(drawing->drawing_area),
1045 "expose_event",
1046 G_CALLBACK (expose_event),
1047 (gpointer)drawing);
1048
1049 g_signal_connect_after (G_OBJECT(drawing->drawing_area),
1050 "expose_event",
1051 G_CALLBACK (after_expose_event),
1052 (gpointer)drawing);
1053
1054 g_signal_connect (G_OBJECT(drawing->drawing_area),
1055 "button-press-event",
1056 G_CALLBACK (button_press_event),
1057 (gpointer)drawing);
1058
1059
1060 gtk_widget_show(drawing->ruler);
1061 gtk_widget_show(drawing->padding);
1062 gtk_widget_show(drawing->ruler_hbox);
1063
1064 gtk_widget_show(drawing->drawing_area);
1065 //gtk_widget_show(drawing->scrolled_window);
1066 gtk_widget_show(drawing->viewport);
1067 gtk_widget_show(drawing->scrollbar);
1068 gtk_widget_show(drawing->hbox);
1069
1070 /* Allocate the colors */
1071 GdkColormap* colormap = gdk_colormap_get_system();
1072 gboolean success[NUM_COLORS];
1073 gdk_colormap_alloc_colors(colormap, drawing_colors, NUM_COLORS, FALSE,
1074 TRUE, success);
1075
1076 drawing->gc =
1077 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1078 drawing->dotted_gc =
1079 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1080
1081 gdk_gc_copy(drawing->gc,
1082 main_window_get_widget(control_flow_data->tab)->style->black_gc);
1083 gdk_gc_copy(drawing->dotted_gc,
1084 main_window_get_widget(control_flow_data->tab)->style->white_gc);
1085
1086 gint8 dash_list[] = { 1, 2 };
1087 gdk_gc_set_line_attributes(drawing->dotted_gc,
1088 1,
1089 GDK_LINE_ON_OFF_DASH,
1090 GDK_CAP_BUTT,
1091 GDK_JOIN_MITER);
1092 gdk_gc_set_dashes(drawing->dotted_gc,
1093 0,
1094 dash_list,
1095 2);
1096
1097 drawing->ruler_gc_butt =
1098 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1099 gdk_gc_copy(drawing->ruler_gc_butt,
1100 main_window_get_widget(control_flow_data->tab)->style->black_gc);
1101 drawing->ruler_gc_round =
1102 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1103 gdk_gc_copy(drawing->ruler_gc_round,
1104 main_window_get_widget(control_flow_data->tab)->style->black_gc);
1105
1106
1107 gdk_gc_set_line_attributes(drawing->ruler_gc_butt,
1108 2,
1109 GDK_LINE_SOLID,
1110 GDK_CAP_BUTT,
1111 GDK_JOIN_MITER);
1112
1113 gdk_gc_set_line_attributes(drawing->ruler_gc_round,
1114 2,
1115 GDK_LINE_SOLID,
1116 GDK_CAP_ROUND,
1117 GDK_JOIN_ROUND);
1118
1119
1120 return drawing;
1121 }
1122
1123 void drawing_destroy(Drawing_t *drawing)
1124 {
1125 g_info("drawing_destroy %p", drawing);
1126
1127 /* Free the colors */
1128 GdkColormap* colormap = gdk_colormap_get_system();
1129
1130 gdk_colormap_free_colors(colormap, drawing_colors, NUM_COLORS);
1131
1132
1133
1134 // Do not unref here, Drawing_t destroyed by it's widget.
1135 //g_object_unref( G_OBJECT(drawing->drawing_area));
1136 if(drawing->gc != NULL)
1137 gdk_gc_unref(drawing->gc);
1138
1139 g_object_unref(drawing->pango_layout);
1140 if(drawing->dotted_gc != NULL) gdk_gc_unref(drawing->dotted_gc);
1141 if(drawing->ruler_gc_butt != NULL) gdk_gc_unref(drawing->ruler_gc_butt);
1142 if(drawing->ruler_gc_round != NULL) gdk_gc_unref(drawing->ruler_gc_round);
1143
1144 g_free(drawing);
1145 g_info("drawing_destroy end");
1146 }
1147
1148 GtkWidget *drawing_get_drawing_area(Drawing_t *drawing)
1149 {
1150 return drawing->drawing_area;
1151 }
1152
1153 GtkWidget *drawing_get_widget(Drawing_t *drawing)
1154 {
1155 return drawing->vbox;
1156 }
1157
1158 void drawing_draw_line( Drawing_t *drawing,
1159 GdkPixmap *pixmap,
1160 guint x1, guint y1,
1161 guint x2, guint y2,
1162 GdkGC *GC)
1163 {
1164 gdk_draw_line (pixmap,
1165 GC,
1166 x1, y1, x2, y2);
1167 }
1168
1169 void drawing_clear(Drawing_t *drawing)
1170 {
1171 //if (drawing->pixmap)
1172 // gdk_pixmap_unref(drawing->pixmap);
1173 ControlFlowData *cfd = drawing->control_flow_data;
1174
1175
1176 rectangle_pixmap(cfd->process_list,
1177 drawing->drawing_area->style->black_gc,
1178 TRUE,
1179 0, 0,
1180 drawing->alloc_width, // do not overlap
1181 -1);
1182
1183 //drawing->height = 1;
1184 /* Allocate a new pixmap with new height */
1185 //drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1186 // drawing->width + SAFETY + EXTRA_ALLOC,
1187 // drawing->height + EXTRA_ALLOC,
1188 // -1);
1189 //drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
1190 //drawing->alloc_height = drawing->height + EXTRA_ALLOC;
1191
1192 //gtk_widget_set_size_request(drawing->drawing_area,
1193 // -1,
1194 // drawing->height);
1195 //gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1196
1197 /* ask for the buffer to be redrawn */
1198 gtk_widget_queue_draw ( drawing->drawing_area);
1199 }
1200
1201 #if 0
1202 /* Insert a square corresponding to a new process in the list */
1203 /* Applies to whole drawing->width */
1204 void drawing_insert_square(Drawing_t *drawing,
1205 guint y,
1206 guint height)
1207 {
1208 //GdkRectangle update_rect;
1209 gboolean reallocate = FALSE;
1210 GdkPixmap *new_pixmap;
1211
1212 /* Allocate a new pixmap with new height */
1213 if(drawing->alloc_height < drawing->height + height) {
1214
1215 new_pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1216 drawing->width + SAFETY + EXTRA_ALLOC,
1217 drawing->height + height + EXTRA_ALLOC,
1218 -1);
1219 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
1220 drawing->alloc_height = drawing->height + height + EXTRA_ALLOC;
1221 reallocate = TRUE;
1222
1223 /* Copy the high region */
1224 gdk_draw_pixmap (new_pixmap,
1225 drawing->drawing_area->style->black_gc,
1226 drawing->pixmap,
1227 0, 0,
1228 0, 0,
1229 drawing->width + SAFETY, y);
1230
1231 } else {
1232 new_pixmap = drawing->pixmap;
1233 }
1234
1235 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1236 // drawing->width + SAFETY,
1237 // drawing->height + height,
1238 // -1);
1239
1240 /* add an empty square */
1241 gdk_draw_rectangle (new_pixmap,
1242 drawing->drawing_area->style->black_gc,
1243 TRUE,
1244 0, y,
1245 drawing->width + SAFETY, // do not overlap
1246 height);
1247
1248 /* copy the bottom of the region */
1249 gdk_draw_pixmap (new_pixmap,
1250 drawing->drawing_area->style->black_gc,
1251 drawing->pixmap,
1252 0, y,
1253 0, y + height,
1254 drawing->width+SAFETY, drawing->height - y);
1255
1256
1257 if(reallocate && likely(drawing->pixmap)) {
1258 gdk_pixmap_unref(drawing->pixmap);
1259 drawing->pixmap = new_pixmap;
1260 }
1261
1262 if(unlikely(drawing->height==1)) drawing->height = height;
1263 else drawing->height += height;
1264
1265 gtk_widget_set_size_request(drawing->drawing_area,
1266 -1,
1267 drawing->height);
1268 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1269
1270 /* ask for the buffer to be redrawn */
1271 gtk_widget_queue_draw_area ( drawing->drawing_area,
1272 0, y,
1273 drawing->width, drawing->height-y);
1274 }
1275
1276
1277 /* Remove a square corresponding to a removed process in the list */
1278 void drawing_remove_square(Drawing_t *drawing,
1279 guint y,
1280 guint height)
1281 {
1282 GdkPixmap *pixmap;
1283
1284 if(unlikely((guint)drawing->height == height)) {
1285 //pixmap = gdk_pixmap_new(
1286 // drawing->drawing_area->window,
1287 // drawing->width + SAFETY,
1288 // 1,
1289 // -1);
1290 pixmap = drawing->pixmap;
1291 drawing->height=1;
1292 } else {
1293 /* Allocate a new pixmap with new height */
1294 //pixmap = gdk_pixmap_new(
1295 // drawing->drawing_area->window,
1296 // drawing->width + SAFETY,
1297 // drawing->height - height,
1298 // -1);
1299 /* Keep the same preallocated pixmap */
1300 pixmap = drawing->pixmap;
1301
1302 /* Copy the high region */
1303 gdk_draw_pixmap (pixmap,
1304 drawing->drawing_area->style->black_gc,
1305 drawing->pixmap,
1306 0, 0,
1307 0, 0,
1308 drawing->width + SAFETY, y);
1309
1310 /* Copy up the bottom of the region */
1311 gdk_draw_pixmap (pixmap,
1312 drawing->drawing_area->style->black_gc,
1313 drawing->pixmap,
1314 0, y + height,
1315 0, y,
1316 drawing->width, drawing->height - y - height);
1317
1318 drawing->height-=height;
1319 }
1320
1321 //if(likely(drawing->pixmap))
1322 // gdk_pixmap_unref(drawing->pixmap);
1323
1324 //drawing->pixmap = pixmap;
1325
1326 gtk_widget_set_size_request(drawing->drawing_area,
1327 -1,
1328 drawing->height);
1329 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1330 /* ask for the buffer to be redrawn */
1331 gtk_widget_queue_draw_area ( drawing->drawing_area,
1332 0, y,
1333 drawing->width, MAX(drawing->height-y, 1));
1334 }
1335 #endif //0
1336
1337 void drawing_update_ruler(Drawing_t *drawing, TimeWindow *time_window)
1338 {
1339 GtkRequisition req;
1340 GdkRectangle rect;
1341
1342 req.width = drawing->ruler->allocation.width;
1343 req.height = drawing->ruler->allocation.height;
1344
1345
1346 rect.x = 0;
1347 rect.y = 0;
1348 rect.width = req.width;
1349 rect.height = req.height;
1350
1351 gtk_widget_queue_draw(drawing->ruler);
1352 //gtk_widget_draw( drawing->ruler, &rect);
1353 }
1354
1355 /* Redraw the ruler */
1356 static gboolean
1357 expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
1358 {
1359 Drawing_t *drawing = (Drawing_t*)user_data;
1360 TimeWindow time_window = lttvwindow_get_time_window(drawing->control_flow_data->tab);
1361 gchar text[255];
1362
1363 PangoContext *context;
1364 PangoLayout *layout;
1365 PangoFontDescription *FontDesc;
1366 PangoRectangle ink_rect;
1367 gint global_width=0;
1368 GdkColor foreground = { 0, 0, 0, 0 };
1369 GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
1370
1371 LttTime window_end = time_window.end_time;
1372 LttTime half_width =
1373 ltt_time_div(time_window.time_width,2.0);
1374 LttTime window_middle =
1375 ltt_time_add(half_width,
1376 time_window.start_time);
1377 g_debug("ruler expose event");
1378
1379 gdk_draw_rectangle (drawing->ruler->window,
1380 drawing->ruler->style->white_gc,
1381 TRUE,
1382 event->area.x, event->area.y,
1383 event->area.width,
1384 event->area.height);
1385
1386 gdk_draw_line (drawing->ruler->window,
1387 drawing->ruler_gc_butt,
1388 event->area.x, 1,
1389 event->area.x + event->area.width, 1);
1390
1391
1392 snprintf(text, 255, "%lus\n%luns",
1393 time_window.start_time.tv_sec,
1394 time_window.start_time.tv_nsec);
1395
1396 layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
1397
1398 context = pango_layout_get_context(layout);
1399 FontDesc = pango_context_get_font_description(context);
1400
1401 pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
1402 pango_layout_context_changed(layout);
1403
1404 pango_layout_set_text(layout, text, -1);
1405 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1406 global_width += ink_rect.width;
1407
1408 gdk_draw_layout_with_colors(drawing->ruler->window,
1409 drawing->ruler_gc_butt,
1410 0,
1411 6,
1412 layout, &foreground, &background);
1413
1414 gdk_draw_line (drawing->ruler->window,
1415 drawing->ruler_gc_round,
1416 1, 1,
1417 1, 7);
1418
1419
1420 snprintf(text, 255, "%lus\n%luns", window_end.tv_sec,
1421 window_end.tv_nsec);
1422
1423 pango_layout_set_text(layout, text, -1);
1424 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1425 global_width += ink_rect.width;
1426
1427 if(global_width <= drawing->ruler->allocation.width)
1428 {
1429 gdk_draw_layout_with_colors(drawing->ruler->window,
1430 drawing->ruler_gc_butt,
1431 drawing->ruler->allocation.width - ink_rect.width,
1432 6,
1433 layout, &foreground, &background);
1434
1435 gdk_draw_line (drawing->ruler->window,
1436 drawing->ruler_gc_butt,
1437 drawing->ruler->allocation.width-1, 1,
1438 drawing->ruler->allocation.width-1, 7);
1439 }
1440
1441
1442 snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec,
1443 window_middle.tv_nsec);
1444
1445 pango_layout_set_text(layout, text, -1);
1446 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1447 global_width += ink_rect.width;
1448
1449 if(global_width <= drawing->ruler->allocation.width)
1450 {
1451 gdk_draw_layout_with_colors(drawing->ruler->window,
1452 drawing->ruler_gc_butt,
1453 (drawing->ruler->allocation.width - ink_rect.width)/2,
1454 6,
1455 layout, &foreground, &background);
1456
1457 gdk_draw_line (drawing->ruler->window,
1458 drawing->ruler_gc_butt,
1459 drawing->ruler->allocation.width/2, 1,
1460 drawing->ruler->allocation.width/2, 7);
1461
1462
1463
1464
1465 }
1466
1467 g_object_unref(layout);
1468
1469 return FALSE;
1470 }
1471
1472
1473 /* notify mouse on ruler */
1474 static gboolean
1475 motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1476 {
1477 //g_debug("motion");
1478 //eventually follow mouse and show time here
1479 return 0;
1480 }
This page took 0.05784 seconds and 3 git commands to generate.