aafa515d48849a87a08c2fb87a2a953bbeb1929b
[lttv.git] /
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
21 /******************************************************************************
22 * drawitem.c
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 *
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 *
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).
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)
60 * - Arc (big points) (color, size)
61 * - background color (color)
62 *
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 *
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
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.
74 *
75 * The array has to be sorted by priority each time we add a task in it.
76 * A priority is associated with each operation type. It permits
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 ),
85 * text being easy to replace with icons. The DrawContext is passed as
86 * call_data for the operation hooks.
87 *
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
91 * memory and set the pointer to the GdkPixmap in the attributes. The
92 * structure pointed to contains the pixmap and the mask bitmap.
93 *
94 * Author : Mathieu Desnoyers, October 2003
95 */
96
97 #ifdef HAVE_CONFIG_H
98 #include <config.h>
99 #endif
100
101 #include <glib.h>
102 #include <gtk/gtk.h>
103 #include <gdk/gdk.h>
104 #include <lttv/hook.h>
105 #include <lttv/attribute.h>
106 #include <lttv/iattribute.h>
107 #include <string.h>
108
109 #include <lttv/tracecontext.h>
110 #include <lttv/state.h>
111 #include <lttv/lttv.h>
112
113 #include "histodrawitem.h"
114
115
116 #define MAX_PATH_LEN 256
117
118 /* drawing hook functions */
119 gboolean histo_draw_text( void *hook_data, void *call_data)
120 {
121 histo_PropertiesText *properties = (histo_PropertiesText*)hook_data;
122 histo_DrawContext *draw_context = (histo_DrawContext*)call_data;
123
124 PangoContext *context;
125 PangoLayout *layout;
126 PangoFontDescription *font_desc;// = pango_font_description_new();
127 PangoRectangle ink_rect;
128
129 layout = draw_context->pango_layout;
130
131 context = pango_layout_get_context(layout);
132 font_desc = pango_context_get_font_description(context);
133
134 pango_font_description_set_size(font_desc, properties->size*PANGO_SCALE);
135 pango_layout_context_changed(layout);
136
137 pango_layout_set_text(layout, properties->text, -1);
138 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
139
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->histo_position.x) {
146 case POS_START:
147 x = draw_context->histo_drawinfo.start.x;
148 switch(properties->histo_position.y) {
149 case OVER:
150 offset = &draw_context->histo_drawinfo.start.offset.over;
151 x += draw_context->histo_drawinfo.start.offset.over;
152 y = draw_context->histo_drawinfo.y.over;
153 break;
154 case MIDDLE:
155 offset = &draw_context->histo_drawinfo.start.offset.middle;
156 x += draw_context->histo_drawinfo.start.offset.middle;
157 y = draw_context->histo_drawinfo.y.middle;
158 break;
159 case UNDER:
160 offset = &draw_context->histo_drawinfo.start.offset.under;
161 x += draw_context->histo_drawinfo.start.offset.under;
162 y = draw_context->histo_drawinfo.y.under;
163 break;
164 }
165 /* verify if there is enough space to draw */
166 if(unlikely(x + width <= draw_context->histo_drawinfo.end.x)) {
167 enough_space = TRUE;
168 *offset += width;
169 }
170 break;
171 case POS_END:
172 x = draw_context->histo_drawinfo.end.x;
173 switch(properties->histo_position.y) {
174 case OVER:
175 offset = &draw_context->histo_drawinfo.end.offset.over;
176 x += draw_context->histo_drawinfo.end.offset.over;
177 y = draw_context->histo_drawinfo.y.over;
178 break;
179 case MIDDLE:
180 offset = &draw_context->histo_drawinfo.end.offset.middle;
181 x += draw_context->histo_drawinfo.end.offset.middle;
182 y = draw_context->histo_drawinfo.y.middle;
183 break;
184 case UNDER:
185 offset = &draw_context->histo_drawinfo.end.offset.under;
186 x += draw_context->histo_drawinfo.end.offset.under;
187 y = draw_context->histo_drawinfo.y.under;
188 break;
189 }
190 /* verify if there is enough space to draw */
191 if(unlikely(x - width >= draw_context->histo_drawinfo.start.x)) {
192 enough_space = TRUE;
193 *offset -= width;
194 }
195 break;
196 }
197
198 if(unlikely(enough_space))
199 gdk_draw_layout_with_colors(draw_context->drawable,
200 draw_context->gc,
201 x,
202 y,
203 layout, properties->foreground, properties->background);
204
205 return 0;
206 }
207
208
209 /* To speed up the process, search in already loaded icons list first. Only
210 * load it if not present.
211 */
212 gboolean histo_draw_icon( void *hook_data, void *call_data)
213 {
214 histo_PropertiesIcon *properties = (histo_PropertiesIcon*)hook_data;
215 histo_DrawContext *draw_context = (histo_DrawContext*)call_data;
216
217 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
218 LttvAttributeValue value;
219 gchar icon_name[MAX_PATH_LEN] = "icons/";
220 histo_IconStruct *icon_info;
221
222 strcat(icon_name, properties->icon_name);
223
224 g_assert(lttv_iattribute_find_by_path(attributes, icon_name,
225 LTTV_POINTER, &value));
226 if(unlikely(*(value.v_pointer) == NULL))
227 {
228 *(value.v_pointer) = icon_info = g_new(histo_IconStruct,1);
229
230 icon_info->pixmap = gdk_pixmap_create_from_xpm(draw_context->drawable,
231 &icon_info->mask, NULL, properties->icon_name);
232 }
233 else
234 {
235 icon_info = *(value.v_pointer);
236 }
237
238 gint x=0, y=0;
239 gint *offset=NULL;
240 gboolean enough_space = FALSE;
241 gint width = properties->width;
242
243 switch(properties->histo_position.x) {
244 case POS_START:
245 x = draw_context->histo_drawinfo.start.x;
246 switch(properties->histo_position.y) {
247 case OVER:
248 offset = &draw_context->histo_drawinfo.start.offset.over;
249 x += draw_context->histo_drawinfo.start.offset.over;
250 y = draw_context->histo_drawinfo.y.over;
251 break;
252 case MIDDLE:
253 offset = &draw_context->histo_drawinfo.start.offset.middle;
254 x += draw_context->histo_drawinfo.start.offset.middle;
255 y = draw_context->histo_drawinfo.y.middle;
256 break;
257 case UNDER:
258 offset = &draw_context->histo_drawinfo.start.offset.under;
259 x += draw_context->histo_drawinfo.start.offset.under;
260 y = draw_context->histo_drawinfo.y.under;
261 break;
262 }
263 /* verify if there is enough space to draw */
264 if(unlikely(x + width <= draw_context->histo_drawinfo.end.x)) {
265 enough_space = TRUE;
266 *offset += width;
267 }
268 break;
269 case POS_END:
270 x = draw_context->histo_drawinfo.end.x;
271 switch(properties->histo_position.y) {
272 case OVER:
273 offset = &draw_context->histo_drawinfo.end.offset.over;
274 x += draw_context->histo_drawinfo.end.offset.over;
275 y = draw_context->histo_drawinfo.y.over;
276 break;
277 case MIDDLE:
278 offset = &draw_context->histo_drawinfo.end.offset.middle;
279 x += draw_context->histo_drawinfo.end.offset.middle;
280 y = draw_context->histo_drawinfo.y.middle;
281 break;
282 case UNDER:
283 offset = &draw_context->histo_drawinfo.end.offset.under;
284 x += draw_context->histo_drawinfo.end.offset.under;
285 y = draw_context->histo_drawinfo.y.under;
286 break;
287 }
288 /* verify if there is enough space to draw */
289 if(unlikely(x - width >= draw_context->histo_drawinfo.start.x)) {
290 enough_space = TRUE;
291 *offset -= width;
292 }
293 break;
294 }
295
296 if(unlikely(enough_space)) {
297 gdk_gc_set_clip_mask(draw_context->gc, icon_info->mask);
298
299 gdk_gc_set_clip_origin(
300 draw_context->gc,
301 x,
302 y);
303 gdk_draw_drawable(draw_context->drawable,
304 draw_context->gc,
305 icon_info->pixmap,
306 0, 0,
307 x,
308 y,
309 properties->width, properties->height);
310
311 gdk_gc_set_clip_origin(draw_context->gc, 0, 0);
312 gdk_gc_set_clip_mask(draw_context->gc, NULL);
313 }
314 return 0;
315 }
316
317 gboolean histo_draw_line( void *hook_data, void *call_data)
318 {
319 histo_PropertiesLine *properties = (histo_PropertiesLine*)hook_data;
320 histo_DrawContext *draw_context = (histo_DrawContext*)call_data;
321
322 gdk_gc_set_foreground(draw_context->gc, &properties->color);
323 //gdk_gc_set_rgb_fg_color(draw_context->gc, &properties->color);
324 gdk_gc_set_line_attributes( draw_context->gc,
325 properties->line_width,
326 properties->style,
327 GDK_CAP_BUTT,
328 GDK_JOIN_MITER);
329 //g_critical("DRAWING LINE : x1: %i, y1: %i, x2:%i, y2:%i",
330 // draw_context->previous->middle->x,
331 // draw_context->previous->middle->y,
332 // draw_context->drawinfo.middle.x,
333 // draw_context->drawinfo.middle.y);
334
335 gint x_begin=0, x_end=0, y=0;
336
337 x_begin = draw_context->histo_drawinfo.start.x;
338 x_end = draw_context->histo_drawinfo.end.x;
339
340 switch(properties->y) {
341 case OVER:
342 y = draw_context->histo_drawinfo.y.over;
343 break;
344 case MIDDLE:
345 y = draw_context->histo_drawinfo.y.middle;
346 break;
347 case UNDER:
348 y = draw_context->histo_drawinfo.y.under;
349 break;
350 }
351
352 histo_drawing_draw_line(
353 NULL, draw_context->drawable,
354 x_begin,
355 y,
356 x_end,
357 y,
358 draw_context->gc);
359
360 return 0;
361 }
362
363 gboolean histo_draw_arc( void *hook_data, void *call_data)
364 {
365 histo_PropertiesArc *properties = (histo_PropertiesArc*)hook_data;
366 histo_DrawContext *draw_context = (histo_DrawContext*)call_data;
367
368 gdk_gc_set_foreground(draw_context->gc, properties->color);
369 //gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color);
370
371 gint x=0, y=0;
372 gint *offset=NULL;
373 gboolean enough_space = FALSE;
374 gint width = properties->size;
375
376 switch(properties->histo_position.x) {
377 case POS_START:
378 x = draw_context->histo_drawinfo.start.x;
379 switch(properties->histo_position.y) {
380 case OVER:
381 offset = &draw_context->histo_drawinfo.start.offset.over;
382 x += draw_context->histo_drawinfo.start.offset.over;
383 y = draw_context->histo_drawinfo.y.over;
384 break;
385 case MIDDLE:
386 offset = &draw_context->histo_drawinfo.start.offset.middle;
387 x += draw_context->histo_drawinfo.start.offset.middle;
388 y = draw_context->histo_drawinfo.y.middle;
389 break;
390 case UNDER:
391 offset = &draw_context->histo_drawinfo.start.offset.under;
392 x += draw_context->histo_drawinfo.start.offset.under;
393 y = draw_context->histo_drawinfo.y.under;
394 break;
395 }
396 /* verify if there is enough space to draw */
397 if(unlikely(x + width <= draw_context->histo_drawinfo.end.x)) {
398 enough_space = TRUE;
399 *offset += width;
400 }
401 break;
402 case POS_END:
403 x = draw_context->histo_drawinfo.end.x;
404 switch(properties->histo_position.y) {
405 case OVER:
406 offset = &draw_context->histo_drawinfo.end.offset.over;
407 x += draw_context->histo_drawinfo.end.offset.over;
408 y = draw_context->histo_drawinfo.y.over;
409 break;
410 case MIDDLE:
411 offset = &draw_context->histo_drawinfo.end.offset.middle;
412 x += draw_context->histo_drawinfo.end.offset.middle;
413 y = draw_context->histo_drawinfo.y.middle;
414 break;
415 case UNDER:
416 offset = &draw_context->histo_drawinfo.end.offset.under;
417 x += draw_context->histo_drawinfo.end.offset.under;
418 y = draw_context->histo_drawinfo.y.under;
419 break;
420 }
421 /* verify if there is enough space to draw */
422 if(unlikely(x - width >= draw_context->histo_drawinfo.start.x)) {
423 enough_space = TRUE;
424 *offset -= width;
425 }
426 break;
427 }
428
429 if(unlikely(enough_space))
430 gdk_draw_arc(draw_context->drawable, draw_context->gc,
431 properties->filled,
432 x,
433 y,
434 properties->size, properties->size, 0, 360*64);
435
436 return 0;
437 }
438
439 gboolean histo_draw_bg( void *hook_data, void *call_data)
440 {
441 histo_PropertiesBG *properties = (histo_PropertiesBG*)hook_data;
442 histo_DrawContext *draw_context = (histo_DrawContext*)call_data;
443
444 gdk_gc_set_foreground(draw_context->gc, properties->color);
445 //gdk_gc_set_rgb_fg_color(draw_context->gc, properties->color);
446
447 //g_critical("DRAWING RECT : x: %i, y: %i, w:%i, h:%i, val1 :%i, val2:%i ",
448 // draw_context->previous->over->x,
449 // draw_context->previous->over->y,
450 // draw_context->drawinfo.over.x - draw_context->previous->over->x,
451 // draw_context->previous->under->y-draw_context->previous->over->y,
452 // draw_context->drawinfo.over.x,
453 // draw_context->previous->over->x);
454 gdk_draw_rectangle(draw_context->drawable, draw_context->gc,
455 TRUE,
456 draw_context->histo_drawinfo.start.x,
457 draw_context->histo_drawinfo.y.over,
458 draw_context->histo_drawinfo.end.x - draw_context->histo_drawinfo.start.x,
459 draw_context->histo_drawinfo.y.under - draw_context->histo_drawinfo.y.over);
460
461 return 0;
462 }
463
464
This page took 0.036788 seconds and 3 git commands to generate.