heavy icon drawing sample
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Event_Hooks.c
1 /*****************************************************************************
2 * Hooks to be called by the main window *
3 *****************************************************************************/
4
5
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
9 //#define PANGO_ENABLE_BACKEND
10 #include <gtk/gtk.h>
11 #include <gdk/gdk.h>
12 #include <glib.h>
13
14 //#include <pango/pango.h>
15
16 #include <lttv/hook.h>
17 #include <lttv/common.h>
18
19 #include "Event_Hooks.h"
20 #include "CFV.h"
21 #include "Process_List.h"
22 #include "Drawing.h"
23 #include "CFV-private.h"
24
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
31 struct _DrawContext {
32 GdkDrawable *drawable;
33 GdkGC *gc;
34
35
36 DrawInfo *Current;
37 DrawInfo *Previous;
38 };
39
40 struct _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 */
67 struct _ItemInfo {
68 gint x, y;
69 LttvTraceState *ts;
70 LttvTracefileState *tfs;
71 };
72
73
74
75 struct _PropertiesIcon {
76 gchar *icon_name;
77 gint width;
78 gint height;
79 RelPos position;
80 };
81
82
83
84 void 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 }
125
126 /* NOTE : no drawing data should be sent there, since the drawing widget
127 * has not been initialized */
128 void 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 {
135 int i,j;
136 ProcessInfo Process_Info = {10000, 12000, 55600};
137 //ProcessInfo Process_Info = {156, 14000, 55500};
138 GtkTreeRowReference *got_RowRef;
139 PangoContext *context;
140 PangoLayout *layout;
141 PangoFontDescription *FontDesc;// = pango_font_description_new();
142 gint Font_Size;
143
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
149 // rectangle
150 GdkColor color = { 0, 0xffff, 0x0000, 0x0000 };
151
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
160
161
162
163 LttTime birth;
164 birth.tv_sec = 12000;
165 birth.tv_nsec = 55500;
166 g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
167 processlist_get_process_pixels(Process_List,
168 1,
169 &birth,
170 &y,
171 &height);
172
173 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
174 drawing_draw_line(
175 Drawing, Pixmap, x,
176 y+(height/2), x + width, y+(height/2),
177 Drawing->Drawing_Area_V->style->black_gc);
178
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
183 birth.tv_sec = 14000;
184 birth.tv_nsec = 55500;
185
186 processlist_get_process_pixels(Process_List,
187 156,
188 &birth,
189 &y,
190 &height);
191
192
193 drawing_draw_line(
194 Drawing, Pixmap, x,
195 y+(height/2), x + width, y+(height/2),
196 Drawing->Drawing_Area_V->style->black_gc);
197
198 g_info("y : %u, height : %u", y, height);
199
200
201
202 birth.tv_sec = 12000;
203 birth.tv_nsec = 55700;
204
205 processlist_get_process_pixels(Process_List,
206 10,
207 &birth,
208 &y,
209 &height);
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);
217
218 drawing_draw_line(
219 Drawing, Pixmap, x,
220 y+(height/2), x + width, y+(height/2),
221 Drawing->Drawing_Area_V->style->black_gc);
222
223
224 /* Draw arc */
225 gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc,
226 TRUE, 100, y, height/2, height/2, 0, 360*64);
227
228 g_info("y : %u, height : %u", y, height);
229
230 for(i=0; i<10; i++)
231 {
232 birth.tv_sec = i*12000;
233 birth.tv_nsec = i*55700;
234
235 processlist_get_process_pixels(Process_List,
236 i,
237 &birth,
238 &y,
239 &height);
240
241
242 drawing_draw_line(
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
254 processlist_get_process_pixels(Process_List,
255 10,
256 &birth,
257 &y,
258 &height);
259
260
261 drawing_draw_line(
262 Drawing, Pixmap, x,
263 y+(height/2), x + width, y+(height/2),
264 Drawing->Drawing_Area_V->style->black_gc);
265
266 g_info("y : %u, height : %u", y, height);
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
303
304
305 pango_font_description_set_size(FontDesc, Font_Size);
306 g_free(gc);
307 g_free(layout);
308 //g_free(context);
309 }
310
311 void send_test_process(ProcessList *Process_List, Drawing_t *Drawing)
312 {
313 guint height, y;
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;
320
321 if(Process_List->Test_Process_Sent) return;
322
323 birth.tv_sec = 12000;
324 birth.tv_nsec = 55500;
325
326 processlist_add(Process_List,
327 1,
328 &birth,
329 &y);
330 processlist_get_process_pixels(Process_List,
331 1,
332 &birth,
333 &y,
334 &height);
335 drawing_insert_square( Drawing, y, height);
336
337 //g_critical("y : %u, height : %u", y, height);
338
339 birth.tv_sec = 14000;
340 birth.tv_nsec = 55500;
341
342 processlist_add(Process_List,
343 156,
344 &birth,
345 &y);
346 processlist_get_process_pixels(Process_List,
347 156,
348 &birth,
349 &y,
350 &height);
351 drawing_insert_square( Drawing, y, height);
352
353 //g_critical("y : %u, height : %u", y, height);
354
355 birth.tv_sec = 12000;
356 birth.tv_nsec = 55700;
357
358 processlist_add(Process_List,
359 10,
360 &birth,
361 &height);
362 processlist_get_process_pixels(Process_List,
363 10,
364 &birth,
365 &y,
366 &height);
367 drawing_insert_square( Drawing, y, height);
368
369 //g_critical("y : %u, height : %u", y, height);
370
371 //drawing_insert_square( Drawing, height, 5);
372
373 for(i=0; i<10; i++)
374 {
375 birth.tv_sec = i*12000;
376 birth.tv_nsec = i*55700;
377
378 processlist_add(Process_List,
379 i,
380 &birth,
381 &height);
382 processlist_get_process_pixels(Process_List,
383 i,
384 &birth,
385 &y,
386 &height);
387 drawing_insert_square( Drawing, y, height);
388
389 // g_critical("y : %u, height : %u", y, height);
390
391 }
392 //g_critical("height : %u", height);
393
394 birth.tv_sec = 12000;
395 birth.tv_nsec = 55600;
396
397 processlist_add(Process_List,
398 10,
399 &birth,
400 &y);
401 processlist_get_process_pixels(Process_List,
402 10,
403 &birth,
404 &y,
405 &height);
406 drawing_insert_square( Drawing, y, height);
407
408 //g_critical("y : %u, height : %u", y, height);
409
410 processlist_add(Process_List,
411 10000,
412 &birth,
413 &height);
414 processlist_get_process_pixels(Process_List,
415 10000,
416 &birth,
417 &y,
418 &height);
419 drawing_insert_square( Drawing, y, height);
420
421 //g_critical("y : %u, height : %u", y, height);
422
423 //drawing_insert_square( Drawing, height, 5);
424 //g_critical("height : %u", height);
425
426
427 processlist_get_process_pixels(Process_List,
428 10000,
429 &birth,
430 &y, &height);
431 processlist_remove( Process_List,
432 10000,
433 &birth);
434
435 drawing_remove_square( Drawing, y, height);
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
451 Process_List->Test_Process_Sent = TRUE;
452
453 }
454
455
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 */
465 GtkWidget *
466 h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key)
467 {
468 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key);
469 ControlFlowData *Control_Flow_Data = guicontrolflow() ;
470
471 Control_Flow_Data->Parent_Window = pmParentWindow;
472
473 get_time_window(pmParentWindow,
474 guicontrolflow_get_time_window(Control_Flow_Data));
475 get_current_time(pmParentWindow,
476 guicontrolflow_get_current_time(Control_Flow_Data));
477
478 // Unreg done in the GuiControlFlow_Destructor
479 reg_update_time_window(update_time_window_hook, Control_Flow_Data,
480 pmParentWindow);
481 reg_update_current_time(update_current_time_hook, Control_Flow_Data,
482 pmParentWindow);
483 return guicontrolflow_get_widget(Control_Flow_Data) ;
484
485 }
486
487 int event_selected_hook(void *hook_data, void *call_data)
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
497 // tree_v_set_cursor(Control_Flow_Data);
498
499 }
500
501 #ifdef DEBUG
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 */
505 int draw_before_hook(void *hook_data, void *call_data)
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 */
535 int draw_event_hook(void *hook_data, void *call_data)
536 {
537 EventRequest *Event_Request = (EventRequest*)hook_data;
538
539 return 0;
540 }
541
542
543 int draw_after_hook(void *hook_data, void *call_data)
544 {
545 EventRequest *Event_Request = (EventRequest*)hook_data;
546
547 g_free(Event_Request);
548 return 0;
549 }
550 #endif
551
552
553
554
555 void update_time_window_hook(void *hook_data, void *call_data)
556 {
557 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
558 TimeWindow* Time_Window =
559 guicontrolflow_get_time_window(Control_Flow_Data);
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;
568 g_info("New time window HOOK : %u, %u to %u, %u",
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);
573
574 drawing_data_request(Control_Flow_Data->Drawing,
575 &Control_Flow_Data->Drawing->Pixmap,
576 0, 0,
577 Control_Flow_Data->Drawing->width,
578 Control_Flow_Data->Drawing->height);
579
580 drawing_refresh(Control_Flow_Data->Drawing,
581 0, 0,
582 Control_Flow_Data->Drawing->width,
583 Control_Flow_Data->Drawing->height);
584
585 }
586
587 void update_current_time_hook(void *hook_data, void *call_data)
588 {
589 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
590 LttTime* Current_Time =
591 guicontrolflow_get_current_time(Control_Flow_Data);
592 *Current_Time = *((LttTime*)call_data);
593 g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec,
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.042548 seconds and 4 git commands to generate.