update compat
[lttv.git] / tags / lttv-0.10.0-pre15-12082008 / lttv / modules / gui / histogram / histodrawing.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2006 Parisa heidari (inspired from CFV by 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 "histodrawing.h"
36 #include "histoeventhooks.h"
37 #include "histocfv.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 #define padding_width 50
46
47 #if 0 /* colors for two lines representation */
48 GdkColor histo_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 histo_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 : red */
76 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
77 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
78 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
79 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
80 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
81 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
82 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
83
84 };
85
86 /*
87 RUN+USER MODE green
88 RUN+SYSCALL
89 RUN+TRAP
90 RUN+IRQ
91 WAIT+foncé
92 WAIT CPU + WAIT FORK vert foncé ou jaune
93 IRQ rouge
94 TRAP: orange
95 SYSCALL: bleu pâle
96
97 ZOMBIE + WAIT EXIT
98 */
99
100
101 /*****************************************************************************
102 * drawing functions *
103 *****************************************************************************/
104
105 static gboolean
106 histo_expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data );
107
108 static gboolean
109 histo_expose_vertical_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data );
110
111 static gboolean
112 histo_motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
113
114 static gboolean
115 histo_motion_notify_vertical_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
116
117 /* Function responsible for updating the exposed area.
118 * It must do an events request to the lttvwindow API to ask for this update.
119 * Note : this function cannot clear the background, because it may
120 * erase drawing already present (SAFETY).
121 */
122 void histo_drawing_data_request(histoDrawing_t *drawing,
123 gint x, gint y,
124 gint width,
125 gint height)
126 {
127
128 }
129
130
131 void histo_drawing_data_request_begin(EventsRequest *events_request, LttvTracesetState *tss)
132 {
133 g_debug("Begin of data request");
134 HistoControlFlowData *cfd = events_request->viewer_data;
135 LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tss);
136 TimeWindow time_window =
137 lttvwindow_get_time_window(cfd->tab);
138
139 guint width = cfd->drawing->width;
140 guint x=0;
141
142 cfd->drawing->last_start = events_request->start_time;
143
144 histo_convert_time_to_pixels(
145 time_window,
146 events_request->start_time,
147 width,
148 &x);
149
150 }
151
152 void histo_drawing_chunk_begin(EventsRequest *events_request, LttvTracesetState *tss)
153 {
154 g_debug("Begin of chunk");
155 HistoControlFlowData *cfd = events_request->viewer_data;
156 LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tss);
157
158 if(cfd->chunk_has_begun) return;
159
160 cfd->chunk_has_begun = TRUE;
161 }
162
163
164 void histo_drawing_request_expose(EventsRequest *events_request,
165 LttvTracesetState *tss,
166 LttTime end_time)
167 {
168 HistoControlFlowData *cfd = events_request->viewer_data;
169 histoDrawing_t *drawing = cfd->drawing;
170
171 gint x, x_end, width;
172 LttvTracesetContext *tsc = (LttvTracesetContext*)tss;
173
174 TimeWindow time_window =
175 lttvwindow_get_time_window(cfd->tab);
176
177 g_debug("histo request expose");
178
179 histo_convert_time_to_pixels(
180 time_window,
181 end_time,
182 drawing->width,
183 &x_end);
184 x = drawing->damage_begin;
185
186 width = x_end - x;
187
188 drawing->damage_begin = x+width;
189
190 // FIXME ?
191 //changed for histogram:
192 gtk_widget_queue_draw_area ( drawing->drawing_area,
193 x, 0,
194 width,
195 drawing->/*drawing_area->allocation.*/height);
196
197 // Update directly when scrolling
198 gdk_window_process_updates(drawing->drawing_area->window,
199 TRUE);
200 }
201
202
203 /* Callbacks */
204
205
206 /* Create a new backing pixmap of the appropriate size */
207 /* As the scaling will always change, it's of no use to copy old
208 * pixmap.
209 *
210 * Change the size if width or height changes.
211 * (different from control flow viewer!)
212 */
213 static gboolean
214 histo_configure_event( GtkWidget *widget, GdkEventConfigure *event,
215 gpointer user_data)
216 {
217 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
218
219 /* First, get the new time interval of the main window */
220 /* we assume (see documentation) that the main window
221 * has updated the time interval before this configure gets
222 * executed.
223 */
224 //lttvwindow_get_time_window(drawing->histo_control_flow_data->mw,
225 // &drawing->histo_control_flow_data->time_window);
226
227 /* New pixmap, size of the configure event */
228 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
229 // widget->allocation.width + SAFETY,
230 // widget->allocation.height + SAFETY,
231 // -1);
232 g_debug("drawing configure event");
233 g_debug("New alloc draw size : %i by %i",widget->allocation.width,
234 widget->allocation.height);
235
236 /*modified for histogram, if width is not changed, GArray is valid so
237 just redraw, else recalculate all.(event request again)*/
238
239 //enabled again for histogram:
240 if(drawing->pixmap)
241 gdk_pixmap_unref(drawing->pixmap);
242
243 drawing->pixmap = gdk_pixmap_new(widget->window,
244 widget->allocation.width ,//+ SAFETY + EXTRA_ALLOC,
245 widget->allocation.height + EXTRA_ALLOC,
246 -1);
247
248 //end add
249 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
250 drawing->alloc_height = drawing->height + EXTRA_ALLOC;
251
252 //drawing->height = widget->allocation.height;
253
254
255
256 // Clear the image
257 // gdk_draw_rectangle (drawing->pixmap,
258 // widget->style->black_gc,
259 // TRUE,
260 // 0, 0,
261 // drawing->width+SAFETY,
262 // drawing->height);
263
264 //g_info("init data request");
265
266
267 /* Initial data request */
268 /* no, do initial data request in the expose event */
269 // Do not need to ask for data of 1 pixel : not synchronized with
270 // main window time at this moment.
271 //histo_drawing_data_request(drawing, &drawing->pixmap, 0, 0,
272 // widget->allocation.width,
273 // widget->allocation.height);
274
275 //drawing->width = widget->allocation.width;
276 //drawing->height = widget->allocation.height;
277
278 drawing->damage_begin = 0;
279 drawing->damage_end = widget->allocation.width;
280
281 if((widget->allocation.width != 1 &&
282 widget->allocation.height != 1)
283 /*&& drawing->damage_begin < drawing->damage_end */)
284 {
285
286 gdk_draw_rectangle (drawing->pixmap,
287 drawing->drawing_area->style->black_gc,
288 TRUE,
289 0, 0,
290 drawing->drawing_area->allocation.width, drawing->drawing_area->allocation.height);
291 /* histo_drawing_data_request(drawing,
292 drawing->damage_begin,
293 0,
294 drawing->damage_end - drawing->damage_begin,
295 drawing->height);*/
296 }
297 //modified for histogram
298
299 if(widget->allocation.width == drawing->width)
300 {
301
302 drawing->height = widget->allocation.height;
303 histogram_show( drawing->histo_control_flow_data,0,
304 drawing->histo_control_flow_data->number_of_process->len);
305 }
306 else
307 {
308 drawing->width = widget->allocation.width;
309 drawing->height = widget->allocation.height;
310
311 g_array_set_size (drawing->histo_control_flow_data->number_of_process,
312 widget->allocation.width);
313 histo_request_event( drawing->histo_control_flow_data,drawing->damage_begin
314 ,drawing->damage_end - drawing->damage_begin);
315 }
316 return TRUE;
317 }
318
319
320 /* Redraw the screen from the backing pixmap */
321 static gboolean
322 histo_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
323 {
324 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
325
326 HistoControlFlowData *histo_control_flow_data =
327 (HistoControlFlowData*)g_object_get_data(
328 G_OBJECT(widget),
329 "histo_control_flow_data");
330 #if 0
331 if(unlikely(drawing->gc == NULL)) {
332 drawing->gc = gdk_gc_new(drawing->drawing_area->window);
333 gdk_gc_copy(drawing->gc, drawing->drawing_area->style->black_gc);
334 }
335 #endif //0
336 TimeWindow time_window =
337 lttvwindow_get_time_window(histo_control_flow_data->tab);
338 LttTime current_time =
339 lttvwindow_get_current_time(histo_control_flow_data->tab);
340
341 guint cursor_x=0;
342
343 LttTime window_end = time_window.end_time;
344
345
346 /* update the screen from the pixmap buffer */
347 //added again for histogram:
348
349 gdk_draw_pixmap(widget->window,
350 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
351 drawing->pixmap,
352 event->area.x, event->area.y,
353 event->area.x, event->area.y,
354 event->area.width, event->area.height);
355 //0
356
357 drawing->height = drawing-> drawing_area ->allocation.height;
358
359 #if 0
360 copy_pixmap_to_screen(histo_control_flow_data->process_list,
361 widget->window,
362 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
363 event->area.x, event->area.y,
364 event->area.width, event->area.height);
365 #endif //0
366
367
368 /* //disabled for histogram
369 copy_pixmap_to_screen(histo_control_flow_data->process_list,
370 widget->window,
371 drawing->gc,
372 event->area.x, event->area.y,
373 event->area.width, event->area.height);*/
374
375 /* Erase the dotted lines left.. */
376 if(widget->allocation.height > drawing->height)
377 {
378 gdk_draw_rectangle (widget->window,
379 drawing->drawing_area->style->black_gc,
380 TRUE,
381 event->area.x, drawing->height,
382 event->area.width, // do not overlap
383 widget->allocation.height - drawing->height);
384 }
385 if(ltt_time_compare(time_window.start_time, current_time) <= 0 &&
386 ltt_time_compare(window_end, current_time) >= 0)
387 {
388 /* Draw the dotted lines */
389 histo_convert_time_to_pixels(
390 time_window,
391 current_time,
392 drawing->width,
393 &cursor_x);
394
395 #if 0
396 if(drawing->dotted_gc == NULL) {
397
398 drawing->dotted_gc = gdk_gc_new(drawing->drawing_area->window);
399 gdk_gc_copy(drawing->dotted_gc, widget->style->white_gc);
400
401 gint8 dash_list[] = { 1, 2 };
402 gdk_gc_set_line_attributes(drawing->dotted_gc,
403 1,
404 GDK_LINE_ON_OFF_DASH,
405 GDK_CAP_BUTT,
406 GDK_JOIN_MITER);
407 gdk_gc_set_dashes(drawing->dotted_gc,
408 0,
409 dash_list,
410 2);
411 }
412 #endif //0
413 gint height_tot = MAX(widget->allocation.height, drawing->height);
414 gdk_draw_line(widget->window,
415 drawing->dotted_gc,
416 cursor_x, 0,
417 cursor_x, height_tot);
418 }
419
420 return FALSE;
421 }
422
423 static gboolean
424 histo_after_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
425 {
426 //g_assert(0);
427 g_debug("AFTER EXPOSE");
428
429 return FALSE;
430 }
431
432 /* mouse click */
433 static gboolean
434 histo_button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data )
435 {
436 HistoControlFlowData *histo_control_flow_data =
437 (HistoControlFlowData*)g_object_get_data(
438 G_OBJECT(widget),
439 "histo_control_flow_data");
440 histoDrawing_t *drawing = histo_control_flow_data->drawing;
441 TimeWindow time_window =
442 lttvwindow_get_time_window(histo_control_flow_data->tab);
443
444 g_debug("click");
445 if(event->button == 1)
446 {
447 LttTime time;
448
449 /* left mouse button click */
450 g_debug("x click is : %f", event->x);
451
452 histo_convert_pixels_to_time(drawing->width, (guint)event->x,
453 time_window,
454 &time);
455
456 lttvwindow_report_current_time(histo_control_flow_data->tab, time);
457 ////report event->y for vertical zoom +,-
458 }
459
460 return FALSE;
461 }
462 /*
463 //Viewer's vertical scroll bar is already omitted, not needed for histogram.
464 static gboolean
465 scrollbar_size_allocate(GtkWidget *widget,
466 GtkAllocation *allocation,
467 gpointer user_data)
468 {
469 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
470
471 gtk_widget_set_size_request(drawing->padding, allocation->width, -1);
472 //gtk_widget_queue_resize(drawing->padding);
473 //gtk_widget_queue_resize(drawing->ruler);
474 gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox));
475 return 0;
476 }
477 */
478
479
480 histoDrawing_t *histo_drawing_construct(HistoControlFlowData *histo_control_flow_data)
481 {
482 histoDrawing_t *drawing = g_new(histoDrawing_t, 1);
483
484 drawing->histo_control_flow_data = histo_control_flow_data;
485
486 drawing->vbox = gtk_vbox_new(FALSE, 1);
487
488
489 drawing->ruler_hbox = gtk_hbox_new(FALSE, 1);
490 drawing->ruler = gtk_drawing_area_new ();
491 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
492
493 drawing->padding = gtk_drawing_area_new ();
494 //gtk_widget_set_size_request(drawing->padding, -1, 27);
495
496 gtk_box_pack_start(GTK_BOX(drawing->ruler_hbox), drawing->padding,FALSE, FALSE, 0);
497
498 gtk_box_pack_end(GTK_BOX(drawing->ruler_hbox), drawing->ruler,
499 TRUE, TRUE, 0);
500
501 drawing->drawing_area = gtk_drawing_area_new ();
502
503 drawing->gc = NULL;
504 /*
505 ///at this time not necessary for histogram
506 drawing->hbox = gtk_hbox_new(FALSE, 1);
507
508 drawing->viewport = gtk_viewport_new(NULL, histo_control_flow_data->v_adjust);
509 drawing->scrollbar = gtk_vscrollbar_new(histo_control_flow_data->v_adjust);
510 gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport,
511 TRUE, TRUE, 0);
512 gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar,
513 FALSE, FALSE, 0);
514 gtk_container_add(GTK_CONTAINER(drawing->viewport),
515 drawing->drawing_area);*/
516
517 //add vertical ruler:
518 drawing->vruler_drawing_hbox = gtk_hbox_new(FALSE, 1);
519 drawing-> vertical_ruler =gtk_drawing_area_new ();
520 gtk_box_pack_start(GTK_BOX(drawing->vruler_drawing_hbox), drawing->vertical_ruler,
521 FALSE, FALSE, 0);
522 gtk_box_pack_end(GTK_BOX(drawing->vruler_drawing_hbox), drawing->drawing_area,
523 TRUE, TRUE, 1);
524 gtk_widget_set_size_request(drawing->vertical_ruler, padding_width, -1);
525
526 gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler_hbox,
527 FALSE, FALSE, 1);
528 gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->vruler_drawing_hbox/*drawing_area*/,
529 TRUE, TRUE, 1);
530
531 drawing->pango_layout =
532 gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
533
534 drawing->height = 1;
535 drawing->width = 1;
536 drawing->depth = 0;
537 drawing->alloc_height = 1;
538 drawing->alloc_width = 1;
539
540 drawing->damage_begin = 0;
541 drawing->damage_end = 0;
542 drawing->horizontal_sel = -1;
543
544 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
545 g_object_set_data_full(
546 G_OBJECT(drawing->drawing_area),
547 "histo_Link_drawing_Data",
548 drawing,
549 (GDestroyNotify)histo_drawing_destroy);
550
551 g_object_set_data(
552 G_OBJECT(drawing->ruler),
553 "histo_drawing",
554 drawing);
555
556 g_object_set_data(
557 G_OBJECT(drawing->vertical_ruler),
558 "histo_drawing",
559 drawing);
560
561 //gtk_widget_modify_bg( drawing->drawing_area,
562 // GTK_STATE_NORMAL,
563 // &CF_Colors[BLACK]);
564
565 //gdk_window_get_geometry(drawing->drawing_area->window,
566 // NULL, NULL,
567 // &(drawing->width),
568 // &(drawing->height),
569 // -1);
570
571 //drawing->pixmap = gdk_pixmap_new(
572 // drawing->drawing_area->window,
573 // drawing->width,
574 // drawing->height,
575 // drawing->depth);
576
577 drawing->pixmap = NULL;
578
579 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
580 // drawing->drawing_area->allocation.width,
581 // drawing->drawing_area->allocation.height,
582 // -1);
583
584 g_signal_connect (G_OBJECT(drawing->drawing_area),
585 "configure_event",
586 G_CALLBACK (histo_configure_event),
587 (gpointer)drawing);
588
589 g_signal_connect (G_OBJECT(drawing->ruler),
590 "expose_event",
591 G_CALLBACK(histo_expose_ruler),
592 (gpointer)drawing);
593
594 gtk_widget_add_events(drawing->ruler, GDK_POINTER_MOTION_MASK);
595 gtk_widget_add_events(drawing->vertical_ruler, GDK_POINTER_MOTION_MASK);
596
597 g_signal_connect (G_OBJECT(drawing->ruler),
598 "motion-notify-event",
599 G_CALLBACK(histo_motion_notify_ruler),
600 (gpointer)drawing);
601
602
603 g_signal_connect (G_OBJECT(drawing->vertical_ruler),
604 "expose_event",
605 G_CALLBACK(histo_expose_vertical_ruler),
606 (gpointer)drawing);
607
608 g_signal_connect (G_OBJECT(drawing->vertical_ruler),
609 "motion-notify-event",
610 G_CALLBACK(histo_motion_notify_vertical_ruler),
611 (gpointer)drawing);
612
613 /*//not necessary for historam.
614 g_signal_connect (G_OBJECT(drawing->drawing_area),
615 "size-allocate",
616 G_CALLBACK(scrollbar_size_allocate),
617 (gpointer)drawing); */
618
619
620 gtk_widget_set_size_request(drawing->padding, padding_width, -1);//use it for vertical ruler
621
622 g_signal_connect (G_OBJECT(drawing->drawing_area),
623 "expose_event",
624 G_CALLBACK (histo_expose_event),
625 (gpointer)drawing);
626
627 g_signal_connect_after (G_OBJECT(drawing->drawing_area),
628 "expose_event",
629 G_CALLBACK (histo_after_expose_event),
630 (gpointer)drawing);
631
632 g_signal_connect (G_OBJECT(drawing->drawing_area),
633 "button-press-event",
634 G_CALLBACK (histo_button_press_event),
635 (gpointer)drawing);
636
637 gtk_widget_show(drawing->ruler);
638 gtk_widget_show(drawing->padding);
639 gtk_widget_show(drawing->ruler_hbox);
640 gtk_widget_show(drawing->vertical_ruler);
641 gtk_widget_show(drawing->vruler_drawing_hbox);
642 gtk_widget_show(drawing->drawing_area);
643
644 /// gtk_widget_show(drawing->viewport);
645 /// gtk_widget_show(drawing->scrollbar);
646 /// gtk_widget_show(drawing->hbox);
647
648 /* Allocate the colors */
649 GdkColormap* colormap = gdk_colormap_get_system();
650 gboolean success[NUM_COLORS];
651 gdk_colormap_alloc_colors(colormap, histo_drawing_colors, NUM_COLORS, FALSE,
652 TRUE, success);
653
654 drawing->gc =
655 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
656 drawing->dotted_gc =
657 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
658
659 gdk_gc_copy(drawing->gc,
660 main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
661 gdk_gc_copy(drawing->dotted_gc,
662 main_window_get_widget(histo_control_flow_data->tab)->style->white_gc);
663
664 gint8 dash_list[] = { 1, 2 };
665 gdk_gc_set_line_attributes(drawing->dotted_gc,
666 1,
667 GDK_LINE_ON_OFF_DASH,
668 GDK_CAP_BUTT,
669 GDK_JOIN_MITER);
670 gdk_gc_set_dashes(drawing->dotted_gc,
671 0,
672 dash_list,
673 2);
674
675 drawing->ruler_gc_butt =
676 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
677 gdk_gc_copy(drawing->ruler_gc_butt,
678 main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
679 drawing->ruler_gc_round =
680 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
681 gdk_gc_copy(drawing->ruler_gc_round,
682 main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
683
684
685 gdk_gc_set_line_attributes(drawing->ruler_gc_butt,
686 2,
687 GDK_LINE_SOLID,
688 GDK_CAP_BUTT,
689 GDK_JOIN_MITER);
690
691 gdk_gc_set_line_attributes(drawing->ruler_gc_round,
692 2,
693 GDK_LINE_SOLID,
694 GDK_CAP_ROUND,
695 GDK_JOIN_ROUND);
696 return drawing;
697 }
698
699 void histo_drawing_destroy(histoDrawing_t *drawing)
700 {
701 g_info("histo_drawing_destroy %p", drawing);
702
703 /* Free the colors */
704 GdkColormap* colormap = gdk_colormap_get_system();
705
706 gdk_colormap_free_colors(colormap, histo_drawing_colors, NUM_COLORS);
707
708 // Do not unref here, histoDrawing_t destroyed by it's widget.
709 //g_object_unref( G_OBJECT(drawing->drawing_area));
710 if(drawing->gc != NULL)
711 gdk_gc_unref(drawing->gc);
712
713 g_object_unref(drawing->pango_layout);
714 if(drawing->dotted_gc != NULL) gdk_gc_unref(drawing->dotted_gc);
715 if(drawing->ruler_gc_butt != NULL) gdk_gc_unref(drawing->ruler_gc_butt);
716 if(drawing->ruler_gc_round != NULL) gdk_gc_unref(drawing->ruler_gc_round);
717
718 //added for histogram
719 if(drawing->pixmap)
720 gdk_pixmap_unref(drawing->pixmap);
721 g_free(drawing);
722 g_info("histo_drawing_destroy end");
723 }
724
725 GtkWidget *histo_drawing_get_drawing_area(histoDrawing_t *drawing)
726 {
727 return drawing->drawing_area;
728 }
729
730 GtkWidget *histo_drawing_get_widget(histoDrawing_t *drawing)
731 {
732 return drawing->vbox;
733 }
734
735 void histo_drawing_draw_line( histoDrawing_t *drawing,
736 GdkPixmap *pixmap,
737 guint x1, guint y1,
738 guint x2, guint y2,
739 GdkGC *GC)
740 {
741 gdk_draw_line (pixmap,
742 GC,
743 x1, y1, x2, y2);
744 }
745
746 void histo_drawing_clear(histoDrawing_t *drawing,guint clear_from,guint clear_to)
747 {
748
749 HistoControlFlowData *cfd = drawing->histo_control_flow_data;
750 guint clear_width = clear_to- clear_from;
751 /*
752 //disabled for histogram
753 rectangle_pixmap(cfd->process_list,
754 drawing->drawing_area->style->black_gc,
755 TRUE,
756 0, 0,
757 drawing->alloc_width, // do not overlap
758 -1);*/
759 //instead, this is added for histogram
760
761 histo_rectangle_pixmap (drawing->drawing_area->style->black_gc,
762 TRUE,
763 clear_from/*0*/, 0,
764 clear_width/*drawing->width*/,
765 -1,drawing);
766
767
768
769 /* gdk_draw_rectangle (drawing->pixmap,
770 drawing->drawing_area->style->black_gc,
771 TRUE,
772 0,0,
773 drawing->drawing_area->allocation.width,drawing->drawing_area->allocation.height );
774
775 /* ask for the buffer to be redrawn */
776 //enabled again for histogram.
777 gtk_widget_queue_draw_area ( drawing->drawing_area,
778 clear_from, 0,
779 clear_width, drawing->height);
780 gdk_window_process_updates(drawing->drawing_area->window,TRUE);
781 //disabled instead for histogram
782 //gtk_widget_queue_draw ( drawing->drawing_area);
783 return;
784 }
785
786 #if 0
787 /* Insert a square corresponding to a new process in the list */
788 /* Applies to whole drawing->width */
789 void drawing_insert_square(histoDrawing_t *drawing,
790 guint y,
791 guint height)
792 {
793 //GdkRectangle update_rect;
794 gboolean reallocate = FALSE;
795 GdkPixmap *new_pixmap;
796
797 /* Allocate a new pixmap with new height */
798 if(drawing->alloc_height < drawing->height + height) {
799
800 new_pixmap = gdk_pixmap_new(drawing->drawing_area->window,
801 drawing->width + SAFETY + EXTRA_ALLOC,
802 drawing->height + height + EXTRA_ALLOC,
803 -1);
804 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
805 drawing->alloc_height = drawing->height + height + EXTRA_ALLOC;
806 reallocate = TRUE;
807
808 /* Copy the high region */
809 gdk_draw_pixmap (new_pixmap,
810 drawing->drawing_area->style->black_gc,
811 drawing->pixmap,
812 0, 0,
813 0, 0,
814 drawing->width + SAFETY, y);
815
816 } else {
817 new_pixmap = drawing->pixmap;
818 }
819
820 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
821 // drawing->width + SAFETY,
822 // drawing->height + height,
823 // -1);
824
825 /* add an empty square */
826 gdk_draw_rectangle (new_pixmap,
827 drawing->drawing_area->style->black_gc,
828 TRUE,
829 0, y,
830 drawing->width + SAFETY, // do not overlap
831 height);
832
833 /* copy the bottom of the region */
834 gdk_draw_pixmap (new_pixmap,
835 drawing->drawing_area->style->black_gc,
836 drawing->pixmap,
837 0, y,
838 0, y + height,
839 drawing->width+SAFETY, drawing->height - y);
840
841
842 if(reallocate && likely(drawing->pixmap)) {
843 gdk_pixmap_unref(drawing->pixmap);
844 drawing->pixmap = new_pixmap;
845 }
846
847 if(unlikely(drawing->height==1)) drawing->height = height;
848 else drawing->height += height;
849
850 gtk_widget_set_size_request(drawing->drawing_area,
851 -1,
852 drawing->height);
853 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
854
855 /* ask for the buffer to be redrawn */
856 gtk_widget_queue_draw_area ( drawing->drawing_area,
857 0, y,
858 drawing->width, drawing->height-y);
859 }
860
861
862 /* Remove a square corresponding to a removed process in the list */
863 void drawing_remove_square(histoDrawing_t *drawing,
864 guint y,
865 guint height)
866 {
867 GdkPixmap *pixmap;
868
869 if(unlikely((guint)drawing->height == height)) {
870 //pixmap = gdk_pixmap_new(
871 // drawing->drawing_area->window,
872 // drawing->width + SAFETY,
873 // 1,
874 // -1);
875 pixmap = drawing->pixmap;
876 drawing->height=1;
877 } else {
878 /* Allocate a new pixmap with new height */
879 //pixmap = gdk_pixmap_new(
880 // drawing->drawing_area->window,
881 // drawing->width + SAFETY,
882 // drawing->height - height,
883 // -1);
884 /* Keep the same preallocated pixmap */
885 pixmap = drawing->pixmap;
886
887 /* Copy the high region */
888 gdk_draw_pixmap (pixmap,
889 drawing->drawing_area->style->black_gc,
890 drawing->pixmap,
891 0, 0,
892 0, 0,
893 drawing->width + SAFETY, y);
894
895 /* Copy up the bottom of the region */
896 gdk_draw_pixmap (pixmap,
897 drawing->drawing_area->style->black_gc,
898 drawing->pixmap,
899 0, y + height,
900 0, y,
901 drawing->width, drawing->height - y - height);
902
903 drawing->height-=height;
904 }
905
906 //if(likely(drawing->pixmap))
907 // gdk_pixmap_unref(drawing->pixmap);
908
909 //drawing->pixmap = pixmap;
910
911 gtk_widget_set_size_request(drawing->drawing_area,
912 -1,
913 drawing->height);
914 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
915 /* ask for the buffer to be redrawn */
916 gtk_widget_queue_draw_area ( drawing->drawing_area,
917 0, y,
918 drawing->width, MAX(drawing->height-y, 1));
919 }
920 #endif //0
921
922 void histo_drawing_update_ruler(histoDrawing_t *drawing, TimeWindow *time_window)
923 {
924 GtkRequisition req;
925 GdkRectangle rect;
926
927 req.width = drawing->ruler->allocation.width;
928 req.height = drawing->ruler->allocation.height;
929
930
931 rect.x = 0;
932 rect.y = 0;
933 rect.width = req.width;
934 rect.height = req.height;
935
936 gtk_widget_queue_draw(drawing->ruler);
937 //gtk_widget_draw( drawing->ruler, &rect);
938 }
939
940 /* Redraw the ruler */
941 static gboolean
942 histo_expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
943 {
944 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
945 TimeWindow time_window = lttvwindow_get_time_window(drawing->histo_control_flow_data->tab);
946 gchar text[255];
947
948 PangoContext *context;
949 PangoLayout *layout;
950 PangoFontDescription *FontDesc;
951 PangoRectangle ink_rect;
952 gint global_width=0;
953 GdkColor foreground = { 0, 0, 0, 0 };
954 GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
955
956 LttTime window_end = time_window.end_time;
957 LttTime half_width =
958 ltt_time_div(time_window.time_width,2.0);
959 LttTime window_middle =
960 ltt_time_add(half_width,
961 time_window.start_time);
962 g_debug("ruler expose event");
963
964 gdk_draw_rectangle (drawing->ruler->window,
965 drawing->ruler->style->white_gc,
966 TRUE,
967 event->area.x, event->area.y,
968 event->area.width,
969 event->area.height);
970
971 gdk_draw_line (drawing->ruler->window,
972 drawing->ruler_gc_butt,
973 event->area.x, 1,
974 event->area.x + event->area.width, 1);
975
976
977 snprintf(text, 255, "%lus\n%luns",
978 time_window.start_time.tv_sec,
979 time_window.start_time.tv_nsec);
980
981 layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
982
983 context = pango_layout_get_context(layout);
984 FontDesc = pango_context_get_font_description(context);
985
986 pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
987 pango_layout_context_changed(layout);
988
989 pango_layout_set_text(layout, text, -1);
990 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
991 global_width += ink_rect.width;
992
993 gdk_draw_layout_with_colors(drawing->ruler->window,
994 drawing->ruler_gc_butt,
995 0,
996 6,
997 layout, &foreground, &background);
998
999 gdk_draw_line (drawing->ruler->window,
1000 drawing->ruler_gc_round,
1001 1, 1,
1002 1, 7);
1003
1004
1005 snprintf(text, 255, "%lus\n%luns", window_end.tv_sec,
1006 window_end.tv_nsec);
1007
1008 pango_layout_set_text(layout, text, -1);
1009 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1010 global_width += ink_rect.width;
1011
1012 if(global_width <= drawing->ruler->allocation.width)
1013 {
1014 gdk_draw_layout_with_colors(drawing->ruler->window,
1015 drawing->ruler_gc_butt,
1016 drawing->ruler->allocation.width - ink_rect.width,
1017 6,
1018 layout, &foreground, &background);
1019
1020 gdk_draw_line (drawing->ruler->window,
1021 drawing->ruler_gc_butt,
1022 drawing->ruler->allocation.width-1, 1,
1023 drawing->ruler->allocation.width-1, 7);
1024 }
1025
1026
1027 snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec,
1028 window_middle.tv_nsec);
1029
1030 pango_layout_set_text(layout, text, -1);
1031 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1032 global_width += ink_rect.width;
1033
1034 if(global_width <= drawing->ruler->allocation.width)
1035 {
1036 gdk_draw_layout_with_colors(drawing->ruler->window,
1037 drawing->ruler_gc_butt,
1038 (drawing->ruler->allocation.width - ink_rect.width)/2,
1039 6,
1040 layout, &foreground, &background);
1041
1042 gdk_draw_line (drawing->ruler->window,
1043 drawing->ruler_gc_butt,
1044 drawing->ruler->allocation.width/2, 1,
1045 drawing->ruler->allocation.width/2, 7);
1046 }
1047
1048 g_object_unref(layout);
1049
1050 return FALSE;
1051 }
1052
1053 void histo_drawing_update_vertical_ruler(histoDrawing_t *drawing)//, TimeWindow *time_window)
1054 {
1055 GtkRequisition req;
1056 GdkRectangle rect;
1057
1058 req.width = drawing->vertical_ruler->allocation.width;
1059 req.height = drawing->vertical_ruler->allocation.height;
1060
1061 rect.x = 0;
1062 rect.y = 0;
1063 rect.width = req.width;
1064 rect.height = req.height;
1065
1066 gtk_widget_queue_draw(drawing->vertical_ruler);
1067 //gtk_widget_draw( drawing->ruler, &rect);
1068 }
1069
1070 /* notify mouse on ruler */
1071 static gboolean
1072 histo_motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1073 {
1074 //g_debug("motion");
1075 //eventually follow mouse and show time here
1076 }
1077
1078 static gboolean
1079 histo_motion_notify_vertical_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1080 {
1081 //g_debug("motion");
1082 //eventually follow mouse and show time here
1083 }
1084
1085
1086
1087 /* Redraw the vertical ruler */
1088 static gboolean
1089 histo_expose_vertical_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
1090 {
1091 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
1092 HistoControlFlowData *histo_cfv = drawing->histo_control_flow_data;
1093 gchar text[255];
1094
1095 PangoContext *context;
1096 PangoLayout *layout;
1097 PangoFontDescription *FontDesc;
1098 PangoRectangle ink_rect;
1099 gint global_height=0;
1100 GdkColor foreground = { 0, 0, 0, 0 };
1101 GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
1102 GdkColor red ={ 0, 0xFFFF, 0x1E00, 0x1000 };
1103 GdkColor magneta ={ 0, 0x8900, 0x0000, 0x8400 };
1104 g_debug("vertical ruler expose event");
1105
1106 gdk_draw_rectangle (drawing->vertical_ruler->window,
1107 drawing->vertical_ruler->style->white_gc,
1108 TRUE,
1109 event->area.x, event->area.y,
1110 event->area.width,
1111 event->area.height);
1112
1113 gdk_draw_line (drawing->vertical_ruler->window,
1114 drawing->ruler_gc_butt,
1115 padding_width-1/*event->area.width-1*/,event->area.y,
1116 padding_width-1/*event->area.width-1*/,event->area.y + event->area.height);
1117
1118 snprintf(text, 255, "%.1f", (float)histo_cfv->max_height);
1119
1120 layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
1121
1122 context = pango_layout_get_context(layout);
1123 FontDesc = pango_context_get_font_description(context);
1124
1125 pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
1126 pango_layout_context_changed(layout);
1127
1128 pango_layout_set_text(layout, text, -1);
1129 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1130 global_height += ink_rect.height;
1131
1132 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1133 drawing->ruler_gc_butt,
1134 1,
1135 1,
1136 layout, &foreground, &background);
1137
1138 gdk_draw_line (drawing->vertical_ruler->window,
1139 drawing->ruler_gc_round,
1140 drawing->vertical_ruler-> allocation.width-1, 1,
1141 drawing->vertical_ruler-> allocation.width-7, 1);
1142
1143
1144 snprintf(text, 255, "%lu",0);
1145
1146 pango_layout_set_text(layout, text, -1);
1147 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1148 global_height += ink_rect.height;
1149
1150 if(global_height <= drawing->vertical_ruler->allocation.height)
1151 {
1152 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1153 drawing->ruler_gc_butt,
1154 1,
1155 drawing->vertical_ruler->allocation.height - ink_rect.height-2,
1156 layout, &foreground, &background);
1157
1158 gdk_draw_line (drawing->vertical_ruler->window,
1159 drawing->ruler_gc_butt,
1160 drawing->vertical_ruler-> allocation.width-1,
1161 drawing->vertical_ruler->allocation.height-1,
1162 drawing->vertical_ruler-> allocation.width-7,
1163 drawing->vertical_ruler->allocation.height-1);
1164 }
1165
1166
1167 snprintf(text, 255, "%.1f",(float) histo_cfv->max_height/2.0);
1168
1169 pango_layout_set_text(layout, text, -1);
1170 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1171 global_height += ink_rect.height;
1172
1173 if(global_height <= drawing->vertical_ruler->allocation.height)
1174 {
1175 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1176 drawing->ruler_gc_butt,
1177 1,
1178 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1179 layout, &foreground, &background);
1180
1181 gdk_draw_line (drawing->vertical_ruler->window,
1182 drawing->ruler_gc_butt,
1183 drawing->vertical_ruler-> allocation.width-1,
1184 drawing->vertical_ruler-> allocation.height/2,
1185 drawing->vertical_ruler-> allocation.width-7,
1186 drawing->vertical_ruler->allocation.height/2);
1187 }
1188
1189 //show number of events at current time:
1190 LttTime current_time =
1191 lttvwindow_get_current_time(histo_cfv->tab);
1192 TimeWindow time_window =
1193 lttvwindow_get_time_window(histo_cfv->tab);
1194 LttTime time_begin = time_window.start_time;
1195 LttTime time_width = time_window.time_width;
1196 LttTime time_end = ltt_time_add(time_begin, time_width);
1197 if((ltt_time_compare(current_time, time_begin) >= 0)&&
1198 (ltt_time_compare(current_time, time_end) <= 0))
1199 {
1200 guint *events_at_currenttime;
1201 guint max_height=histo_cfv ->max_height;
1202 guint x;
1203 histo_convert_time_to_pixels(
1204 time_window,
1205 current_time,
1206 drawing->width,
1207 &x);
1208 // if(x_test<histo_cfv->number_of_process->len)
1209
1210 {
1211 events_at_currenttime =
1212 &g_array_index(histo_cfv->number_of_process,guint,x);
1213
1214
1215 if((*events_at_currenttime) > max_height)
1216 {
1217 snprintf(text, 255, "OverFlow!");
1218 pango_layout_set_text(layout, text, -1);
1219 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1220 global_height += ink_rect.height;
1221 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1222 drawing->ruler_gc_butt,
1223 1,
1224 (drawing->vertical_ruler->allocation.height - ink_rect.height)/5,
1225 layout, &red, &background);
1226 }else
1227 // if((*events_at_currenttime) <= max_height)
1228 {
1229 snprintf(text, 255, "%.1f",
1230 (float) *events_at_currenttime);
1231
1232 pango_layout_set_text(layout, text, -1);
1233 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1234 global_height += ink_rect.height;
1235
1236 if ((*events_at_currenttime) == 0)
1237 {
1238 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1239 drawing->ruler_gc_butt,
1240 1,
1241 (drawing->vertical_ruler->allocation.height - ink_rect.height)-2,
1242 layout, &red, &background);
1243 }
1244 else if ((*events_at_currenttime) == max_height)
1245 {
1246 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1247 drawing->ruler_gc_butt,
1248 1,
1249 1,
1250 layout, &red, &background);
1251 }
1252 /*else if ((*events_at_currenttime) == max_height/2)
1253 {
1254 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1255 drawing->ruler_gc_butt,
1256 1,
1257 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1258 layout, &red, &background);
1259 }*/
1260 else if ((*events_at_currenttime) > max_height/2)
1261 {
1262 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1263 drawing->ruler_gc_butt,
1264 1,
1265 (drawing->vertical_ruler->allocation.height - ink_rect.height)/4,
1266 layout, &red, &background);
1267 }
1268 else{
1269 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1270 drawing->ruler_gc_butt,
1271 1,
1272 ((drawing->vertical_ruler->allocation.height
1273 - ink_rect.height)*3)/4,
1274 layout, &red, &background);
1275 }
1276 }
1277
1278 }
1279 }
1280
1281 g_object_unref(layout);
1282
1283 return FALSE;
1284 }
1285
This page took 0.093332 seconds and 4 git commands to generate.