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