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