1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
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;
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.
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,
21 /******************************************************************************
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.
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.)
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.
51 * Information can be printed as
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)
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.
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.
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.
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.
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.
94 * Author : Mathieu Desnoyers, October 2003
100 #include <lttv/hook.h>
101 #include <lttv/attribute.h>
102 #include <lttv/iattribute.h>
105 #include <lttv/tracecontext.h>
106 #include <lttv/state.h>
108 #include "drawitem.h"
111 #define MAX_PATH_LEN 256
113 /* drawing hook functions */
114 gboolean
draw_text( void *hook_data
, void *call_data
)
116 PropertiesText
*properties
= (PropertiesText
*)hook_data
;
117 DrawContext
*draw_context
= (DrawContext
*)call_data
;
119 PangoContext
*context
;
121 PangoAttribute
*attribute
;
122 PangoFontDescription
*font_desc
;// = pango_font_description_new();
124 PangoRectangle ink_rect
;
126 layout
= draw_context
->pango_layout
;
128 context
= pango_layout_get_context(layout
);
129 font_desc
= pango_context_get_font_description(context
);
131 pango_font_description_set_size(font_desc
, properties
->size
*PANGO_SCALE
);
132 pango_layout_context_changed(layout
);
134 pango_layout_set_text(layout
, properties
->text
, -1);
135 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
139 gboolean enough_space
= FALSE
;
140 gint width
= ink_rect
.width
;
142 switch(properties
->position
.x
) {
144 x
= draw_context
->drawinfo
.start
.x
;
145 switch(properties
->position
.y
) {
147 offset
= &draw_context
->drawinfo
.start
.offset
.over
;
148 x
+= draw_context
->drawinfo
.start
.offset
.over
;
149 y
= draw_context
->drawinfo
.y
.over
;
152 offset
= &draw_context
->drawinfo
.start
.offset
.middle
;
153 x
+= draw_context
->drawinfo
.start
.offset
.middle
;
154 y
= draw_context
->drawinfo
.y
.middle
;
157 offset
= &draw_context
->drawinfo
.start
.offset
.under
;
158 x
+= draw_context
->drawinfo
.start
.offset
.under
;
159 y
= draw_context
->drawinfo
.y
.under
;
162 /* verify if there is enough space to draw */
163 if(x
+ width
<= draw_context
->drawinfo
.end
.x
) {
169 x
= draw_context
->drawinfo
.end
.x
;
170 switch(properties
->position
.y
) {
172 offset
= &draw_context
->drawinfo
.end
.offset
.over
;
173 x
+= draw_context
->drawinfo
.end
.offset
.over
;
174 y
= draw_context
->drawinfo
.y
.over
;
177 offset
= &draw_context
->drawinfo
.end
.offset
.middle
;
178 x
+= draw_context
->drawinfo
.end
.offset
.middle
;
179 y
= draw_context
->drawinfo
.y
.middle
;
182 offset
= &draw_context
->drawinfo
.end
.offset
.under
;
183 x
+= draw_context
->drawinfo
.end
.offset
.under
;
184 y
= draw_context
->drawinfo
.y
.under
;
187 /* verify if there is enough space to draw */
188 if(x
- width
>= draw_context
->drawinfo
.start
.x
) {
196 gdk_draw_layout_with_colors(draw_context
->drawable
,
200 layout
, properties
->foreground
, properties
->background
);
206 /* To speed up the process, search in already loaded icons list first. Only
207 * load it if not present.
209 gboolean
draw_icon( void *hook_data
, void *call_data
)
211 PropertiesIcon
*properties
= (PropertiesIcon
*)hook_data
;
212 DrawContext
*draw_context
= (DrawContext
*)call_data
;
214 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
215 LttvAttributeValue value
;
216 gchar icon_name
[MAX_PATH_LEN
] = "icons/";
217 IconStruct
*icon_info
;
219 strcat(icon_name
, properties
->icon_name
);
221 g_assert(lttv_iattribute_find_by_path(attributes
, icon_name
,
222 LTTV_POINTER
, &value
));
223 if(*(value
.v_pointer
) == NULL
)
225 *(value
.v_pointer
) = icon_info
= g_new(IconStruct
,1);
227 icon_info
->pixmap
= gdk_pixmap_create_from_xpm(draw_context
->drawable
,
228 &icon_info
->mask
, NULL
, properties
->icon_name
);
232 icon_info
= *(value
.v_pointer
);
237 gboolean enough_space
= FALSE
;
238 gint width
= properties
->width
;
240 switch(properties
->position
.x
) {
242 x
= draw_context
->drawinfo
.start
.x
;
243 switch(properties
->position
.y
) {
245 offset
= &draw_context
->drawinfo
.start
.offset
.over
;
246 x
+= draw_context
->drawinfo
.start
.offset
.over
;
247 y
= draw_context
->drawinfo
.y
.over
;
250 offset
= &draw_context
->drawinfo
.start
.offset
.middle
;
251 x
+= draw_context
->drawinfo
.start
.offset
.middle
;
252 y
= draw_context
->drawinfo
.y
.middle
;
255 offset
= &draw_context
->drawinfo
.start
.offset
.under
;
256 x
+= draw_context
->drawinfo
.start
.offset
.under
;
257 y
= draw_context
->drawinfo
.y
.under
;
260 /* verify if there is enough space to draw */
261 if(x
+ width
<= draw_context
->drawinfo
.end
.x
) {
267 x
= draw_context
->drawinfo
.end
.x
;
268 switch(properties
->position
.y
) {
270 offset
= &draw_context
->drawinfo
.end
.offset
.over
;
271 x
+= draw_context
->drawinfo
.end
.offset
.over
;
272 y
= draw_context
->drawinfo
.y
.over
;
275 offset
= &draw_context
->drawinfo
.end
.offset
.middle
;
276 x
+= draw_context
->drawinfo
.end
.offset
.middle
;
277 y
= draw_context
->drawinfo
.y
.middle
;
280 offset
= &draw_context
->drawinfo
.end
.offset
.under
;
281 x
+= draw_context
->drawinfo
.end
.offset
.under
;
282 y
= draw_context
->drawinfo
.y
.under
;
285 /* verify if there is enough space to draw */
286 if(x
- width
>= draw_context
->drawinfo
.start
.x
) {
294 gdk_gc_set_clip_mask(draw_context
->gc
, icon_info
->mask
);
296 gdk_gc_set_clip_origin(
300 gdk_draw_drawable(draw_context
->drawable
,
306 properties
->width
, properties
->height
);
308 gdk_gc_set_clip_origin(draw_context
->gc
, 0, 0);
309 gdk_gc_set_clip_mask(draw_context
->gc
, NULL
);
314 gboolean
draw_line( void *hook_data
, void *call_data
)
316 PropertiesLine
*properties
= (PropertiesLine
*)hook_data
;
317 DrawContext
*draw_context
= (DrawContext
*)call_data
;
319 //gdk_gc_set_foreground(draw_context->gc, properties->color);
320 gdk_gc_set_rgb_fg_color(draw_context
->gc
, &properties
->color
);
321 //gdk_gc_set_foreground(gc, properties->color);
322 gdk_gc_set_line_attributes( draw_context
->gc
,
323 properties
->line_width
,
327 //g_critical("DRAWING LINE : x1: %i, y1: %i, x2:%i, y2:%i",
328 // draw_context->previous->middle->x,
329 // draw_context->previous->middle->y,
330 // draw_context->drawinfo.middle.x,
331 // draw_context->drawinfo.middle.y);
333 gint x_begin
=0, x_end
=0, y
=0;
335 x_begin
= draw_context
->drawinfo
.start
.x
;
336 x_end
= draw_context
->drawinfo
.end
.x
;
338 switch(properties
->y
) {
340 y
= draw_context
->drawinfo
.y
.over
;
343 y
= draw_context
->drawinfo
.y
.middle
;
346 y
= draw_context
->drawinfo
.y
.under
;
351 NULL
, draw_context
->drawable
,
361 gboolean
draw_arc( void *hook_data
, void *call_data
)
363 PropertiesArc
*properties
= (PropertiesArc
*)hook_data
;
364 DrawContext
*draw_context
= (DrawContext
*)call_data
;
366 //gdk_gc_set_foreground(draw_context->gc, properties->color);
367 gdk_gc_set_rgb_fg_color(draw_context
->gc
, properties
->color
);
371 gboolean enough_space
= FALSE
;
372 gint width
= properties
->size
;
374 switch(properties
->position
.x
) {
376 x
= draw_context
->drawinfo
.start
.x
;
377 switch(properties
->position
.y
) {
379 offset
= &draw_context
->drawinfo
.start
.offset
.over
;
380 x
+= draw_context
->drawinfo
.start
.offset
.over
;
381 y
= draw_context
->drawinfo
.y
.over
;
384 offset
= &draw_context
->drawinfo
.start
.offset
.middle
;
385 x
+= draw_context
->drawinfo
.start
.offset
.middle
;
386 y
= draw_context
->drawinfo
.y
.middle
;
389 offset
= &draw_context
->drawinfo
.start
.offset
.under
;
390 x
+= draw_context
->drawinfo
.start
.offset
.under
;
391 y
= draw_context
->drawinfo
.y
.under
;
394 /* verify if there is enough space to draw */
395 if(x
+ width
<= draw_context
->drawinfo
.end
.x
) {
401 x
= draw_context
->drawinfo
.end
.x
;
402 switch(properties
->position
.y
) {
404 offset
= &draw_context
->drawinfo
.end
.offset
.over
;
405 x
+= draw_context
->drawinfo
.end
.offset
.over
;
406 y
= draw_context
->drawinfo
.y
.over
;
409 offset
= &draw_context
->drawinfo
.end
.offset
.middle
;
410 x
+= draw_context
->drawinfo
.end
.offset
.middle
;
411 y
= draw_context
->drawinfo
.y
.middle
;
414 offset
= &draw_context
->drawinfo
.end
.offset
.under
;
415 x
+= draw_context
->drawinfo
.end
.offset
.under
;
416 y
= draw_context
->drawinfo
.y
.under
;
419 /* verify if there is enough space to draw */
420 if(x
- width
>= draw_context
->drawinfo
.start
.x
) {
428 gdk_draw_arc(draw_context
->drawable
, draw_context
->gc
,
432 properties
->size
, properties
->size
, 0, 360*64);
437 gboolean
draw_bg( void *hook_data
, void *call_data
)
439 PropertiesBG
*properties
= (PropertiesBG
*)hook_data
;
440 DrawContext
*draw_context
= (DrawContext
*)call_data
;
442 //gdk_gc_set_foreground(draw_context->gc, properties->color);
443 gdk_gc_set_rgb_fg_color(draw_context
->gc
, properties
->color
);
445 //g_critical("DRAWING RECT : x: %i, y: %i, w:%i, h:%i, val1 :%i, val2:%i ",
446 // draw_context->previous->over->x,
447 // draw_context->previous->over->y,
448 // draw_context->drawinfo.over.x - draw_context->previous->over->x,
449 // draw_context->previous->under->y-draw_context->previous->over->y,
450 // draw_context->drawinfo.over.x,
451 // draw_context->previous->over->x);
452 gdk_draw_rectangle(draw_context
->drawable
, draw_context
->gc
,
454 draw_context
->drawinfo
.start
.x
,
455 draw_context
->drawinfo
.y
.over
,
456 draw_context
->drawinfo
.end
.x
- draw_context
->drawinfo
.start
.x
,
457 draw_context
->drawinfo
.y
.under
- draw_context
->drawinfo
.y
.over
);
This page took 0.041112 seconds and 4 git commands to generate.