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