heavy icon drawing sample
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Event_Hooks.c
CommitLineData
f0d936c0 1/*****************************************************************************
2 * Hooks to be called by the main window *
3 *****************************************************************************/
4
f0d936c0 5
189a5d08 6#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
7#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
8
cf6cb7e0 9//#define PANGO_ENABLE_BACKEND
558aa013 10#include <gtk/gtk.h>
11#include <gdk/gdk.h>
5f16133f 12#include <glib.h>
13
cf6cb7e0 14//#include <pango/pango.h>
15
558aa013 16#include <lttv/hook.h>
17#include <lttv/common.h>
f0d936c0 18
1ab818de 19#include "Event_Hooks.h"
f0d936c0 20#include "CFV.h"
5f16133f 21#include "Process_List.h"
1ab3d149 22#include "Drawing.h"
f7afe191 23#include "CFV-private.h"
5f16133f 24
1a31868c 25#define MAX_PATH_LEN 256
26
27//FIXME : remove this include when tests finished.
28#include "Draw_Item.h"
29#include <string.h>
30
31struct _DrawContext {
32 GdkDrawable *drawable;
33 GdkGC *gc;
34
35
36 DrawInfo *Current;
37 DrawInfo *Previous;
38};
39
40struct _DrawInfo {
41 ItemInfo *over;
42 ItemInfo *middle;
43 ItemInfo *under;
44
45 ItemInfo *modify_over;
46 ItemInfo *modify_middle;
47 ItemInfo *modify_under;
48};
49
50/* LttvExecutionState is accessible through the LttvTracefileState. Is has
51 * a pointer to the LttvProcessState which points to the top of stack
52 * execution state : LttvExecutionState *state.
53 *
54 * LttvExecutionState contains (useful here):
55 * LttvExecutionMode t,
56 * LttvExecutionSubmode n,
57 * LttvProcessStatus s
58 *
59 *
60 * LttvTraceState will be used in the case we need the string of the
61 * different processes, eventtype_names, syscall_names, trap_names, irq_names.
62 *
63 * LttvTracefileState also gives the cpu_name and, as it herits from
64 * LttvTracefileContext, it gives the LttEvent structure, which is needed
65 * to get facility name and event name.
66 */
67struct _ItemInfo {
68 gint x, y;
69 LttvTraceState *ts;
70 LttvTracefileState *tfs;
71};
72
73
74
75struct _PropertiesIcon {
76 gchar *icon_name;
77 gint width;
78 gint height;
79 RelPos position;
80};
81
82
83
84void test_draw_item(Drawing_t *Drawing,
85 GdkPixmap *Pixmap)
86{
87 PropertiesIcon properties_icon;
88 DrawContext draw_context;
89
90 DrawInfo current, previous;
91 ItemInfo over, middle, under, modify_over, modify_middle, modify_under;
92
93 int i,j;
94
95 for(i=0; i<1024;i=i+15)
96 {
97 for(j=0;j<768;j=j+15)
98 {
99 over.x = i;
100 over.y = j;
101 over.ts = NULL;
102 over.tfs = NULL;
103
104 current.modify_over = &over;
105
106 draw_context.drawable = Pixmap;
107 draw_context.gc = Drawing->Drawing_Area_V->style->black_gc;
108
109 draw_context.Current = &current;
110 draw_context.Previous = NULL;
111
112 properties_icon.icon_name = g_new(char, MAX_PATH_LEN);
113 strncpy(properties_icon.icon_name,
114 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
115 MAX_PATH_LEN);
116 properties_icon.width = -1;
117 properties_icon.height = -1;
118 properties_icon.position = OVER;
119
120 draw_icon(&properties_icon, &draw_context);
121 }
122 }
123
124}
f7afe191 125
189a5d08 126/* NOTE : no drawing data should be sent there, since the drawing widget
96cfe486 127 * has not been initialized */
f7afe191 128void send_test_drawing(ProcessList *Process_List,
129 Drawing_t *Drawing,
130 GdkPixmap *Pixmap,
131 gint x, gint y, // y not used here?
132 gint width,
133 gint height) // height won't be used here ?
134{
1a31868c 135 int i,j;
f7afe191 136 ProcessInfo Process_Info = {10000, 12000, 55600};
137 //ProcessInfo Process_Info = {156, 14000, 55500};
138 GtkTreeRowReference *got_RowRef;
cf6cb7e0 139 PangoContext *context;
140 PangoLayout *layout;
141 PangoFontDescription *FontDesc;// = pango_font_description_new();
142 gint Font_Size;
143
189a5d08 144 //icon
145 GdkBitmap *mask = g_new(GdkBitmap, 1);
146 GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
147 GdkGC * gc = gdk_gc_new(Pixmap);
148
6d5ed1c3 149 // rectangle
150 GdkColor color = { 0, 0xffff, 0x0000, 0x0000 };
151
cf6cb7e0 152 /* Sent text data */
153 layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V,
154 NULL);
155 context = pango_layout_get_context(layout);
156 FontDesc = pango_context_get_font_description(context);
157 Font_Size = pango_font_description_get_size(FontDesc);
158 pango_font_description_set_size(FontDesc, Font_Size-3*PANGO_SCALE);
159
f7afe191 160
cf6cb7e0 161
162
f7afe191 163 LttTime birth;
164 birth.tv_sec = 12000;
165 birth.tv_nsec = 55500;
189a5d08 166 g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
4c69e0cc 167 processlist_get_process_pixels(Process_List,
f7afe191 168 1,
169 &birth,
170 &y,
171 &height);
172
189a5d08 173 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
4c69e0cc 174 drawing_draw_line(
f7afe191 175 Drawing, Pixmap, x,
176 y+(height/2), x + width, y+(height/2),
177 Drawing->Drawing_Area_V->style->black_gc);
178
cf6cb7e0 179 pango_layout_set_text(layout, "Test", -1);
180 gdk_draw_layout(Pixmap, Drawing->Drawing_Area_V->style->black_gc,
181 0, y+height, layout);
182
f7afe191 183 birth.tv_sec = 14000;
184 birth.tv_nsec = 55500;
185
4c69e0cc 186 processlist_get_process_pixels(Process_List,
f7afe191 187 156,
188 &birth,
189 &y,
190 &height);
191
192
4c69e0cc 193 drawing_draw_line(
f7afe191 194 Drawing, Pixmap, x,
195 y+(height/2), x + width, y+(height/2),
196 Drawing->Drawing_Area_V->style->black_gc);
197
189a5d08 198 g_info("y : %u, height : %u", y, height);
f7afe191 199
6d5ed1c3 200
201
f7afe191 202 birth.tv_sec = 12000;
203 birth.tv_nsec = 55700;
204
4c69e0cc 205 processlist_get_process_pixels(Process_List,
f7afe191 206 10,
207 &birth,
208 &y,
209 &height);
6d5ed1c3 210
211 /* Draw rectangle (background color) */
212 gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
213 gdk_gc_set_rgb_fg_color(gc, &color);
214 gdk_draw_rectangle(Pixmap, gc,
215 TRUE,
216 x, y, width, height);
f7afe191 217
4c69e0cc 218 drawing_draw_line(
f7afe191 219 Drawing, Pixmap, x,
220 y+(height/2), x + width, y+(height/2),
221 Drawing->Drawing_Area_V->style->black_gc);
222
6d5ed1c3 223
224 /* Draw arc */
225 gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc,
2f9f7ee0 226 TRUE, 100, y, height/2, height/2, 0, 360*64);
6d5ed1c3 227
189a5d08 228 g_info("y : %u, height : %u", y, height);
f7afe191 229
230 for(i=0; i<10; i++)
231 {
232 birth.tv_sec = i*12000;
233 birth.tv_nsec = i*55700;
234
4c69e0cc 235 processlist_get_process_pixels(Process_List,
f7afe191 236 i,
237 &birth,
238 &y,
239 &height);
240
241
4c69e0cc 242 drawing_draw_line(
f7afe191 243 Drawing, Pixmap, x,
244 y+(height/2), x + width, y+(height/2),
245 Drawing->Drawing_Area_V->style->black_gc);
246
247 g_critical("y : %u, height : %u", y, height);
248
249 }
250
251 birth.tv_sec = 12000;
252 birth.tv_nsec = 55600;
253
4c69e0cc 254 processlist_get_process_pixels(Process_List,
f7afe191 255 10,
256 &birth,
257 &y,
258 &height);
259
260
4c69e0cc 261 drawing_draw_line(
f7afe191 262 Drawing, Pixmap, x,
263 y+(height/2), x + width, y+(height/2),
264 Drawing->Drawing_Area_V->style->black_gc);
265
189a5d08 266 g_info("y : %u, height : %u", y, height);
1a31868c 267
268
269 /* IMPORTANT : This action uses the cpu heavily! */
270 //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
271// "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
272 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
273
274 // gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
275
276// for(i=x;i<x+width;i=i+15)
277// {
278// for(j=0;j<height*20;j=j+15)
279// {
280
281 /* Draw icon */
282 //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
283// gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
284// gdk_draw_drawable(Pixmap,
285// Drawing->Drawing_Area_V->style->black_gc,
286// icon_pixmap,
287// 0, 0, i, j, -1, -1);
288
289// }
290// }
291
292 test_draw_item(Drawing,Pixmap);
293
294 //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
295 //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
296
297 //g_free(icon_pixmap);
298 //g_free(mask);
299
300
301
302
cf6cb7e0 303
304
305 pango_font_description_set_size(FontDesc, Font_Size);
6d5ed1c3 306 g_free(gc);
cf6cb7e0 307 g_free(layout);
308 //g_free(context);
f7afe191 309}
310
311void send_test_process(ProcessList *Process_List, Drawing_t *Drawing)
5f16133f 312{
f7afe191 313 guint height, y;
5f16133f 314 int i;
315 ProcessInfo Process_Info = {10000, 12000, 55600};
316 //ProcessInfo Process_Info = {156, 14000, 55500};
317 GtkTreeRowReference *got_RowRef;
318
319 LttTime birth;
f7afe191 320
321 if(Process_List->Test_Process_Sent) return;
322
5f16133f 323 birth.tv_sec = 12000;
324 birth.tv_nsec = 55500;
325
4c69e0cc 326 processlist_add(Process_List,
5f16133f 327 1,
328 &birth,
f7afe191 329 &y);
4c69e0cc 330 processlist_get_process_pixels(Process_List,
f7afe191 331 1,
332 &birth,
333 &y,
334 &height);
4c69e0cc 335 drawing_insert_square( Drawing, y, height);
1ab3d149 336
f7afe191 337 //g_critical("y : %u, height : %u", y, height);
5f16133f 338
339 birth.tv_sec = 14000;
340 birth.tv_nsec = 55500;
341
4c69e0cc 342 processlist_add(Process_List,
5f16133f 343 156,
344 &birth,
f7afe191 345 &y);
4c69e0cc 346 processlist_get_process_pixels(Process_List,
f7afe191 347 156,
348 &birth,
349 &y,
350 &height);
4c69e0cc 351 drawing_insert_square( Drawing, y, height);
f7afe191 352
353 //g_critical("y : %u, height : %u", y, height);
354
5f16133f 355 birth.tv_sec = 12000;
356 birth.tv_nsec = 55700;
357
4c69e0cc 358 processlist_add(Process_List,
5f16133f 359 10,
360 &birth,
361 &height);
4c69e0cc 362 processlist_get_process_pixels(Process_List,
f7afe191 363 10,
364 &birth,
365 &y,
366 &height);
4c69e0cc 367 drawing_insert_square( Drawing, y, height);
f7afe191 368
369 //g_critical("y : %u, height : %u", y, height);
370
4c69e0cc 371 //drawing_insert_square( Drawing, height, 5);
5f16133f 372
373 for(i=0; i<10; i++)
374 {
375 birth.tv_sec = i*12000;
376 birth.tv_nsec = i*55700;
377
4c69e0cc 378 processlist_add(Process_List,
5f16133f 379 i,
380 &birth,
381 &height);
4c69e0cc 382 processlist_get_process_pixels(Process_List,
f7afe191 383 i,
384 &birth,
385 &y,
386 &height);
4c69e0cc 387 drawing_insert_square( Drawing, y, height);
f7afe191 388
389 // g_critical("y : %u, height : %u", y, height);
390
5f16133f 391 }
f7afe191 392 //g_critical("height : %u", height);
5f16133f 393
394 birth.tv_sec = 12000;
395 birth.tv_nsec = 55600;
396
4c69e0cc 397 processlist_add(Process_List,
5f16133f 398 10,
399 &birth,
f7afe191 400 &y);
4c69e0cc 401 processlist_get_process_pixels(Process_List,
f7afe191 402 10,
403 &birth,
404 &y,
405 &height);
4c69e0cc 406 drawing_insert_square( Drawing, y, height);
f7afe191 407
408 //g_critical("y : %u, height : %u", y, height);
409
4c69e0cc 410 processlist_add(Process_List,
5f16133f 411 10000,
412 &birth,
413 &height);
4c69e0cc 414 processlist_get_process_pixels(Process_List,
f7afe191 415 10000,
416 &birth,
417 &y,
418 &height);
4c69e0cc 419 drawing_insert_square( Drawing, y, height);
f7afe191 420
421 //g_critical("y : %u, height : %u", y, height);
422
4c69e0cc 423 //drawing_insert_square( Drawing, height, 5);
f7afe191 424 //g_critical("height : %u", height);
5f16133f 425
426
4c69e0cc 427 processlist_get_process_pixels(Process_List,
1ab3d149 428 10000,
429 &birth,
f7afe191 430 &y, &height);
4c69e0cc 431 processlist_remove( Process_List,
5f16133f 432 10000,
433 &birth);
1ab3d149 434
4c69e0cc 435 drawing_remove_square( Drawing, y, height);
5f16133f 436
437 if(got_RowRef =
438 (GtkTreeRowReference*)g_hash_table_lookup(
439 Process_List->Process_Hash,
440 &Process_Info))
441 {
442 g_critical("key found");
443 g_critical("position in the list : %s",
444 gtk_tree_path_to_string (
445 gtk_tree_row_reference_get_path(
446 (GtkTreeRowReference*)got_RowRef)
447 ));
448
449 }
450
f7afe191 451 Process_List->Test_Process_Sent = TRUE;
452
5f16133f 453}
454
455
f0d936c0 456
457/**
458 * Event Viewer's constructor hook
459 *
460 * This constructor is given as a parameter to the menuitem and toolbar button
461 * registration. It creates the list.
462 * @param pmParentWindow A pointer to the parent window.
463 * @return The widget created.
464 */
465GtkWidget *
4c69e0cc 466h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key)
f0d936c0 467{
189a5d08 468 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key);
4c69e0cc 469 ControlFlowData *Control_Flow_Data = guicontrolflow() ;
189a5d08 470
471 Control_Flow_Data->Parent_Window = pmParentWindow;
f0d936c0 472
41a76985 473 get_time_window(pmParentWindow,
cb1686f6 474 guicontrolflow_get_time_window(Control_Flow_Data));
41a76985 475 get_current_time(pmParentWindow,
cb1686f6 476 guicontrolflow_get_current_time(Control_Flow_Data));
f7afe191 477
478 // Unreg done in the GuiControlFlow_Destructor
3cff8cc1 479 reg_update_time_window(update_time_window_hook, Control_Flow_Data,
f7afe191 480 pmParentWindow);
3cff8cc1 481 reg_update_current_time(update_current_time_hook, Control_Flow_Data,
f7afe191 482 pmParentWindow);
3cff8cc1 483 return guicontrolflow_get_widget(Control_Flow_Data) ;
f0d936c0 484
485}
486
3cff8cc1 487int event_selected_hook(void *hook_data, void *call_data)
f0d936c0 488{
489 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
490 guint *Event_Number = (guint*) call_data;
491
492 g_critical("DEBUG : event selected by main window : %u", *Event_Number);
493
494// Control_Flow_Data->Currently_Selected_Event = *Event_Number;
495// Control_Flow_Data->Selected_Event = TRUE ;
496
4c69e0cc 497// tree_v_set_cursor(Control_Flow_Data);
f0d936c0 498
499}
500
558aa013 501#ifdef DEBUG
f0d936c0 502/* Hook called before drawing. Gets the initial context at the beginning of the
503 * drawing interval and copy it to the context in Event_Request.
504 */
4c69e0cc 505int draw_before_hook(void *hook_data, void *call_data)
f0d936c0 506{
507 EventRequest *Event_Request = (EventRequest*)hook_data;
508 EventsContext Events_Context = (EventsContext*)call_data;
509
510 Event_Request->Events_Context = Events_Context;
511
512 return 0;
513}
514
515/*
516 * The draw event hook is called by the reading API to have a
517 * particular event drawn on the screen.
518 * @param hook_data ControlFlowData structure of the viewer.
519 * @param call_data Event context.
520 *
521 * This function basically draw lines and icons. Two types of lines are drawn :
522 * one small (3 pixels?) representing the state of the process and the second
523 * type is thicker (10 pixels?) representing on which CPU a process is running
524 * (and this only in running state).
525 *
526 * Extremums of the lines :
527 * x_min : time of the last event context for this process kept in memory.
528 * x_max : time of the current event.
529 * y : middle of the process in the process list. The process is found in the
530 * list, therefore is it's position in pixels.
531 *
532 * The choice of lines'color is defined by the context of the last event for this
533 * process.
534 */
4c69e0cc 535int draw_event_hook(void *hook_data, void *call_data)
f0d936c0 536{
537 EventRequest *Event_Request = (EventRequest*)hook_data;
538
539 return 0;
540}
541
542
4c69e0cc 543int draw_after_hook(void *hook_data, void *call_data)
f0d936c0 544{
545 EventRequest *Event_Request = (EventRequest*)hook_data;
546
547 g_free(Event_Request);
548 return 0;
549}
558aa013 550#endif
f7afe191 551
552
553
554
4c69e0cc 555void update_time_window_hook(void *hook_data, void *call_data)
f7afe191 556{
557 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
558 TimeWindow* Time_Window =
3cff8cc1 559 guicontrolflow_get_time_window(Control_Flow_Data);
f7afe191 560 TimeWindow *New_Time_Window = ((TimeWindow*)call_data);
561
562 // As the time interval change will mostly be used for
563 // zoom in and out, it's not useful to keep old drawing
564 // sections, as scale will be changed.
565
566
567 *Time_Window = *New_Time_Window;
189a5d08 568 g_info("New time window HOOK : %u, %u to %u, %u",
bca3b81f 569 Time_Window->start_time.tv_sec,
570 Time_Window->start_time.tv_nsec,
571 Time_Window->time_width.tv_sec,
572 Time_Window->time_width.tv_nsec);
f7afe191 573
6d5ed1c3 574 drawing_data_request(Control_Flow_Data->Drawing,
f7afe191 575 &Control_Flow_Data->Drawing->Pixmap,
576 0, 0,
577 Control_Flow_Data->Drawing->width,
578 Control_Flow_Data->Drawing->height);
579
4c69e0cc 580 drawing_refresh(Control_Flow_Data->Drawing,
f7afe191 581 0, 0,
582 Control_Flow_Data->Drawing->width,
583 Control_Flow_Data->Drawing->height);
584
585}
586
4c69e0cc 587void update_current_time_hook(void *hook_data, void *call_data)
f7afe191 588{
589 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
590 LttTime* Current_Time =
4c69e0cc 591 guicontrolflow_get_current_time(Control_Flow_Data);
f7afe191 592 *Current_Time = *((LttTime*)call_data);
189a5d08 593 g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec,
f7afe191 594 Current_Time->tv_nsec);
595
596 /* If current time is inside time interval, just move the highlight
597 * bar */
598
599 /* Else, we have to change the time interval. We have to tell it
600 * to the main window. */
601 /* The time interval change will take care of placing the current
602 * time at the center of the visible area */
603
604}
605
This page took 0.048641 seconds and 4 git commands to generate.