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 | |
b9ce0bad YB |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
16 | * MA 02110-1301, USA. | |
ce0214a6 | 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> |
7d5ffafa | 108 | |
b782dd11 | 109 | #include <lttv/state.h> |
2eef04b5 | 110 | #include <lttv/lttv.h> |
b782dd11 | 111 | |
5e96e7e3 | 112 | #include "drawing.h" |
d66666fe | 113 | #include "drawitem.h" |
1a31868c | 114 | |
115 | ||
116 | #define MAX_PATH_LEN 256 | |
117 | ||
501d5405 | 118 | /* drawing hook functions */ |
6550d711 | 119 | gboolean draw_text( void *hook_data, void *call_data) |
b782dd11 | 120 | { |
e800cf84 | 121 | PropertiesText *properties = (PropertiesText*)hook_data; |
c8bba5fa | 122 | DrawContext *draw_context = (DrawContext*)call_data; |
a56a1ba4 | 123 | |
124 | PangoContext *context; | |
125 | PangoLayout *layout; | |
c8bba5fa | 126 | PangoFontDescription *font_desc;// = pango_font_description_new(); |
a56a1ba4 | 127 | PangoRectangle ink_rect; |
128 | ||
c8bba5fa | 129 | layout = draw_context->pango_layout; |
a56a1ba4 | 130 | |
131 | context = pango_layout_get_context(layout); | |
c8bba5fa | 132 | font_desc = pango_context_get_font_description(context); |
a56a1ba4 | 133 | |
e800cf84 | 134 | pango_font_description_set_size(font_desc, properties->size*PANGO_SCALE); |
a56a1ba4 | 135 | pango_layout_context_changed(layout); |
136 | ||
e800cf84 | 137 | pango_layout_set_text(layout, properties->text, -1); |
a56a1ba4 | 138 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
a56a1ba4 | 139 | |
e800cf84 | 140 | gint x=0, y=0; |
141 | gint *offset=NULL; | |
142 | gboolean enough_space = FALSE; | |
143 | gint width = ink_rect.width; | |
144 | ||
145 | switch(properties->position.x) { | |
146 | case POS_START: | |
147 | x = draw_context->drawinfo.start.x; | |
148 | switch(properties->position.y) { | |
149 | case OVER: | |
150 | offset = &draw_context->drawinfo.start.offset.over; | |
151 | x += draw_context->drawinfo.start.offset.over; | |
152 | y = draw_context->drawinfo.y.over; | |
153 | break; | |
154 | case MIDDLE: | |
155 | offset = &draw_context->drawinfo.start.offset.middle; | |
156 | x += draw_context->drawinfo.start.offset.middle; | |
157 | y = draw_context->drawinfo.y.middle; | |
158 | break; | |
159 | case UNDER: | |
160 | offset = &draw_context->drawinfo.start.offset.under; | |
161 | x += draw_context->drawinfo.start.offset.under; | |
162 | y = draw_context->drawinfo.y.under; | |
163 | break; | |
164 | } | |
165 | /* verify if there is enough space to draw */ | |
1d1df11d | 166 | if(unlikely(x + width <= draw_context->drawinfo.end.x)) { |
e800cf84 | 167 | enough_space = TRUE; |
168 | *offset += width; | |
169 | } | |
a56a1ba4 | 170 | break; |
e800cf84 | 171 | case POS_END: |
172 | x = draw_context->drawinfo.end.x; | |
173 | switch(properties->position.y) { | |
174 | case OVER: | |
175 | offset = &draw_context->drawinfo.end.offset.over; | |
176 | x += draw_context->drawinfo.end.offset.over; | |
177 | y = draw_context->drawinfo.y.over; | |
178 | break; | |
179 | case MIDDLE: | |
180 | offset = &draw_context->drawinfo.end.offset.middle; | |
181 | x += draw_context->drawinfo.end.offset.middle; | |
182 | y = draw_context->drawinfo.y.middle; | |
183 | break; | |
184 | case UNDER: | |
185 | offset = &draw_context->drawinfo.end.offset.under; | |
186 | x += draw_context->drawinfo.end.offset.under; | |
187 | y = draw_context->drawinfo.y.under; | |
188 | break; | |
189 | } | |
190 | /* verify if there is enough space to draw */ | |
1d1df11d | 191 | if(unlikely(x - width >= draw_context->drawinfo.start.x)) { |
e800cf84 | 192 | enough_space = TRUE; |
193 | *offset -= width; | |
194 | } | |
a56a1ba4 | 195 | break; |
196 | } | |
197 | ||
1d1df11d | 198 | if(unlikely(enough_space)) |
e800cf84 | 199 | gdk_draw_layout_with_colors(draw_context->drawable, |
200 | draw_context->gc, | |
201 | x, | |
202 | y, | |
203 | layout, properties->foreground, properties->background); | |
204 | ||
a56a1ba4 | 205 | return 0; |
b782dd11 | 206 | } |
207 | ||
1a31868c | 208 | |
209 | /* To speed up the process, search in already loaded icons list first. Only | |
210 | * load it if not present. | |
211 | */ | |
6550d711 | 212 | gboolean draw_icon( void *hook_data, void *call_data) |
b782dd11 | 213 | { |
c8bba5fa | 214 | PropertiesIcon *properties = (PropertiesIcon*)hook_data; |
215 | DrawContext *draw_context = (DrawContext*)call_data; | |
b782dd11 | 216 | |
1a31868c | 217 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
a56a1ba4 | 218 | LttvAttributeValue value; |
219 | gchar icon_name[MAX_PATH_LEN] = "icons/"; | |
220 | IconStruct *icon_info; | |
8f318283 | 221 | gboolean retval; |
8d088fb2 | 222 | |
c8bba5fa | 223 | strcat(icon_name, properties->icon_name); |
a56a1ba4 | 224 | |
8f318283 BP |
225 | retval= lttv_iattribute_find_by_path(attributes, icon_name, LTTV_POINTER, |
226 | &value); | |
227 | g_assert(retval); | |
1d1df11d | 228 | if(unlikely(*(value.v_pointer) == NULL)) |
a56a1ba4 | 229 | { |
230 | *(value.v_pointer) = icon_info = g_new(IconStruct,1); | |
231 | ||
c8bba5fa | 232 | icon_info->pixmap = gdk_pixmap_create_from_xpm(draw_context->drawable, |
233 | &icon_info->mask, NULL, properties->icon_name); | |
a56a1ba4 | 234 | } |
235 | else | |
236 | { | |
237 | icon_info = *(value.v_pointer); | |
238 | } | |
239 | ||
e800cf84 | 240 | gint x=0, y=0; |
241 | gint *offset=NULL; | |
242 | gboolean enough_space = FALSE; | |
243 | gint width = properties->width; | |
a56a1ba4 | 244 | |
e800cf84 | 245 | switch(properties->position.x) { |
246 | case POS_START: | |
247 | x = draw_context->drawinfo.start.x; | |
248 | switch(properties->position.y) { | |
249 | case OVER: | |
250 | offset = &draw_context->drawinfo.start.offset.over; | |
251 | x += draw_context->drawinfo.start.offset.over; | |
252 | y = draw_context->drawinfo.y.over; | |
253 | break; | |
254 | case MIDDLE: | |
255 | offset = &draw_context->drawinfo.start.offset.middle; | |
256 | x += draw_context->drawinfo.start.offset.middle; | |
257 | y = draw_context->drawinfo.y.middle; | |
258 | break; | |
259 | case UNDER: | |
260 | offset = &draw_context->drawinfo.start.offset.under; | |
261 | x += draw_context->drawinfo.start.offset.under; | |
262 | y = draw_context->drawinfo.y.under; | |
263 | break; | |
264 | } | |
265 | /* verify if there is enough space to draw */ | |
1d1df11d | 266 | if(unlikely(x + width <= draw_context->drawinfo.end.x)) { |
e800cf84 | 267 | enough_space = TRUE; |
268 | *offset += width; | |
269 | } | |
a56a1ba4 | 270 | break; |
e800cf84 | 271 | case POS_END: |
272 | x = draw_context->drawinfo.end.x; | |
273 | switch(properties->position.y) { | |
274 | case OVER: | |
275 | offset = &draw_context->drawinfo.end.offset.over; | |
276 | x += draw_context->drawinfo.end.offset.over; | |
277 | y = draw_context->drawinfo.y.over; | |
278 | break; | |
279 | case MIDDLE: | |
280 | offset = &draw_context->drawinfo.end.offset.middle; | |
281 | x += draw_context->drawinfo.end.offset.middle; | |
282 | y = draw_context->drawinfo.y.middle; | |
283 | break; | |
284 | case UNDER: | |
285 | offset = &draw_context->drawinfo.end.offset.under; | |
286 | x += draw_context->drawinfo.end.offset.under; | |
287 | y = draw_context->drawinfo.y.under; | |
288 | break; | |
289 | } | |
290 | /* verify if there is enough space to draw */ | |
1d1df11d | 291 | if(unlikely(x - width >= draw_context->drawinfo.start.x)) { |
e800cf84 | 292 | enough_space = TRUE; |
293 | *offset -= width; | |
294 | } | |
a56a1ba4 | 295 | break; |
296 | } | |
297 | ||
1d1df11d | 298 | if(unlikely(enough_space)) { |
e800cf84 | 299 | gdk_gc_set_clip_mask(draw_context->gc, icon_info->mask); |
300 | ||
301 | gdk_gc_set_clip_origin( | |
302 | draw_context->gc, | |
303 | x, | |
304 | y); | |
305 | gdk_draw_drawable(draw_context->drawable, | |
306 | draw_context->gc, | |
307 | icon_info->pixmap, | |
308 | 0, 0, | |
309 | x, | |
310 | y, | |
311 | properties->width, properties->height); | |
312 | ||
313 | gdk_gc_set_clip_origin(draw_context->gc, 0, 0); | |
314 | gdk_gc_set_clip_mask(draw_context->gc, NULL); | |
315 | } | |
a56a1ba4 | 316 | return 0; |
b782dd11 | 317 | } |
318 | ||
6550d711 | 319 | gboolean draw_line( void *hook_data, void *call_data) |
b782dd11 | 320 | { |
c8bba5fa | 321 | PropertiesLine *properties = (PropertiesLine*)hook_data; |
322 | DrawContext *draw_context = (DrawContext*)call_data; | |
a56a1ba4 | 323 | |
f16a5569 | 324 | gdk_gc_set_foreground(draw_context->gc, &properties->color); |
325 | //gdk_gc_set_rgb_fg_color(draw_context->gc, &properties->color); | |
c8bba5fa | 326 | gdk_gc_set_line_attributes( draw_context->gc, |
327 | properties->line_width, | |
328 | properties->style, | |
a56a1ba4 | 329 | GDK_CAP_BUTT, |
330 | GDK_JOIN_MITER); | |
d0cd7f09 | 331 | //g_critical("DRAWING LINE : x1: %i, y1: %i, x2:%i, y2:%i", |
c8bba5fa | 332 | // draw_context->previous->middle->x, |
333 | // draw_context->previous->middle->y, | |
334 | // draw_context->drawinfo.middle.x, | |
335 | // draw_context->drawinfo.middle.y); | |
a56a1ba4 | 336 | |
e800cf84 | 337 | gint x_begin=0, x_end=0, y=0; |
338 | ||
339 | x_begin = draw_context->drawinfo.start.x; | |
340 | x_end = draw_context->drawinfo.end.x; | |
341 | ||
342 | switch(properties->y) { | |
a56a1ba4 | 343 | case OVER: |
e800cf84 | 344 | y = draw_context->drawinfo.y.over; |
a56a1ba4 | 345 | break; |
346 | case MIDDLE: | |
e800cf84 | 347 | y = draw_context->drawinfo.y.middle; |
a56a1ba4 | 348 | break; |
349 | case UNDER: | |
e800cf84 | 350 | y = draw_context->drawinfo.y.under; |
a56a1ba4 | 351 | break; |
352 | } | |
e800cf84 | 353 | |
354 | drawing_draw_line( | |
355 | NULL, draw_context->drawable, | |
356 | x_begin, | |
357 | y, | |
358 | x_end, | |
359 | y, | |
360 | draw_context->gc); | |
a56a1ba4 | 361 | |
362 | return 0; | |
b782dd11 | 363 | } |
364 | ||
6550d711 | 365 | gboolean draw_arc( void *hook_data, void *call_data) |
b782dd11 | 366 | { |
c8bba5fa | 367 | PropertiesArc *properties = (PropertiesArc*)hook_data; |
368 | DrawContext *draw_context = (DrawContext*)call_data; | |
a56a1ba4 | 369 | |
f16a5569 | 370 | gdk_gc_set_foreground(draw_context->gc, properties->color); |
371 | //gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color); | |
a56a1ba4 | 372 | |
e800cf84 | 373 | gint x=0, y=0; |
374 | gint *offset=NULL; | |
375 | gboolean enough_space = FALSE; | |
376 | gint width = properties->size; | |
a56a1ba4 | 377 | |
e800cf84 | 378 | switch(properties->position.x) { |
379 | case POS_START: | |
380 | x = draw_context->drawinfo.start.x; | |
381 | switch(properties->position.y) { | |
382 | case OVER: | |
383 | offset = &draw_context->drawinfo.start.offset.over; | |
384 | x += draw_context->drawinfo.start.offset.over; | |
385 | y = draw_context->drawinfo.y.over; | |
386 | break; | |
387 | case MIDDLE: | |
388 | offset = &draw_context->drawinfo.start.offset.middle; | |
389 | x += draw_context->drawinfo.start.offset.middle; | |
390 | y = draw_context->drawinfo.y.middle; | |
391 | break; | |
392 | case UNDER: | |
393 | offset = &draw_context->drawinfo.start.offset.under; | |
394 | x += draw_context->drawinfo.start.offset.under; | |
395 | y = draw_context->drawinfo.y.under; | |
396 | break; | |
397 | } | |
398 | /* verify if there is enough space to draw */ | |
1d1df11d | 399 | if(unlikely(x + width <= draw_context->drawinfo.end.x)) { |
e800cf84 | 400 | enough_space = TRUE; |
401 | *offset += width; | |
402 | } | |
403 | break; | |
404 | case POS_END: | |
405 | x = draw_context->drawinfo.end.x; | |
406 | switch(properties->position.y) { | |
407 | case OVER: | |
408 | offset = &draw_context->drawinfo.end.offset.over; | |
409 | x += draw_context->drawinfo.end.offset.over; | |
410 | y = draw_context->drawinfo.y.over; | |
411 | break; | |
412 | case MIDDLE: | |
413 | offset = &draw_context->drawinfo.end.offset.middle; | |
414 | x += draw_context->drawinfo.end.offset.middle; | |
415 | y = draw_context->drawinfo.y.middle; | |
416 | break; | |
417 | case UNDER: | |
418 | offset = &draw_context->drawinfo.end.offset.under; | |
419 | x += draw_context->drawinfo.end.offset.under; | |
420 | y = draw_context->drawinfo.y.under; | |
421 | break; | |
422 | } | |
423 | /* verify if there is enough space to draw */ | |
1d1df11d | 424 | if(unlikely(x - width >= draw_context->drawinfo.start.x)) { |
e800cf84 | 425 | enough_space = TRUE; |
426 | *offset -= width; | |
427 | } | |
a56a1ba4 | 428 | break; |
429 | } | |
430 | ||
1d1df11d | 431 | if(unlikely(enough_space)) |
e800cf84 | 432 | gdk_draw_arc(draw_context->drawable, draw_context->gc, |
433 | properties->filled, | |
434 | x, | |
435 | y, | |
436 | properties->size, properties->size, 0, 360*64); | |
a56a1ba4 | 437 | |
438 | return 0; | |
b782dd11 | 439 | } |
440 | ||
6550d711 | 441 | gboolean draw_bg( void *hook_data, void *call_data) |
b782dd11 | 442 | { |
c8bba5fa | 443 | PropertiesBG *properties = (PropertiesBG*)hook_data; |
444 | DrawContext *draw_context = (DrawContext*)call_data; | |
b782dd11 | 445 | |
f16a5569 | 446 | gdk_gc_set_foreground(draw_context->gc, properties->color); |
447 | //gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color); | |
09e2606f | 448 | |
d0cd7f09 | 449 | //g_critical("DRAWING RECT : x: %i, y: %i, w:%i, h:%i, val1 :%i, val2:%i ", |
c8bba5fa | 450 | // draw_context->previous->over->x, |
451 | // draw_context->previous->over->y, | |
452 | // draw_context->drawinfo.over.x - draw_context->previous->over->x, | |
453 | // draw_context->previous->under->y-draw_context->previous->over->y, | |
454 | // draw_context->drawinfo.over.x, | |
455 | // draw_context->previous->over->x); | |
456 | gdk_draw_rectangle(draw_context->drawable, draw_context->gc, | |
a56a1ba4 | 457 | TRUE, |
e800cf84 | 458 | draw_context->drawinfo.start.x, |
459 | draw_context->drawinfo.y.over, | |
460 | draw_context->drawinfo.end.x - draw_context->drawinfo.start.x, | |
461 | draw_context->drawinfo.y.under - draw_context->drawinfo.y.over); | |
09e2606f | 462 | |
a56a1ba4 | 463 | return 0; |
b782dd11 | 464 | } |
465 | ||
466 |