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