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