1 /******************************************************************************
4 * This file contains methods responsible for drawing a generic type of data
5 * in a drawable. Doing this generically will permit user defined drawing
6 * behavior in a later time.
8 * This file provides an API which is meant to be reusable for all viewers that
9 * need to show information in line, icon, text, background or point form in
10 * a drawable area having time for x axis. The y axis, in the control flow
11 * viewer case, is corresponding to the different processes, but it can be
12 * reused integrally for cpu, and eventually locks, buffers, network
13 * interfaces... What will differ between the viewers is the precise
14 * information which interests us. We may think that the most useful
15 * information for control flow are some specific events, like schedule
16 * change, and processes'states. It may differ for a cpu viewer : the
17 * interesting information could be more the execution mode of each cpu.
18 * This API in meant to make viewer's writers life easier : it will become
19 * a simple choice of icons and line types for the precise information
20 * the viewer has to provide (agremented with keeping supplementary records
21 * and modifying slightly the DrawContext to suit the needs.)
23 * We keep each data type in attributes, keys to specific information
24 * being formed from the GQuark corresponding to the information received.
25 * (facilities / facility_name / events / eventname.)
26 * (cpus/cpu_name, process_states/ps_name,
27 * execution_modes/em_name, execution_submodes/es_name).
28 * The goal is then to provide a generic way to print information on the
29 * screen for all this different information.
31 * Information can be printed as
33 * - text (text + color + size + position (over or under line)
34 * - icon (icon filename, corresponding to a loaded icon, accessible through
35 * a GQuark. Icons are loaded statically at the guiControlFlow level during
36 * module initialization and can be added on the fly if not present in the
37 * GQuark.) The habitual place for xpm icons is in
38 * ${prefix}/share/LinuxTraceToolkit.) + position (over or under line)
39 * - line (color, width, style)
40 * - Arc (big points) (color, size)
41 * - background color (color)
43 * An item is a leaf of the attributes tree. It is, in that case, including
44 * all kind of events categories we can have. It then associates each category
45 * with one or more actions (drawing something) or nothing.
47 * Each item has an array of hooks (hook list). Each hook represents an
48 * operation to perform. We seek the array each time we want to
49 * draw an item. We execute each operation in order. An operation type
50 * is associated with each hook to permit user listing and modification
51 * of these operations. The operation type is also used to find the
52 * corresponding priority for the sorting. Operation type and priorities
53 * are enum and a static int table.
55 * The array has to be sorted by priority each time we add a task in it.
56 * A priority is associated with each operation type. It permits
57 * to perform background color selection before line or text drawing. We also
58 * draw lines before text, so the text appears over the lines.
60 * Executing all the arrays of operations for a specific event (which
61 * implies information for state, event, cpu, execution mode and submode)
62 * has to be done in a same DrawContext. The goal there is to keep the offset
63 * of the text and icons over and under the middle line, so a specific
64 * event could be printed as ( R Si 0 for running, scheduled in, cpu 0 ),
65 * text being easy to replace with icons. The DrawContext is passed as
66 * call_data for the operation hooks.
68 * We use the lttv global attributes to keep track of the loaded icons.
69 * If we need an icon, we look for it in the icons / icon name pathname.
70 * If found, we use the pointer to it. If not, we load the pixmap in
71 * memory and set the pointer to the GdkPixmap in the attributes. The
72 * structure pointed to contains the pixmap and the mask bitmap.
74 * Author : Mathieu Desnoyers, October 2003
80 #include <lttv/hook.h>
81 #include <lttv/attribute.h>
82 #include <lttv/iattribute.h>
85 #include <lttv/processTrace.h>
86 #include <lttv/state.h>
88 #include "Draw_Item.h"
91 #define MAX_PATH_LEN 256
93 /* The DrawContext keeps information about the current drawing position and
94 * the previous one, so we can use both to draw lines.
96 * over : position for drawing over the middle line.
97 * middle : middle line position.
98 * under : position for drawing under the middle line.
100 * the modify_* are used to take into account that we should go forward
101 * when we draw a text, an arc or an icon, while it's unneeded when we
102 * draw a line or background.
105 struct _DrawContext
{
106 GdkDrawable
*drawable
;
119 ItemInfo
*modify_over
;
120 ItemInfo
*modify_middle
;
121 ItemInfo
*modify_under
;
124 /* LttvExecutionState is accessible through the LttvTracefileState. Is has
125 * a pointer to the LttvProcessState which points to the top of stack
126 * execution state : LttvExecutionState *state.
128 * LttvExecutionState contains (useful here):
129 * LttvExecutionMode t,
130 * LttvExecutionSubmode n,
131 * LttvProcessStatus s
134 * LttvTraceState will be used in the case we need the string of the
135 * different processes, eventtype_names, syscall_names, trap_names, irq_names.
137 * LttvTracefileState also gives the cpu_name and, as it herits from
138 * LttvTracefileContext, it gives the LttEvent structure, which is needed
139 * to get facility name and event name.
144 LttvTracefileState
*tfs
;
148 * Structure used to keep information about icons.
157 * The Item element is only used so the DrawOperation is modifiable by users.
158 * During drawing, only the Hook is needed.
160 struct _DrawOperation
{
166 * We define here each items that can be drawn, together with their
167 * associated priority. Many item types can have the same priority,
168 * it's only used for quicksorting the operations when we add a new one
169 * to the array of operations to perform. Lower priorities are executed
170 * first. So, for example, we may want to give background color a value
171 * of 10 while a line would have 20, so the background color, which
172 * is in fact a rectangle, does not hide the line.
175 static int Items_Priorities
[] = {
180 10 /* ITEM_BACKGROUND */
184 * Here are the different structures describing each item type that can be
185 * drawn. They contain the information necessary to draw the item : not the
186 * position (this is provided by the DrawContext), but the text, icon name,
187 * line width, color; all the properties of the specific items.
190 struct _PropertiesText
{
191 GdkColor
*foreground
;
192 GdkColor
*background
;
199 struct _PropertiesIcon
{
206 struct _PropertiesLine
{
213 struct _PropertiesArc
{
215 gint size
; /* We force circle by width = height */
220 struct _PropertiesBG
{
225 /* Drawing hook functions */
226 gboolean
draw_text( void *hook_data
, void *call_data
)
228 PropertiesText
*Properties
= (PropertiesText
*)hook_data
;
229 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
231 PangoContext
*context
;
233 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
235 PangoRectangle ink_rect
;
237 gdk_gc_set_foreground(Draw_Context
->gc
, Properties
->foreground
);
238 gdk_gc_set_background(Draw_Context
->gc
, Properties
->background
);
240 layout
= gtk_widget_create_pango_layout(GTK_WIDGET(Draw_Context
->drawable
), NULL
);
241 context
= pango_layout_get_context(layout
);
242 FontDesc
= pango_context_get_font_description(context
);
243 Font_Size
= pango_font_description_get_size(FontDesc
);
244 pango_font_description_set_size(FontDesc
, Properties
->size
*PANGO_SCALE
);
247 pango_layout_set_text(layout
, Properties
->Text
, -1);
248 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
249 switch(Properties
->position
) {
251 gdk_draw_layout(Draw_Context
->drawable
, Draw_Context
->gc
,
252 Draw_Context
->Current
->modify_over
->x
,
253 Draw_Context
->Current
->modify_over
->y
,
255 Draw_Context
->Current
->modify_over
->x
+= ink_rect
.width
;
259 gdk_draw_layout(Draw_Context
->drawable
, Draw_Context
->gc
,
260 Draw_Context
->Current
->modify_middle
->x
,
261 Draw_Context
->Current
->modify_middle
->y
,
263 Draw_Context
->Current
->modify_middle
->x
+= ink_rect
.width
;
266 gdk_draw_layout(Draw_Context
->drawable
, Draw_Context
->gc
,
267 Draw_Context
->Current
->modify_under
->x
,
268 Draw_Context
->Current
->modify_under
->y
,
270 Draw_Context
->Current
->modify_under
->x
+= ink_rect
.width
;
275 pango_font_description_set_size(FontDesc
, Font_Size
);
282 /* To speed up the process, search in already loaded icons list first. Only
283 * load it if not present.
285 gboolean
draw_icon( void *hook_data
, void *call_data
)
287 PropertiesIcon
*Properties
= (PropertiesIcon
*)hook_data
;
288 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
290 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
291 LttvAttributeValue value
;
292 gchar icon_name
[MAX_PATH_LEN
] = "icons/";
293 IconStruct
*icon_info
;
295 strcat(icon_name
, Properties
->icon_name
);
297 g_assert(lttv_iattribute_find_by_path(attributes
, icon_name
,
298 LTTV_POINTER
, &value
));
299 if(*(value
.v_pointer
) == NULL
)
301 *(value
.v_pointer
) = icon_info
= g_new(IconStruct
,1);
303 icon_info
->pixmap
= gdk_pixmap_create_from_xpm(Draw_Context
->drawable
,
304 &icon_info
->mask
, NULL
, Properties
->icon_name
);
308 icon_info
= *(value
.v_pointer
);
311 gdk_gc_set_clip_mask(Draw_Context
->gc
, icon_info
->mask
);
313 switch(Properties
->position
) {
315 gdk_gc_set_clip_origin(
317 Draw_Context
->Current
->modify_over
->x
,
318 Draw_Context
->Current
->modify_over
->y
);
319 gdk_draw_drawable(Draw_Context
->drawable
,
323 Draw_Context
->Current
->modify_over
->x
,
324 Draw_Context
->Current
->modify_over
->y
,
325 Properties
->width
, Properties
->height
);
327 Draw_Context
->Current
->modify_over
->x
+= Properties
->width
;
331 gdk_gc_set_clip_origin(
333 Draw_Context
->Current
->modify_middle
->x
,
334 Draw_Context
->Current
->modify_middle
->y
);
335 gdk_draw_drawable(Draw_Context
->drawable
,
339 Draw_Context
->Current
->modify_middle
->x
,
340 Draw_Context
->Current
->modify_middle
->y
,
341 Properties
->width
, Properties
->height
);
343 Draw_Context
->Current
->modify_middle
->x
+= Properties
->width
;
346 gdk_gc_set_clip_origin(
348 Draw_Context
->Current
->modify_under
->x
,
349 Draw_Context
->Current
->modify_under
->y
);
350 gdk_draw_drawable(Draw_Context
->drawable
,
354 Draw_Context
->Current
->modify_under
->x
,
355 Draw_Context
->Current
->modify_under
->y
,
356 Properties
->width
, Properties
->height
);
358 Draw_Context
->Current
->modify_under
->x
+= Properties
->width
;
362 gdk_gc_set_clip_origin(Draw_Context
->gc
, 0, 0);
363 gdk_gc_set_clip_mask(Draw_Context
->gc
, NULL
);
368 gboolean
draw_line( void *hook_data
, void *call_data
)
370 PropertiesLine
*Properties
= (PropertiesLine
*)hook_data
;
371 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
373 gdk_gc_set_foreground(Draw_Context
->gc
, Properties
->color
);
374 gdk_gc_set_line_attributes( Draw_Context
->gc
,
375 Properties
->line_width
,
380 switch(Properties
->position
) {
383 NULL
, Draw_Context
->drawable
,
384 Draw_Context
->Previous
->over
->x
,
385 Draw_Context
->Previous
->over
->y
,
386 Draw_Context
->Current
->over
->x
,
387 Draw_Context
->Current
->over
->y
,
392 NULL
, Draw_Context
->drawable
,
393 Draw_Context
->Previous
->middle
->x
,
394 Draw_Context
->Previous
->middle
->y
,
395 Draw_Context
->Current
->middle
->x
,
396 Draw_Context
->Current
->middle
->y
,
401 NULL
, Draw_Context
->drawable
,
402 Draw_Context
->Previous
->under
->x
,
403 Draw_Context
->Previous
->under
->y
,
404 Draw_Context
->Current
->under
->x
,
405 Draw_Context
->Current
->under
->y
,
414 gboolean
draw_arc( void *hook_data
, void *call_data
)
416 PropertiesArc
*Properties
= (PropertiesArc
*)hook_data
;
417 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
419 gdk_gc_set_foreground(Draw_Context
->gc
, Properties
->color
);
421 switch(Properties
->position
) {
423 gdk_draw_arc(Draw_Context
->drawable
, Draw_Context
->gc
,
425 Draw_Context
->Current
->modify_over
->x
,
426 Draw_Context
->Current
->modify_over
->y
,
427 Properties
->size
, Properties
->size
, 0, 360*64);
428 Draw_Context
->Current
->modify_over
->x
+= Properties
->size
;
432 gdk_draw_arc(Draw_Context
->drawable
, Draw_Context
->gc
,
434 Draw_Context
->Current
->modify_middle
->x
,
435 Draw_Context
->Current
->modify_middle
->y
,
436 Properties
->size
, Properties
->size
, 0, 360*64);
437 Draw_Context
->Current
->modify_middle
->x
+= Properties
->size
;
441 gdk_draw_arc(Draw_Context
->drawable
, Draw_Context
->gc
,
443 Draw_Context
->Current
->modify_under
->x
,
444 Draw_Context
->Current
->modify_under
->y
,
445 Properties
->size
, Properties
->size
, 0, 360*64);
446 Draw_Context
->Current
->modify_under
->x
+= Properties
->size
;
455 gboolean
draw_bg( void *hook_data
, void *call_data
)
457 PropertiesBG
*Properties
= (PropertiesBG
*)hook_data
;
458 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
460 gdk_gc_set_foreground(Draw_Context
->gc
, Properties
->color
);
463 gdk_draw_rectangle(Draw_Context
->drawable
, Draw_Context
->gc
,
465 Draw_Context
->Previous
->over
->x
,
466 Draw_Context
->Previous
->over
->y
,
467 Draw_Context
->Current
->over
->x
- Draw_Context
->Previous
->over
->x
,
468 Draw_Context
->Previous
->under
->y
);
This page took 0.058552 seconds and 4 git commands to generate.