Commit | Line | Data |
---|---|---|
ce0214a6 | 1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 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 | ||
20 | ||
cf6cb7e0 | 21 | /****************************************************************************** |
d66666fe | 22 | * drawitem.c |
cf6cb7e0 | 23 | * |
24 | * This file contains methods responsible for drawing a generic type of data | |
25 | * in a drawable. Doing this generically will permit user defined drawing | |
26 | * behavior in a later time. | |
27 | * | |
b782dd11 | 28 | * This file provides an API which is meant to be reusable for all viewers that |
29 | * need to show information in line, icon, text, background or point form in | |
30 | * a drawable area having time for x axis. The y axis, in the control flow | |
31 | * viewer case, is corresponding to the different processes, but it can be | |
32 | * reused integrally for cpu, and eventually locks, buffers, network | |
33 | * interfaces... What will differ between the viewers is the precise | |
34 | * information which interests us. We may think that the most useful | |
35 | * information for control flow are some specific events, like schedule | |
36 | * change, and processes'states. It may differ for a cpu viewer : the | |
37 | * interesting information could be more the execution mode of each cpu. | |
38 | * This API in meant to make viewer's writers life easier : it will become | |
39 | * a simple choice of icons and line types for the precise information | |
40 | * the viewer has to provide (agremented with keeping supplementary records | |
41 | * and modifying slightly the DrawContext to suit the needs.) | |
42 | * | |
f0728492 | 43 | * We keep each data type in attributes, keys to specific information |
44 | * being formed from the GQuark corresponding to the information received. | |
45 | * (facilities / facility_name / events / eventname.) | |
46 | * (cpus/cpu_name, process_states/ps_name, | |
47 | * execution_modes/em_name, execution_submodes/es_name). | |
cf6cb7e0 | 48 | * The goal is then to provide a generic way to print information on the |
49 | * screen for all this different information. | |
50 | * | |
51 | * Information can be printed as | |
52 | * | |
53 | * - text (text + color + size + position (over or under line) | |
54 | * - icon (icon filename, corresponding to a loaded icon, accessible through | |
55 | * a GQuark. Icons are loaded statically at the guiControlFlow level during | |
56 | * module initialization and can be added on the fly if not present in the | |
57 | * GQuark.) The habitual place for xpm icons is in | |
58 | * ${prefix}/share/LinuxTraceToolkit.) + position (over or under line) | |
59 | * - line (color, width, style) | |
189a5d08 | 60 | * - Arc (big points) (color, size) |
cf6cb7e0 | 61 | * - background color (color) |
62 | * | |
189a5d08 | 63 | * An item is a leaf of the attributes tree. It is, in that case, including |
64 | * all kind of events categories we can have. It then associates each category | |
65 | * with one or more actions (drawing something) or nothing. | |
66 | * | |
7d5ffafa | 67 | * Each item has an array of hooks (hook list). Each hook represents an |
68 | * operation to perform. We seek the array each time we want to | |
a2e850ff | 69 | * draw an item. We execute each operation in order. An operation type |
70 | * is associated with each hook to permit user listing and modification | |
71 | * of these operations. The operation type is also used to find the | |
72 | * corresponding priority for the sorting. Operation type and priorities | |
73 | * are enum and a static int table. | |
cf6cb7e0 | 74 | * |
75 | * The array has to be sorted by priority each time we add a task in it. | |
a2e850ff | 76 | * A priority is associated with each operation type. It permits |
cf6cb7e0 | 77 | * to perform background color selection before line or text drawing. We also |
78 | * draw lines before text, so the text appears over the lines. | |
79 | * | |
80 | * Executing all the arrays of operations for a specific event (which | |
81 | * implies information for state, event, cpu, execution mode and submode) | |
82 | * has to be done in a same DrawContext. The goal there is to keep the offset | |
83 | * of the text and icons over and under the middle line, so a specific | |
84 | * event could be printed as ( R Si 0 for running, scheduled in, cpu 0 ), | |
7d5ffafa | 85 | * text being easy to replace with icons. The DrawContext is passed as |
86 | * call_data for the operation hooks. | |
cf6cb7e0 | 87 | * |
b782dd11 | 88 | * We use the lttv global attributes to keep track of the loaded icons. |
89 | * If we need an icon, we look for it in the icons / icon name pathname. | |
90 | * If found, we use the pointer to it. If not, we load the pixmap in | |
1a31868c | 91 | * memory and set the pointer to the GdkPixmap in the attributes. The |
92 | * structure pointed to contains the pixmap and the mask bitmap. | |
b782dd11 | 93 | * |
cf6cb7e0 | 94 | * Author : Mathieu Desnoyers, October 2003 |
95 | */ | |
7d5ffafa | 96 | |
4e4d11b3 | 97 | #ifdef HAVE_CONFIG_H |
98 | #include <config.h> | |
99 | #endif | |
100 | ||
7d5ffafa | 101 | #include <glib.h> |
09e2606f | 102 | #include <gtk/gtk.h> |
103 | #include <gdk/gdk.h> | |
7d5ffafa | 104 | #include <lttv/hook.h> |
f0728492 | 105 | #include <lttv/attribute.h> |
106 | #include <lttv/iattribute.h> | |
1a31868c | 107 | #include <string.h> |
88bf15f0 | 108 | #ifdef BABEL_CLEANUP |
d8f124de | 109 | #include <lttv/tracecontext.h> |
88bf15f0 | 110 | #endif //babel_cleanup |
b782dd11 | 111 | #include <lttv/state.h> |
2eef04b5 | 112 | #include <lttv/lttv.h> |
b782dd11 | 113 | |
5e96e7e3 | 114 | #include "drawing.h" |
d66666fe | 115 | #include "drawitem.h" |
1a31868c | 116 | |
117 | ||
118 | #define MAX_PATH_LEN 256 | |
119 | ||
501d5405 | 120 | /* drawing hook functions */ |
6550d711 | 121 | gboolean draw_text( void *hook_data, void *call_data) |
b782dd11 | 122 | { |
e800cf84 | 123 | PropertiesText *properties = (PropertiesText*)hook_data; |
c8bba5fa | 124 | DrawContext *draw_context = (DrawContext*)call_data; |
a56a1ba4 | 125 | |
126 | PangoContext *context; | |
127 | PangoLayout *layout; | |
c8bba5fa | 128 | PangoFontDescription *font_desc;// = pango_font_description_new(); |
a56a1ba4 | 129 | PangoRectangle ink_rect; |
130 | ||
c8bba5fa | 131 | layout = draw_context->pango_layout; |
a56a1ba4 | 132 | |
133 | context = pango_layout_get_context(layout); | |
c8bba5fa | 134 | font_desc = pango_context_get_font_description(context); |
a56a1ba4 | 135 | |
e800cf84 | 136 | pango_font_description_set_size(font_desc, properties->size*PANGO_SCALE); |
a56a1ba4 | 137 | pango_layout_context_changed(layout); |
138 | ||
e800cf84 | 139 | pango_layout_set_text(layout, properties->text, -1); |
a56a1ba4 | 140 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
a56a1ba4 | 141 | |
e800cf84 | 142 | gint x=0, y=0; |
143 | gint *offset=NULL; | |
144 | gboolean enough_space = FALSE; | |
145 | gint width = ink_rect.width; | |
146 | ||
147 | switch(properties->position.x) { | |
148 | case POS_START: | |
149 | x = draw_context->drawinfo.start.x; | |
150 | switch(properties->position.y) { | |
151 | case OVER: | |
152 | offset = &draw_context->drawinfo.start.offset.over; | |
153 | x += draw_context->drawinfo.start.offset.over; | |
154 | y = draw_context->drawinfo.y.over; | |
155 | break; | |
156 | case MIDDLE: | |
157 | offset = &draw_context->drawinfo.start.offset.middle; | |
158 | x += draw_context->drawinfo.start.offset.middle; | |
159 | y = draw_context->drawinfo.y.middle; | |
160 | break; | |
161 | case UNDER: | |
162 | offset = &draw_context->drawinfo.start.offset.under; | |
163 | x += draw_context->drawinfo.start.offset.under; | |
164 | y = draw_context->drawinfo.y.under; | |
165 | break; | |
166 | } | |
167 | /* verify if there is enough space to draw */ | |
1d1df11d | 168 | if(unlikely(x + width <= draw_context->drawinfo.end.x)) { |
e800cf84 | 169 | enough_space = TRUE; |
170 | *offset += width; | |
171 | } | |
a56a1ba4 | 172 | break; |
e800cf84 | 173 | case POS_END: |
174 | x = draw_context->drawinfo.end.x; | |
175 | switch(properties->position.y) { | |
176 | case OVER: | |
177 | offset = &draw_context->drawinfo.end.offset.over; | |
178 | x += draw_context->drawinfo.end.offset.over; | |
179 | y = draw_context->drawinfo.y.over; | |
180 | break; | |
181 | case MIDDLE: | |
182 | offset = &draw_context->drawinfo.end.offset.middle; | |
183 | x += draw_context->drawinfo.end.offset.middle; | |
184 | y = draw_context->drawinfo.y.middle; | |
185 | break; | |
186 | case UNDER: | |
187 | offset = &draw_context->drawinfo.end.offset.under; | |
188 | x += draw_context->drawinfo.end.offset.under; | |
189 | y = draw_context->drawinfo.y.under; | |
190 | break; | |
191 | } | |
192 | /* verify if there is enough space to draw */ | |
1d1df11d | 193 | if(unlikely(x - width >= draw_context->drawinfo.start.x)) { |
e800cf84 | 194 | enough_space = TRUE; |
195 | *offset -= width; | |
196 | } | |
a56a1ba4 | 197 | break; |
198 | } | |
199 | ||
1d1df11d | 200 | if(unlikely(enough_space)) |
e800cf84 | 201 | gdk_draw_layout_with_colors(draw_context->drawable, |
202 | draw_context->gc, | |
203 | x, | |
204 | y, | |
205 | layout, properties->foreground, properties->background); | |
206 | ||
a56a1ba4 | 207 | return 0; |
b782dd11 | 208 | } |
209 | ||
1a31868c | 210 | |
211 | /* To speed up the process, search in already loaded icons list first. Only | |
212 | * load it if not present. | |
213 | */ | |
6550d711 | 214 | gboolean draw_icon( void *hook_data, void *call_data) |
b782dd11 | 215 | { |
c8bba5fa | 216 | PropertiesIcon *properties = (PropertiesIcon*)hook_data; |
217 | DrawContext *draw_context = (DrawContext*)call_data; | |
8f318283 | 218 | gboolean retval; |
b782dd11 | 219 | |
1a31868c | 220 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
a56a1ba4 | 221 | LttvAttributeValue value; |
222 | gchar icon_name[MAX_PATH_LEN] = "icons/"; | |
223 | IconStruct *icon_info; | |
8d088fb2 | 224 | |
c8bba5fa | 225 | strcat(icon_name, properties->icon_name); |
a56a1ba4 | 226 | |
8f318283 BP |
227 | retval= lttv_iattribute_find_by_path(attributes, icon_name, LTTV_POINTER, |
228 | &value); | |
229 | g_assert(retval); | |
1d1df11d | 230 | if(unlikely(*(value.v_pointer) == NULL)) |
a56a1ba4 | 231 | { |
232 | *(value.v_pointer) = icon_info = g_new(IconStruct,1); | |
233 | ||
c8bba5fa | 234 | icon_info->pixmap = gdk_pixmap_create_from_xpm(draw_context->drawable, |
235 | &icon_info->mask, NULL, properties->icon_name); | |
a56a1ba4 | 236 | } |
237 | else | |
238 | { | |
239 | icon_info = *(value.v_pointer); | |
240 | } | |
241 | ||
e800cf84 | 242 | gint x=0, y=0; |
243 | gint *offset=NULL; | |
244 | gboolean enough_space = FALSE; | |
245 | gint width = properties->width; | |
a56a1ba4 | 246 | |
e800cf84 | 247 | switch(properties->position.x) { |
248 | case POS_START: | |
249 | x = draw_context->drawinfo.start.x; | |
250 | switch(properties->position.y) { | |
251 | case OVER: | |
252 | offset = &draw_context->drawinfo.start.offset.over; | |
253 | x += draw_context->drawinfo.start.offset.over; | |
254 | y = draw_context->drawinfo.y.over; | |
255 | break; | |
256 | case MIDDLE: | |
257 | offset = &draw_context->drawinfo.start.offset.middle; | |
258 | x += draw_context->drawinfo.start.offset.middle; | |
259 | y = draw_context->drawinfo.y.middle; | |
260 | break; | |
261 | case UNDER: | |
262 | offset = &draw_context->drawinfo.start.offset.under; | |
263 | x += draw_context->drawinfo.start.offset.under; | |
264 | y = draw_context->drawinfo.y.under; | |
265 | break; | |
266 | } | |
267 | /* verify if there is enough space to draw */ | |
1d1df11d | 268 | if(unlikely(x + width <= draw_context->drawinfo.end.x)) { |
e800cf84 | 269 | enough_space = TRUE; |
270 | *offset += width; | |
271 | } | |
a56a1ba4 | 272 | break; |
e800cf84 | 273 | case POS_END: |
274 | x = draw_context->drawinfo.end.x; | |
275 | switch(properties->position.y) { | |
276 | case OVER: | |
277 | offset = &draw_context->drawinfo.end.offset.over; | |
278 | x += draw_context->drawinfo.end.offset.over; | |
279 | y = draw_context->drawinfo.y.over; | |
280 | break; | |
281 | case MIDDLE: | |
282 | offset = &draw_context->drawinfo.end.offset.middle; | |
283 | x += draw_context->drawinfo.end.offset.middle; | |
284 | y = draw_context->drawinfo.y.middle; | |
285 | break; | |
286 | case UNDER: | |
287 | offset = &draw_context->drawinfo.end.offset.under; | |
288 | x += draw_context->drawinfo.end.offset.under; | |
289 | y = draw_context->drawinfo.y.under; | |
290 | break; | |
291 | } | |
292 | /* verify if there is enough space to draw */ | |
1d1df11d | 293 | if(unlikely(x - width >= draw_context->drawinfo.start.x)) { |
e800cf84 | 294 | enough_space = TRUE; |
295 | *offset -= width; | |
296 | } | |
a56a1ba4 | 297 | break; |
298 | } | |
299 | ||
1d1df11d | 300 | if(unlikely(enough_space)) { |
e800cf84 | 301 | gdk_gc_set_clip_mask(draw_context->gc, icon_info->mask); |
302 | ||
303 | gdk_gc_set_clip_origin( | |
304 | draw_context->gc, | |
305 | x, | |
306 | y); | |
307 | gdk_draw_drawable(draw_context->drawable, | |
308 | draw_context->gc, | |
309 | icon_info->pixmap, | |
310 | 0, 0, | |
311 | x, | |
312 | y, | |
313 | properties->width, properties->height); | |
314 | ||
315 | gdk_gc_set_clip_origin(draw_context->gc, 0, 0); | |
316 | gdk_gc_set_clip_mask(draw_context->gc, NULL); | |
317 | } | |
a56a1ba4 | 318 | return 0; |
b782dd11 | 319 | } |
320 | ||
6550d711 | 321 | gboolean draw_line( void *hook_data, void *call_data) |
b782dd11 | 322 | { |
c8bba5fa | 323 | PropertiesLine *properties = (PropertiesLine*)hook_data; |
324 | DrawContext *draw_context = (DrawContext*)call_data; | |
a56a1ba4 | 325 | |
f16a5569 | 326 | gdk_gc_set_foreground(draw_context->gc, &properties->color); |
327 | //gdk_gc_set_rgb_fg_color(draw_context->gc, &properties->color); | |
c8bba5fa | 328 | gdk_gc_set_line_attributes( draw_context->gc, |
329 | properties->line_width, | |
330 | properties->style, | |
a56a1ba4 | 331 | GDK_CAP_BUTT, |
332 | GDK_JOIN_MITER); | |
d0cd7f09 | 333 | //g_critical("DRAWING LINE : x1: %i, y1: %i, x2:%i, y2:%i", |
c8bba5fa | 334 | // draw_context->previous->middle->x, |
335 | // draw_context->previous->middle->y, | |
336 | // draw_context->drawinfo.middle.x, | |
337 | // draw_context->drawinfo.middle.y); | |
a56a1ba4 | 338 | |
e800cf84 | 339 | gint x_begin=0, x_end=0, y=0; |
340 | ||
341 | x_begin = draw_context->drawinfo.start.x; | |
342 | x_end = draw_context->drawinfo.end.x; | |
343 | ||
344 | switch(properties->y) { | |
a56a1ba4 | 345 | case OVER: |
e800cf84 | 346 | y = draw_context->drawinfo.y.over; |
a56a1ba4 | 347 | break; |
348 | case MIDDLE: | |
e800cf84 | 349 | y = draw_context->drawinfo.y.middle; |
a56a1ba4 | 350 | break; |
351 | case UNDER: | |
e800cf84 | 352 | y = draw_context->drawinfo.y.under; |
a56a1ba4 | 353 | break; |
354 | } | |
e800cf84 | 355 | |
356 | drawing_draw_line( | |
357 | NULL, draw_context->drawable, | |
358 | x_begin, | |
359 | y, | |
360 | x_end, | |
361 | y, | |
362 | draw_context->gc); | |
a56a1ba4 | 363 | |
364 | return 0; | |
b782dd11 | 365 | } |
366 | ||
6550d711 | 367 | gboolean draw_arc( void *hook_data, void *call_data) |
b782dd11 | 368 | { |
c8bba5fa | 369 | PropertiesArc *properties = (PropertiesArc*)hook_data; |
370 | DrawContext *draw_context = (DrawContext*)call_data; | |
a56a1ba4 | 371 | |
f16a5569 | 372 | gdk_gc_set_foreground(draw_context->gc, properties->color); |
373 | //gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color); | |
a56a1ba4 | 374 | |
e800cf84 | 375 | gint x=0, y=0; |
376 | gint *offset=NULL; | |
377 | gboolean enough_space = FALSE; | |
378 | gint width = properties->size; | |
a56a1ba4 | 379 | |
e800cf84 | 380 | switch(properties->position.x) { |
381 | case POS_START: | |
382 | x = draw_context->drawinfo.start.x; | |
383 | switch(properties->position.y) { | |
384 | case OVER: | |
385 | offset = &draw_context->drawinfo.start.offset.over; | |
386 | x += draw_context->drawinfo.start.offset.over; | |
387 | y = draw_context->drawinfo.y.over; | |
388 | break; | |
389 | case MIDDLE: | |
390 | offset = &draw_context->drawinfo.start.offset.middle; | |
391 | x += draw_context->drawinfo.start.offset.middle; | |
392 | y = draw_context->drawinfo.y.middle; | |
393 | break; | |
394 | case UNDER: | |
395 | offset = &draw_context->drawinfo.start.offset.under; | |
396 | x += draw_context->drawinfo.start.offset.under; | |
397 | y = draw_context->drawinfo.y.under; | |
398 | break; | |
399 | } | |
400 | /* verify if there is enough space to draw */ | |
1d1df11d | 401 | if(unlikely(x + width <= draw_context->drawinfo.end.x)) { |
e800cf84 | 402 | enough_space = TRUE; |
403 | *offset += width; | |
404 | } | |
405 | break; | |
406 | case POS_END: | |
407 | x = draw_context->drawinfo.end.x; | |
408 | switch(properties->position.y) { | |
409 | case OVER: | |
410 | offset = &draw_context->drawinfo.end.offset.over; | |
411 | x += draw_context->drawinfo.end.offset.over; | |
412 | y = draw_context->drawinfo.y.over; | |
413 | break; | |
414 | case MIDDLE: | |
415 | offset = &draw_context->drawinfo.end.offset.middle; | |
416 | x += draw_context->drawinfo.end.offset.middle; | |
417 | y = draw_context->drawinfo.y.middle; | |
418 | break; | |
419 | case UNDER: | |
420 | offset = &draw_context->drawinfo.end.offset.under; | |
421 | x += draw_context->drawinfo.end.offset.under; | |
422 | y = draw_context->drawinfo.y.under; | |
423 | break; | |
424 | } | |
425 | /* verify if there is enough space to draw */ | |
1d1df11d | 426 | if(unlikely(x - width >= draw_context->drawinfo.start.x)) { |
e800cf84 | 427 | enough_space = TRUE; |
428 | *offset -= width; | |
429 | } | |
a56a1ba4 | 430 | break; |
431 | } | |
432 | ||
1d1df11d | 433 | if(unlikely(enough_space)) |
e800cf84 | 434 | gdk_draw_arc(draw_context->drawable, draw_context->gc, |
435 | properties->filled, | |
436 | x, | |
437 | y, | |
438 | properties->size, properties->size, 0, 360*64); | |
a56a1ba4 | 439 | |
440 | return 0; | |
b782dd11 | 441 | } |
442 | ||
6550d711 | 443 | gboolean draw_bg( void *hook_data, void *call_data) |
b782dd11 | 444 | { |
c8bba5fa | 445 | PropertiesBG *properties = (PropertiesBG*)hook_data; |
446 | DrawContext *draw_context = (DrawContext*)call_data; | |
b782dd11 | 447 | |
f16a5569 | 448 | gdk_gc_set_foreground(draw_context->gc, properties->color); |
449 | //gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color); | |
09e2606f | 450 | |
d0cd7f09 | 451 | //g_critical("DRAWING RECT : x: %i, y: %i, w:%i, h:%i, val1 :%i, val2:%i ", |
c8bba5fa | 452 | // draw_context->previous->over->x, |
453 | // draw_context->previous->over->y, | |
454 | // draw_context->drawinfo.over.x - draw_context->previous->over->x, | |
455 | // draw_context->previous->under->y-draw_context->previous->over->y, | |
456 | // draw_context->drawinfo.over.x, | |
457 | // draw_context->previous->over->x); | |
458 | gdk_draw_rectangle(draw_context->drawable, draw_context->gc, | |
a56a1ba4 | 459 | TRUE, |
e800cf84 | 460 | draw_context->drawinfo.start.x, |
461 | draw_context->drawinfo.y.over, | |
462 | draw_context->drawinfo.end.x - draw_context->drawinfo.start.x, | |
463 | draw_context->drawinfo.y.under - draw_context->drawinfo.y.over); | |
09e2606f | 464 | |
a56a1ba4 | 465 | return 0; |
b782dd11 | 466 | } |
467 | ||
468 |