b2b8fb977872b40ff8495a8da195645f4bb12a84
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/processTrace.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
*FontDesc
;// = pango_font_description_new();
124 PangoRectangle ink_rect
;
126 layout
= Draw_Context
->pango_layout
;
128 context
= pango_layout_get_context(layout
);
129 FontDesc
= pango_context_get_font_description(context
);
131 pango_font_description_set_size(FontDesc
, 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
);
136 switch(Properties
->position
) {
138 gdk_draw_layout_with_colors(Draw_Context
->drawable
,
140 Draw_Context
->current
->modify_over
->x
,
141 Draw_Context
->current
->modify_over
->y
,
142 layout
, Properties
->foreground
, Properties
->background
);
143 Draw_Context
->current
->modify_over
->x
+= ink_rect
.width
;
147 gdk_draw_layout_with_colors(Draw_Context
->drawable
,
149 Draw_Context
->current
->modify_middle
->x
,
150 Draw_Context
->current
->modify_middle
->y
,
151 layout
, Properties
->foreground
, Properties
->background
);
152 Draw_Context
->current
->modify_middle
->x
+= ink_rect
.width
;
155 gdk_draw_layout_with_colors(Draw_Context
->drawable
,
157 Draw_Context
->current
->modify_under
->x
,
158 Draw_Context
->current
->modify_under
->y
,
159 layout
, Properties
->foreground
, Properties
->background
);
160 Draw_Context
->current
->modify_under
->x
+= ink_rect
.width
;
168 /* To speed up the process, search in already loaded icons list first. Only
169 * load it if not present.
171 gboolean
draw_icon( void *hook_data
, void *call_data
)
173 PropertiesIcon
*Properties
= (PropertiesIcon
*)hook_data
;
174 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
176 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
177 LttvAttributeValue value
;
178 gchar icon_name
[MAX_PATH_LEN
] = "icons/";
179 IconStruct
*icon_info
;
181 strcat(icon_name
, Properties
->icon_name
);
183 g_assert(lttv_iattribute_find_by_path(attributes
, icon_name
,
184 LTTV_POINTER
, &value
));
185 if(*(value
.v_pointer
) == NULL
)
187 *(value
.v_pointer
) = icon_info
= g_new(IconStruct
,1);
189 icon_info
->pixmap
= gdk_pixmap_create_from_xpm(Draw_Context
->drawable
,
190 &icon_info
->mask
, NULL
, Properties
->icon_name
);
194 icon_info
= *(value
.v_pointer
);
197 gdk_gc_set_clip_mask(Draw_Context
->gc
, icon_info
->mask
);
199 switch(Properties
->position
) {
201 gdk_gc_set_clip_origin(
203 Draw_Context
->current
->modify_over
->x
,
204 Draw_Context
->current
->modify_over
->y
);
205 gdk_draw_drawable(Draw_Context
->drawable
,
209 Draw_Context
->current
->modify_over
->x
,
210 Draw_Context
->current
->modify_over
->y
,
211 Properties
->width
, Properties
->height
);
213 Draw_Context
->current
->modify_over
->x
+= Properties
->width
;
217 gdk_gc_set_clip_origin(
219 Draw_Context
->current
->modify_middle
->x
,
220 Draw_Context
->current
->modify_middle
->y
);
221 gdk_draw_drawable(Draw_Context
->drawable
,
225 Draw_Context
->current
->modify_middle
->x
,
226 Draw_Context
->current
->modify_middle
->y
,
227 Properties
->width
, Properties
->height
);
229 Draw_Context
->current
->modify_middle
->x
+= Properties
->width
;
232 gdk_gc_set_clip_origin(
234 Draw_Context
->current
->modify_under
->x
,
235 Draw_Context
->current
->modify_under
->y
);
236 gdk_draw_drawable(Draw_Context
->drawable
,
240 Draw_Context
->current
->modify_under
->x
,
241 Draw_Context
->current
->modify_under
->y
,
242 Properties
->width
, Properties
->height
);
244 Draw_Context
->current
->modify_under
->x
+= Properties
->width
;
248 gdk_gc_set_clip_origin(Draw_Context
->gc
, 0, 0);
249 gdk_gc_set_clip_mask(Draw_Context
->gc
, NULL
);
254 gboolean
draw_line( void *hook_data
, void *call_data
)
256 PropertiesLine
*Properties
= (PropertiesLine
*)hook_data
;
257 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
258 //GdkGC *gc = gdk_gc_new(Draw_Context->drawable);
260 //gdk_gc_set_foreground(Draw_Context->gc, Properties->color);
261 gdk_gc_set_rgb_fg_color(Draw_Context
->gc
, Properties
->color
);
262 //gdk_gc_set_foreground(gc, Properties->color);
263 gdk_gc_set_line_attributes( Draw_Context
->gc
,
264 Properties
->line_width
,
269 switch(Properties
->position
) {
272 NULL
, Draw_Context
->drawable
,
273 Draw_Context
->previous
->over
->x
,
274 Draw_Context
->previous
->over
->y
,
275 Draw_Context
->current
->over
->x
,
276 Draw_Context
->current
->over
->y
,
281 NULL
, Draw_Context
->drawable
,
282 Draw_Context
->previous
->middle
->x
,
283 Draw_Context
->previous
->middle
->y
,
284 Draw_Context
->current
->middle
->x
,
285 Draw_Context
->current
->middle
->y
,
290 NULL
, Draw_Context
->drawable
,
291 Draw_Context
->previous
->under
->x
,
292 Draw_Context
->previous
->under
->y
,
293 Draw_Context
->current
->under
->x
,
294 Draw_Context
->current
->under
->y
,
305 gboolean
draw_arc( void *hook_data
, void *call_data
)
307 PropertiesArc
*Properties
= (PropertiesArc
*)hook_data
;
308 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
310 //gdk_gc_set_foreground(Draw_Context->gc, Properties->color);
311 gdk_gc_set_rgb_fg_color(Draw_Context
->gc
, Properties
->color
);
313 switch(Properties
->position
) {
315 gdk_draw_arc(Draw_Context
->drawable
, Draw_Context
->gc
,
317 Draw_Context
->current
->modify_over
->x
,
318 Draw_Context
->current
->modify_over
->y
,
319 Properties
->size
, Properties
->size
, 0, 360*64);
320 Draw_Context
->current
->modify_over
->x
+= Properties
->size
;
323 gdk_draw_arc(Draw_Context
->drawable
, Draw_Context
->gc
,
325 Draw_Context
->current
->modify_middle
->x
,
326 Draw_Context
->current
->modify_middle
->y
,
327 Properties
->size
, Properties
->size
, 0, 360*64);
328 Draw_Context
->current
->modify_middle
->x
+= Properties
->size
;
332 gdk_draw_arc(Draw_Context
->drawable
, Draw_Context
->gc
,
334 Draw_Context
->current
->modify_under
->x
,
335 Draw_Context
->current
->modify_under
->y
,
336 Properties
->size
, Properties
->size
, 0, 360*64);
337 Draw_Context
->current
->modify_under
->x
+= Properties
->size
;
346 gboolean
draw_bg( void *hook_data
, void *call_data
)
348 PropertiesBG
*Properties
= (PropertiesBG
*)hook_data
;
349 DrawContext
*Draw_Context
= (DrawContext
*)call_data
;
351 //gdk_gc_set_foreground(Draw_Context->gc, Properties->color);
352 gdk_gc_set_rgb_fg_color(Draw_Context
->gc
, Properties
->color
);
355 gdk_draw_rectangle(Draw_Context
->drawable
, Draw_Context
->gc
,
357 Draw_Context
->previous
->over
->x
,
358 Draw_Context
->previous
->over
->y
,
359 Draw_Context
->current
->over
->x
- Draw_Context
->previous
->over
->x
,
360 Draw_Context
->previous
->under
->y
);
This page took 0.037844 seconds and 3 git commands to generate.